-
Notifications
You must be signed in to change notification settings - Fork 55
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
Feature Request: Allowing grammar to filter out constants #76
Comments
davaya
changed the title
Feature: grammar ignores constants
Feature Request: Allowing grammar to filter out constants
May 31, 2020
On branch https://github.com/textX/Arpeggio/tree/76-suppress-constant is the current work on this feature. Most pieces were already in place. Here is what is implemented so far:
Please see the docs and tests in the commit above for how it is used. This needs more docs to be considered completed. |
igordejanovic
added a commit
that referenced
this issue
Oct 11, 2020
igordejanovic
added a commit
that referenced
this issue
Oct 11, 2020
igordejanovic
added a commit
that referenced
this issue
Oct 11, 2020
igordejanovic
added a commit
that referenced
this issue
Oct 11, 2020
igordejanovic
added a commit
that referenced
this issue
Oct 11, 2020
Implemented on the |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Arpeggio returns a parse tree containing every byte of the input text whether it is meaningful or not. Other grammar languages (e.g., https://lark-parser.readthedocs.io/en/latest/tree_construction/#shaping-the-tree) filter out constants in the grammar by default because they don't convey useful information. This is analogous to regular expressions that return match groups but don't return characters outside the groups. (https://docs.python.org/3/howto/regex.html#grouping)
Using https://github.com/textX/Arpeggio/tree/master/examples/simple as an example, if program.simple is modified to have a parameterlist with three symbols (
function fak(n, m, x)
), the resulting parse tree is:parameterlist contains seven tokens
(
,n
,,
,m
,,
,x
, and)
, but the only information of interest is the three parametersn
,m
, andx
; the punctuation is just noise bloating up the tree. Lark discards punctuation by default, but allows rules to preserve it by beginning them with an exclamation mark, noting:It is possible to use visitors to transform trees into a more useful format, but it shouldn't be necessary in common cases that can be controlled by the grammar.
Feature Request: Add the ability for grammar rules to filter unneeded tokens from the parse tree.
The text was updated successfully, but these errors were encountered: