Skip to content

Commit

Permalink
Fix PEG parsers' "comment" rule
Browse files Browse the repository at this point in the history
The problem with the previous version was that if there is no text after
the '//', regular whitespace processing kicked in and the regexp was
applied to the next non-empty line.

The effect of this was that the next line gets commented off
unconditionally, which is kindof not what you want.
  • Loading branch information
smurfix committed Jan 4, 2024
1 parent 087c3c4 commit 022dcfe
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 3 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ please take a look at related PRs and issues and see if the change affects you.
- fix: #98 suppressed match in zero-or-more [#98]. Thanks @vpavlu for reporting
the issue.

- fix: empty comments in .peg files hid the next line, commented or not.

[#101]: https://github.com/textX/Arpeggio/issues/101
[#98]: https://github.com/textX/Arpeggio/issues/98
[#96]: https://github.com/textX/Arpeggio/issues/96
Expand Down
2 changes: 1 addition & 1 deletion arpeggio/cleanpeg.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def rule_name(): return _(r"[a-zA-Z_]([a-zA-Z_]|[0-9])*")
def rule_crossref(): return rule_name
def str_match(): return _(r'''(?s)('[^'\\]*(?:\\.[^'\\]*)*')|'''
r'''("[^"\\]*(?:\\.[^"\\]*)*")''')
def comment(): return "//", _(".*\n")
def comment(): return _("//.*\n", multiline=False)


class ParserPEG(ParserPEGOrig):
Expand Down
4 changes: 2 additions & 2 deletions arpeggio/peg.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ def regex(): return [("r'", _(r'''[^'\\]*(?:\\.[^'\\]*)*'''), "'"),
def rule_name(): return _(r"[a-zA-Z_]([a-zA-Z_]|[0-9])*")
def rule_crossref(): return rule_name
def str_match(): return _(r'''(?s)('[^'\\]*(?:\\.[^'\\]*)*')|'''
r'''("[^"\\]*(?:\\.[^"\\]*)*")''')
def comment(): return "//", _(".*\n")
r'''("[^"\\]*(?:\\.[^"\\]*)*")''')
def comment(): return _("//.*\n", multiline=False)


# Escape sequences supported in PEG literal string matches
Expand Down
1 change: 1 addition & 0 deletions arpeggio/tests/test_peg_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
factor <- ("+" / "-")?
(number / "(" expression ")");
// This is another comment
//
term <- factor (( "*" / "/") factor)*;
expression <- term (("+" / "-") term)*;
calc <- expression+ EOF;
Expand Down

0 comments on commit 022dcfe

Please sign in to comment.