Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
badw-it
DHParser
Commits
c13ed3d3
Commit
c13ed3d3
authored
Aug 02, 2017
by
Eckhart Arnold
Browse files
- more LaTeX tests
parent
d434f8ae
Changes
4
Hide whitespace changes
Inline
Side-by-side
examples/LaTeX/LaTeX.ebnf
View file @
c13ed3d3
...
...
@@ -85,13 +85,13 @@ text_elements = command | text | block | inline_environment
inline_environment = known_inline_env | generic_inline_env
known_inline_env = inline_math
generic_inline_env = begin_inline_env { text_elements }+ §end_
inline_env
generic_inline_env =
(
begin_inline_env { text_elements }+ §end_
environment)
begin_inline_env = (-!LB begin_environment) | (begin_environment -!LB)
end_inline_env = (-!LB end_environment) | (end_environment -!LB) # ambiguity with genric_block when EOF
#
end_inline_env = (-!LB end_environment) | (end_environment -!LB) # ambiguity with genric_block when EOF
begin_environment = "\begin{" §NAME §"}"
end_environment = "\end{" §::NAME §"}"
inline_math = "$"
MATH
"$"
inline_math = "$"
/[^$]*/
"$"
#### commands ####
...
...
@@ -138,7 +138,6 @@ structural = "subsection" | "section" | "chapter" | "subsubsection"
CMDNAME = /\\(?:(?!_)\w)+/~
NAME = /\w+/~
MATH = /[\w_^{}[\]]*/~
ESCAPED = /\\[%$&_\/]/
BRACKETS = /[\[\]]/ # left or right square bracket: [ ]
...
...
examples/LaTeX/LaTeXCompiler.py
View file @
c13ed3d3
...
...
@@ -136,13 +136,13 @@ class LaTeXGrammar(Grammar):
inline_environment = known_inline_env | generic_inline_env
known_inline_env = inline_math
generic_inline_env = begin_inline_env { text_elements }+ §end_
inline_env
generic_inline_env =
(
begin_inline_env { text_elements }+ §end_
environment)
begin_inline_env = (-!LB begin_environment) | (begin_environment -!LB)
end_inline_env = (-!LB end_environment) | (end_environment -!LB) # ambiguity with genric_block when EOF
#
end_inline_env = (-!LB end_environment) | (end_environment -!LB) # ambiguity with genric_block when EOF
begin_environment = "\begin{" §NAME §"}"
end_environment = "\end{" §::NAME §"}"
inline_math = "$"
MATH
"$"
inline_math = "$"
/[^$]*/
"$"
#### commands ####
...
...
@@ -189,7 +189,6 @@ class LaTeXGrammar(Grammar):
CMDNAME = /\\(?:(?!_)\w)+/~
NAME = /\w+/~
MATH = /[\w_^{}[\]]*/~
ESCAPED = /\\[%$&_\/]/
BRACKETS = /[\[\]]/ # left or right square bracket: [ ]
...
...
@@ -209,7 +208,7 @@ class LaTeXGrammar(Grammar):
block_of_paragraphs
=
Forward
()
end_generic_block
=
Forward
()
text_elements
=
Forward
()
source_hash__
=
"7f
03d711d094ceb016614cec9e954fe3
"
source_hash__
=
"7f
6e1c72047e44b0b39db4d20f5186e2
"
parser_initialization__
=
"upon instantiation"
COMMENT__
=
r
'%.*(?:\n|$)'
WSP__
=
mixin_comment
(
whitespace
=
r
'[ \t]*(?:\n(?![ \t]*\n)[ \t]*)?'
,
comment
=
r
'%.*(?:\n|$)'
)
...
...
@@ -223,7 +222,6 @@ class LaTeXGrammar(Grammar):
TEXTCHUNK
=
RegExp
(
'[^
\\\\
%$&
\\
{
\\
}
\\
[
\\
]
\\
s
\\
n]+'
)
BRACKETS
=
RegExp
(
'[
\\
[
\\
]]'
)
ESCAPED
=
RegExp
(
'
\\\\
[%$&_/]'
)
MATH
=
RE
(
'[
\\
w_^{}[
\\
]]*'
)
NAME
=
Capture
(
RE
(
'
\\
w+'
))
CMDNAME
=
RE
(
'
\\\\
(?:(?!_)
\\
w)+'
)
structural
=
Alternative
(
Token
(
"subsection"
),
Token
(
"section"
),
Token
(
"chapter"
),
Token
(
"subsubsection"
),
Token
(
"paragraph"
),
Token
(
"subparagraph"
),
Token
(
"item"
))
...
...
@@ -240,12 +238,11 @@ class LaTeXGrammar(Grammar):
generic_command
=
Series
(
NegativeLookahead
(
no_command
),
CMDNAME
,
Optional
(
Series
(
Optional
(
Series
(
RE
(
''
),
config
)),
RE
(
''
),
block
)))
known_command
=
Alternative
(
footnote
,
includegraphics
,
caption
)
command
=
Alternative
(
known_command
,
generic_command
)
inline_math
=
Series
(
Token
(
"$"
),
MATH
,
Token
(
"$"
))
inline_math
=
Series
(
Token
(
"$"
),
RegExp
(
'[^$]*'
)
,
Token
(
"$"
))
end_environment
=
Series
(
Token
(
"
\\
end{"
),
Required
(
Pop
(
NAME
)),
Required
(
Token
(
"}"
)))
begin_environment
=
Series
(
Token
(
"
\\
begin{"
),
Required
(
NAME
),
Required
(
Token
(
"}"
)))
end_inline_env
=
Alternative
(
Series
(
NegativeLookbehind
(
LB
),
end_environment
),
Series
(
end_environment
,
NegativeLookbehind
(
LB
)))
begin_inline_env
=
Alternative
(
Series
(
NegativeLookbehind
(
LB
),
begin_environment
),
Series
(
begin_environment
,
NegativeLookbehind
(
LB
)))
generic_inline_env
=
Series
(
begin_inline_env
,
OneOrMore
(
text_elements
),
Required
(
end_
inline_
en
v
))
generic_inline_env
=
Series
(
begin_inline_env
,
OneOrMore
(
text_elements
),
Required
(
end_
environm
en
t
))
known_inline_env
=
Synonym
(
inline_math
)
inline_environment
=
Alternative
(
known_inline_env
,
generic_inline_env
)
text_elements
.
set
(
Alternative
(
command
,
text
,
block
,
inline_environment
))
...
...
examples/LaTeX/grammar_tests/test_
block
en
v
.ini
→
examples/LaTeX/grammar_tests/test_
environm
en
t
.ini
View file @
c13ed3d3
...
...
@@ -18,3 +18,31 @@
3
:
\begin{quote}
a
known
block
element
\end{quote}
[fail:block_environment]
1
:
"\begin{generic}inline
environment\end{generic}"
2
:
"""\begin{generic}inline
environment
\end{generic}
"""
3
:
"""\begin{generic}
invalid
enivronment
\end{generic}
"""
[match:inline_environment]
1
:
"\begin{generic}inline
environment\end{generic}"
2
:
"""\begin{generic}inline
environment
\end{generic}
"""
3
:
"$
inline
math
$"
[fail:inline_environment]
3
:
"""\begin{generic}
invalid
enivronment
\end{generic}
"""
examples/LaTeX/tst_LaTeX_grammar.py
View file @
c13ed3d3
...
...
@@ -42,3 +42,5 @@ if error_report:
print
(
'
\n
'
)
print
(
error_report
)
sys
.
exit
(
1
)
else
:
print
(
'
\n
SUCCESS! All tests passed :-)'
)
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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