Exemplo n.º 1
0
def parsespec(fname, outfname, debug=0):
    pylly_lextab.lineno = 1
    pylly_lextab.tabstop = 8
    pylly_lextab.codedata = ""
    pylly_lextab.curindent = [0]

    l = lexer.lexer(lexspec)
    l.setinput(fname)
    g = srgram.SRGram(gt.gramspec)
    p = glr.GLR(g)
    p.setlexer(l)

    from . import nfa
    gt.n = nfa.nfa()
    gt.globcode = ""
    gt.namedmachines = dict()
    gt.statenums = dict()
    gt.eofacts = []
    gt.statemachs = []
    gt.actions = [None]
    gt.relist = [None]

    try:
        tree = p.parse()
        if debug >= 10:
            glr.dottree(tree)
        helpers.proctree(tree, gt)
    except ParseError, e:
        raise SpecError("%s:%d: parse error at %r" %
                        (fname, pylly_lextab.lineno, e.str))
Exemplo n.º 2
0
def parsespec(fname, outfname, debug = 0) :
	pylly_lextab.lineno = 1
	pylly_lextab.tabstop = 8
	pylly_lextab.codedata = ""
	pylly_lextab.curindent = [0]

	l = lexer.lexer(lexspec)
	l.setinput(fname)
	g = srgram.SRGram(gt.gramspec)
	p = glr.GLR(g)
	p.setlexer(l)

	from . import nfa
	gt.n = nfa.nfa()
	gt.globcode = ""
	gt.namedmachines = dict()
	gt.statenums = dict()
	gt.eofacts = []
	gt.statemachs = []
	gt.actions = [None]
	gt.relist = [None]

	try :
		tree = p.parse()
		if debug >= 10 :
			glr.dottree(tree)
		helpers.proctree(tree, gt)
	except ParseError,e :
		raise SpecError("%s:%d: parse error at %r" % (fname, pylly_lextab.lineno, e.str))
Exemplo n.º 3
0
def get_lexer(filename):
    prefix = os.path.basename(filename)[:-4]
    temp = NamedTemporaryFile(prefix = prefix, suffix = "lextab.py")
    lex = {}
    pylly.parsespec(filename, temp.name)
    exec temp.read() in lex
    temp.close()
    return lexer.lexer(lex['lexspec'])
Exemplo n.º 4
0
def getlexer(specfname, debug=0, forcegen=0) :
	"""
	Generate a lexer table, construct a lexer for lexing fname and return it.
	Both the lexer and the generated module are returned.
	"""
	from pyggy import lexer

	if specfname[-4:] != ".pyl" :
		raise ApiError("bad spec filename %s" % specfname)
	tab = specfname[:-4] + "_lextab.py"
	generate(specfname, tab, debug=debug, forcegen=forcegen)
	l = _import(tab)
	return lexer.lexer(l.lexspec), l
Exemplo n.º 5
0
def parsespec(fname, outfname, debug = 0) :
	"""
	Parse the spec file, generate parsing tables and write it out.

	Debug levels less than 10 are for showing data about the parsed spec file
	levels 10 and higher are for showing internal data.
	"""
	l = lexer.lexer(pyggy_lextab.lexspec)
	l.setinput(fname)
	g = srgram.SRGram(gt.gramspec)
	p = glr.GLR(g)
	p.setlexer(l)

	try :
		tree = p.parse()
		# print the parse tree of the spec file
		if debug >= 11 :
			printcover = (debug >= 12)
			glr.dottree(tree, printcover)
		helpers.proctree(tree, gt)
	except ParseError,e :
		raise SpecError("%s:%d: parse error at %r" % (fname, pyggy_lextab.lineno, e.str))
Exemplo n.º 6
0
def parsespec(fname, outfname, debug=0):
    """
	Parse the spec file, generate parsing tables and write it out.

	Debug levels less than 10 are for showing data about the parsed spec file
	levels 10 and higher are for showing internal data.
	"""
    l = lexer.lexer(pyggy_lextab.lexspec)
    l.setinput(fname)
    g = srgram.SRGram(gt.gramspec)
    p = glr.GLR(g)
    p.setlexer(l)

    try:
        tree = p.parse()
        # print the parse tree of the spec file
        if debug >= 11:
            printcover = (debug >= 12)
            glr.dottree(tree, printcover)
        helpers.proctree(tree, gt)
    except ParseError, e:
        raise SpecError("%s:%d: parse error at %r" %
                        (fname, pyggy_lextab.lineno, e.str))