Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
A
arpeggio-gm
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
backend
arpeggio-gm
Commits
f0ac5e4c
Commit
f0ac5e4c
authored
Oct 14, 2014
by
Igor Dejanovic
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
README update
parent
f22474b1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
34 additions
and
34 deletions
+34
-34
README.rst
README.rst
+34
-34
No files found.
README.rst
View file @
f0ac5e4c
...
...
@@ -41,51 +41,51 @@ Quick start
Write a grammar. There are several ways to do that:
- The canonical grammar format uses Python statements and expressions.
Each rule is specified as Python function which should return a data
structure that defines the rule. For example a grammar for simple
calculator can be written as:
- The canonical grammar format uses Python statements and expressions.
Each rule is specified as Python function which should return a data
structure that defines the rule. For example a grammar for simple
calculator can be written as:
.. code:: python
.. code:: python
from arpeggio import Optional, ZeroOrMore, OneOrMore, EOF
from arpeggio import RegExMatch as _
from arpeggio import Optional, ZeroOrMore, OneOrMore, EOF
from arpeggio import RegExMatch as _
def number(): return _(r'\d*\.\d*|\d+')
def factor(): return Optional(["+","-"]),
[number, ("(", expression, ")")]
def term(): return factor, ZeroOrMore(["*","/"], factor)
def expression(): return term, ZeroOrMore(["+", "-"], term)
def calc(): return OneOrMore(expression), EOF
def number(): return _(r'\d*\.\d*|\d+')
def factor(): return Optional(["+","-"]),
[number, ("(", expression, ")")]
def term(): return factor, ZeroOrMore(["*","/"], factor)
def expression(): return term, ZeroOrMore(["+", "-"], term)
def calc(): return OneOrMore(expression), EOF
The python lists in the data structure represent ordered choices while the tuples represent sequences from the PEG.
For terminal matches use plain strings or regular expressions.
The python lists in the data structure represent ordered choices while the tuples represent sequences from the PEG.
For terminal matches use plain strings or regular expressions.
- The same grammar could also be written using traditional textual PEG syntax like this:
- The same grammar could also be written using traditional textual PEG syntax like this:
::
::
number <- r'\d*\.\d*|\d+'; // this is a comment
factor <- ("+" / "-")?
(number / "(" expression ")");
term <- factor (( "*" / "/") factor)*;
expression <- term (("+" / "-") term)*;
calc <- expression+ EOF;
number <- r'\d*\.\d*|\d+'; // this is a comment
factor <- ("+" / "-")?
(number / "(" expression ")");
term <- factor (( "*" / "/") factor)*;
expression <- term (("+" / "-") term)*;
calc <- expression+ EOF;
- Or similar syntax but a little bit more readable like this:
- Or similar syntax but a little bit more readable like this:
::
::
number = r'\d*\.\d*|\d+' # this is a comment
factor = ("+" / "-")?
(number / "(" expression ")")
term = factor (( "*" / "/") factor)*
expression = term (("+" / "-") term)*
calc = expression+ EOF
number = r'\d*\.\d*|\d+' # this is a comment
factor = ("+" / "-")?
(number / "(" expression ")")
term = factor (( "*" / "/") factor)*
expression = term (("+" / "-") term)*
calc = expression+ EOF
The second and third options are implemented using canonical first form.
Feel free to implement your own grammar syntax if you don't like these
(see modules :code:`arpeggio.peg` and :code:`arpeggio.cleanpeg`).
The second and third options are implemented using canonical first form.
Feel free to implement your own grammar syntax if you don't like these
(see modules :code:`arpeggio.peg` and :code:`arpeggio.cleanpeg`).
Instantiate a parser. Parser works as grammar interpreter. There is no code generation.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment