Skip to content

Consolidate grammar comments with parser logic. #195

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 5, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 12 additions & 15 deletions source/parse.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ auto violates_lifetime_safety = false;
//

//G prefix-operator:
//G one of '!'
//G one of '!' '-' '+'
//G
auto is_prefix_operator(lexeme l) -> bool
{
Expand Down Expand Up @@ -68,7 +68,7 @@ auto is_postfix_operator(lexeme l) -> bool


//G assignment-operator:
//G one of '=' '*=' '/=' '%=' '+=' '-=' '>>=' '<<='
//G one of '=' '*=' '/=' '%=' '+=' '-=' '>>=' '<<=' '&=' '^=' '|='
//G
auto is_assignment_operator(lexeme l) -> bool
{
Expand Down Expand Up @@ -1549,8 +1549,7 @@ class parser
return n;
}

if (curr().type() == lexeme::Identifier ||
curr().type() == lexeme::DecimalLiteral ||
if (curr().type() == lexeme::DecimalLiteral ||
curr().type() == lexeme::FloatLiteral ||
curr().type() == lexeme::StringLiteral ||
curr().type() == lexeme::CharacterLiteral ||
Expand Down Expand Up @@ -1944,7 +1943,7 @@ class parser

//G bit-xor-expression:
//G bit-and-expression
//G bit-xor-expression '&' bit-and-expression
//G bit-xor-expression '^' bit-and-expression
//G
auto bit_xor_expression(bool allow_angle_operators = true) {
return binary_expression<bit_xor_expression_node> (
Expand All @@ -1955,7 +1954,7 @@ class parser

//G bit-or-expression:
//G bit-xor-expression
//G bit-or-expression '&' bit-xor-expression
//G bit-or-expression '|' bit-xor-expression
//G
auto bit_or_expression(bool allow_angle_operators = true) {
return binary_expression<bit_or_expression_node> (
Expand Down Expand Up @@ -1990,7 +1989,7 @@ class parser

//G assignment-expression:
//G logical-or-expression
//G assignment-expression assignment-operator assignment-expression
//G assignment-expression assignment-operator logical-or-expression
//G
auto assignment_expression(bool allow_angle_operators = true) -> std::unique_ptr<assignment_expression_node> {
//return binary_expression<assignment_expression_node> (
Expand Down Expand Up @@ -2037,7 +2036,7 @@ class parser

//G expression-list:
//G parameter-direction? expression
//G expression-list ',' expression
//G expression-list ',' parameter-direction? expression
//G
auto expression_list(token const* open_paren, bool inside_initializer = false) -> std::unique_ptr<expression_list_node> {
auto pass = passing_style::in;
Expand Down Expand Up @@ -2078,6 +2077,10 @@ class parser
pass = passing_style::move;
next();
}
else if (curr().type() == lexeme::Identifier && curr() == "forward") {
pass = passing_style::forward;
next();
}
auto expr = expression();
if (!expr) {
error("invalid text in expression list");
Expand Down Expand Up @@ -2128,12 +2131,6 @@ class parser
n->id = std::move(id);
assert (n->id.index() == type_id_node::unqualified);
}
else if (curr().type() == lexeme::Keyword || curr().type() == lexeme::Cpp2FixedType) {
n->pos = curr().position();
n->id = &curr();
next();
assert (n->id.index() == type_id_node::keyword);
}
else {
if (!n->pc_qualifiers.empty()) {
error("'*'/'const' type qualifiers must be followed by a type name or '_' wildcard");
Expand Down Expand Up @@ -2939,7 +2936,7 @@ class parser


//G parameter-declaration:
//G parameter-direction? declaration
//G parameter-direction? this-specifier? declaration
//G
//G parameter-direction: one of
//G 'in' 'copy' 'inout' 'out' 'move' 'forward'
Expand Down