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
2
Merge Requests
2
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
郭家华
arpeggio-gm
Commits
59b4c15d
Commit
59b4c15d
authored
Jan 19, 2011
by
Igor Dejanovic
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Switch to standard python logging facility.
parent
de1ffa74
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
44 additions
and
48 deletions
+44
-48
__init__.py
arpeggio/__init__.py
+16
-18
peg.py
arpeggio/peg.py
+12
-8
calc.py
examples/calc.py
+8
-11
calc_peg.py
examples/calc_peg.py
+2
-3
json.py
examples/json.py
+2
-3
peg_peg.py
examples/peg_peg.py
+2
-3
simple.py
examples/simple.py
+2
-2
No files found.
arpeggio/__init__.py
View file @
59b4c15d
...
@@ -12,8 +12,10 @@
...
@@ -12,8 +12,10 @@
import
re
import
re
import
bisect
import
bisect
import
logging
logger
=
logging
.
getLogger
(
'arpeggio'
)
DEBUG
=
False
DEFAULT_WS
=
'
\t\n\r
'
DEFAULT_WS
=
'
\t\n\r
'
class
ArpeggioError
(
Exception
):
class
ArpeggioError
(
Exception
):
...
@@ -47,10 +49,6 @@ class NoMatch(Exception):
...
@@ -47,10 +49,6 @@ class NoMatch(Exception):
self
.
_up
=
True
# By default when NoMatch is thrown we will go up the Parse Model Tree.
self
.
_up
=
True
# By default when NoMatch is thrown we will go up the Parse Model Tree.
def
_log
(
msg
):
if
DEBUG
:
print
msg
def
flatten
(
_iterable
):
def
flatten
(
_iterable
):
'''Flattening of python iterables.'''
'''Flattening of python iterables.'''
result
=
[]
result
=
[]
...
@@ -105,7 +103,7 @@ class ParsingExpression(object):
...
@@ -105,7 +103,7 @@ class ParsingExpression(object):
return
id
(
self
)
return
id
(
self
)
def
_parse_intro
(
self
,
parser
):
def
_parse_intro
(
self
,
parser
):
_lo
g
(
"Parsing
%
s"
%
self
.
name
)
logger
.
debu
g
(
"Parsing
%
s"
%
self
.
name
)
results
=
[]
results
=
[]
parser
.
_skip_ws
()
parser
.
_skip_ws
()
self
.
c_pos
=
parser
.
position
self
.
c_pos
=
parser
.
position
...
@@ -117,7 +115,7 @@ class ParsingExpression(object):
...
@@ -117,7 +115,7 @@ class ParsingExpression(object):
#If this position is already parsed by this parser expression than use
#If this position is already parsed by this parser expression than use
#the result
#the result
if
self
.
result_cache
.
has_key
(
self
.
c_pos
):
if
self
.
result_cache
.
has_key
(
self
.
c_pos
):
_lo
g
(
"Result for [
%
s,
%
s] founded in result_cache."
%
(
self
,
self
.
c_pos
))
logger
.
debu
g
(
"Result for [
%
s,
%
s] founded in result_cache."
%
(
self
,
self
.
c_pos
))
result
,
new_pos
=
self
.
result_cache
[
self
.
c_pos
]
result
,
new_pos
=
self
.
result_cache
[
self
.
c_pos
]
parser
.
position
=
new_pos
parser
.
position
=
new_pos
return
result
return
result
...
@@ -362,10 +360,10 @@ class RegExMatch(Match):
...
@@ -362,10 +360,10 @@ class RegExMatch(Match):
m
=
self
.
regex
.
match
(
parser
.
input
[
parser
.
position
:])
m
=
self
.
regex
.
match
(
parser
.
input
[
parser
.
position
:])
if
m
:
if
m
:
parser
.
position
+=
len
(
m
.
group
())
parser
.
position
+=
len
(
m
.
group
())
_lo
g
(
"Match
%
s at
%
d"
%
(
m
.
group
(),
self
.
c_pos
))
logger
.
debu
g
(
"Match
%
s at
%
d"
%
(
m
.
group
(),
self
.
c_pos
))
return
Terminal
(
self
.
rule
if
self
.
root
else
''
,
self
.
c_pos
,
m
.
group
())
return
Terminal
(
self
.
rule
if
self
.
root
else
''
,
self
.
c_pos
,
m
.
group
())
else
:
else
:
_lo
g
(
"NoMatch at
%
d"
%
self
.
c_pos
)
logger
.
debu
g
(
"NoMatch at
%
d"
%
self
.
c_pos
)
parser
.
_nm_raise
(
self
.
root
if
self
.
root
else
self
.
name
,
self
.
c_pos
,
parser
)
parser
.
_nm_raise
(
self
.
root
if
self
.
root
else
self
.
name
,
self
.
c_pos
,
parser
)
class
StrMatch
(
Match
):
class
StrMatch
(
Match
):
...
@@ -382,10 +380,10 @@ class StrMatch(Match):
...
@@ -382,10 +380,10 @@ class StrMatch(Match):
def
_parse
(
self
,
parser
):
def
_parse
(
self
,
parser
):
if
parser
.
input
[
parser
.
position
:]
.
startswith
(
self
.
to_match
):
if
parser
.
input
[
parser
.
position
:]
.
startswith
(
self
.
to_match
):
parser
.
position
+=
len
(
self
.
to_match
)
parser
.
position
+=
len
(
self
.
to_match
)
_lo
g
(
"Match
%
s at
%
d"
%
(
self
.
to_match
,
self
.
c_pos
))
logger
.
debu
g
(
"Match
%
s at
%
d"
%
(
self
.
to_match
,
self
.
c_pos
))
return
Terminal
(
self
.
rule
if
self
.
root
else
''
,
self
.
c_pos
,
self
.
to_match
)
return
Terminal
(
self
.
rule
if
self
.
root
else
''
,
self
.
c_pos
,
self
.
to_match
)
else
:
else
:
_lo
g
(
"NoMatch at
%
d"
%
self
.
c_pos
)
logger
.
debu
g
(
"NoMatch at
%
d"
%
self
.
c_pos
)
parser
.
_nm_raise
(
self
.
to_match
,
self
.
c_pos
,
parser
)
parser
.
_nm_raise
(
self
.
to_match
,
self
.
c_pos
,
parser
)
def
__str__
(
self
):
def
__str__
(
self
):
...
@@ -422,7 +420,7 @@ class EndOfFile(Match):
...
@@ -422,7 +420,7 @@ class EndOfFile(Match):
if
len
(
parser
.
input
)
==
parser
.
position
:
if
len
(
parser
.
input
)
==
parser
.
position
:
return
Terminal
(
self
.
rule
if
self
.
root
else
''
,
self
.
c_pos
,
'EOF'
)
return
Terminal
(
self
.
rule
if
self
.
root
else
''
,
self
.
c_pos
,
'EOF'
)
else
:
else
:
_lo
g
(
"EOF not matched."
)
logger
.
debu
g
(
"EOF not matched."
)
parser
.
_nm_raise
(
self
.
name
,
self
.
c_pos
,
parser
)
parser
.
_nm_raise
(
self
.
name
,
self
.
c_pos
,
parser
)
...
@@ -579,10 +577,10 @@ class Parser(object):
...
@@ -579,10 +577,10 @@ class Parser(object):
return
retval
return
retval
_lo
g
(
"ASG: First pass"
)
logger
.
debu
g
(
"ASG: First pass"
)
asg
=
tree_walk
(
self
.
parse_tree
)
asg
=
tree_walk
(
self
.
parse_tree
)
_lo
g
(
"ASG: Second pass"
)
logger
.
debu
g
(
"ASG: Second pass"
)
# Second pass
# Second pass
for
sa_name
,
asg_node
in
for_second_pass
:
for
sa_name
,
asg_node
in
for_second_pass
:
sem_actions
[
sa_name
]
.
second_pass
(
self
,
asg_node
)
sem_actions
[
sa_name
]
.
second_pass
(
self
,
asg_node
)
...
@@ -679,7 +677,7 @@ class ParserPython(Parser):
...
@@ -679,7 +677,7 @@ class ParserPython(Parser):
root
=
False
root
=
False
while
callable
(
expression
):
# Is this expression a parser rule?
while
callable
(
expression
):
# Is this expression a parser rule?
if
self
.
__rule_cache
.
has_key
(
expression
.
__name__
):
if
self
.
__rule_cache
.
has_key
(
expression
.
__name__
):
_lo
g
(
"Rule
%
s founded in cache."
%
expression
.
__name__
)
logger
.
debu
g
(
"Rule
%
s founded in cache."
%
expression
.
__name__
)
return
self
.
__rule_cache
.
get
(
expression
.
__name__
)
return
self
.
__rule_cache
.
get
(
expression
.
__name__
)
rule
=
expression
.
__name__
rule
=
expression
.
__name__
root
=
True
root
=
True
...
@@ -687,7 +685,7 @@ class ParserPython(Parser):
...
@@ -687,7 +685,7 @@ class ParserPython(Parser):
if
hasattr
(
expression
,
"sem"
):
if
hasattr
(
expression
,
"sem"
):
self
.
sem_actions
[
rule
]
=
expression
.
sem
self
.
sem_actions
[
rule
]
=
expression
.
sem
_lo
g
(
"push :
%
s"
%
rule
)
logger
.
debu
g
(
"push :
%
s"
%
rule
)
self
.
__rule_stack
.
append
(
rule
)
self
.
__rule_stack
.
append
(
rule
)
expression
=
expression
()
expression
=
expression
()
...
@@ -715,7 +713,7 @@ class ParserPython(Parser):
...
@@ -715,7 +713,7 @@ class ParserPython(Parser):
# in order to support recursive definitions
# in order to support recursive definitions
if
root
:
if
root
:
self
.
__rule_cache
[
rule
]
=
retval
self
.
__rule_cache
[
rule
]
=
retval
_lo
g
(
"New rule:
%
s ->
%
s"
%
(
rule
,
retval
.
__class__
.
__name__
))
logger
.
debu
g
(
"New rule:
%
s ->
%
s"
%
(
rule
,
retval
.
__class__
.
__name__
))
retval
.
nodes
=
[
self
.
_from_python
(
e
)
for
e
in
expression
]
retval
.
nodes
=
[
self
.
_from_python
(
e
)
for
e
in
expression
]
elif
type
(
expression
)
is
str
:
elif
type
(
expression
)
is
str
:
...
@@ -730,7 +728,7 @@ class ParserPython(Parser):
...
@@ -730,7 +728,7 @@ class ParserPython(Parser):
if
root
:
if
root
:
name
=
self
.
__rule_stack
.
pop
()
name
=
self
.
__rule_stack
.
pop
()
_lo
g
(
"pop:
%
s"
%
name
)
logger
.
debu
g
(
"pop:
%
s"
%
name
)
return
retval
return
retval
...
...
arpeggio/peg.py
View file @
59b4c15d
...
@@ -10,8 +10,10 @@
...
@@ -10,8 +10,10 @@
__all__
=
[
'ParserPEG'
]
__all__
=
[
'ParserPEG'
]
from
arpeggio
import
*
from
arpeggio
import
*
from
arpeggio
import
_log
from
arpeggio
import
RegExMatch
as
_
from
arpeggio
import
RegExMatch
as
_
import
logging
logger
=
logging
.
getLogger
(
'arpeggio.peg'
)
# PEG Grammar
# PEG Grammar
def
grammar
():
return
OneOrMore
(
rule
),
EOF
def
grammar
():
return
OneOrMore
(
rule
),
EOF
...
@@ -93,7 +95,7 @@ class SemOrderedChoice(PEGSemanticAction):
...
@@ -93,7 +95,7 @@ class SemOrderedChoice(PEGSemanticAction):
class
SemPrefix
(
PEGSemanticAction
):
class
SemPrefix
(
PEGSemanticAction
):
def
first_pass
(
self
,
parser
,
node
,
nodes
):
def
first_pass
(
self
,
parser
,
node
,
nodes
):
_lo
g
(
"Prefix:
%
s "
%
str
(
nodes
))
logger
.
debu
g
(
"Prefix:
%
s "
%
str
(
nodes
))
if
len
(
nodes
)
==
2
:
if
len
(
nodes
)
==
2
:
if
nodes
[
0
]
==
NOT
():
if
nodes
[
0
]
==
NOT
():
retval
=
Not
()
retval
=
Not
()
...
@@ -110,9 +112,9 @@ class SemPrefix(PEGSemanticAction):
...
@@ -110,9 +112,9 @@ class SemPrefix(PEGSemanticAction):
class
SemSufix
(
PEGSemanticAction
):
class
SemSufix
(
PEGSemanticAction
):
def
first_pass
(
self
,
parser
,
node
,
nodes
):
def
first_pass
(
self
,
parser
,
node
,
nodes
):
_lo
g
(
"Sufix :
%
s"
%
str
(
nodes
))
logger
.
debu
g
(
"Sufix :
%
s"
%
str
(
nodes
))
if
len
(
nodes
)
==
2
:
if
len
(
nodes
)
==
2
:
_lo
g
(
"Sufix :
%
s"
%
str
(
nodes
[
1
]))
logger
.
debu
g
(
"Sufix :
%
s"
%
str
(
nodes
[
1
]))
if
nodes
[
1
]
==
STAR
():
if
nodes
[
1
]
==
STAR
():
retval
=
ZeroOrMore
(
nodes
[
0
])
retval
=
ZeroOrMore
(
nodes
[
0
])
elif
nodes
[
1
]
==
QUESTION
():
elif
nodes
[
1
]
==
QUESTION
():
...
@@ -130,7 +132,7 @@ class SemSufix(PEGSemanticAction):
...
@@ -130,7 +132,7 @@ class SemSufix(PEGSemanticAction):
class
SemExpression
(
PEGSemanticAction
):
class
SemExpression
(
PEGSemanticAction
):
def
first_pass
(
self
,
parser
,
node
,
nodes
):
def
first_pass
(
self
,
parser
,
node
,
nodes
):
_lo
g
(
"Expression :
%
s"
%
str
(
nodes
))
logger
.
debu
g
(
"Expression :
%
s"
%
str
(
nodes
))
if
len
(
nodes
)
==
1
:
if
len
(
nodes
)
==
1
:
return
nodes
[
0
]
return
nodes
[
0
]
else
:
else
:
...
@@ -138,17 +140,17 @@ class SemExpression(PEGSemanticAction):
...
@@ -138,17 +140,17 @@ class SemExpression(PEGSemanticAction):
class
SemIdentifier
(
SemanticAction
):
class
SemIdentifier
(
SemanticAction
):
def
first_pass
(
self
,
parser
,
node
,
nodes
):
def
first_pass
(
self
,
parser
,
node
,
nodes
):
_lo
g
(
"Identifier
%
s."
%
node
.
value
)
logger
.
debu
g
(
"Identifier
%
s."
%
node
.
value
)
return
node
return
node
class
SemRegEx
(
SemanticAction
):
class
SemRegEx
(
SemanticAction
):
def
first_pass
(
self
,
parser
,
node
,
nodes
):
def
first_pass
(
self
,
parser
,
node
,
nodes
):
_lo
g
(
"RegEx
%
s."
%
nodes
[
2
]
.
value
)
logger
.
debu
g
(
"RegEx
%
s."
%
nodes
[
2
]
.
value
)
return
RegExMatch
(
nodes
[
2
]
.
value
)
return
RegExMatch
(
nodes
[
2
]
.
value
)
class
SemLiteral
(
SemanticAction
):
class
SemLiteral
(
SemanticAction
):
def
first_pass
(
self
,
parser
,
node
,
nodes
):
def
first_pass
(
self
,
parser
,
node
,
nodes
):
_lo
g
(
"Literal:
%
s"
%
node
.
value
)
logger
.
debu
g
(
"Literal:
%
s"
%
node
.
value
)
match_str
=
node
.
value
[
1
:
-
1
]
match_str
=
node
.
value
[
1
:
-
1
]
match_str
=
match_str
.
replace
(
"
\\
'"
,
"'"
)
match_str
=
match_str
.
replace
(
"
\\
'"
,
"'"
)
match_str
=
match_str
.
replace
(
"
\\\\
"
,
"
\\
"
)
match_str
=
match_str
.
replace
(
"
\\\\
"
,
"
\\
"
)
...
@@ -197,6 +199,8 @@ class ParserPEG(Parser):
...
@@ -197,6 +199,8 @@ class ParserPEG(Parser):
if
__name__
==
"__main__"
:
if
__name__
==
"__main__"
:
try
:
try
:
logging
.
basicConfig
(
level
=
logging
.
DEBUG
)
parser
=
ParserPython
(
grammar
,
None
)
parser
=
ParserPython
(
grammar
,
None
)
f
=
open
(
"peg_parser_model.dot"
,
"w"
)
f
=
open
(
"peg_parser_model.dot"
,
"w"
)
...
...
examples/calc.py
View file @
59b4c15d
...
@@ -13,7 +13,7 @@
...
@@ -13,7 +13,7 @@
from
arpeggio
import
*
from
arpeggio
import
*
from
arpeggio.export
import
PMDOTExport
,
PTDOTExport
from
arpeggio.export
import
PMDOTExport
,
PTDOTExport
from
arpeggio
import
RegExMatch
as
_
from
arpeggio
import
RegExMatch
as
_
from
arpeggio
import
_log
import
logging
def
number
():
return
_
(
r'\d*\.\d*|\d+'
)
def
number
():
return
_
(
r'\d*\.\d*|\d+'
)
def
factor
():
return
[
number
,
(
"("
,
expression
,
")"
)]
def
factor
():
return
[
number
,
(
"("
,
expression
,
")"
)]
...
@@ -25,13 +25,13 @@ def calc(): return expression, EndOfFile
...
@@ -25,13 +25,13 @@ def calc(): return expression, EndOfFile
class
ToFloat
(
SemanticAction
):
class
ToFloat
(
SemanticAction
):
'''Converts node value to float.'''
'''Converts node value to float.'''
def
first_pass
(
self
,
parser
,
node
,
nodes
):
def
first_pass
(
self
,
parser
,
node
,
nodes
):
_lo
g
(
"Converting
%
s."
%
node
.
value
)
logging
.
debu
g
(
"Converting
%
s."
%
node
.
value
)
return
float
(
node
.
value
)
return
float
(
node
.
value
)
class
Factor
(
SemanticAction
):
class
Factor
(
SemanticAction
):
'''Removes parenthesis if exists and returns what was contained inside.'''
'''Removes parenthesis if exists and returns what was contained inside.'''
def
first_pass
(
self
,
parser
,
node
,
nodes
):
def
first_pass
(
self
,
parser
,
node
,
nodes
):
_lo
g
(
"Factor
%
s"
%
nodes
)
logging
.
debu
g
(
"Factor
%
s"
%
nodes
)
if
nodes
[
0
]
==
"("
:
if
nodes
[
0
]
==
"("
:
return
nodes
[
1
]
return
nodes
[
1
]
else
:
else
:
...
@@ -43,14 +43,14 @@ class Term(SemanticAction):
...
@@ -43,14 +43,14 @@ class Term(SemanticAction):
Factor nodes will be already evaluated.
Factor nodes will be already evaluated.
'''
'''
def
first_pass
(
self
,
parser
,
node
,
nodes
):
def
first_pass
(
self
,
parser
,
node
,
nodes
):
_lo
g
(
"Term
%
s"
%
nodes
)
logging
.
debu
g
(
"Term
%
s"
%
nodes
)
term
=
nodes
[
0
]
term
=
nodes
[
0
]
for
i
in
range
(
2
,
len
(
nodes
),
2
):
for
i
in
range
(
2
,
len
(
nodes
),
2
):
if
nodes
[
i
-
1
]
==
"*"
:
if
nodes
[
i
-
1
]
==
"*"
:
term
*=
nodes
[
i
]
term
*=
nodes
[
i
]
else
:
else
:
term
/=
nodes
[
i
]
term
/=
nodes
[
i
]
_lo
g
(
"Term =
%
f"
%
term
)
logging
.
debu
g
(
"Term =
%
f"
%
term
)
return
term
return
term
class
Expr
(
SemanticAction
):
class
Expr
(
SemanticAction
):
...
@@ -59,7 +59,7 @@ class Expr(SemanticAction):
...
@@ -59,7 +59,7 @@ class Expr(SemanticAction):
Term nodes will be already evaluated.
Term nodes will be already evaluated.
'''
'''
def
first_pass
(
self
,
parser
,
node
,
nodes
):
def
first_pass
(
self
,
parser
,
node
,
nodes
):
_lo
g
(
"Expression
%
s"
%
nodes
)
logging
.
debu
g
(
"Expression
%
s"
%
nodes
)
expr
=
0
expr
=
0
start
=
0
start
=
0
# Check for unary + or - operator
# Check for unary + or - operator
...
@@ -72,7 +72,7 @@ class Expr(SemanticAction):
...
@@ -72,7 +72,7 @@ class Expr(SemanticAction):
else
:
else
:
expr
+=
nodes
[
i
]
expr
+=
nodes
[
i
]
_lo
g
(
"Expression =
%
f"
%
expr
)
logging
.
debu
g
(
"Expression =
%
f"
%
expr
)
return
expr
return
expr
class
Calc
(
SemanticAction
):
class
Calc
(
SemanticAction
):
...
@@ -88,10 +88,7 @@ calc.sem = Calc()
...
@@ -88,10 +88,7 @@ calc.sem = Calc()
if
__name__
==
"__main__"
:
if
__name__
==
"__main__"
:
try
:
try
:
import
arpeggio
logging
.
basicConfig
(
level
=
logging
.
DEBUG
)
# Setting DEBUG to true will show log messages.
arpeggio
.
DEBUG
=
True
# First we will make a parser - an instance of the calc parser model.
# First we will make a parser - an instance of the calc parser model.
# Parser model is given in the form of python constructs therefore we
# Parser model is given in the form of python constructs therefore we
...
...
examples/calc_peg.py
View file @
59b4c15d
...
@@ -16,6 +16,7 @@
...
@@ -16,6 +16,7 @@
from
arpeggio
import
*
from
arpeggio
import
*
from
arpeggio.peg
import
ParserPEG
from
arpeggio.peg
import
ParserPEG
from
arpeggio.export
import
PMDOTExport
,
PTDOTExport
from
arpeggio.export
import
PMDOTExport
,
PTDOTExport
import
logging
# Semantic actions
# Semantic actions
from
calc
import
ToFloat
,
Factor
,
Term
,
Expr
,
Calc
from
calc
import
ToFloat
,
Factor
,
Term
,
Expr
,
Calc
...
@@ -39,9 +40,7 @@ sem_actions = {
...
@@ -39,9 +40,7 @@ sem_actions = {
}
}
try
:
try
:
# Turning debugging on
logging
.
basicConfig
(
level
=
logging
.
DEBUG
)
import
arpeggio
arpeggio
.
DEBUG
=
True
# First we will make a parser - an instance of the calc parser model.
# First we will make a parser - an instance of the calc parser model.
# Parser model is given in the form of PEG notation therefore we
# Parser model is given in the form of PEG notation therefore we
...
...
examples/json.py
View file @
59b4c15d
...
@@ -36,6 +36,7 @@ value
...
@@ -36,6 +36,7 @@ value
from
arpeggio
import
*
from
arpeggio
import
*
from
arpeggio.export
import
PMDOTExport
,
PTDOTExport
from
arpeggio.export
import
PMDOTExport
,
PTDOTExport
from
arpeggio
import
RegExMatch
as
_
from
arpeggio
import
RegExMatch
as
_
import
logging
def
TRUE
():
return
"true"
def
TRUE
():
return
"true"
def
FALSE
():
return
"false"
def
FALSE
():
return
"false"
...
@@ -82,9 +83,7 @@ if __name__ == "__main__":
...
@@ -82,9 +83,7 @@ if __name__ == "__main__":
}
}
"""
"""
try
:
try
:
logging
.
basicConfig
(
level
=
logging
.
DEBUG
)
import
arpeggio
arpeggio
.
DEBUG
=
True
# Creating parser from parser model.
# Creating parser from parser model.
parser
=
ParserPython
(
jsonFile
)
parser
=
ParserPython
(
jsonFile
)
...
...
examples/peg_peg.py
View file @
59b4c15d
...
@@ -12,9 +12,9 @@
...
@@ -12,9 +12,9 @@
##############################################################################
##############################################################################
from
arpeggio
import
*
from
arpeggio
import
*
from
arpeggio.export
import
PMDOTExport
,
PTDOTExport
from
arpeggio.export
import
PMDOTExport
,
PTDOTExport
from
arpeggio
import
_log
from
arpeggio
import
RegExMatch
as
_
from
arpeggio
import
RegExMatch
as
_
from
arpeggio.peg
import
ParserPEG
from
arpeggio.peg
import
ParserPEG
import
logging
# Semantic actions
# Semantic actions
from
arpeggio.peg
import
SemGrammar
,
SemRule
,
SemOrderedChoice
,
SemSequence
,
SemPrefix
,
\
from
arpeggio.peg
import
SemGrammar
,
SemRule
,
SemOrderedChoice
,
SemSequence
,
SemPrefix
,
\
...
@@ -66,8 +66,7 @@ peg_grammar = r"""
...
@@ -66,8 +66,7 @@ peg_grammar = r"""
try
:
try
:
import
arpeggio
logging
.
basicConfig
(
level
=
logging
.
DEBUG
)
arpeggio
.
DEBUG
=
True
# ParserPEG will use ParserPython to parse peg_grammar definition and
# ParserPEG will use ParserPython to parse peg_grammar definition and
# create parser_model for parsing PEG based grammars
# create parser_model for parsing PEG based grammars
...
...
examples/simple.py
View file @
59b4c15d
...
@@ -12,6 +12,7 @@
...
@@ -12,6 +12,7 @@
from
arpeggio
import
*
from
arpeggio
import
*
from
arpeggio.export
import
PMDOTExport
,
PTDOTExport
from
arpeggio.export
import
PMDOTExport
,
PTDOTExport
from
arpeggio
import
RegExMatch
as
_
from
arpeggio
import
RegExMatch
as
_
import
logging
def
comment
():
return
[
_
(
"//.*"
),
_
(
"/
\
*.*
\
*/"
)]
def
comment
():
return
[
_
(
"//.*"
),
_
(
"/
\
*.*
\
*/"
)]
def
literal
():
return
_
(
r'\d*\.\d*|\d+|".*?"'
)
def
literal
():
return
_
(
r'\d*\.\d*|\d+|".*?"'
)
...
@@ -30,8 +31,7 @@ def function(): return Kwd("function"), symbol, parameterlist, block
...
@@ -30,8 +31,7 @@ def function(): return Kwd("function"), symbol, parameterlist, block
def
simpleLanguage
():
return
function
def
simpleLanguage
():
return
function
try
:
try
:
import
arpeggio
logging
.
basicConfig
(
level
=
logging
.
DEBUG
)
arpeggio
.
DEBUG
=
True
# Parser instantiation. simpleLanguage is root definition and comment is
# Parser instantiation. simpleLanguage is root definition and comment is
# grammar rule for comments.
# grammar rule for comments.
...
...
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