本文整理汇总了Python中Lexer.Lexer.build方法的典型用法代码示例。如果您正苦于以下问题:Python Lexer.build方法的具体用法?Python Lexer.build怎么用?Python Lexer.build使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Lexer.Lexer
的用法示例。
在下文中一共展示了Lexer.build方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Parser
# 需要导入模块: from Lexer import Lexer [as 别名]
# 或者: from Lexer.Lexer import build [as 别名]
class Parser(PLYParser):
def __init__(
self,
lex_optimize=True,
lextab='pyparser.lextab',
yacc_optimize=True,
yacctab='pyparser.yacctab',
yacc_debug=False):
""" Create a new parser.
Some arguments for controlling the debug/optimization
level of the parser are provided. The defaults are
tuned for release/performance mode.
The simple rules for using them are:
*) When tweaking the lexer/parser, set these to False
*) When releasing a stable parser, set to True
lex_optimize:
Set to False when you're modifying the lexer.
Otherwise, changes in the lexer won't be used, if
some lextab.py file exists.
When releasing with a stable lexer, set to True
to save the re-generation of the lexer table on
each run.
lextab:
Points to the lex table that's used for optimized
mode. Only if you're modifying the lexer and want
some tests to avoid re-generating the table, make
this point to a local lex table file (that's been
earlier generated with lex_optimize=True)
yacc_optimize:
Set to False when you're modifying the parser.
Otherwise, changes in the parser won't be used, if
some parsetab.py file exists.
When releasing with a stable parser, set to True
to save the re-generation of the parser table on
each run.
yacctab:
Points to the yacc table that's used for optimized
mode. Only if you're modifying the parser, make
this point to a local yacc table file
yacc_debug:
Generate a parser.out file that explains how yacc
built the parsing table from the ammar.
"""
self.logger = logging.getLogger('parser')
self.lex = Lexer(
error_func=self._lex_error_func,
type_lookup_func=self._lex_type_lookup_func)
self.lex.build(
optimize=lex_optimize,
lextab=lextab)
self.tokens = self.lex.tokens
self.parser = ply.yacc.yacc(
module=self,
start='statements',
debug=yacc_debug,
optimize=yacc_optimize,
tabmodule=yacctab)
self.addresses = []
self.accounts = {}
self.statements = 0
self.totalPages = 0
self.pdf_doc = PDFDoc()
self.pdf_doc.InitSecurityHandler()
self.timesRoman = Font.Create(self.pdf_doc.GetSDFDoc(), Font.e_times_roman, True)
self.courierNew = Font.Create(self.pdf_doc.GetSDFDoc(), Font.e_courier, True)
self.eb = ElementBuilder()
self.writer = ElementWriter()
def parse(self, text, filename='', debuglevel=0):
""" Parses a file and returns a pdf.
text:
A string containing the C source code
filename:
Name of the file being parsed (for meaningful
error messages)
debuglevel:
Debug level to yacc
"""
self.lex.filename = filename
self.lex.reset_lineno()
self._scope_stack = [set()]
self.logger.info("_______________________________________________")
self.logger.info("parsing input...")
if not text or text.isspace():
return []
else:
self.logger.info("_______________________________________________")
#.........这里部分代码省略.........