Conversation
|
445da70 to
a06179b
Compare
69af5d6 to
3a7f5ae
Compare
99bcd05 to
9f5d166
Compare
2f7d455 to
acfa26c
Compare
9f5d166 to
8150fcf
Compare
acfa26c to
4cc4786
Compare
8d49a31 to
6711af3
Compare
4cc4786 to
072144d
Compare
6711af3 to
4b6bc06
Compare
072144d to
d95ed0d
Compare
18a9e63 to
3bd60df
Compare
3bd60df to
d16de5a
Compare
fb9d550 to
c14dcbf
Compare
88717aa to
d9ea068
Compare
45918e8 to
7abaedc
Compare
b33f4f1 to
31cb39c
Compare
7abaedc to
0e123dd
Compare
31cb39c to
c86cbe9
Compare
c5d1842 to
71d73b7
Compare
836f1d5 to
711c3d6
Compare
2cd6afb to
f89ae1d
Compare
59f53c8 to
b6d5922
Compare
OmarTawfik
left a comment
There was a problem hiding this comment.
Left a few questions/suggestions. Thanks!
| producing_type: Identifier, | ||
| options: Vec<LALRPOPOption>, | ||
| pub inline: bool, | ||
| pub pubb: bool, |
There was a problem hiding this comment.
WDYT of using public for clarity?
| /// }; | ||
| /// ``` | ||
| #[derive(Clone, Debug, Serialize)] | ||
| pub(crate) struct LALRPOPItemInner { |
There was a problem hiding this comment.
WDYT of using LALRPOPDerivedItem instead of "inner" here, as opposed to the verbatim ones.
There was a problem hiding this comment.
Much better name, thanks!
| /// <_OverrideSpecifier: OverrideSpecifier> => new_modifier_attribute_override_specifier(<>), | ||
| /// ``` | ||
| #[derive(Clone, Debug, Serialize)] | ||
| struct LALRPOPOption { |
There was a problem hiding this comment.
I initially misunderstood these options as LALRPOP configuration/settings.
WDYT of using LALRPOPDefinition instead? similar to how LALRPOP docs call them.
|
|
||
| /// Checks if a given version specifier enables the supported version | ||
| fn is_enabled(enabled: Option<&VersionSpecifier>) -> bool { | ||
| enabled.as_ref().is_none_or(|v| v.contains(&VERSION)) |
There was a problem hiding this comment.
nit: in an earlier PR you introduced Always and auto-derived Default for it, along with its contains() semantics.
I suggest reusing it here: enabled.unwrap_or_default().contains(....)
There was a problem hiding this comment.
You're right, this function is older than that and didn't remember to change it. Thank you!
There was a problem hiding this comment.
Changed it to enabled.unwrap_or(&VersionSpecifier::default()).contains(&VERSION), since &VersionSpecifier doesn't implement Default
| /// In the case multiple operators are defined within a precedence expression, we wrap them in their own rule, | ||
| /// basically converting this into syntactic sugar for using an enum item. | ||
| /// | ||
| /// TODO(v2): We're assuming that Precedence Items follow a strict shape, in particular that Binary Operators |
There was a problem hiding this comment.
We can definetely improve this structure. Let's discuss options f2f if you like.
Not blocking of course.
There was a problem hiding this comment.
Cool, I think it's out of the scope of this PR
|
|
||
| grammar<'source>(source: &'source str); | ||
|
|
||
| Sep<S, T>: Vec<T> = { |
There was a problem hiding this comment.
rather than the shortnames, WDYT of using the full names we already use in the language definition?
Separated, SeparatedAllowEmpty, Repeated, RepeatedAllowEmpty
| pub(crate) mod nodes; | ||
|
|
||
| lalrpop_mod!( | ||
| #[allow(clippy::all)] |
There was a problem hiding this comment.
is this temporary? should we add a TODO(v2) to remove it?
Otherwise, if possible, I suggest using allowing specific rules on the parts that need it for clarity.
There was a problem hiding this comment.
Added a TODO, will clean it in another PR since I may need to change the rules a bit.
| use crate::lexer::contexts::ContextKind; | ||
| use crate::lexer::definition::Lexer; | ||
|
|
||
| pub(crate) mod nodes; |
There was a problem hiding this comment.
//! This module contains certain nodes and functions used internally by the parser.
//!
//! They shouldn't be used outside of the parser, and should be transformed into AST nodes.
should this be private to the parser?
There was a problem hiding this comment.
You're right, changed it!
| FunctionTypeAttribute::PublicKeyword(terminal) => { | ||
| StateVariableAttribute::PublicKeyword(terminal) | ||
| } | ||
| _ => panic!("This is wrong, I don't really know what to do for now, but it should fail gracefully (like a parser error)") |
There was a problem hiding this comment.
Generally, we try to skip/recover from such errors, rather than panicking, even if we don't validate for it now.
I wonder if panicking is needed here? are there other places that can panic from user input?
There was a problem hiding this comment.
I added comments on this and another similar case, for now skipping it here, and returning an invalid Identifier (with range 0..0) in the other case. Once we start working on validation we can improve here.
Cargo.toml
Outdated
| Inflector = { version = "0.11.4" } | ||
| itertools = { version = "0.13.0" } | ||
| lalrpop = { version = "0.22.2" } | ||
| lalrpop-util = { version = "0.22.2", features = ["lexer", "unicode"] } |
There was a problem hiding this comment.
given that we are using logos for lexing, why are these additional features needed here?
There was a problem hiding this comment.
You're right, I used the built-in lexer when doing early experiments and forgot about it.
I also upgraded to 0.23.0 since it was easy enough.
| // TODO(v2): Errors should be something other than `String` | ||
| fn parse(input: &str, version: LanguageVersion) -> Result<Self::NonTerminal, String>; | ||
|
|
||
| fn check_version(version: LanguageVersion) -> Result<(), String> { |
There was a problem hiding this comment.
IIUC, we will restrict LanguageVersion itself to the set of supported languages. Would this check_version() be needed here?
There was a problem hiding this comment.
Added a comment, we should remove it in the future.
| /// The type of the non-terminal that this parser produces | ||
| type NonTerminal; | ||
|
|
||
| // TODO(v2): Errors should be something other than `String` |
There was a problem hiding this comment.
If not a big change, I suggest prioritizing this sooner than later, as currently the "unexpected" tokens are being categorized as "unrecognized" in the error message, which conflict with the UNRECOGNIZED lexeme.
There was a problem hiding this comment.
I'll prioritize this as a follow up PR. Thanks!
| } | ||
| None | ||
| } | ||
| } |
There was a problem hiding this comment.
discussed f2f: splitting the snapshot tests for v1/v2, for a few reasons:
- v2 is not versioned, so we don't need diffing over versions
- v2 only allows source unit/statement/expression inputs, so we need to rewrite/refactor the tests to fit one of these three
- v2 produces the AST directly, so we can serialize this to the snapshot directly, rather than comparing with the legacy CST nodes. Maybe we can generate a similar YAML serializer for the new L0 types.
We should probably do this in a separate PR that doesn't contain product changes (only test changes) to make sure we don't introduce any bugs. That PR will have a ton of newly added snapshots, and it would make it harder to spot any issues with manual reviews.
| @@ -0,0 +1,229 @@ | |||
| //! This module contains certain nodes and functions used internally by the parser. | |||
There was a problem hiding this comment.
IIUC, these helpers will eventually move to the ParserConsumer structure you proposed earlier. Is that correct? should we add a TODO here?
There was a problem hiding this comment.
I think this depends on whether we go down that path or not. But even then I'm not sure if we would, the ParserConsumer should follow strictly the language definition, where as most of the code here is only there to resolve conflicts in the parser.
|
Thanks for the review, I think I addressed/replied to everything. These are the tasks that I should look at next:
|
- Generating LALRPOP grammar rules - Changes in the language definition - Added some tests and comparison against V1
77c89ff to
d9aa154
Compare
|
Review the following changes in direct dependencies. Learn more about Socket for GitHub.
|
The PR is huge, but most of the changes are generated or snapshot tests. The actual changes can be summarised as:
grammar.lalrpop.jinja2)function (uint a) internal internal foo;as the function type having twointernalattributes, but the second should be an attribute of the state variable, this works as expected on V2.uint transient;, V2 correctly parse it as anuintwith thetransientidentifier (not a storage attribute).