Skip to content
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

Fix PEG parsers' "comment" rule #124

Merged
merged 1 commit into from
Jan 5, 2024
Merged
Show file tree
Hide file tree
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
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