hedit.py revision 2632:1bb2f91485ea
1# ----------------------------------------------------------------------------- 2# hedit.py 3# 4# Paring of Fortran H Edit descriptions (Contributed by Pearu Peterson) 5# 6# These tokens can't be easily tokenized because they are of the following 7# form: 8# 9# nHc1...cn 10# 11# where n is a positive integer and c1 ... cn are characters. 12# 13# This example shows how to modify the state of the lexer to parse 14# such tokens 15# ----------------------------------------------------------------------------- 16 17tokens = ( 18 'H_EDIT_DESCRIPTOR', 19 ) 20 21# Tokens 22t_ignore = " \t\n" 23 24def t_H_EDIT_DESCRIPTOR(t): 25 r"\d+H.*" # This grabs all of the remaining text 26 i = t.value.index('H') 27 n = eval(t.value[:i]) 28 29 # Adjust the tokenizing position 30 t.lexer.lexpos -= len(t.value) - (i+1+n) 31 32 t.value = t.value[i+1:i+1+n] 33 return t 34 35def t_error(t): 36 print "Illegal character '%s'" % t.value[0] 37 t.skip(1) 38 39# Build the lexer 40import lex 41lex.lex() 42lex.runmain() 43 44 45