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
aadc7396
Commit
aadc7396
authored
Jan 08, 2015
by
Igor Dejanovic
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added information about file name to facilitate better error reporting.
parent
3791d3ba
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
23 additions
and
7 deletions
+23
-7
__init__.py
arpeggio/__init__.py
+23
-7
No files found.
arpeggio/__init__.py
View file @
aadc7396
...
@@ -63,7 +63,7 @@ class NoMatch(Exception):
...
@@ -63,7 +63,7 @@ class NoMatch(Exception):
occurred.
occurred.
parser (Parser): An instance of a parser.
parser (Parser): An instance of a parser.
exp_str(str): What is expected? If not given it is deduced from
exp_str(str): What is expected? If not given it is deduced from
the rule.
the rule.
Used in error messages.
soft(bool): Used to indicate soft no match exception.
soft(bool): Used to indicate soft no match exception.
"""
"""
def
__init__
(
self
,
rule
,
position
,
parser
,
exp_str
=
None
,
soft
=
False
):
def
__init__
(
self
,
rule
,
position
,
parser
,
exp_str
=
None
,
soft
=
False
):
...
@@ -89,10 +89,17 @@ class NoMatch(Exception):
...
@@ -89,10 +89,17 @@ class NoMatch(Exception):
self
.
_up
=
True
self
.
_up
=
True
def
__str__
(
self
):
def
__str__
(
self
):
return
"Expected '{}' at position {} => '{}'."
\
if
self
.
parser
.
file_name
:
.
format
(
self
.
exp_str
,
return
"Expected '{}' at {}{} => '{}'."
\
text
(
self
.
parser
.
pos_to_linecol
(
self
.
position
)),
.
format
(
self
.
exp_str
,
self
.
parser
.
context
(
position
=
self
.
position
))
self
.
parser
.
file_name
,
text
(
self
.
parser
.
pos_to_linecol
(
self
.
position
)),
self
.
parser
.
context
(
position
=
self
.
position
))
else
:
return
"Expected '{}' at position {} => '{}'."
\
.
format
(
self
.
exp_str
,
text
(
self
.
parser
.
pos_to_linecol
(
self
.
position
)),
self
.
parser
.
context
(
position
=
self
.
position
))
def
__unicode__
(
self
):
def
__unicode__
(
self
):
return
self
.
__str__
()
return
self
.
__str__
()
...
@@ -1188,11 +1195,20 @@ class Parser(object):
...
@@ -1188,11 +1195,20 @@ class Parser(object):
else
:
else
:
self
.
_ws
=
self
.
_real_ws
self
.
_ws
=
self
.
_real_ws
def
parse
(
self
,
_input
):
def
parse
(
self
,
_input
,
file_name
=
None
):
"""
Parses input and produces parse tree.
Args:
_input(str): An input string to parse.
file_name(str): If input is loaded from file this can be
set to file name. It is used in error messages.
"""
self
.
position
=
0
# Input position
self
.
position
=
0
# Input position
self
.
nm
=
None
# Last NoMatch exception
self
.
nm
=
None
# Last NoMatch exception
self
.
line_ends
=
[]
self
.
line_ends
=
[]
self
.
input
=
_input
self
.
input
=
_input
self
.
file_name
=
file_name
self
.
parser_model
.
clear_cache
()
self
.
parser_model
.
clear_cache
()
if
self
.
comments_model
:
if
self
.
comments_model
:
self
.
comments_model
.
clear_cache
()
self
.
comments_model
.
clear_cache
()
...
@@ -1216,7 +1232,7 @@ class Parser(object):
...
@@ -1216,7 +1232,7 @@ class Parser(object):
with
codecs
.
open
(
file_name
,
'r'
,
'utf-8'
)
as
f
:
with
codecs
.
open
(
file_name
,
'r'
,
'utf-8'
)
as
f
:
content
=
f
.
read
()
content
=
f
.
read
()
return
self
.
parse
(
content
)
return
self
.
parse
(
content
,
file_name
=
file_name
)
def
getASG
(
self
,
sem_actions
=
None
,
defaults
=
True
):
def
getASG
(
self
,
sem_actions
=
None
,
defaults
=
True
):
"""
"""
...
...
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