Commit 502591de authored by Maxime Perrotin's avatar Maxime Perrotin
Browse files

remove samnmax module

antlr3 for python3 does not print anything on the console anymore
parent f46fe760
......@@ -45,7 +45,7 @@ from antlr3 import tree
from . import sdl92Lexer as lexer
from .sdl92Parser import sdl92Parser
from . import samnmax, ogAST
from . import ogAST
from .Asn1scc import parse_asn1, ASN1, create_choice_determinant_types
LOG = logging.getLogger(__name__)
......@@ -5259,15 +5259,7 @@ def add_to_ast(ast, filename=None, string=None):
except IOError as err:
LOG.error('Parser initialization error: ' + str(err))
# Use Sam & Max output capturer to get errors from ANTLR parser
# (not anymore, antlr3 for python3 does not print anything)
tree_rule_return_scope = parser.pr_file()
# with samnmax.capture_output() as (stdout, stderr):
# tree_rule_return_scope = parser.pr_file()
# for e in stderr:
# errors.append([e.strip()])
# for w in stdout:
# warnings.append([w.strip()])
# Root of the AST is of type antlr3.tree.CommonTree
# Add it as a child of the common tree
subtree = tree_rule_return_scope.tree
......@@ -5370,12 +5362,7 @@ def parseSingleElement(elem='', string='', context=None):
warnings = []
t = None
if parser:
#with samnmax.capture_output() as (stdout, stderr):
r = parser_ptr()
#for e in stderr:
# syntax_errors.append(e.strip())
#for w in stdout:
# syntax_errors.append(w.strip())
# Get the root of the Antlr-AST to build our own AST entry
root = r.tree
#print (isinstance(tree, antlr3.tree.CommonErrorNode))
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# vim: ai ts=4 sts=4 et sw=4 nu
This module was developed by Sam & Max
import sys
from io import BytesIO
from contextlib import contextmanager
def capture_output(stdout_to=None, stderr_to=None):
Context manager that captures any printed output in the 'with' block.
>>> with capture_output() as (stdout, stderr):
... print "hello",
>>> print stdout.getvalue().upper()
>>> with capture_output() as (stdout, stderr):
... assert False
Traceback (most recent call last):
>>> from tempfile import NamedTemporaryFile
>>> f = NamedTemporaryFile(mode="rw+b")
>>> with capture_output(f) as (stdout, stderr):
... print "hello",
>>> print
.. :warning: this is NOT thread safe.
.. :note: The file like objects containing the capture are not closed
automatically by this context manager. You are responsible
to do it.
It does not capture exception, so they bubble out and print the stack
trace anyway.
stdout, stderr = sys.stdout, sys.stderr
sys.stdout = c1 = stdout_to or BytesIO()
sys.stderr = c2 = stderr_to or BytesIO()
yield c1, c2
sys.stdout = stdout
sys.stderr = stderr
except (ValueError, TypeError):
except (ValueError, TypeError):
Supports Markdown
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