Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
badw-it
DHParser
Commits
d63e24d4
Commit
d63e24d4
authored
May 26, 2021
by
di68kap
Browse files
Merge remote-tracking branch 'origin/development' into development
parents
67fc5023
0531aa7f
Changes
1
Hide whitespace changes
Inline
Side-by-side
examples/LaTeX/LaTeXParser.py
View file @
d63e24d4
...
...
@@ -50,7 +50,7 @@ from DHParser import start_logging, suspend_logging, resume_logging, is_filename
has_attr
,
has_parent
,
ThreadLocalSingletonFactory
,
Error
,
canonical_error_strings
,
\
has_errors
,
apply_unless
,
WARNING
,
ERROR
,
FATAL
,
EMPTY_NODE
,
TreeReduction
,
CombinedParser
,
\
PreprocessorResult
,
preprocess_includes
,
gen_find_include_func
,
flatten_sxpr
,
\
replace_content_with
gen_neutral_srcmap_func
,
make_preprocessor
,
chain_preprocessors
#######################################################################
...
...
@@ -60,16 +60,25 @@ from DHParser import start_logging, suspend_logging, resume_logging, is_filename
#######################################################################
R
X_TEX_INPUT
=
r
'\\input{(?P<name>.*)}'
R
E_INCLUDE
=
r
'\\input{(?P<name>.*)}'
def
LaTeXPreprocessor
(
text
:
str
,
file_name
:
str
)
->
PreprocessorResult
:
find_includes
=
gen_find_include_func
(
RX_TEX_INPUT
,
LaTeXGrammar
.
comment_rx__
)
return
preprocess_includes
(
text
,
file_name
,
find_includes
)
def
LaTeXTokenizer
(
original_text
)
->
str
:
return
original_text
def
preprocessor_factory
()
->
PreprocessorFunc
:
find_next_include
=
gen_find_include_func
(
RE_INCLUDE
,
LaTeXGrammar
.
comment_rx__
)
include_prep
=
partial
(
preprocess_includes
,
find_next_include
=
find_next_include
)
LaTeXPreprocessor
=
make_preprocessor
(
LaTeXTokenizer
)
return
chain_preprocessors
(
include_prep
,
LaTeXPreprocessor
)
_raw_preprocessor
=
ThreadLocalSingletonFactory
(
preprocessor_factory
,
ident
=
1
)
def
get_preprocessor
()
->
PreprocessorFunc
:
return
LaTeXP
reprocessor
return
_raw_p
reprocessor
()
#######################################################################
...
...
@@ -238,6 +247,7 @@ class LaTeXGrammar(Grammar):
_raw_grammar
=
ThreadLocalSingletonFactory
(
LaTeXGrammar
,
ident
=
1
)
def
get_grammar
()
->
LaTeXGrammar
:
grammar
=
_raw_grammar
()
if
get_config_value
(
'resume_notices'
):
...
...
@@ -245,7 +255,8 @@ def get_grammar() -> LaTeXGrammar:
elif
get_config_value
(
'history_tracking'
):
set_tracer
(
grammar
,
trace_history
)
return
grammar
def
parse_LaTeX
(
document
,
start_parser
=
"root_parser__"
,
*
,
complete_match
=
True
):
return
get_grammar
()(
document
,
start_parser
,
complete_match
)
...
...
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