Comments (11)
There are two ways to define grammars in Arpeggio. A canonical is based on Python expressions and statements. The other is a textual PEG syntax and it is implemented using the Arpeggio itself (you can find the grammar of PEG language in the arpeggio.peg module). This implementation is based on PEG language and it requires that each rule terminates with ";" (see the rule function in the arpeggio.peg
).
The PEG grammar definition is parsed using Arpeggio instantiated with the grammar from arpeggio.peg
and during semantic analysis a new parser is constructed using your PEG definition. While a PEG should be more or less portable between different parsers if you want maximum performance use Python for grammar definition. Or, if you want to build a language give textX a try.
Best regards,
Igor
from arpeggio.
I'm not interested in python based functions as they will make it very specific to this lib.
Yes I agree for portability it should contain but it should be optional in lib itself. I mean if someone write it internally ignore that and make lib grammar reading easy.
<- can become =
Generic case ( Current version)
operation <- symbol operator (literal, functioncall);
expression <- literal operation functioncall;
expressionlist <- expression ("," expression)*;
Clean looking ( Requested version)
operation = symbol operator (literal, functioncall)
expression = literal operation functioncall
expressionlist = expression ("," expression)*
I guess I may be wrong but I found this style much everywhere so yes you can use it. Or provide some internal ways to support both. If it sounds interesting.
I want to parse PHP and similar web languages I'm not sure textX will be suited in that case or not. I don't want to parse full things only desired portion from PHP files and similar other langs. I'm not designing any lang just parsing few existing web langs.
Thanks,
Yash
from arpeggio.
I agree that this is cleaner looking. The current syntax is based on the original papers on PEG.
PEG language in arpeggio.peg
module is just one of the languages implemented in Arpeggio. Consider it as an example of what can be done in Arpeggio and change it as you see fit.
The syntax is very easy to alter. Make a copy of module arpeggio.peg
and remove ";" from the end of the rule and change "<-" to "=" in the LEFT_ARROW.
Use this altered module in place of the original arpeggio.peg
.
Let me now if this works for you.
Best,
Igor
from arpeggio.
Cool . Thank you. Let me try it. 😄
from arpeggio.
I followed your instruction and created a cleanpeg module with above mention changes.
Unfortunately it didn't work
Error log
http://pastebin.com/Z7m6FND9
Used grammer
// Grammar is defined using textual specification based on PEG language.
calc_grammar = """
number = r'\d_.\d_|\d+'
factor = ("+" / "-")? (number / "(" expression ")")
term = factor (( "" / "/") factor)
expression = term (("+" / "-") term)*
calc = expression+ EOF
"""
Imp point from log..I think is
!! EOF not matched.
Please let me know if I'm doing anything wrong.
Thanks,
Yash
from arpeggio.
Don't have time to look more thoroughly but I think that the grammar is ambiguous now.
The lhs of the next rule is matched as the part of the previous rule. Your best bet is to leave rule termination as is (";") so that the parser will now when the rule ends. The "=" is ok.
Regards,
Igor
from arpeggio.
Actually, the PEG grammar can't be ambiguous and in this case the lhs will always be matched as a part of previous rule so the "=" will never be matched. Still, the best is to leave rule termination (";") or you could alter the grammar to use syntax predicates (e.g. Not) to check if the next part of the rule is not followed by the "=" and to match is only if it is not. This will ensure that lhs of the following rule is never matched by the previous rule.
Hope this helps,
Igor
from arpeggio.
ok with ; and <- it works perfectly. It looks we need to change little more about handling ending of rules.
I've a idea internally you can check for /n if that is possible instead of ;
Thanks,
Yash
from arpeggio.
Just added change on branch cleanpeg. Check this commit.
Regards,
Igor
from arpeggio.
Great 👍 😄 Let me try it
from arpeggio.
Work superbly no error reported this time. Thank you.
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
- Comments in strings / regexps
- Suppressing rules doesn't seem to work
- 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.