Skip to content

Commit

Permalink
perf: Simplify single-line grammar parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
slavek-kucera authored Oct 2, 2023
1 parent 45a8f02 commit 625a8b0
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 32 deletions.
24 changes: 0 additions & 24 deletions parser_library/src/parsing/grammar/ca_expr_rules.g4
Original file line number Diff line number Diff line change
Expand Up @@ -314,30 +314,6 @@ data_attribute_value returns [std::variant<context::id_index, semantics::vs_ptr,
$value = $id.name;
};

vs_id returns [id_index name]
: ORDSYMBOL
{
std::string text = $ORDSYMBOL->getText();
auto first = $ORDSYMBOL;
auto last = first;
}
(
NUM
{
text += $NUM->getText();
last = $NUM;
}
|
ORDSYMBOL
{
text += $ORDSYMBOL->getText();
last = $ORDSYMBOL;
}
)*
{
$name = parse_identifier(std::move(text), provider.get_range(first, last));
};

var_def returns [vs_ptr vs]
: var_def_name var_def_substr
{
Expand Down
24 changes: 24 additions & 0 deletions parser_library/src/parsing/grammar/hlasmparser_multiline.g4
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,30 @@ id_no_dot returns [id_index name] locals [std::string buffer]
}
;

vs_id returns [id_index name]
: ORDSYMBOL
{
std::string text = $ORDSYMBOL->getText();
auto first = $ORDSYMBOL;
auto last = first;
}
(
NUM
{
text += $NUM->getText();
last = $NUM;
}
|
ORDSYMBOL
{
text += $ORDSYMBOL->getText();
last = $ORDSYMBOL;
}
)*
{
$name = parse_identifier(std::move(text), provider.get_range(first, last));
};

remark
: (DOT|ASTERISK|MINUS|PLUS|LT|GT|COMMA|LPAR|RPAR|SLASH|EQUALS|AMPERSAND|APOSTROPHE|IDENTIFIER|NUM|VERTICAL|ORDSYMBOL|SPACE|ATTR)*;

Expand Down
19 changes: 11 additions & 8 deletions parser_library/src/parsing/grammar/hlasmparser_singleline.g4
Original file line number Diff line number Diff line change
Expand Up @@ -211,25 +211,28 @@ lab_instr returns [std::optional<std::string> op_text, range op_range, size_t op
_errHandler->recover(this, _localctx->exception);
}

num_ch
: NUM+;

num returns [self_def_t value]
: num_ch {$value = parse_self_def_term("D",get_context_text($num_ch.ctx),provider.get_range($num_ch.ctx));};
: NUM {$value = parse_self_def_term("D",$NUM->getText(),provider.get_range($NUM));};

signed_num_ch
: MINUS? NUM+;
: MINUS? NUM;

id returns [id_index name, id_index using_qualifier]
: f=id_no_dot {$name = $f.name;} (dot s=id_no_dot {$name = $s.name; $using_qualifier = $f.name;})?;

id_no_dot returns [id_index name] locals [std::string buffer]
: ORDSYMBOL { $buffer = $ORDSYMBOL->getText(); } (l=(IDENTIFIER|NUM|ORDSYMBOL) {$buffer.append($l->getText());})*
id_no_dot returns [id_index name]
: ORDSYMBOL
{
$name = parse_identifier(std::move($buffer),provider.get_range($ORDSYMBOL,$l?$l:$ORDSYMBOL));
$name = parse_identifier($ORDSYMBOL->getText(),provider.get_range($ORDSYMBOL));
}
;

vs_id returns [id_index name]
: ORDSYMBOL
{
$name = parse_identifier($ORDSYMBOL->getText(), provider.get_range($ORDSYMBOL));
};

remark
: (DOT|ASTERISK|MINUS|PLUS|LT|GT|COMMA|LPAR|RPAR|SLASH|EQUALS|AMPERSAND|APOSTROPHE|IDENTIFIER|NUM|VERTICAL|ORDSYMBOL|SPACE|ATTR)*;

Expand Down

0 comments on commit 625a8b0

Please sign in to comment.