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
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 is not None:
child_namespace = namespace + '.' +
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):
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
......@@ -790,3 +815,22 @@ if __name__ == "__main__":
if ARGS.autogenerate_metainfo:
parser.AST.declaration_nomadmetainfo(sys.stdout, 'x_fplo_in')
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)
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)
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