当前位置: 首页>>代码示例>>Python>>正文


Python antlr4.CommonTokenStream方法代码示例

本文整理汇总了Python中antlr4.CommonTokenStream方法的典型用法代码示例。如果您正苦于以下问题:Python antlr4.CommonTokenStream方法的具体用法?Python antlr4.CommonTokenStream怎么用?Python antlr4.CommonTokenStream使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在antlr4的用法示例。


在下文中一共展示了antlr4.CommonTokenStream方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __init__

# 需要导入模块: import antlr4 [as 别名]
# 或者: from antlr4 import CommonTokenStream [as 别名]
def __init__(self, source):
        self._stream = CommonTokenStream(LuaLexer(InputStream(source)))
        # contains a list of CommonTokens
        self._line_count: int = 0
        self._right_index: int = 0
        self._last_expr_type: int = None

        # following stack are used to backup values
        self._index_stack: List[int] = []
        self._right_index_stack: List[int] = []
        self.text: str = ''  # last token text
        self.type: int = -1  # last token type

        # contains expected token in case of invalid input code
        self._expected = []

        # comments waiting to be inserted into ast nodes
        self._comments_index_stack: List[int] = []
        self.comments: List[Comment] = []
        self._hidden_handled: bool = False
        self._hidden_handled_stack: List[bool] = [] 
开发者ID:boolangery,项目名称:py-lua-parser,代码行数:23,代码来源:builder.py

示例2: prg2py_after_preproc

# 需要导入模块: import antlr4 [as 别名]
# 或者: from antlr4 import CommonTokenStream [as 别名]
def prg2py_after_preproc(data, parser_start, input_filename):
    input_stream = antlr4.InputStream(data)
    lexer = VisualFoxpro9Lexer(input_stream)
    stream = antlr4.CommonTokenStream(lexer)
    parser = VisualFoxpro9Parser(stream)
    tree = run_parser(stream, parser, parser_start)
    TreeCleanVisitor().visit(tree)
    output_tree = PythonConvertVisitor(input_filename).visit(tree)
    if not isinstance(output_tree, list):
        return output_tree
    output = add_indents(output_tree, 0)
    options = autopep8.parse_args(['--max-line-length', '100000', '-'])
    output = autopep8.fix_code(output, options)
    tokens = list(tokenize.generate_tokens(io.StringIO(output).readline))
    for i, token in enumerate(tokens):
        token = list(token)
        if token[0] == tokenize.STRING and token[1].startswith('u'):
            token[1] = token[1][1:]
        tokens[i] = tuple(token)
    return tokenize.untokenize(tokens) 
开发者ID:mwisslead,项目名称:vfp2py,代码行数:22,代码来源:vfp2py.py

示例3: parseCSharp

# 需要导入模块: import antlr4 [as 别名]
# 或者: from antlr4 import CommonTokenStream [as 别名]
def parseCSharp(code):
  code = code.replace('\\n', '\n')
  parsedVersion = []
  stream = antlr4.InputStream(code)
  lexer = CSharp4Lexer(stream)
  toks = antlr4.CommonTokenStream(lexer)
  toks.fetch(500)

  identifiers = {}
  identCount = 0
  for token in toks.tokens:
    if token.type == 109:
      parsedVersion += ["CODE_INTEGER"]
    elif token.type == 111:
      parsedVersion += ["CODE_REAL"]
    elif token.type == 112:
      parsedVersion += ["CODE_CHAR"]
    elif token.type == 113:
      parsedVersion += ["CODE_STRING"]
    elif token.type == 9 or token.type == 7 or token.type == 6: # whitespace and comments and newline
      pass
    else:
      parsedVersion += [str(token.text)]

  return parsedVersion 
开发者ID:sriniiyer,项目名称:codenn,代码行数:27,代码来源:CSharpTemplate.py

示例4: run_parser

# 需要导入模块: import antlr4 [as 别名]
# 或者: from antlr4 import CommonTokenStream [as 别名]
def run_parser(quil):
    # type: (str) -> List[AbstractInstruction]
    """
    Run the ANTLR parser.

    :param str quil: a single or multiline Quil program
    :return: list of instructions that were parsed
    """
    # Step 1: Run the Lexer
    input_stream = InputStream(quil)
    lexer = QuilLexer(input_stream)
    stream = CommonTokenStream(lexer)

    # Step 2: Run the Parser
    parser = QuilParser(stream)
    parser.removeErrorListeners()
    parser.addErrorListener(CustomErrorListener())
    tree = parser.quil()

    # Step 3: Run the Listener
    pyquil_listener = PyQuilListener()
    walker = ParseTreeWalker()
    walker.walk(pyquil_listener, tree)

    return pyquil_listener.result 
开发者ID:rigetti,项目名称:pyquil,代码行数:27,代码来源:PyQuilListener.py

示例5: _parse_input_stream

# 需要导入模块: import antlr4 [as 别名]
# 或者: from antlr4 import CommonTokenStream [as 别名]
def _parse_input_stream(input_stream: antlr4.InputStream) -> RootNode:
    error_listener = _ConsoleErrorListener()

    lexer = JSONPathLexer(input_stream)

    lexer.addErrorListener(error_listener)

    token_stream = antlr4.CommonTokenStream(lexer)

    parser = _JSONPathParser(token_stream)

    parser.addErrorListener(error_listener)

    tree = parser.jsonpath()

    listener = _JSONPathListener(_stack=[])

    walker = antlr4.ParseTreeWalker()
    walker.walk(listener, tree)

    # pylint: disable=protected-access
    return listener._stack.pop()
    # pylint: enable=protected-access 
开发者ID:pacifica,项目名称:python-jsonpath2,代码行数:25,代码来源:__init__.py

示例6: process_sympy

# 需要导入模块: import antlr4 [as 别名]
# 或者: from antlr4 import CommonTokenStream [as 别名]
def process_sympy(sympy):

    matherror = MathErrorListener(sympy)

    stream = antlr4.InputStream(sympy)
    lex    = PSLexer(stream)
    lex.removeErrorListeners()
    lex.addErrorListener(matherror)

    tokens = antlr4.CommonTokenStream(lex)
    parser = PSParser(tokens)

    # remove default console error listener
    parser.removeErrorListeners()
    parser.addErrorListener(matherror)


    relation = parser.math().relation()
    expr = convert_relation(relation)

    return expr 
开发者ID:augustt198,项目名称:latex2sympy,代码行数:23,代码来源:process_latex.py

示例7: _parse_boolexpr

# 需要导入模块: import antlr4 [as 别名]
# 或者: from antlr4 import CommonTokenStream [as 别名]
def _parse_boolexpr(self, s):
        lexer = BoolExprLexer(
            antlr4.InputStream(s)
        )
        stream = antlr4.CommonTokenStream(lexer)
        parser = BoolExprParser(stream)
        tree = parser.booleanExpression()

        eb = _BECompiler()
        walker = antlr4.ParseTreeWalker()
        walker.walk(eb, tree)

        return eb.expression, eb.comparator, eb.value 
开发者ID:PaloAltoNetworks,项目名称:minemeld-core,代码行数:15,代码来源:interface.py

示例8: _parse_string

# 需要导入模块: import antlr4 [as 别名]
# 或者: from antlr4 import CommonTokenStream [as 别名]
def _parse_string(s):
    lexer = minemeld.ft.condition.BoolExprLexer(
        antlr4.InputStream(s)
    )
    stream = antlr4.CommonTokenStream(lexer)
    parser = minemeld.ft.condition.BoolExprParser(stream)
    tree = parser.booleanExpression()

    eb = ExprBuilder()
    walker = antlr4.ParseTreeWalker()
    walker.walk(eb, tree)

    return eb 
开发者ID:PaloAltoNetworks,项目名称:minemeld-core,代码行数:15,代码来源:test_ft_boolexpr.py

示例9: get_token_stream

# 需要导入模块: import antlr4 [as 别名]
# 或者: from antlr4 import CommonTokenStream [as 别名]
def get_token_stream(source: str) -> CommonTokenStream:
    """ Get the antlr token stream.
    """
    lexer = LuaLexer(InputStream(source))
    stream = CommonTokenStream(lexer)
    return stream 
开发者ID:boolangery,项目名称:py-lua-parser,代码行数:8,代码来源:ast.py

示例10: fill

# 需要导入模块: import antlr4 [as 别名]
# 或者: from antlr4 import CommonTokenStream [as 别名]
def fill(self, stream):
    """Helper function. antlr4.CommonTokenStream.fill should work, but
    it does not fetch all of the tokens. This is a replacement that works."""
    i = 0
    while stream.fetch(1):
      i += 1
    return i 
开发者ID:google,项目名称:clusterfuzz,代码行数:9,代码来源:antlr_tokenizer.py

示例11: tokenize

# 需要导入模块: import antlr4 [as 别名]
# 或者: from antlr4 import CommonTokenStream [as 别名]
def tokenize(self, data):
    """Takes in a file and uses the antlr lexer to return a list of tokens"""
    # Antlr expects a string, but test cases are not necessarily valid utf-8.
    try:
      lexer_input = antlr4.InputStream(data.decode('utf-8'))
    except UnicodeDecodeError:
      raise errors.AntlrDecodeError

    stream = antlr4.CommonTokenStream(self._lexer(lexer_input))
    end = self.fill(stream)
    tokens = stream.getTokens(0, end)
    return [token.text for token in tokens] 
开发者ID:google,项目名称:clusterfuzz,代码行数:14,代码来源:antlr_tokenizer.py

示例12: parse

# 需要导入模块: import antlr4 [as 别名]
# 或者: from antlr4 import CommonTokenStream [as 别名]
def parse(self, equel):
        lexer = equelLexer(equel)
        tokenstream = CommonTokenStream(lexer)
        parser = equelParser(tokenstream)
        parsetree = parser.equel()
        walker = ParseTreeWalker()
        listener = EQUELParserListener(self.engine)
        walker.walk(listener, parsetree)
        return parsetree 
开发者ID:thomaspatzke,项目名称:EQUEL,代码行数:11,代码来源:parser.py

示例13: parse

# 需要导入模块: import antlr4 [as 别名]
# 或者: from antlr4 import CommonTokenStream [as 别名]
def parse(self, query_string: str) -> list:
        lexer = evaql_lexer(InputStream(query_string))
        stream = CommonTokenStream(lexer)

        parser = evaql_parser(stream)
        # Attach error listener for debugging parser errrors
        # parser._listeners = [self._error_listener]

        tree = parser.root()

        return self._visitor.visit(tree) 
开发者ID:georgia-tech-db,项目名称:eva,代码行数:13,代码来源:parser.py

示例14: sub

# 需要导入模块: import antlr4 [as 别名]
# 或者: from antlr4 import CommonTokenStream [as 别名]
def sub():
    # Parse the input file
    input_stream = antlr4.FileStream("c.c")

    lexer = CLexer(input_stream)
    token_stream = antlr4.CommonTokenStream(lexer)

    parser = CParser(token_stream)


    errors = ErrorListener()
    parser.addErrorListener(errors)
    tree = parser.compilationUnit() 
开发者ID:FederatedAI,项目名称:FATE,代码行数:15,代码来源:ctest.py

示例15: preprocess_code

# 需要导入模块: import antlr4 [as 别名]
# 或者: from antlr4 import CommonTokenStream [as 别名]
def preprocess_code(data, encoding):
    input_stream = antlr4.InputStream(data)
    lexer = VisualFoxpro9Lexer(input_stream)
    stream = antlr4.CommonTokenStream(lexer)
    parser = VisualFoxpro9Parser(stream)
    tree = run_parser(stream, parser, 'preprocessorCode')
    visitor = PreprocessVisitor(encoding)
    visitor.tokens = visitor.visit(tree)
    return visitor 
开发者ID:mwisslead,项目名称:vfp2py,代码行数:11,代码来源:vfp2py.py


注:本文中的antlr4.CommonTokenStream方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。