本文整理汇总了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
示例2: __init__
def __init__( self, parent = None ):
QsciLexerPostScript.__init__( self, parent )
Lexer.__init__( self )
self.commentString = "%"
return
示例3: __init__
def __init__( self, parent = None ):
QsciLexerLua.__init__( self, parent )
Lexer.__init__( self )
self.commentString = "--"
return
示例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)
示例5: __init__
def __init__( self, parent = None ):
QsciLexerBatch.__init__( self, parent )
Lexer.__init__( self )
self.commentString = "REM "
return
示例6: __init__
def __init__( self, parent = None ):
QsciLexerYAML.__init__( self, parent )
Lexer.__init__( self )
self.commentString = "#"
return
示例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
示例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
示例9: __init__
def __init__( self, parent = None ):
QsciLexerFortran.__init__( self, parent )
Lexer.__init__( self )
self.commentString = "!"
return
示例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()
示例11: __init__
def __init__( self, parent = None ):
QsciLexer.__init__( self, parent )
Lexer.__init__( self )
self.editor = parent
return
示例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())
示例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
示例14: __init__
def __init__( self, parent = None ):
QsciLexerMakefile.__init__( self, parent )
Lexer.__init__( self )
self.commentString = "#"
self._alwaysKeepTabs = True
return
示例15: __init__
def __init__( self, parent = None ):
QsciLexerHTML.__init__( self, parent )
Lexer.__init__( self )
self.streamCommentString = { 'start' : '<!-- ',
'end' : ' -->' }
return