Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
  • Loading branch information
OmarTawfik committed Oct 10, 2023
1 parent 890f704 commit fd8c3ce
Show file tree
Hide file tree
Showing 2 changed files with 97 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,9 @@ impl ParseHelpers {
input: ParseStream,
errors: &mut ErrorsCollection,
) -> Result<Vec<T>> {
match Self::delimited(Delimiter::Bracket, input, |span, inner_input| {
match Self::delimited(Delimiter::Bracket, input, |_, inner_input| {
let mut result = Vec::new();

if inner_input.is_empty() {
errors.add(&span, &Errors::NoEntriesFound);
}

while !inner_input.is_empty() {
result.push(ParseInputTokens::parse_named_value(&inner_input, errors)?);

Expand Down Expand Up @@ -62,13 +58,9 @@ impl ParseHelpers {
input: ParseStream,
errors: &mut ErrorsCollection,
) -> Result<IndexMap<Spanned<K>, Spanned<V>>> {
match Self::delimited(Delimiter::Parenthesis, input, |span, inner_input| {
match Self::delimited(Delimiter::Parenthesis, input, |_, inner_input| {
let mut result = IndexMap::new();

if inner_input.is_empty() {
errors.add(&span, &Errors::NoEntriesFound);
}

while !inner_input.is_empty() {
let key = ParseInputTokens::parse_named_value(&inner_input, errors)?;

Expand Down Expand Up @@ -159,8 +151,6 @@ fn delimited<T>(

#[derive(thiserror::Error, Debug)]
enum Errors<'err> {
#[error("Expected at least one entry.")]
NoEntriesFound,
#[error("Expected field: '{0}'.")]
ExpectedField(&'err str),
#[error("Duplicate map key.")]
Expand Down
103 changes: 95 additions & 8 deletions crates/solidity/inputs/language/src/definition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2509,10 +2509,6 @@ codegen_language_macros::compile!(
not_followed_by = Fragment(IdentifierPart)
)
),
Fragment(
name = HexCharacter,
scanner = Choice([Range('0'..'9'), Range('a'..'f'), Range('A'..'F')])
),
Token(
// TODO: figure out versioning
name = DecimalLiteral,
Expand Down Expand Up @@ -2556,7 +2552,7 @@ codegen_language_macros::compile!(
fields = (keyword = Single(Token([WeiKeyword])))
),
Variant(
name = Gwei,// 1e-9 ETH
name = Gwei, // 1e-9 ETH
enabled_in = "0.6.11",
fields = (keyword = Single(Token([GweiKeyword])))
),
Expand Down Expand Up @@ -2606,14 +2602,105 @@ codegen_language_macros::compile!(
Topic(
title = "Strings",
items = [
// TODO: replace this placeholder token with the the complete list of tokens in this topic
Enum(
name = StringExpression,
variants = [
Variant(
name = Hex,
fields = (literals = Single(Rule(HexStringLiterals)))
),
Variant(
name = Ascii,
fields = (literals = Single(Rule(AsciiStringLiterals)))
),
Variant(
name = Unicode,
enabled_in = "0.7.0",
fields = (literals = Single(Rule(UnicodeStringLiterals)))
)
]
),
Repeated(name = HexStringLiterals, repeated = HexStringLiteral),
Token(
name = AsciiStringLiteral,
name = HexStringLiteral,
scanner = TrailingContext(
scanner = Choice([
Fragment(SingleQuotedHexString),
Fragment(DoubleQuotedHexString)
]),
not_followed_by = Fragment(IdentifierPart)
)
),
Fragment(
name = SingleQuotedHexString,
scanner = Sequence([
Terminal("hex"),
Terminal("'"),
Optional(Fragment(HexStringContents)),
Terminal("'")
])
),
Fragment(
name = DoubleQuotedHexString,
scanner = Sequence([
Terminal("hex"),
Terminal("\""),
ZeroOrMore(Choice([Range('a'..'z'), Range('A'..'Z')])),
Optional(Fragment(HexStringContents)),
Terminal("\"")
])
),
Fragment(
name = HexStringContents,
scanner = Sequence([
Fragment(HexCharacter),
Fragment(HexCharacter),
ZeroOrMore(Sequence([
Optional(Terminal("_")),
Fragment(HexCharacter),
Fragment(HexCharacter)
]))
])
),
Fragment(
name = HexCharacter,
scanner = Choice([Range('0'..'9'), Range('a'..'f'), Range('A'..'F')])
),
Repeated(name = AsciiStringLiterals, repeated = AsciiStringLiteral),
Token(
name = AsciiStringLiteral,
scanner = TrailingContext(
scanner = Choice([
Fragment(SingleQuotedAsciiString),
Fragment(DoubleQuotedAsciiString)
]),
not_followed_by = Fragment(IdentifierPart)
)
),
Fragment(
name = SingleQuotedAsciiString,
scanner = Sequence([
Terminal("'"),
ZeroOrMore(Choice([
Fragment(EscapeSequence),
Range(' '..'&'),
Range('('..'['),
Range(']'..'~')
])),
Terminal("'")
])
),
Fragment(
name = DoubleQuotedAsciiString,
scanner = Sequence([
Terminal("'"),
ZeroOrMore(Choice([
Fragment(EscapeSequence),
Range(' '..'!'),
Range('#'..'['),
Range(']'..'~')
])),
Terminal("'")
])
)
]
),
Expand Down

0 comments on commit fd8c3ce

Please sign in to comment.