How to deal with member access "." preceding whitespace #795
Replies: 3 comments 6 replies
-
Issue Label Bot is not confident enough to auto-label this issue. See dashboard for more details. |
Beta Was this translation helpful? Give feedback.
-
Yeah, as you said,
|
Beta Was this translation helpful? Give feedback.
-
thanks for the ideas. member access can probably be between two identifiers/subscript_expressions, but this programming language is really uh, flexible and you can use arbitrary expressions in a lot of places you wouldn’t expect, so i generally default to using expression instead of more specific things because i have been bitten by that in the past. unfortunately the language
so it’s hard to say what is exactly right. if i can express the rhs as a terminal, then yes, i could use token.immediate() on that. but i think that is probably not going to work out because of at least the possibility of subscripting. i already have an external scanner for herestrings, so i’ll look into what the bash grammar does. it’s really a shame that i need to hack the parser up for something that is really a UX related thing. it’s possible that i could detect this white space while iterating through the syntax tree (by finding the “.” token in the text buffer and then checking the adjacent characters), but that still leaves the post-whitespace mangled syntax tree as a problem for the rest of the document. |
Beta Was this translation helpful? Give feedback.
-
I have a problem with my grammar where if you were to type
it will parse that as a valid member access expression: name.other_thing. Which it is. And it would be if I were to leave the code in this state, however, when I press "." after name, I'm generally looking to get the member list, not screw up my entire program by potentially creating a member access between two really weird things.
for instance:
now makes this try to do member access between name and Person, which stops Person from being a valid struct syntactically, causing a cascade of errors everywhere i've used Person.
the rule is what you would expect:
member_access: $ => prec.left(seq($.expression, ".", $.expression)),
I've tried making member access use token.immediate(".") but it seems to only matter for the preceding whitespace, not the whitespace following the rule.
ok:
expression. expression
not ok:
expression .expression
So, I am wondering if there is something I can do to get tree sitter to error out when whitespace follows the "."
I'd appreciate your thoughts on this problem.
Thanks,
Kelly
Beta Was this translation helpful? Give feedback.
All reactions