Created
August 7, 2012 11:46
-
-
Save 4toblerone/3284755 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
Created on Aug 6, 2012 | |
@author: Sasa Trifunovic | |
I should write test(s) so i could be sure every one of theme is working | |
as i intended them to do!!! | |
''' | |
tokens = ( | |
'LCURLYB', | |
'RCURLYB', | |
'LBRACKET', | |
'RBRACKET', | |
'COMMA', | |
'DOTCOMMA', | |
'EQUAL', | |
'EXCLAMATION', | |
'2XEQUAL', | |
'EXCLAMATIONEQUAL', | |
'STRING', | |
'WORD', | |
'NUMBER', | |
'WHITESPACES' | |
) | |
def t_LCURLYB(token): | |
r'{' | |
return token | |
def t_RCURLYB(token): | |
r'}' | |
return token | |
def t_LBRACKET(token): | |
r'\(' | |
return token | |
def t_RBRACKET(token): | |
r'\)' | |
return token | |
def t_COMMA(token): | |
r',' | |
return token | |
def t_DOTCOMMA(token): | |
r';' | |
return token | |
def t_EQUAL(token): | |
r'=' | |
return token | |
def t_EXCLAMATION(token): | |
r'!' | |
return token | |
def t_2XEQUAL(token): | |
r'==' | |
return token | |
def t_EXCLAMATIONEQUAL(token): | |
r'!=' | |
return token | |
def t_STRING(t): | |
r'"[^"]*"' | |
t.value = t.value[1:-1] # drop "surrounding quotes" | |
return t | |
""" | |
This token definition is maybe redundant and it should be placed in HTML token definitions | |
""" | |
def t_WORD(token): | |
r'[a-z]+' | |
return token | |
def t_NUMBER(token): | |
r'[0-9]+' | |
token.value = int(token.value) | |
return token | |
def t_WHITESPACES(token): | |
r'" "' | |
pass | |
def t_error(t): | |
print 'Illegal character' | |
t.lexer.skip(1) | |
t_ignore = ' \t\v\r' # shortcut for whitespace |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment