Skip to content

Commit

Permalink
WIP: Remove new EndOfInput trivia and match DSL v1 for now
Browse files Browse the repository at this point in the history
So that we carefully maintain parity for now, during the transition.
  • Loading branch information
Xanewok committed Nov 10, 2023
1 parent 6b09b65 commit 8d46847
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,14 @@ fn collect_trivia<'l>(parser: &'l TriviaParser, acc: &mut Vec<&'l Identifier>) {
collect_trivia(parser, acc);
}
}
TriviaParser::ZeroOrMore { parser } | TriviaParser::Optional { parser } => {
TriviaParser::OneOrMore { parser }
| TriviaParser::ZeroOrMore { parser }
| TriviaParser::Optional { parser } => {
collect_trivia(parser, acc);
}
TriviaParser::Trivia { trivia } => {
acc.push(trivia);
}
TriviaParser::EndOfInput => {}
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -262,13 +262,14 @@ fn check_trivia_parser(analysis: &mut Analysis, parser: &TriviaParser, enablemen
check_trivia_parser(analysis, parser, &enablement);
}
}
TriviaParser::ZeroOrMore { parser } | TriviaParser::Optional { parser } => {
TriviaParser::OneOrMore { parser }
| TriviaParser::ZeroOrMore { parser }
| TriviaParser::Optional { parser } => {
check_trivia_parser(analysis, parser, &enablement);
}
TriviaParser::Trivia { trivia } => {
check_reference(analysis, None, trivia, &enablement, ReferenceFilter::Trivia);
}
TriviaParser::EndOfInput => {}
};
}

Expand Down
4 changes: 2 additions & 2 deletions crates/codegen/language/definition/src/model/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,11 +187,11 @@ mod wrapper {
Sequence { parsers: Vec<TriviaParser> },
Choice { parsers: Vec<TriviaParser> },

ZeroOrMore { parser: Box<TriviaParser> },
Optional { parser: Box<TriviaParser> },
OneOrMore { parser: Box<TriviaParser> },
ZeroOrMore { parser: Box<TriviaParser> },

Trivia { trivia: Identifier },
EndOfInput,
}

#[derive(Debug, Eq, PartialEq, Serialize)]
Expand Down
17 changes: 8 additions & 9 deletions crates/solidity/inputs/language/src/definition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,19 +39,18 @@ impl GrammarConstructorDslV2 for codegen_grammar::Grammar {
codegen_language_macros::compile!(Language(
name = Solidity,
root_item = SourceUnit,
leading_trivia = ZeroOrMore(Choice([
// NOTE: For now this is on par with the DSL v1 definition to minimize the fallout.
// At the final stage, we should use the correct trivia definition from https://github.com/NomicFoundation/slang/pull/629
leading_trivia = OneOrMore(Choice([
Trivia(Whitespace),
Trivia(EndOfLine),
Trivia(SingleLineComment),
Trivia(MultilineComment)
Trivia(MultilineComment),
Trivia(SingleLineComment)
])),
trailing_trivia = Sequence([
ZeroOrMore(Choice([
Trivia(Whitespace),
Trivia(SingleLineComment),
Trivia(MultilineComment)
])),
Choice([Trivia(EndOfLine), EndOfInput])
Optional(Trivia(Whitespace)),
Optional(Trivia(SingleLineComment)),
Trivia(EndOfLine)
]),
versions = [
"0.4.11", "0.4.12", "0.4.13", "0.4.14", "0.4.15", "0.4.16", "0.4.17", "0.4.18", "0.4.19",
Expand Down

0 comments on commit 8d46847

Please sign in to comment.