Enrique Pérez
unread,Oct 26, 2012, 10:48:15 AM10/26/12Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to ply-...@googlegroups.com
I am writing a parser for a grammar, and I want to allow Python sections (delimitd by '\n<-\n' and '\n->\n') within code generated from that grammar. I do not want to parse Python; I will feed it to exec. I just want to get the whole lines, including whitespace.
This is in my lexer:
def t_begin_pycode(self, t):
r'<-'
t.lexer.begin('pycode')
def t_pycode_newline(self, t):
r'\n+'
t.lexer.lineno += len(t.value)
def t_pycode_IMPLIES(self, t):
r'->'
t.lexer.begin('INITIAL')
return t
def t_pycode_PYCODE(self, t):
r'.+'
return t
t_pycode_ignore = ''
However, somewhere between this and the parser, the leading whitespace is lost...
What am I doing wrong?
I have looked at the GardenSnake parser by Andrew Dalke but I do not need to parse indentation or distinguish types of whitespace.