Skip to content

Commit 004d2c0

Browse files
authored
Use partiql_ast::ast::AstTypeMap for LocationMap (#394)
Addressing the comment in PR #389, this PR re-uses the `AstTypeMap` for `LocationMap` which removes a dependency to `HashMap` as `AstTypeMap` uses `IndexMap`.
1 parent babd7ac commit 004d2c0

File tree

6 files changed

+11
-10
lines changed

6 files changed

+11
-10
lines changed

partiql-ast/Cargo.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ path = "src/lib.rs"
2020
bench = false
2121

2222
[dependencies]
23-
indexmap = "1.9"
23+
indexmap = { version = "1.9", default-features = false }
2424
rust_decimal = { version = "1.25.0", default-features = false, features = ["std"] }
2525
serde = { version = "1.*", features = ["derive"], optional = true }
2626

@@ -31,7 +31,8 @@ default = []
3131
serde = [
3232
"dep:serde",
3333
"rust_decimal/serde-with-str",
34-
"rust_decimal/serde"
34+
"rust_decimal/serde",
35+
"indexmap/serde",
3536
]
3637

3738
[dependencies.partiql-ast-macros]

partiql-parser/src/lib.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,6 @@ use parse::{parse_partiql, AstData, ErrorData};
3030
use partiql_ast::ast;
3131
use partiql_source_map::line_offset_tracker::LineOffsetTracker;
3232
use partiql_source_map::location::BytePosition;
33-
34-
use partiql_ast::ast::NodeId;
3533
use partiql_source_map::metadata::LocationMap;
3634
#[cfg(feature = "serde")]
3735
use serde::{Deserialize, Serialize};
@@ -82,7 +80,7 @@ pub struct Parsed<'input> {
8280
pub text: &'input str,
8381
pub offsets: LineOffsetTracker,
8482
pub ast: Box<ast::Expr>,
85-
pub locations: LocationMap<NodeId>,
83+
pub locations: LocationMap,
8684
}
8785

8886
/// The output of errors when parsing PartiQL statement strings: an errors and auxiliary data.

partiql-parser/src/parse/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ use crate::parse::parser_state::{IdGenerator, ParserState};
1212
use crate::preprocessor::{PreprocessingPartiqlLexer, BUILT_INS};
1313
use lalrpop_util as lpop;
1414
use partiql_ast::ast;
15-
use partiql_ast::ast::NodeId;
1615
use partiql_source_map::line_offset_tracker::LineOffsetTracker;
1716
use partiql_source_map::location::{ByteOffset, BytePosition, ToLocated};
1817
use partiql_source_map::metadata::LocationMap;
@@ -41,7 +40,7 @@ type LalrpopErrorRecovery<'input> =
4140
#[derive(Debug, Clone)]
4241
pub(crate) struct AstData {
4342
pub ast: Box<ast::Expr>,
44-
pub locations: LocationMap<NodeId>,
43+
pub locations: LocationMap,
4544
pub offsets: LineOffsetTracker,
4645
}
4746

@@ -535,6 +534,7 @@ mod tests {
535534

536535
mod set_ops {
537536
use super::*;
537+
use partiql_ast::ast::NodeId;
538538

539539
#[derive(Default)]
540540
pub(crate) struct NullIdGenerator {}

partiql-parser/src/parse/parser_state.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ pub(crate) struct ParserState<'input, Id: IdGenerator> {
5353
/// Generator for 'fresh' [`NodeId`]s
5454
pub id_gen: Id,
5555
/// Maps AST [`NodeId`]s to the location in the source from which each was derived.
56-
pub locations: LocationMap<NodeId>,
56+
pub locations: LocationMap,
5757
/// Any errors accumulated during parse.
5858
pub errors: ParseErrors<'input>,
5959

partiql-source-map/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ edition.workspace = true
1919
bench = false
2020

2121
[dependencies]
22+
partiql-ast = { path = "../partiql-ast", version = "0.5.*" }
23+
2224
smallvec = { version = "1.*" }
2325
serde = { version = "1.*", features = ["derive"], optional = true }
2426

partiql-source-map/src/metadata.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use crate::location::{BytePosition, Location};
2-
use std::collections::HashMap;
2+
use partiql_ast::ast::AstTypeMap;
33

44
/// Map of `T` to a [`Location<BytePosition>>`]
5-
pub type LocationMap<T> = HashMap<T, Location<BytePosition>>;
5+
pub type LocationMap = AstTypeMap<Location<BytePosition>>;

0 commit comments

Comments
 (0)