From 61dcf3915f0528289de61bfa4ea77eaf3e7d51df Mon Sep 17 00:00:00 2001 From: Maximilian Roos <5635139+max-sixty@users.noreply.github.com> Date: Wed, 5 Jun 2024 00:25:26 -0700 Subject: [PATCH] refactor: Move `Token` next to `Expr` (#4521) --- Cargo.toml | 1 + prqlc/prqlc-ast/Cargo.toml | 2 +- prqlc/prqlc-ast/src/expr.rs | 10 +- prqlc/prqlc-ast/src/expr/literal.rs | 81 ------ prqlc/prqlc-ast/src/lib.rs | 2 + prqlc/prqlc-ast/src/token.rs | 232 ++++++++++++++++++ prqlc/prqlc-parser/src/err/parse_error.rs | 3 +- prqlc/prqlc-parser/src/expr.rs | 2 +- prqlc/prqlc-parser/src/interpolation.rs | 2 +- prqlc/prqlc-parser/src/lexer.rs | 166 +------------ prqlc/prqlc-parser/src/lib.rs | 26 +- prqlc/prqlc-parser/src/stmt.rs | 13 +- prqlc/prqlc-parser/src/types.rs | 1 - prqlc/prqlc/Cargo.toml | 2 +- prqlc/prqlc/src/codegen/ast.rs | 1 + prqlc/prqlc/src/ir/pl/expr.rs | 3 +- prqlc/prqlc/src/semantic/reporting.rs | 2 +- .../tests/integration/ast_code_matches.rs | 19 +- 18 files changed, 283 insertions(+), 285 deletions(-) delete mode 100644 prqlc/prqlc-ast/src/expr/literal.rs create mode 100644 prqlc/prqlc-ast/src/token.rs diff --git a/Cargo.toml b/Cargo.toml index 6b80736a7d2b..0e7f4698b088 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -48,6 +48,7 @@ consolidate-commits = true [workspace.dependencies] anyhow = "1.0.86" +enum-as-inner = "0.6.0" insta = {version = "1.39.0", features = ["colors", "glob", "yaml"]} insta-cmd = "0.6.0" itertools = "0.12.0" diff --git a/prqlc/prqlc-ast/Cargo.toml b/prqlc/prqlc-ast/Cargo.toml index 2d325ef93fe0..443b513f8431 100644 --- a/prqlc/prqlc-ast/Cargo.toml +++ b/prqlc/prqlc-ast/Cargo.toml @@ -12,7 +12,7 @@ version.workspace = true doctest = false [dependencies] -enum-as-inner = "0.6.0" +enum-as-inner = {workspace = true} semver = {version = "1.0.23", features = ["serde"]} serde = {workspace = true} serde_yaml = {workspace = true, optional = true} diff --git a/prqlc/prqlc-ast/src/expr.rs b/prqlc/prqlc-ast/src/expr.rs index 3e22ceb82814..7c21e8c60f14 100644 --- a/prqlc/prqlc-ast/src/expr.rs +++ b/prqlc/prqlc-ast/src/expr.rs @@ -1,6 +1,5 @@ pub mod generic; mod ident; -mod literal; mod ops; use std::collections::HashMap; @@ -9,8 +8,9 @@ use enum_as_inner::EnumAsInner; use serde::{Deserialize, Serialize}; pub use self::ident::Ident; -pub use self::literal::{Literal, ValueAndUnit}; pub use self::ops::{BinOp, UnOp}; +pub use self::token::{Literal, ValueAndUnit}; +use super::token; use crate::span::Span; use crate::Ty; @@ -51,7 +51,7 @@ pub enum ExprKind { feature = "serde_yaml", serde(with = "serde_yaml::with::singleton_map") )] - Literal(Literal), + Literal(token::Literal), Pipeline(Pipeline), Tuple(Vec), @@ -153,8 +153,8 @@ pub type Range = generic::Range>; pub type InterpolateItem = generic::InterpolateItem; pub type SwitchCase = generic::SwitchCase>; -impl From for ExprKind { - fn from(value: Literal) -> Self { +impl From for ExprKind { + fn from(value: token::Literal) -> Self { ExprKind::Literal(value) } } diff --git a/prqlc/prqlc-ast/src/expr/literal.rs b/prqlc/prqlc-ast/src/expr/literal.rs deleted file mode 100644 index ba27d6ac1e4a..000000000000 --- a/prqlc/prqlc-ast/src/expr/literal.rs +++ /dev/null @@ -1,81 +0,0 @@ -use enum_as_inner::EnumAsInner; -use serde::{Deserialize, Serialize}; - -#[derive(Debug, EnumAsInner, PartialEq, Clone, Serialize, Deserialize, strum::AsRefStr)] -pub enum Literal { - Null, - Integer(i64), - Float(f64), - Boolean(bool), - String(String), - Date(String), - Time(String), - Timestamp(String), - ValueAndUnit(ValueAndUnit), -} - -// Compound units, such as "2 days 3 hours" can be represented as `2days + 3hours` -#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] -pub struct ValueAndUnit { - pub n: i64, // Do any DBs use floats or decimals for this? - pub unit: String, // Could be an enum IntervalType, -} - -impl std::fmt::Display for Literal { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - match self { - Literal::Null => write!(f, "null")?, - Literal::Integer(i) => write!(f, "{i}")?, - Literal::Float(i) => write!(f, "{i}")?, - - Literal::String(s) => { - quote_string(s, f)?; - } - - Literal::Boolean(b) => { - f.write_str(if *b { "true" } else { "false" })?; - } - - Literal::Date(inner) | Literal::Time(inner) | Literal::Timestamp(inner) => { - write!(f, "@{inner}")?; - } - - Literal::ValueAndUnit(i) => { - write!(f, "{}{}", i.n, i.unit)?; - } - } - Ok(()) - } -} - -fn quote_string(s: &str, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - let s = escape_all_except_quotes(s); - - if !s.contains('"') { - return write!(f, r#""{s}""#); - } - - if !s.contains('\'') { - return write!(f, "'{s}'"); - } - - // when string contains both single and double quotes - // find minimum number of double quotes - let mut quotes = "\"\"".to_string(); - while s.contains("es) { - quotes += "\""; - } - write!(f, "{quotes}{s}{quotes}") -} - -fn escape_all_except_quotes(s: &str) -> String { - let mut result = String::new(); - for ch in s.chars() { - if ch == '"' || ch == '\'' { - result.push(ch); - } else { - result.extend(ch.escape_default()); - } - } - result -} diff --git a/prqlc/prqlc-ast/src/lib.rs b/prqlc/prqlc-ast/src/lib.rs index 4d2a03c58200..ec8101ccf097 100644 --- a/prqlc/prqlc-ast/src/lib.rs +++ b/prqlc/prqlc-ast/src/lib.rs @@ -1,9 +1,11 @@ pub mod expr; pub mod span; pub mod stmt; +pub mod token; mod types; pub use expr::*; pub use span::*; pub use stmt::*; +pub use token::*; pub use types::*; diff --git a/prqlc/prqlc-ast/src/token.rs b/prqlc/prqlc-ast/src/token.rs new file mode 100644 index 000000000000..06ae543f3b41 --- /dev/null +++ b/prqlc/prqlc-ast/src/token.rs @@ -0,0 +1,232 @@ +use enum_as_inner::EnumAsInner; +use serde::{Deserialize, Serialize}; + +#[derive(Clone, PartialEq, Serialize, Deserialize, Eq)] +pub struct Token { + pub kind: TokenKind, + pub span: std::ops::Range, +} + +#[derive(Clone, PartialEq, Debug, Serialize, Deserialize)] +pub enum TokenKind { + NewLine, + + Ident(String), + Keyword(String), + #[cfg_attr( + feature = "serde_yaml", + serde(with = "serde_yaml::with::singleton_map") + )] + Literal(Literal), + Param(String), + + Range { + /// Whether the left side of the range is bound by the previous token + /// (but it's not contained in this token) + bind_left: bool, + bind_right: bool, + }, + Interpolation(char, String), + + /// single-char control tokens + Control(char), + + ArrowThin, // -> + ArrowFat, // => + Eq, // == + Ne, // != + Gte, // >= + Lte, // <= + RegexSearch, // ~= + And, // && + Or, // || + Coalesce, // ?? + DivInt, // // + // Pow, // ** + Annotate, // @ + + // Aesthetics only + Comment(String), + DocComment(String), + /// Vec containing comments between the newline and the line wrap + // Currently we include the comments with the LineWrap token. This isn't + // ideal, but I'm not sure of an easy way of having them be separate. + // - The line wrap span technically includes the comments — on a newline, + // we need to look ahead to _after_ the comments to see if there's a + // line wrap, and exclude the newline if there is. + // - We can only pass one token back + // + // Alternatives: + // - Post-process the stream, removing the newline prior to a line wrap. + // But requires a whole extra pass. + // - Change the functionality. But it's very nice to be able to comment + // something out and have line-wraps still work. + LineWrap(Vec), +} + +#[derive(Debug, EnumAsInner, PartialEq, Clone, Serialize, Deserialize, strum::AsRefStr)] +pub enum Literal { + Null, + Integer(i64), + Float(f64), + Boolean(bool), + String(String), + Date(String), + Time(String), + Timestamp(String), + ValueAndUnit(ValueAndUnit), +} + +impl TokenKind { + pub fn range(bind_left: bool, bind_right: bool) -> Self { + TokenKind::Range { + bind_left, + bind_right, + } + } +} +// Compound units, such as "2 days 3 hours" can be represented as `2days + 3hours` +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +pub struct ValueAndUnit { + pub n: i64, // Do any DBs use floats or decimals for this? + pub unit: String, // Could be an enum IntervalType, +} + +impl std::fmt::Display for Literal { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + match self { + Literal::Null => write!(f, "null")?, + Literal::Integer(i) => write!(f, "{i}")?, + Literal::Float(i) => write!(f, "{i}")?, + + Literal::String(s) => { + quote_string(s, f)?; + } + + Literal::Boolean(b) => { + f.write_str(if *b { "true" } else { "false" })?; + } + + Literal::Date(inner) | Literal::Time(inner) | Literal::Timestamp(inner) => { + write!(f, "@{inner}")?; + } + + Literal::ValueAndUnit(i) => { + write!(f, "{}{}", i.n, i.unit)?; + } + } + Ok(()) + } +} + +fn quote_string(s: &str, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + let s = escape_all_except_quotes(s); + + if !s.contains('"') { + return write!(f, r#""{s}""#); + } + + if !s.contains('\'') { + return write!(f, "'{s}'"); + } + + // when string contains both single and double quotes + // find minimum number of double quotes + let mut quotes = "\"\"".to_string(); + while s.contains("es) { + quotes += "\""; + } + write!(f, "{quotes}{s}{quotes}") +} + +fn escape_all_except_quotes(s: &str) -> String { + let mut result = String::new(); + for ch in s.chars() { + if ch == '"' || ch == '\'' { + result.push(ch); + } else { + result.extend(ch.escape_default()); + } + } + result +} + +// This is here because Literal::Float(f64) does not implement Hash, so we cannot simply derive it. +// There are reasons for that, but chumsky::Error needs Hash for the TokenKind, so it can deduplicate +// tokens in error. +// So this hack could lead to duplicated tokens in error messages. Oh no. +#[allow(clippy::derived_hash_with_manual_eq)] +impl std::hash::Hash for TokenKind { + fn hash(&self, state: &mut H) { + core::mem::discriminant(self).hash(state); + } +} + +impl std::cmp::Eq for TokenKind {} + +impl std::fmt::Display for TokenKind { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + match self { + TokenKind::NewLine => write!(f, "new line"), + TokenKind::Ident(s) => { + if s.is_empty() { + // FYI this shows up in errors + write!(f, "an identifier") + } else { + write!(f, "{s}") + } + } + TokenKind::Keyword(s) => write!(f, "keyword {s}"), + TokenKind::Literal(lit) => write!(f, "{}", lit), + TokenKind::Control(c) => write!(f, "{c}"), + + TokenKind::ArrowThin => f.write_str("->"), + TokenKind::ArrowFat => f.write_str("=>"), + TokenKind::Eq => f.write_str("=="), + TokenKind::Ne => f.write_str("!="), + TokenKind::Gte => f.write_str(">="), + TokenKind::Lte => f.write_str("<="), + TokenKind::RegexSearch => f.write_str("~="), + TokenKind::And => f.write_str("&&"), + TokenKind::Or => f.write_str("||"), + TokenKind::Coalesce => f.write_str("??"), + TokenKind::DivInt => f.write_str("//"), + // TokenKind::Pow => f.write_str("**"), + TokenKind::Annotate => f.write_str("@{"), + + TokenKind::Param(id) => write!(f, "${id}"), + + TokenKind::Range { + bind_left, + bind_right, + } => write!( + f, + "'{}..{}'", + if *bind_left { "" } else { " " }, + if *bind_right { "" } else { " " } + ), + TokenKind::Interpolation(c, s) => { + write!(f, "{c}\"{}\"", s) + } + TokenKind::Comment(s) => { + writeln!(f, "#{}", s) + } + TokenKind::DocComment(s) => { + writeln!(f, "#!{}", s) + } + TokenKind::LineWrap(comments) => { + write!(f, "\n\\ ")?; + for comment in comments { + write!(f, "{}", comment)?; + } + Ok(()) + } + } + } +} + +impl std::fmt::Debug for Token { + fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { + write!(f, "{}..{}: {:?}", self.span.start, self.span.end, self.kind) + } +} diff --git a/prqlc/prqlc-parser/src/err/parse_error.rs b/prqlc/prqlc-parser/src/err/parse_error.rs index f14270d0ff54..a4d86ef6eec6 100644 --- a/prqlc/prqlc-parser/src/err/parse_error.rs +++ b/prqlc/prqlc-parser/src/err/parse_error.rs @@ -3,9 +3,10 @@ use std::collections::HashSet; use std::fmt::Display; use std::hash::Hash; +use prqlc_ast::TokenKind; + use crate::ast::Span; use crate::err::error::{Error, ErrorSource, Reason, WithErrorInfo}; -use crate::lexer::TokenKind; #[derive(Clone, Debug)] pub struct ChumError { diff --git a/prqlc/prqlc-parser/src/expr.rs b/prqlc/prqlc-parser/src/expr.rs index 477849c86dcd..a5585087a900 100644 --- a/prqlc/prqlc-parser/src/expr.rs +++ b/prqlc/prqlc-parser/src/expr.rs @@ -3,10 +3,10 @@ use std::collections::HashMap; use chumsky::prelude::*; use prqlc_ast::expr::*; use prqlc_ast::Span; +use prqlc_ast::TokenKind; use super::common::*; use super::interpolation; -use super::lexer::TokenKind; use crate::err::parse_error::PError; use crate::types::type_expr; diff --git a/prqlc/prqlc-parser/src/interpolation.rs b/prqlc/prqlc-parser/src/interpolation.rs index 009fb80b442a..12af7f14f46f 100644 --- a/prqlc/prqlc-parser/src/interpolation.rs +++ b/prqlc/prqlc-parser/src/interpolation.rs @@ -1,12 +1,12 @@ use chumsky::prelude::*; use itertools::Itertools; +use prqlc_ast::TokenKind; use super::common::into_expr; use crate::ast::expr::*; use crate::ast::Literal; use crate::ast::{string_stream, Span}; use crate::err::parse_error::{ChumError, PError}; -use crate::lexer::TokenKind; /// Parses interpolated strings pub fn parse(string: String, span_base: Span) -> Result, Vec> { diff --git a/prqlc/prqlc-parser/src/lexer.rs b/prqlc/prqlc-parser/src/lexer.rs index c01181ee2837..c28d16a48f5c 100644 --- a/prqlc/prqlc-parser/src/lexer.rs +++ b/prqlc/prqlc-parser/src/lexer.rs @@ -3,72 +3,9 @@ use chumsky::{ prelude::*, text::{newline, Character}, }; -use prqlc_ast::expr::*; +use prqlc_ast::token::{Literal, Token, TokenKind, ValueAndUnit}; use serde::{Deserialize, Serialize}; -#[derive(Clone, PartialEq, Serialize, Deserialize)] -pub struct Token { - pub kind: TokenKind, - pub span: std::ops::Range, -} - -#[derive(Clone, PartialEq, Debug, Serialize, Deserialize)] -pub enum TokenKind { - NewLine, - - Ident(String), - Keyword(String), - #[cfg_attr( - feature = "serde_yaml", - serde(with = "serde_yaml::with::singleton_map") - )] - Literal(Literal), - Param(String), - - Range { - /// Whether the left side of the range is bound by the previous token - /// (but it's not contained in this token) - bind_left: bool, - bind_right: bool, - }, - Interpolation(char, String), - - /// single-char control tokens - Control(char), - - ArrowThin, // -> - ArrowFat, // => - Eq, // == - Ne, // != - Gte, // >= - Lte, // <= - RegexSearch, // ~= - And, // && - Or, // || - Coalesce, // ?? - DivInt, // // - // Pow, // ** - Annotate, // @ - - // Aesthetics only - Comment(String), - DocComment(String), - /// Vec containing comments between the newline and the line wrap - // Currently we include the comments with the LineWrap token. This isn't - // ideal, but I'm not sure of an easy way of having them be separate. - // - The line wrap span technically includes the comments — on a newline, - // we need to look ahead to _after_ the comments to see if there's a - // line wrap, and exclude the newline if there is. - // - We can only pass one token back - // - // Alternatives: - // - Post-process the stream, removing the newline prior to a line wrap. - // But requires a whole extra pass. - // - Change the functionality. But it's very nice to be able to comment - // something out and have line-wraps still work. - LineWrap(Vec), -} - /// Lex chars to tokens until the end of the input pub fn lexer() -> impl Parser, Error = Cheap> { lex_token() @@ -489,108 +426,9 @@ fn end_expr() -> impl Parser> { .rewind() } -impl TokenKind { - pub fn range(bind_left: bool, bind_right: bool) -> Self { - TokenKind::Range { - bind_left, - bind_right, - } - } -} - -// This is here because Literal::Float(f64) does not implement Hash, so we cannot simply derive it. -// There are reasons for that, but chumsky::Error needs Hash for the TokenKind, so it can deduplicate -// tokens in error. -// So this hack could lead to duplicated tokens in error messages. Oh no. -#[allow(clippy::derived_hash_with_manual_eq)] -impl std::hash::Hash for TokenKind { - fn hash(&self, state: &mut H) { - core::mem::discriminant(self).hash(state); - } -} - -impl std::cmp::Eq for TokenKind {} - -impl std::fmt::Display for TokenKind { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - match self { - TokenKind::NewLine => write!(f, "new line"), - TokenKind::Ident(s) => { - if s.is_empty() { - // FYI this shows up in errors - write!(f, "an identifier") - } else { - write!(f, "{s}") - } - } - TokenKind::Keyword(s) => write!(f, "keyword {s}"), - TokenKind::Literal(lit) => write!(f, "{}", lit), - TokenKind::Control(c) => write!(f, "{c}"), - - TokenKind::ArrowThin => f.write_str("->"), - TokenKind::ArrowFat => f.write_str("=>"), - TokenKind::Eq => f.write_str("=="), - TokenKind::Ne => f.write_str("!="), - TokenKind::Gte => f.write_str(">="), - TokenKind::Lte => f.write_str("<="), - TokenKind::RegexSearch => f.write_str("~="), - TokenKind::And => f.write_str("&&"), - TokenKind::Or => f.write_str("||"), - TokenKind::Coalesce => f.write_str("??"), - TokenKind::DivInt => f.write_str("//"), - // TokenKind::Pow => f.write_str("**"), - TokenKind::Annotate => f.write_str("@{"), - - TokenKind::Param(id) => write!(f, "${id}"), - - TokenKind::Range { - bind_left, - bind_right, - } => write!( - f, - "'{}..{}'", - if *bind_left { "" } else { " " }, - if *bind_right { "" } else { " " } - ), - TokenKind::Interpolation(c, s) => { - write!(f, "{c}\"{}\"", s) - } - TokenKind::Comment(s) => { - writeln!(f, "#{}", s) - } - TokenKind::DocComment(s) => { - writeln!(f, "#!{}", s) - } - TokenKind::LineWrap(comments) => { - write!(f, "\n\\ ")?; - for comment in comments { - write!(f, "{}", comment)?; - } - Ok(()) - } - } - } -} - -impl std::fmt::Debug for Token { - fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { - write!(f, "{}..{}: {:?}", self.span.start, self.span.end, self.kind) - } -} - -#[derive(Serialize, Deserialize, Debug)] +#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)] pub struct TokenVec(pub Vec); -// impl std::fmt::Debug for TokenVec { -// fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { -// writeln!(f, "TokenVec (")?; -// for token in self.0.iter() { -// writeln!(f, " {:?},", token)?; -// } -// write!(f, ")") -// } -// } - #[cfg(test)] mod test { use insta::assert_debug_snapshot; diff --git a/prqlc/prqlc-parser/src/lib.rs b/prqlc/prqlc-parser/src/lib.rs index 7ad67a281eb9..91a408f0a10a 100644 --- a/prqlc/prqlc-parser/src/lib.rs +++ b/prqlc/prqlc-parser/src/lib.rs @@ -1,26 +1,22 @@ -use chumsky::{prelude::*, Stream}; -use err::error::Reason; -use err::error::{Error, WithErrorInfo}; -use lexer::TokenKind; -pub use lexer::{Token, TokenVec}; -use prqlc_ast::span::Span; -use prqlc_ast::stmt::*; - -use crate::err::error::ErrorSource; - +pub mod err; mod expr; mod interpolation; mod lexer; - mod stmt; #[cfg(test)] mod test; mod types; -// pub use prqlc_ast; -pub mod err; - +use chumsky::{prelude::*, Stream}; pub use prqlc_ast as ast; +use prqlc_ast::span::Span; +use prqlc_ast::stmt::*; +use prqlc_ast::token::*; + +use self::err::error::Reason; +use self::err::error::{Error, WithErrorInfo}; +pub use self::lexer::TokenVec; +use crate::err::error::ErrorSource; /// Build PRQL AST from a PRQL query string. pub fn parse_source(source: &str, source_id: u16) -> Result, Vec> { @@ -78,11 +74,11 @@ mod common { use chumsky::prelude::*; use prqlc_ast::expr::*; use prqlc_ast::stmt::*; + use prqlc_ast::token::*; use prqlc_ast::Span; use prqlc_ast::Ty; use prqlc_ast::TyKind; - use super::lexer::TokenKind; use crate::err::parse_error::PError; pub fn ident_part() -> impl Parser { diff --git a/prqlc/prqlc-parser/src/stmt.rs b/prqlc/prqlc-parser/src/stmt.rs index 348778cf6a16..c63c25a2b20f 100644 --- a/prqlc/prqlc-parser/src/stmt.rs +++ b/prqlc/prqlc-parser/src/stmt.rs @@ -2,15 +2,16 @@ use std::collections::HashMap; use chumsky::prelude::*; use itertools::Itertools; -use prqlc_ast::expr::*; -use prqlc_ast::stmt::*; +use prqlc_ast::expr::{ExprKind, IndirectionKind}; +use prqlc_ast::stmt::{ + Annotation, ImportDef, ModuleDef, QueryDef, Stmt, StmtKind, TypeDef, VarDef, VarDefKind, +}; +use prqlc_ast::token::{Literal, TokenKind}; use semver::VersionReq; -use super::common::*; -use super::expr::*; -use super::lexer::TokenKind; +use super::common::{ctrl, ident_part, into_stmt, keyword, new_line}; +use super::expr::{expr, expr_call, ident, pipeline}; use crate::err::parse_error::PError; -// use crate::ast::err::chumsky_error::PError; use crate::types::type_expr; pub fn source() -> impl Parser, Error = PError> { diff --git a/prqlc/prqlc-parser/src/types.rs b/prqlc/prqlc-parser/src/types.rs index c2087597371e..689febb1ae24 100644 --- a/prqlc/prqlc-parser/src/types.rs +++ b/prqlc/prqlc-parser/src/types.rs @@ -2,7 +2,6 @@ use chumsky::prelude::*; use prqlc_ast::*; use super::common::*; -use super::lexer::TokenKind; use crate::err::parse_error::PError; use crate::expr::ident; diff --git a/prqlc/prqlc/Cargo.toml b/prqlc/prqlc/Cargo.toml index aac8e334ba10..255ddabcb5c9 100644 --- a/prqlc/prqlc/Cargo.toml +++ b/prqlc/prqlc/Cargo.toml @@ -47,7 +47,7 @@ anstream = {version = "0.6.14", features = ["auto"]} ariadne = "0.4.1" chrono = "0.4.38" csv = "1.3.0" -enum-as-inner = "0.6.0" +enum-as-inner = {workspace = true} itertools = {workspace = true} log = {workspace = true} once_cell = "1.19.0" diff --git a/prqlc/prqlc/src/codegen/ast.rs b/prqlc/prqlc/src/codegen/ast.rs index bdb7688e83b3..683af23ff903 100644 --- a/prqlc/prqlc/src/codegen/ast.rs +++ b/prqlc/prqlc/src/codegen/ast.rs @@ -1,6 +1,7 @@ use std::collections::HashSet; use once_cell::sync::Lazy; +use prqlc_ast::expr::*; use regex::Regex; use super::{WriteOpt, WriteSource}; diff --git a/prqlc/prqlc/src/ir/pl/expr.rs b/prqlc/prqlc/src/ir/pl/expr.rs index e5f7696ce763..3483098b6c0d 100644 --- a/prqlc/prqlc/src/ir/pl/expr.rs +++ b/prqlc/prqlc/src/ir/pl/expr.rs @@ -1,11 +1,12 @@ use std::collections::HashMap; use enum_as_inner::EnumAsInner; +use prqlc_ast::token::Literal; use serde::{Deserialize, Serialize}; use super::{Lineage, TransformCall}; use crate::ast::generic; -use crate::ast::{GenericTypeParam, Ident, Literal, Span, Ty}; +use crate::ast::{GenericTypeParam, Ident, Span, Ty}; use crate::codegen::write_ty; // The following code is tested by the tests_misc crate to match expr.rs in prqlc_ast. diff --git a/prqlc/prqlc/src/semantic/reporting.rs b/prqlc/prqlc/src/semantic/reporting.rs index c58f99f7686b..f7a9cdcce3dc 100644 --- a/prqlc/prqlc/src/semantic/reporting.rs +++ b/prqlc/prqlc/src/semantic/reporting.rs @@ -1,8 +1,8 @@ -use serde::Serialize; use std::collections::HashMap; use std::ops::Range; use ariadne::{Color, Label, Report, ReportBuilder, ReportKind, Source}; +use serde::Serialize; use crate::ast; use crate::ir::decl::{DeclKind, Module, RootModule, TableDecl, TableExpr}; diff --git a/prqlc/prqlc/tests/integration/ast_code_matches.rs b/prqlc/prqlc/tests/integration/ast_code_matches.rs index 3df1e8de2226..293306015201 100644 --- a/prqlc/prqlc/tests/integration/ast_code_matches.rs +++ b/prqlc/prqlc/tests/integration/ast_code_matches.rs @@ -30,8 +30,9 @@ fn test_expr_ast_code_matches() { - feature = "serde_yaml", - serde(with = "serde_yaml::with::singleton_map") - )] - @@ .. @@ + - Literal(token::Literal), - Pipeline(Pipeline), + + Literal(Literal), @@ .. @@ - Range(Range), - Binary(BinaryExpr), @@ -44,14 +45,14 @@ fn test_expr_ast_code_matches() { - Name(String), - Position(i64), - Star, - -} - - + @@ .. @@ -#[derive(Debug, PartialEq, Clone, Serialize, Deserialize)] -pub struct BinaryExpr { - pub left: Box, - pub op: BinOp, - pub right: Box, - @@ .. @@ + -} + - -#[derive(Debug, PartialEq, Clone, Serialize, Deserialize)] -pub struct UnaryExpr { - pub op: UnOp, @@ -59,6 +60,8 @@ fn test_expr_ast_code_matches() { -} - @@ .. @@ + -} + - -#[derive(Debug, PartialEq, Clone, Serialize, Deserialize)] -pub struct GenericTypeParam { - /// Assigned name of this generic type argument. @@ -68,14 +71,18 @@ fn test_expr_ast_code_matches() { - /// For a given instance of this function, the argument must be - /// exactly one of types in the domain. - pub domain: Vec, - -} - - + @@ .. @@ -/// A value and a series of functions that are to be applied to that value one after another. -#[derive(Debug, PartialEq, Clone, Serialize, Deserialize)] -pub struct Pipeline { - pub exprs: Vec, -} - + @@ .. @@ + -impl From for ExprKind { + - fn from(value: token::Literal) -> Self { + +impl From for ExprKind { + + fn from(value: Literal) -> Self { "### ); }