Description
Adding the concept of quantifiers to the AST parser will enable more of the expected syntax to be ready after the parsing stage instead of requiring another round of validation.
For example, the syntax for macro_struct_def
can be redefined as:
- syntax @"builtin macro struct_def" <- 500 = "struct" "{" body "}";
+ syntax @"builtin macro struct_def" <- 500 = "struct" "{" field[ key ":" value ]* "}";
which would parse source code as:
Ast::Complex {
values: Tuple {
named: BTreeMap{{
"field": Quantifier::ZeroOrMore (
Vec{[ Ast::Complex { ... }, Ast::Complex { ... }, ... ]}
)
})
}
}
after the signature for Ast::Complex
has been changed from values: Tuple<Self>
to values: Tuple<Quantifier<Self>>
These quantifiers can also use the advantage of Tuple
to be unnamed fields if no keyword is provided before the [
like field[
in the struct_def example.
Syntax for macro_list
can then be reduced like this:
- syntax @"builtin macro list" <- 100000 = "list" "[" values "]";
- syntax @"builtin macro list" <- 100000 = "list" "[" "]";
+ syntax @"builtin macro list" <- 100000 = "list" "[" [ value ]* "]";
where the first unnamed field in the parsed tuple is Quantifier::ZeroOrMore(...)
I would like to try working on this, and start a discussion on whether there are any considerations before starting, including any feedback on these regex-style quantifiers, i.e:
group[ key ]?
parses 0 or 1 child expressions (Quantifier::ZeroOrOne( Option<Tuple> )
)group[ key ]+
parses 1 or more child expressions (Quantifier::OneOrMore( Tuple, Vec<Tuple> )
)group[ key ]*
parses 0 or more child expressions (Quantifier::ZeroOrMore( Vec<Tuple> )
)
This will also bring more iteration as opposed to recursion to the parsing stage which is nice.