Commit 989b4716 authored by Henning Glawe's avatar Henning Glawe
Browse files

import+setup json backend by default in FploInputParser

parent e1240a9b
...@@ -17,7 +17,10 @@ import sys ...@@ -17,7 +17,10 @@ import sys
import os import os
import logging import logging
import json import json
import FploCommon as FploC
from nomadcore.match_highlighter import ANSI from nomadcore.match_highlighter import ANSI
from nomadcore.parser_backend import JsonParseEventsWriterBackend
from nomadcore.caching_backend import CachingLevel, ActiveBackend
LOGGER = logging.getLogger(__name__) LOGGER = logging.getLogger(__name__)
...@@ -253,6 +256,16 @@ class AST_node(dict): ...@@ -253,6 +256,16 @@ class AST_node(dict):
if isinstance(child, AST_node): if isinstance(child, AST_node):
child.declaration_nomadmetainfo(output_file, child_namespace) 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): class AST_block(AST_node):
"""generic block (sequence of statements) in AST""" """generic block (sequence of statements) in AST"""
...@@ -284,6 +297,11 @@ class AST_root(AST_block): ...@@ -284,6 +297,11 @@ class AST_root(AST_block):
'}\n' '}\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): class AST_section(AST_block):
"""section block (sequence of statements) in AST""" """section block (sequence of statements) in AST"""
...@@ -769,6 +787,13 @@ if __name__ == "__main__": ...@@ -769,6 +787,13 @@ if __name__ == "__main__":
help='write nomadmetainfo to stdout') help='write nomadmetainfo to stdout')
ARGPARSER.add_argument('fplo_input', type=str, nargs='+', help='FPLO input files') ARGPARSER.add_argument('fplo_input', type=str, nargs='+', help='FPLO input files')
ARGS = ARGPARSER.parse_args() 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: if ARGS.annotate:
ANNOTATEFILE = sys.stderr ANNOTATEFILE = sys.stderr
else: else:
...@@ -790,3 +815,22 @@ if __name__ == "__main__": ...@@ -790,3 +815,22 @@ if __name__ == "__main__":
sys.stderr.flush() sys.stderr.flush()
if ARGS.autogenerate_metainfo: if ARGS.autogenerate_metainfo:
parser.AST.declaration_nomadmetainfo(sys.stdout, 'x_fplo_in') 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("]")
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment