Comments (4)
Hello adontz,
There are two issues you are having.
The first one is that you are using left-recursive grammar which is not possible with Arpeggio as it is recursive-descent (top-down) parser.
I just made a troubleshooting guide entry of how to handle left recursive rules.
The second issue is the infinite recursion in resolve
which should not happen. It looks like you hit a bug in the support for textual PEG syntax. I will investigate the issue as soon as I find some time.
In the meantime you could try to use a cannonical Python notation.
Here is something to get you going:
from __future__ import unicode_literals
from arpeggio import *
from arpeggio import RegExMatch as _
from arpeggio.cleanpeg import ParserPEG
def number_token(): return _(r'(\d+|\d+\.\d*|\d*\.\d+)')
def identifier_token(): return _(r'[a-zA-Z_][a-zA-Z0-9_]*')
def unqualified_identifier_expression(): return identifier_token
def qualified_identifier_expression(): return identifier_token, ZeroOrMore(".", identifier_token)
def unary_expression(): return [number_token, qualified_identifier_expression]
def lvalue_expression(): return qualified_identifier_expression
def rvalue_expression(): return expression
def expression(): return [compound_expression, unary_expression]
def compound_expression(): return qualified_identifier_expression,\
ZeroOrMore([method_call_par, index_par])
def method_call_par(): return "(", Optional( rvalue_expression, ZeroOrMore( ",", rvalue_expression)), ")"
def index_par(): return "[", rvalue_expression, ZeroOrMore( ",", rvalue_expression ), "]"
def belang(): return ZeroOrMore(expression), EOF
parser = ParserPython(belang, debug=True)
parser.parse('a [0](1)[2]')
from arpeggio.
Check this test.
grammar2
will parse the expression you need.
You could also start with your left-recursive grammar and do a proper lef-recursion removal.
from arpeggio.
BTW, If you are building a language I highly recommend you to use textX. It is built on top of Arpeggio and is specifically crafted for language implementation. The docs with tutorials is here.
from arpeggio.
Thank you very much!
from arpeggio.
Related Issues (20)
- Detect and report invalid grammars
- Question to the possible design of the reporting functionality
- 2.0.1: started require deprecated `pytest-runner` HOT 2
- Create .peg/.cleanpeg files from parsers written in python. HOT 1
- Create .peg/clean.peg files from parsers written in python. HOT 1
- Question: Is there a way to convert the graph of Arpeggio nodes into a state machine? HOT 1
- Please read this before asking questions
- help(parse_tree) trigger an AssertionError HOT 1
- Match until end of line HOT 2
- setup.py fails with UnicodeDecodeError
- ParserPEG with multiple root rules HOT 1
- How to define a recursive rule with Python style? HOT 2
- performance issue when parsing => grammar not good? HOT 7
- Repetitions with separators terminate on empty separator match
- 1.10.2: pytest warnings
- pytest-runner is not required
- Lookahead rules always showed as not matched in debug mode HOT 1
- Lookahead not working in OrderedChoice HOT 5
- Can PEG syntax (cleanpeg) use reduce_tree and memoization? HOT 6
- Unexpected NoMatch when suppressing a StrMatch from the parse tree 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 arpeggio.