Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
nomad-lab
parser-fplo
Commits
989b4716
Commit
989b4716
authored
Nov 14, 2016
by
Henning Glawe
Browse files
import+setup json backend by default in FploInputParser
parent
e1240a9b
Changes
1
Hide whitespace changes
Inline
Side-by-side
parser/parser-fplo/FploInputParser.py
View file @
989b4716
...
...
@@ -17,7 +17,10 @@ import sys
import
os
import
logging
import
json
import
FploCommon
as
FploC
from
nomadcore.match_highlighter
import
ANSI
from
nomadcore.parser_backend
import
JsonParseEventsWriterBackend
from
nomadcore.caching_backend
import
CachingLevel
,
ActiveBackend
LOGGER
=
logging
.
getLogger
(
__name__
)
...
...
@@ -253,6 +256,16 @@ class AST_node(dict):
if
isinstance
(
child
,
AST_node
):
child
.
declaration_nomadmetainfo
(
output_file
,
child_namespace
)
def
data_nomadmetainfo
(
self
,
backend
,
namespace
):
if
self
.
name
is
not
None
:
child_namespace
=
namespace
+
'.'
+
self
.
name
else
:
child_namespace
=
namespace
for
child
in
self
.
child
:
if
isinstance
(
child
,
AST_node
):
child
.
data_nomadmetainfo
(
backend
,
child_namespace
)
class
AST_block
(
AST_node
):
"""generic block (sequence of statements) in AST"""
...
...
@@ -284,6 +297,11 @@ class AST_root(AST_block):
'}
\n
'
)
def
data_nomadmetainfo
(
self
,
backend
,
namespace
):
gIndex
=
backend
.
openSection
(
namespace
)
AST_node
.
data_nomadmetainfo
(
self
,
backend
,
namespace
)
backend
.
closeSection
(
namespace
,
gIndex
)
class
AST_section
(
AST_block
):
"""section block (sequence of statements) in AST"""
...
...
@@ -769,6 +787,13 @@ if __name__ == "__main__":
help
=
'write nomadmetainfo to stdout'
)
ARGPARSER
.
add_argument
(
'fplo_input'
,
type
=
str
,
nargs
=
'+'
,
help
=
'FPLO input files'
)
ARGS
=
ARGPARSER
.
parse_args
()
cachingLevelForMetaName
=
{}
for
name
in
FploC
.
META_INFO
.
infoKinds
:
# set all temporaries to caching-only
if
name
.
startswith
(
'x_fplo_t_'
):
cachingLevelForMetaName
[
name
]
=
CachingLevel
.
Cache
if
ARGS
.
annotate
:
ANNOTATEFILE
=
sys
.
stderr
else
:
...
...
@@ -790,3 +815,22 @@ if __name__ == "__main__":
sys
.
stderr
.
flush
()
if
ARGS
.
autogenerate_metainfo
:
parser
.
AST
.
declaration_nomadmetainfo
(
sys
.
stdout
,
'x_fplo_in'
)
else
:
outF
=
sys
.
stdout
jsonBackend
=
JsonParseEventsWriterBackend
(
FploC
.
META_INFO
,
outF
)
sys
.
stderr
.
write
(
'WTF2:'
+
str
(
FploC
.
META_INFO
)
+
'
\n
'
)
backend
=
ActiveBackend
.
activeBackend
(
metaInfoEnv
=
FploC
.
META_INFO
,
cachingLevelForMetaName
=
cachingLevelForMetaName
,
defaultDataCachingLevel
=
CachingLevel
.
ForwardAndCache
,
defaultSectionCachingLevel
=
CachingLevel
.
Forward
,
superBackend
=
jsonBackend
)
outF
.
write
(
"["
)
backend
.
startedParsingSession
(
'file://'
+
fplo_in
,
FploC
.
PARSER_INFO_DEFAULT
)
run_gIndex
=
backend
.
openSection
(
'section_run'
)
method_gIndex
=
backend
.
openSection
(
'section_method'
)
parser
.
AST
.
data_nomadmetainfo
(
backend
,
'x_fplo_in'
)
backend
.
closeSection
(
'section_method'
,
method_gIndex
)
backend
.
closeSection
(
'section_run'
,
run_gIndex
)
backend
.
finishedParsingSession
(
"ParseSuccess"
,
None
)
outF
.
write
(
"]"
)
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