preserving whitespace

116 views
Skip to first unread message

Enrique Pérez

unread,
Oct 26, 2012, 10:48:15 AM10/26/12
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.

Enrique Pérez Arnaud

unread,
Oct 30, 2012, 1:51:58 PM10/30/12
to ply-...@googlegroups.com
The problem was elsewhere, not in my usage of ply.

Sorry about the noise

2012/10/26 Enrique Pérez <enriqu...@gmail.com>

--
You received this message because you are subscribed to the Google Groups "ply-hack" group.
To post to this group, send email to ply-...@googlegroups.com.
To unsubscribe from this group, send email to ply-hack+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msg/ply-hack/-/W2Y9RLtuVPMJ.
For more options, visit https://groups.google.com/groups/opt_out.
 
 



--
Enrique Pérez Arnaud
enriqu...@gmail.com
Reply all
Reply to author
Forward
0 new messages