Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pass current line and column to action #72

Open
gadlopes opened this issue Jan 4, 2018 · 1 comment
Open

pass current line and column to action #72

gadlopes opened this issue Jan 4, 2018 · 1 comment

Comments

@gadlopes
Copy link

gadlopes commented Jan 4, 2018

Dear developers,
Is there a way to pass the current line and column of the file being parsed to the action of a rule?

For example:

the grammar:

parameter = (word:w -> AnAction('parameter',str(w),line,column) )

the python file:

def AnAction(name, value, line, column):
   print(value +' ' + str(line) + ' ' + str(column))

the input text:

hello this is
a test

the output:

hello 1 1
this 1 7
is 1 12
a 2 1
test 2 3

I'm trying to build a compiler and I would like to check if a variable is already defined. So to make an error message it would be nice if Parsley would provide me with the location of the variable, even when the file has the correct syntax.

Thanks in advance!!!

@gadlopes
Copy link
Author

gadlopes commented Jan 4, 2018

I just noticed that self.input.position will give the current character count of the input file. With this I can figure out the line and column. Please let me know if you have a better idea.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant