Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
D
DHParser
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Iterations
Merge Requests
0
Merge Requests
0
Requirements
Requirements
List
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Operations
Operations
Incidents
Analytics
Analytics
Code Review
Insights
Issue
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
badw-it
DHParser
Commits
5ec9ebc8
Commit
5ec9ebc8
authored
Aug 20, 2017
by
Eckhart Arnold
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
- LaTeX tables can now be parsed (or so it ssems...)
parent
3fd3a2dc
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
20 additions
and
14 deletions
+20
-14
DHParser/parser.py
DHParser/parser.py
+6
-4
examples/LaTeX/LaTeX.ebnf
examples/LaTeX/LaTeX.ebnf
+4
-3
examples/LaTeX/LaTeXCompiler.py
examples/LaTeX/LaTeXCompiler.py
+10
-7
No files found.
DHParser/parser.py
View file @
5ec9ebc8
...
...
@@ -156,7 +156,9 @@ class HistoryRecord:
FAIL
=
"FAIL"
def
__init__
(
self
,
call_stack
:
List
[
'Parser'
],
node
:
Node
,
remaining
:
int
)
->
None
:
self
.
call_stack
=
call_stack
# type: List['Parser']
# copy call stack, dropping uninformative Forward-Parsers
self
.
call_stack
=
[
p
for
p
in
call_stack
if
p
.
ptype
!=
":Forward"
]
# type: List['Parser']
self
.
node
=
node
# type: Node
self
.
remaining
=
remaining
# type: int
document
=
call_stack
[
-
1
].
grammar
.
document__
if
call_stack
else
''
...
...
@@ -184,7 +186,6 @@ class HistoryRecord:
return
(
slice
(
-
self
.
remaining
-
self
.
node
.
len
,
-
self
.
remaining
)
if
self
.
node
else
slice
(
-
self
.
remaining
,
None
))
@
staticmethod
def
last_match
(
history
:
List
[
'HistoryRecord'
])
->
Optional
[
'HistoryRecord'
]:
"""
...
...
@@ -280,7 +281,7 @@ def add_parser_guard(parser_func):
if
grammar
.
history_tracking__
:
# don't track returning parsers except in case an error has occurred
if
grammar
.
moving_forward__
or
(
node
and
node
.
_errors
):
record
=
HistoryRecord
(
grammar
.
call_stack__
.
copy
()
,
node
,
len
(
rest
))
record
=
HistoryRecord
(
grammar
.
call_stack__
,
node
,
len
(
rest
))
grammar
.
history__
.
append
(
record
)
# print(record.stack, record.status, rest[:20].replace('\n', '|'))
grammar
.
call_stack__
.
pop
()
...
...
@@ -1365,7 +1366,8 @@ class Alternative(NaryOperator):
def
__init__
(
self
,
*
parsers
:
Parser
,
name
:
str
=
''
)
->
None
:
super
(
Alternative
,
self
).
__init__
(
*
parsers
,
name
=
name
)
assert
len
(
self
.
parsers
)
>=
1
assert
all
(
not
isinstance
(
p
,
Optional
)
for
p
in
self
.
parsers
)
# only the last alternative may be optional. Could this be checked at compile time?
assert
all
(
not
isinstance
(
p
,
Optional
)
for
p
in
self
.
parsers
[:
-
1
])
self
.
been_here
=
dict
()
# type: Dict[int, int]
def
__call__
(
self
,
text
:
str
)
->
Tuple
[
Node
,
str
]:
...
...
examples/LaTeX/LaTeX.ebnf
View file @
5ec9ebc8
...
...
@@ -69,13 +69,14 @@ quotation = ("\begin{quotation}" sequence §"\end{quotation}")
| ("\begin{quote}" sequence §"\end{quote}")
verbatim = "\begin{verbatim}" sequence §"\end{verbatim}"
tabular = "\begin{tabular}" tabular_config { tabular_row } §"\end{tabular}"
tabular_row = [multicolumn | tabular_cell] { "&" [multicolumn | tabular_cell] } "\\" [ hline | cline ]
tabular_cell = { text_element //~ }+
tabular_row = (multicolumn | tabular_cell) { "&" (multicolumn | tabular_cell) }
"\\" ( hline | { cline } )
tabular_cell = { text_element //~ }
tabular_config = "{" /[lcr|]+/~ §"}"
#### paragraphs and sequences of paragraphs ####
block_of_paragraphs =
/{/~ [sequence] §/}/
block_of_paragraphs =
"{" [sequence] §"}"
sequence = { (paragraph | block_environment ) [PARSEP] }+
paragraph = { !blockcmd (text_element | LINEFEED) //~ }+
text_element = text | block | inline_environment | command
...
...
examples/LaTeX/LaTeXCompiler.py
View file @
5ec9ebc8
...
...
@@ -118,13 +118,14 @@ class LaTeXGrammar(Grammar):
| ("\begin{quote}" sequence §"\end{quote}")
verbatim = "\begin{verbatim}" sequence §"\end{verbatim}"
tabular = "\begin{tabular}" tabular_config { tabular_row } §"\end{tabular}"
tabular_row = [multicolumn | tabular_cell] { "&" [multicolumn | tabular_cell] } "\\" [ hline | cline ]
tabular_cell = { text_element //~ }+
tabular_row = (multicolumn | tabular_cell) { "&" (multicolumn | tabular_cell) }
"\\" ( hline | { cline } )
tabular_cell = { text_element //~ }
tabular_config = "{" /[lcr|]+/~ §"}"
#### paragraphs and sequences of paragraphs ####
block_of_paragraphs =
/{/~ [sequence] §/}/
block_of_paragraphs =
"{" [sequence] §"}"
sequence = { (paragraph | block_environment ) [PARSEP] }+
paragraph = { !blockcmd (text_element | LINEFEED) //~ }+
text_element = text | block | inline_environment | command
...
...
@@ -218,7 +219,7 @@ class LaTeXGrammar(Grammar):
paragraph
=
Forward
()
tabular_config
=
Forward
()
text_element
=
Forward
()
source_hash__
=
"
4003d206b4ecbd76dd8be99df87af4c0
"
source_hash__
=
"
e493869bdc02eb835ec3ce1ebfb0a4ea
"
parser_initialization__
=
"upon instantiation"
COMMENT__
=
r
'%.*(?:\n|$)'
WSP__
=
mixin_comment
(
whitespace
=
r
'[ \t]*(?:\n(?![ \t]*\n)[ \t]*)?'
,
comment
=
r
'%.*(?:\n|$)'
)
...
...
@@ -269,10 +270,12 @@ class LaTeXGrammar(Grammar):
text_element
.
set
(
Alternative
(
text
,
block
,
inline_environment
,
command
))
paragraph
.
set
(
OneOrMore
(
Series
(
NegativeLookahead
(
blockcmd
),
Alternative
(
text_element
,
LINEFEED
),
RE
(
''
))))
sequence
=
OneOrMore
(
Series
(
Alternative
(
paragraph
,
block_environment
),
Optional
(
PARSEP
)))
block_of_paragraphs
.
set
(
Series
(
RE
(
'{'
),
Optional
(
sequence
),
Required
(
RegExp
(
'}'
))))
block_of_paragraphs
.
set
(
Series
(
Token
(
"{"
),
Optional
(
sequence
),
Required
(
Token
(
"}"
))))
tabular_config
.
set
(
Series
(
Token
(
"{"
),
RE
(
'[lcr|]+'
),
Required
(
Token
(
"}"
))))
tabular_cell
=
OneOrMore
(
Series
(
text_element
,
RE
(
''
)))
tabular_row
=
Series
(
Optional
(
Alternative
(
multicolumn
,
tabular_cell
)),
ZeroOrMore
(
Series
(
Token
(
"&"
),
Optional
(
Alternative
(
multicolumn
,
tabular_cell
)))),
Token
(
"
\\\\
"
),
Optional
(
Alternative
(
hline
,
cline
)))
tabular_cell
=
ZeroOrMore
(
Series
(
text_element
,
RE
(
''
)))
tabular_row
=
Series
(
Alternative
(
multicolumn
,
tabular_cell
),
ZeroOrMore
(
Series
(
Token
(
"&"
),
Alternative
(
multicolumn
,
tabular_cell
))),
Token
(
"
\\\\
"
),
Alternative
(
hline
,
ZeroOrMore
(
cline
)))
tabular
=
Series
(
Token
(
"
\\
begin{tabular}"
),
tabular_config
,
ZeroOrMore
(
tabular_row
),
Required
(
Token
(
"
\\
end{tabular}"
)))
verbatim
=
Series
(
Token
(
"
\\
begin{verbatim}"
),
sequence
,
Required
(
Token
(
"
\\
end{verbatim}"
)))
quotation
=
Alternative
(
Series
(
Token
(
"
\\
begin{quotation}"
),
sequence
,
Required
(
Token
(
"
\\
end{quotation}"
))),
Series
(
Token
(
"
\\
begin{quote}"
),
sequence
,
Required
(
Token
(
"
\\
end{quote}"
))))
...
...
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