ply yacc lineno not working?

L

Laszlo Nagy

This is a fragment from my yacc file:


import ply.yacc as yacc
from lex import tokens
from ast import *

def p_msd(p):
r"""msd : SCHEMA WORD LBRACE defs RBRACE """
p[0] = MSDSchema(p[2])
print p.lineno(5) # Line number of the right brace
p[0].items = p[4]


Here is a test input: """

schema TestSchema {
field name : varchar { required; size 100; }
}

"""


My program prints out 1. No matter what I do, YaccProduction.lineno(n)
returns 1 for every possible n between 0 and 5. What am I doing wrong?
Can it be a problem if I use this in my lexer:

# Whitespace is mostly ignored, except inside quoted words.
def t_ws(t):
r'[\n\r\t ]+'
# We do not return anything so this will be ignored.


If so, how can I easily ignore newlines while preserving the line number
for yacc.parse ?

Thanks,

Laszlo
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,479
Members
44,899
Latest member
RodneyMcAu

Latest Threads

Top