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


Python Lexer.Lexer类代码示例

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


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

示例1: test_math_symbols

def test_math_symbols():
    lexer = Lexer('+ - * /')

    assert lexer.next_token() == Token(TokenTypes.ADD)
    assert lexer.next_token() == Token(TokenTypes.SUB)
    assert lexer.next_token() == Token(TokenTypes.MUL)
    assert lexer.next_token() == Token(TokenTypes.DIV)
开发者ID:Demotivated,项目名称:parsec,代码行数:7,代码来源:test_lexer.py

示例2: test_next_token

def test_next_token():
    lexer = Lexer('1+ 3')

    assert lexer.next_token() == Token(TokenTypes.INT, 1)
    assert lexer.next_token() == Token(TokenTypes.ADD)
    assert lexer.next_token() == Token(TokenTypes.INT, 3)
    assert lexer.next_token() == Token(TokenTypes.EOF)
开发者ID:Demotivated,项目名称:parsec,代码行数:7,代码来源:test_lexer.py

示例3: __init__

 def __init__(self, parent=None):
     """
     Constructor
     
     @param parent parent widget of this lexer
     """
     QsciLexerSQL.__init__(self, parent)
     Lexer.__init__(self)
开发者ID:usc-bbdl,项目名称:R01_HSC_cadaver_system,代码行数:8,代码来源:LexerSQL.py

示例4: test_skip_whitespace

def test_skip_whitespace():
    lexer = Lexer('1   +3 9')

    assert lexer.next_token() == Token(TokenTypes.INT, 1)
    assert lexer.next_token() == Token(TokenTypes.ADD)
    assert lexer.next_token() == Token(TokenTypes.INT, 3)
    assert lexer.next_token() == Token(TokenTypes.INT, 9)
    assert lexer.next_token() == Token(TokenTypes.EOF)
开发者ID:Demotivated,项目名称:parsec,代码行数:8,代码来源:test_lexer.py

示例5: getTokens

 def getTokens(self, filename):
     """ lex file and return list of tokens (tokenizer) """
     lexer = Lexer()
     try:
         tokenizer = lexer.fileScan(filename)
     except Exception, inst:
         sys.stderr.write(str(inst)+'\n')
         sys.exit(1)
开发者ID:bjarneh,项目名称:moo,代码行数:8,代码来源:Parser.py

示例6: evaluate

 def evaluate(self):
     #lexer
     lexer = Lexer(self.input)
     token_list = lexer.lex()
 
     #parser
     parser = Parser(token_list)
     value = parser.parse()
     return value
开发者ID:dbarisakkurt,项目名称:interpreter-tutorial,代码行数:9,代码来源:Interpreter.py

示例7: testScanNegativeInteger

    def testScanNegativeInteger(self):
        lexer = Lexer()
        lexer.input("def number = -102")
        (tokens, errors) = lexer.allTokens()

        # assert that no error occured
        self.assertEqual(errors, [])

        # assert correct token scanning
        self.assertEqual(types(tokens), 'DEF ID = INT')
开发者ID:z-lang,项目名称:z-lang,代码行数:10,代码来源:LexerTest.py

示例8: __init__

 def __init__(self, parent=None):
     """
     Constructor
     
     @param parent parent widget of this lexer
     """
     QsciLexerVHDL.__init__(self, parent)
     Lexer.__init__(self)
     
     self.commentString = QString("--")
开发者ID:usc-bbdl,项目名称:R01_HSC_cadaver_system,代码行数:10,代码来源:LexerVHDL.py

示例9: testScanVariable

    def testScanVariable(self):
        lexer = Lexer()
        lexer.input("def x = y")
        (tokens, errors) = lexer.allTokens()

        # assert that no error occured
        self.assertEqual(errors, [])

        # assert correct token scanning
        self.assertEqual(types(tokens), 'DEF ID = ID')
开发者ID:z-lang,项目名称:z-lang,代码行数:10,代码来源:LexerTest.py

示例10: testScanBooleanTrue

    def testScanBooleanTrue(self):
        lexer = Lexer()
        lexer.input("def boolean = true")
        (tokens, errors) = lexer.allTokens()

        # assert that no error occured
        self.assertEqual(errors, [])

        # assert correct token scanning
        self.assertEqual(types(tokens), 'DEF ID = BOOL')
开发者ID:z-lang,项目名称:z-lang,代码行数:10,代码来源:LexerTest.py

示例11: testScanString

    def testScanString(self):
        lexer = Lexer()
        lexer.input("def string = \"hello, world!\"")
        (tokens, errors) = lexer.allTokens()

        # assert that no error occured
        self.assertEqual(errors, [])

        # assert correct token scanning
        self.assertEqual(types(tokens), 'DEF ID = STRING')
开发者ID:z-lang,项目名称:z-lang,代码行数:10,代码来源:LexerTest.py

示例12: testScanLambda

    def testScanLambda(self):
        lexer = Lexer()
        lexer.input("def f(x) = lambda(y) x")
        (tokens, errors) = lexer.allTokens()

        # assert that no error occured
        self.assertEqual(errors, [])

        # assert correct token scanning
        self.assertEqual(types(tokens), 'DEF ID ( ID ) = LAMBDA ( ID ) ID')
开发者ID:z-lang,项目名称:z-lang,代码行数:10,代码来源:LexerTest.py

示例13: testScanList

    def testScanList(self):
        lexer = Lexer()
        lexer.input("def t = [a, b]")
        (tokens, errors) = lexer.allTokens()

        # assert that no error occured
        self.assertEqual(errors, [])

        # assert correct token scanning
        self.assertEqual(types(tokens), 'DEF ID = [ ID , ID ]')
开发者ID:z-lang,项目名称:z-lang,代码行数:10,代码来源:LexerTest.py

示例14: testScanTuple

    def testScanTuple(self):
        lexer = Lexer()
        lexer.input("def t = (a, b)")
        (tokens, errors) = lexer.allTokens()

        # assert that no error occured
        self.assertEqual(errors, [])

        # assert correct token scanning
        self.assertEqual(types(tokens), 'DEF ID = ( ID , ID )')
开发者ID:z-lang,项目名称:z-lang,代码行数:10,代码来源:LexerTest.py

示例15: testScanFunction

    def testScanFunction(self):
        lexer = Lexer()
        lexer.input("def f(x) = x")
        (tokens, errors) = lexer.allTokens()

        # assert that no error occured
        self.assertEqual(errors, [])

        # assert correct token scanning
        self.assertEqual(types(tokens), 'DEF ID ( ID ) = ID')
开发者ID:z-lang,项目名称:z-lang,代码行数:10,代码来源:LexerTest.py


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