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

Line and position context to Lexer/Parser #2864

Closed
wants to merge 3 commits into from

Conversation

srfrog
Copy link
Contributor

@srfrog srfrog commented Jan 3, 2019

This PR adds line counts to the lexer so that parsers can make use of it. Also, adds line counters for the GQL and RDF parsers (LF or CR). This information is tracked in the lexer struct and returned with lexer errors, along with the position where the error happened.

Example error ouput:

# line 2 position 48
line 2:48: while lexing {set { _:a1 <reg> \"a1 content\" . }}\n\t\tsomething: Invalid operation type: something

Ref: #2815


This change is Reviewable

Copy link
Contributor

@manishrjain manishrjain left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add some tests? Ensure that they catch the line number correctly?

Reviewable status: 0 of 3 files reviewed, 1 unresolved discussion (waiting on @srfrog and @manishrjain)


lex/lexer.go, line 148 at r1 (raw file):

	l.items = append(l.items, Item{
		Typ: ItemError,
		Val: fmt.Sprintf("line %d:%d: while lexing %v: "+format,

We can't really tell the character on that line, because l.Pos does NOT take into account the line separation. It is global to the input. So, maybe just do it at the line number level.

Copy link
Contributor Author

@srfrog srfrog left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like the counts wont work correctly without some extra tracking. We miss the toplevel and the op block counts.

Reviewable status: 0 of 3 files reviewed, 1 unresolved discussion (waiting on @srfrog)

@srfrog srfrog closed this Jan 3, 2019
@srfrog srfrog deleted the srfrog/lexer_line_numbers branch January 3, 2019 05:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants