Comments (4)
Yes, it parses successfully, but aliases then break or get ignored in the post processing. This has been on my radar for some time, but you are actually the first person I remember running into this issue so it's low priority.
from lark.
Nesting aliases inside of other constructs is not supported, and honestly should be throwing errors way earlier. Aliases should always be top level in a rule definition in an alternation (i.e. |
). I am not even sure what you want do with all the []
pairs, but those are causing problems here.
from lark.
Nesting aliases inside of other constructs is not supported, and honestly should be throwing errors way earlier.
I can see why that would be (I've hand-coded parsers many times), but I should point out that the Lark documentation doesn't even imply that, and this grammar parses successfully with the grammars/lark.lark
parser:
import lark
grammar = '''
start: pipesyn
pipesyn: ["any"i ("c"i ("a"i ("s"i ("e"i)? )? )? )? -> anycase]
| [("mixed"i
| "one"i ("s"i)?
| "zero"i ("s"i)?) -> mask]
| ["anyo"i ("f"i)? -> anyof]
'''
parser = lark.Lark(open("C:/Ross/Source/Pype/.venv/Lib/site-packages/lark/grammars/lark.lark"), parser="lalr")
parse_tree = parser.parse(grammar)
print(parse_tree.pretty())
yields:
start
rule
start
rule_params None
alias
expr
name pipesyn
None
None
None
rule
pipesyn
rule_params None
expansions
alias
expr
maybe
alias
expansion
expr
literal "any"i
None
None
expr
alias
expansion
expr
literal "c"i
None
None
... much elided ...
alias
expr
maybe
alias
expansion
expr
literal "anyo"i
None
None
expr
alias
expr
literal "f"i
None
None
None
?
anyof
None
None
None
from lark.
Yes, it parses successfully, but aliases then break or get ignored in the post processing.
Got it.
so it's low priority.
Agreed. I'll change my use of Lark to not do this, and I'll probably work up a documentation PR to clarify the use of rule aliases.
from lark.
Related Issues (20)
- Breaking changes / docs out of date HOT 7
- Can not chain or merge two transformers HOT 7
- Black formatter breaks Lark standalone parser generation
- Is it possible to parse a list of terminals? HOT 2
- Partial parsing HOT 11
- Is there a way to receive callbacks when a rule finishes
- Checking for allowed tokens with accepts() triggers transformer callbacks HOT 4
- Directly used literals not returned by transformer HOT 1
- Ability to search for parseable substrings HOT 6
- Improve IMAP ID parser HOT 13
- multiline strings in python3 grammar HOT 1
- Type of `tree.data` is wrong. HOT 1
- File input to `parse` method gives TypeError: object of type '_io.TextIOWrapper' has no len() HOT 5
- CPython 3.11.7 breaks `regex` module compatible pattern width calculations HOT 9
- Exclude classes in create_tranformer by user provided pedicate
- Make Token inherit from Generic. HOT 2
- Data structure for getting possible terminal sequences? HOT 2
- AssertionError when using templates HOT 4
- lark.exceptions.UnexpectedCharacters: No terminal matches ',' in the current parser context, at line 1 col 8 HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from lark.