How to use the ply.yacc.PlyLogger function in ply

To help you get started, we’ve selected a few ply examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github pywbem / pywbem / pywbem / _mof_compiler.py View on Github external
# the YACC table module file.
    write_tables = (out_dir is not None)

    # In yacc(), the 'debug' parameter controls the main error
    # messages to the 'errorlog' in addition to the debug messages
    # to the 'debuglog'. Because we want to see the error messages,
    # we enable debug but set the debuglog to the NullLogger.
    # To enable debug logging, set debuglog to some other logger
    # (ex. PlyLogger(sys.stdout) to generate log output.
    return yacc.yacc(optimize=_optimize,
                     tabmodule=_tabmodule,
                     outputdir=out_dir,
                     write_tables=write_tables,
                     debug=verbose,
                     debuglog=yacc.NullLogger(),
                     errorlog=yacc.PlyLogger(sys.stdout) if verbose
                     else yacc.NullLogger())
github Zeex / sampgdk / scripts / cidl.py View on Github external
super(UndeclaredConstError, self).__init__()
    self._constname = constname
    self._location = location

  @property
  def location(self):
    return self._location

  @property
  def constname(self):
    return self._constname

  def __str__(self):
    return "Undeclared constant '%s':\n%s" % (self._constname, self._location)

class Logger(ply.yacc.PlyLogger):
  def __init__(self):
    super(Logger, self).__init__(sys.stderr)

  def debug(self, msg, *args, **kwargs):
    pass

class Parser(object):
  keywords = {
    'const' : 'CONST',
  }

  tokens = [
    'BOOL',
    'FLOAT',
    'HEX',
    'OCT',
github john-tornblom / llvm-p86 / llvm_p86 / pre.py View on Github external
def parser(debug=False):
    if debug:
        logger = yacc.PlyLogger(sys.stderr)
    else:
        logger = yacc.NullLogger()

    tab = "llvm_p86._p86pre_parsetab"
    mod = sys.modules[__name__]
    return yacc.yacc(debuglog=logger,
                     errorlog=logger,
                     optimize=1,
                     tabmodule=tab,
                     outputdir=os.path.dirname(__file__),
                     module=mod)
github dabeaz / ply / ply / yacc.py View on Github external
def __init__(self,pdict,log=None):
        self.pdict      = pdict
        self.start      = None
        self.error_func = None
        self.tokens     = None
        self.modules    = {}
        self.grammar    = []
        self.error      = 0

        if log is None:
            self.log = PlyLogger(sys.stderr)
        else:
            self.log = log
github dabeaz / ply / ply / yacc.py View on Github external
def yacc(method='LALR', debug=yaccdebug, module=None, tabmodule=tab_module, start=None, 
         check_recursion=1, optimize=0, write_tables=1, debugfile=debug_file,outputdir='',
         debuglog=None, errorlog = None, picklefile=None):

    global parse                 # Reference to the parsing method of the last built parser

    # If pickling is enabled, table files are not created

    if picklefile:
        write_tables = 0

    if errorlog is None:
        errorlog = PlyLogger(sys.stderr)

    # Get the module dictionary used for the parser
    if module:
        _items = [(k,getattr(module,k)) for k in dir(module)]
        pdict = dict(_items)
    else:
        pdict = get_caller_module_dict(2)

    # Set start symbol if it's specified directly using an argument
    if start is not None:
        pdict['start'] = start

    # Collect parser information from the dictionary
    pinfo = ParserReflect(pdict,log=errorlog)
    pinfo.get_all()
github cournape / Bento / bento / parser / parser.py View on Github external
def _has_parser_changed(picklefile):
    # FIXME: private function to determine whether ply will need to write to
    # the pickled grammar file. Highly implementation dependent.
    from ply.yacc import PlyLogger, get_caller_module_dict, ParserReflect, YaccError, LRTable
    errorlog = PlyLogger(sys.stderr)

    pdict = get_caller_module_dict(2)

    # Collect parser information from the dictionary
    pinfo = ParserReflect(pdict, log=errorlog)
    pinfo.get_all()

    if pinfo.error:
        raise YaccError("Unable to build parser")

    # Check signature against table files (if any)
    signature = pinfo.signature()

    # Read the tables
    try:
        lr = LRTable()
github john-tornblom / llvm-p86 / llvm_p86 / grammar.py View on Github external
def parser(debug=False):
    if debug:
        logger = yacc.PlyLogger(sys.stderr)
    else:
        logger = yacc.NullLogger()

    tab = "llvm_p86._p86_parsetab"
    mod = sys.modules[__name__]
    return yacc.yacc(debuglog=logger,
                     errorlog=logger,
                     optimize=1,
                     tabmodule=tab,
                     outputdir=os.path.dirname(__file__),
                     module=mod)
github pywbem / pywbem / pywbem / _mof_compiler.py View on Github external
# Unfortunately, lex() does not support a write_tables argument. It
    # always tries to write the tables if optimize=True, so we supply a dummy
    # output directory. Always setting optimize=False is also not a good
    # solution because that causes the input table not to be used.
    if out_dir is None:
        out_dir = tempfile.gettempdir()

    # To debug lex you may set debug=True and enable the debuglog statement.
    # or other logger definition.
    return lex.lex(optimize=_optimize,
                   lextab=_lextab,
                   outputdir=out_dir,
                   debug=False,
                   # debuglog = lex.PlyLogger(sys.stdout),
                   errorlog=yacc.PlyLogger(sys.stdout) if verbose
                   else yacc.NullLogger())