Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def main(options={},filename=False):
logger = yacc.NullLogger()
yacc.yacc(debug = logger, errorlog= logger )
data = get_input(filename)
ast = yacc.parse(data,lexer = lex.lex(nowarn=1))
if options.graph:
from codegen.graph import graph
graph(ast, filename)
try:
check(ast)
except Exception, e:
print "Error: %s" % e
sys.exit()
try:
p[0] = {"type": "ident", "name": p[1]}
def p_expression_const(p):
"expression : NUM"
p[0] = {"type": "const", "value": p[1]}
def p_error(p):
if p:
print(("Unexpected token: {}".format(p)))
else:
print("Unexpectedly reached end of input")
lexer = lex.lex(errorlog=yacc.NullLogger())
parser = yacc.yacc(errorlog=yacc.NullLogger())
def parse_expr(s):
return parser.parse(s)
Returns:
policy object or False (if parse error).
"""
try:
if definitions:
globals()['DEFINITIONS'] = definitions
else:
globals()['DEFINITIONS'] = naming.Naming(DEFAULT_DEFINITIONS)
globals()['_OPTIMIZE'] = optimize
globals()['_SHADE_CHECK'] = shade_check
lexer = lex.lex()
preprocessed_data = '\n'.join(_Preprocess(data, base_dir=base_dir))
p = yacc.yacc(write_tables=False, debug=0, errorlog=yacc.NullLogger())
policy = p.parse(preprocessed_data, lexer=lexer)
policy.filename = filename
return policy
except IndexError:
return False
def write_tables(self):
"""Write the parser and lexer tables.
"""
parse_dir, parse_mod = self._tables_location()
# Using optimized = 0 force yacc to compare the parser signature to the
# parse_tab signature and will update it if necessary.
yacc.yacc(method='LALR',
module=self,
start='enaml',
tabmodule=parse_mod,
outputdir=parse_dir,
optimize=0,
debug=0,
errorlog=yacc.NullLogger())
def __init__(self, **kwargs):
if 'tokens' in kwargs.keys(): # MANDATORY
self.tokens = kwargs['tokens']
kwargs.pop('tokens', None)
# debugging and logging http://www.dabeaz.com/ply/ply.html#ply_nn44
#self.parser = yacc.yacc(module=self, start='step', errorlog=yacc.NullLogger(), debug = True, debugfile='debug_file', **kwargs)
self.parser = yacc.yacc(module=self, start='step', errorlog=yacc.NullLogger(), debug = False, **kwargs)
def p_negation_arg(p):
''' negation_arg : type_selector
| universal
| hash
| class
| pseudo '''
def p_error(p):
raise SelectorSyntaxError('invalid syntax')
_parser = yacc.yacc(
debug=0, outputdir=_lex_dir, tabmodule=_parse_mod, optimize=1,
errorlog=yacc.NullLogger(),
)
def parse_selector(selector):
try:
r = _parser.parse(selector.strip(), debug=0, lexer=SelectorLexer())
return r
except SelectorSyntaxError:
print 'invalid selector: %s' % selector
def reset(self):
self.engine = yacc.yacc(
module=self,
start=self._start,
outputdir=self._tempdir,
write_tables=bool(self._tempdir),
debug=self._debug,
debuglog=log if self._debug else yacc.NullLogger(),
errorlog=log if self._debug else yacc.NullLogger(),
)
#
# Copyright (c) Microsoft Corporation. All Rights Reserved.
#
from ivy_dafny_lexer import *
from ivy_dafny_grammar import *
from ivy_utils import p_error, parse_with
import ply.yacc as yacc
import os
tabdir = os.path.dirname(os.path.abspath(__file__))
parser = yacc.yacc(start='top',tabmodule='ivy_dafny_parsetab',errorlog=yacc.NullLogger(),outputdir=tabdir)
def parse(s):
return parse_with(s,parser,lexer)
if __name__ == "__main__":
print parser.parse('var x : y; method P(x:T) ensures x == y; {x := y;}')
def __init__(self):
self.tokens = self.lexer().tokens
# Get a save directory for the lex and parse tables
parse_dir, parse_mod = self._tables_location()
self.parser = yacc.yacc(
method='LALR',
module=self,
start='enaml',
tabmodule=parse_mod,
outputdir=parse_dir,
optimize=1,
debug=0,
errorlog=yacc.NullLogger())
p[0] = p[1]
def p_all_items(p):
'''all_items : ALL
'''
p[0] = tree.AllItems()
# Error rule for syntax errors
def p_error(p):
raise YaccError("Syntax error in '{}'".format(str(p)))
# TODO: use file for logging
#yacc_errorlog = ply.yacc.PlyLogger(open(os.path.join(USER_CONFIG_DIR, "yacc.log"), "w"))
yacc_errorlog = yacc.NullLogger()
tokens # This line is needed to supress warning that 'tokens is unused'
lexer = build_lexer()
parsetabPyDir = consts.USER_CONFIG_DIR
parser = yacc.yacc(errorlog=yacc_errorlog,
debug=(1 if consts.DEBUG else 0), # If debug yacc creates parser.out log file
tabmodule="parsetab_query",
outputdir=parsetabPyDir)
def parse(text):
'''
Returns the root node of syntax tree, constructed from text.
'''
return parser.parse(text, lexer=lexer)