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


Python lexer.Lexer类代码示例

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


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

示例1: __init__

    def __init__( self, parent = None ):

        QsciLexerProperties.__init__( self, parent )
        Lexer.__init__( self )

        self.commentString = "#"
        return
开发者ID:eaglexmw,项目名称:codimension,代码行数:7,代码来源:lexerproperties.py

示例2: __init__

    def __init__( self, parent = None ):

        QsciLexerPostScript.__init__( self, parent )
        Lexer.__init__( self )

        self.commentString = "%"
        return
开发者ID:eaglexmw,项目名称:codimension,代码行数:7,代码来源:lexerpostscript.py

示例3: __init__

    def __init__( self, parent = None ):

        QsciLexerLua.__init__( self, parent )
        Lexer.__init__( self )

        self.commentString = "--"
        return
开发者ID:eaglexmw,项目名称:codimension,代码行数:7,代码来源:lexerlua.py

示例4: parse_file

 def parse_file(self, fpath):
     lexer = Lexer()
     try:
         lexer.parse_file(fpath)
     except IOError:
         raise ParseError, "file not accessible"
     return self.parse_with_lexer(lexer)
开发者ID:barosl,项目名称:lr-parser,代码行数:7,代码来源:parser2.py

示例5: __init__

    def __init__( self, parent = None ):

        QsciLexerBatch.__init__( self, parent )
        Lexer.__init__( self )

        self.commentString = "REM "
        return
开发者ID:eaglexmw,项目名称:codimension,代码行数:7,代码来源:lexerbatch.py

示例6: __init__

    def __init__( self, parent = None ):

        QsciLexerYAML.__init__( self, parent )
        Lexer.__init__( self )

        self.commentString = "#"
        return
开发者ID:eaglexmw,项目名称:codimension,代码行数:7,代码来源:lexeryaml.py

示例7: vhdl_unit_name

def vhdl_unit_name(file):
    """ Given the name of a VHDL file, attempts to find the unit
        (entity or package) name in this file.
        
        If several units are present, the first is returned.
        None is returned if no unit name is found.
    """
    rules = [
        ('--[^\n]*\n',  'COMMENT'),
        ('\n+',         'NEWLINE'),
        ('\w+',         'ID'),
        ('\s+',         'WHITESPACE'),
        ('[^\w\n]+',    'NONE'),
    ]

    lx = Lexer(rules, skip_whitespace=False)
    lx.input(open(file).read())
    
    window = [None, None, None]
    
    try:
        for tok in lx.tokens():
            # Implements a simple sliding window looking for 
            # (entity|package) <name> is
            # as 3 consecutive IDs
            #
            if tok.type == 'ID':
                window = window[1:3] + [tok.val.lower()]
                
                if (    window[0] in ('entity', 'package') and 
                        window[2] == 'is'):
                    return window[1]
    except LexerError, err:
        return None
开发者ID:duongbaoduy,项目名称:luz-cpu,代码行数:34,代码来源:vhdl_utils.py

示例8: test_lexer_extracts_single_integer

def test_lexer_extracts_single_integer():
    text = "11"

    l = Lexer()
    l.lex(text)

    assert l.get_next_token().value == 11
开发者ID:MrLokans,项目名称:SimpleInterpreter,代码行数:7,代码来源:test_lexer.py

示例9: __init__

    def __init__( self, parent = None ):

        QsciLexerFortran.__init__( self, parent )
        Lexer.__init__( self )

        self.commentString = "!"
        return
开发者ID:eaglexmw,项目名称:codimension,代码行数:7,代码来源:lexerfortran.py

示例10: parse

def parse(filename, context):
    file = open(filename, 'r')

    try:
        lexer = Lexer(file, context)
        token = lexer.getToken()

        while token.type != 'EOF':
            if token.type != 'STRING':
                raise UnexpectedTokenError(token.value, 'STRING', 'STRING', line=lexer.getLine())

            cmd_name = token.value
            token = lexer.getToken()
            if token.type != '(':
                raise UnexpectedTokenError(token.value, '(', 'STRING', line=lexer.getLine())

            cmd_args = []
            token = lexer.getToken()
            while token.type != ')':
                if token.type != 'STRING':
                    raise UnexpectedTokenError(token.value, 'STRING', line=lexer.getLine())
                cmd_args.append(token.value)
                token = lexer.getToken()

            context.run_cmd(cmd_name, cmd_args)
            token = lexer.getToken()
    except LanguageError as e:
        # fixup filename and line number if needed and re-raise
        if not e.getLine(): e.setLine(lexer.getLine())
        if not e.getFile(): e.setFile(filename)
        raise e
    finally:
        file.close()
开发者ID:rudchenkos,项目名称:pycmake,代码行数:33,代码来源:parser.py

示例11: __init__

    def __init__( self, parent = None ):

        QsciLexer.__init__( self, parent )
        Lexer.__init__( self )

        self.editor = parent
        return
开发者ID:eaglexmw,项目名称:codimension,代码行数:7,代码来源:lexercontainer.py

示例12: testLexer

def testLexer():
	""" Ukazka pouziti lexeru. """
	s = " append (bd fdfdg)"
	l = Lexer() # timhle si zalozite objekt lexilaniho analyzatoru
	l.analyzeString(s) # timhle mu reknete, aby naparsoval string, ktery jste napsali
	while (not l.isEOF()): # tohle slouzi k vypsani vsech tokenu
		print(l.popToken())
开发者ID:mikicz,项目名称:tomki,代码行数:7,代码来源:Tomiki-test.py

示例13: testParser

def testParser():
	s = """
		function quicksort(seznam)
			{
				x = len(seznam);
				if (x <= 1)
					{
						return seznam;
					}
				else
					{
						pivot = pop(seznam,0);
						mali = [];
						velci = [];
						for prvek in seznam
							{
								if (prvek<pivot)
									{
										append(mali,prvek);
									}
								else
									{
										append(velci,prvek);
									};
							};
						vystup1 = quicksort(mali);
						vystup2 = quicksort(velci);
						vystup = join (vystup1, pivot, vystup2);
						return vystup;
					};
			};
		a = [7,758,6,87,25465,487,654,87,564,687,65];
		b = quicksort(a);
		print b;
		
			"""
	"""s = 
		function rekurze(bla) 
			{
				if(bla<=0){
					return(bla);
				};
				print bla;
				bla = bla - 1;
				return( rekurze(bla) );
			}; 
		rekurze(10); """
#	s = """ 		bla = 5;		function nekdo(){			print("test");		};		nekdo();		print bla;"""
	l = Lexer() # timhle si zalozite objekt lexilaniho analyzatoru
	l.analyzeString(s) # timhle mu reknete, aby naparsoval string, ktery jste napsali

	p = Parser(l) # zalozim si parser a dam mu lexer ze ktereho bude cist tokeny
	ast = p.parse() # naparsuju co mam v lexeru a vratim AST 

	frame = Frame(None)
	ffy=FunctionFrame()
	print(ast) # zobrazim ten strom
	ast.run(frame,ffy)
	print frame.locals
开发者ID:mikicz,项目名称:tomki,代码行数:59,代码来源:Tomiki-test.py

示例14: __init__

    def __init__( self, parent = None ):

        QsciLexerMakefile.__init__( self, parent )
        Lexer.__init__( self )

        self.commentString = "#"
        self._alwaysKeepTabs = True
        return
开发者ID:eaglexmw,项目名称:codimension,代码行数:8,代码来源:lexermakefile.py

示例15: __init__

    def __init__( self, parent = None ):

        QsciLexerHTML.__init__( self, parent )
        Lexer.__init__( self )

        self.streamCommentString = { 'start' : '<!-- ',
                                     'end'   : ' -->' }
        return
开发者ID:eaglexmw,项目名称:codimension,代码行数:8,代码来源:lexerhtml.py


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