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

expose Token, Value, TokenToName and Pos on LexToken #133

Open
wants to merge 5 commits into
base: master
from

Conversation

@sneakywombat
Copy link

sneakywombat commented Jun 11, 2020

I am using your library to write a custom parser, and thus only depend on the lex functionality. While writing it, I found it useful to be able to access these values. Tossing it up here to see if you agree. thanks for writing such a new library!

It's useful to be able to get at the token, value and pos on lextoken when writing a parser that only relies on the lex functionality of this library.
…more

expose Token, Value and Pos on LexToken
@codecov-commenter
Copy link

codecov-commenter commented Jun 11, 2020

Codecov Report

Merging #133 into master will decrease coverage by 0.06%.
The diff coverage is 0.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #133      +/-   ##
==========================================
- Coverage   72.92%   72.85%   -0.07%     
==========================================
  Files          60       60              
  Lines       12002    12013      +11     
==========================================
  Hits         8752     8752              
- Misses       2715     2726      +11     
  Partials      535      535              
Impacted Files Coverage Δ
parser/lexer.go 88.07% <0.00%> (-1.91%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 4c28217...547bf8c. Read the comment docs.

Missed adding this one.
@sneakywombat sneakywombat changed the title expose Token, Value and Pos on LexToken expose Token, Value, TokenToName and Pos on LexToken Jun 11, 2020
@@ -330,6 +330,30 @@ func (lt *LexToken) String() string {
return fmt.Sprintf("%q (%d) = %T{%v} %d:%d", name, lt.token, lt.value, lt.value, lt.pos.Lineno, lt.pos.ColOffset)
}

// TokenToName returns the string name of a given token
func (lt *LexToken) TokenToName() string {
name, ok := tokenToString[lt.token]

This comment has been minimized.

@sbinet

sbinet Jun 16, 2020

Member

perhaps we could make the token implement fmt.Stringer instead ?

This comment has been minimized.

@sneakywombat

sneakywombat Jun 25, 2020

Author

sure, i'll take a look. random question, i hacked in comment support in my branch because I wanted to capture those. any interest in supporting comment capture in gpython? I saw that it was tossed away in lexer.go.

This comment has been minimized.

@sbinet

sbinet Jun 25, 2020

Member

IMHO, it would be useful.
but @ncw would know best.

This comment has been minimized.

@ncw

ncw Jun 26, 2020

Collaborator

Comment support sounds interesting. Is it part of the standard Python lexer? I don't remember

lexer.go drops comments, but i'd like to keep them.  hack in a capture op.
update lexer.go to support comments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

4 participants
You can’t perform that action at this time.