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

--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to