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))
raise
# 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
https://raw.github.com/sametmax/Bat-belt/master/batbelt/hack.py
'''
import sys
from io import BytesIO
from contextlib import contextmanager
@contextmanager
def capture_output(stdout_to=None, stderr_to=None):
"""
Context manager that captures any printed output in the 'with' block.
:Exemple:
>>> with capture_output() as (stdout, stderr):
... print "hello",
...
>>> print stdout.getvalue().upper()
HELLO
>>> with capture_output() as (stdout, stderr):
# doctest: +IGNORE_EXCEPTION_DETAIL
... assert False
...
Traceback (most recent call last):
AssertionError
>>> from tempfile import NamedTemporaryFile
>>> f = NamedTemporaryFile(mode="rw+b")
>>> with capture_output(f) as (stdout, stderr):
... print "hello",
...
>>> print stdout.read()
hello
.. :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.
"""
try:
stdout, stderr = sys.stdout, sys.stderr
sys.stdout = c1 = stdout_to or BytesIO()
sys.stderr = c2 = stderr_to or BytesIO()
yield c1, c2
finally:
sys.stdout = stdout
sys.stderr = stderr
try:
c1.flush()
c1.seek(0)
except (ValueError, TypeError):
pass
try:
c2.flush()
c2.seek(0)
except (ValueError, TypeError):
pass
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