-
Notifications
You must be signed in to change notification settings - Fork 123
capture if pushed rules have advanced and reflect when popped #85
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
capture if pushed rules have advanced and reflect when popped #85
Conversation
|
@egamma, @alexandrudima, any chance this could get looked at yet during this update cycle? The reason being, in addition to the issues detailed above and those detailed as duplicated in them, as I keep working on a rewrite of the PowerShell grammar, I keep running in to this. In many cases I can work around it, but in all the cases I go over to Atom, and the issue does not occur. Current issue: {
"comment": "could be a numeric constant or a limited list of unary operators, that we should switch to expression mode",
"begin": "(?=[\\d.!+\\x{2013}-\\x{2015}-])",
"end": "$(?=\\n)|(?=[;|)}\\]])",
"patterns": [
{
"include": "#numericConstant"
},
{
"include": "#operators_preUnary"
},
{
"comment": "if numeric constant advanced, switch to expression mode",
"begin": "(?!\\G)(?!$(?=\\n)|(?=[;|)}\\]]))",
"end": "$(?=\\n)|(?=[;|)}\\]])",
"patterns": [
{
"include": "#expression_mode"
}
]
},
{
"comment": "if numeric constant didn't advanced, try finishing command mode with a command name",
"begin": "\\G(?!$(?=\\n)|(?=[;|)}\\]]))",
"end": "$(?=\\n)|(?=[;|)}\\]])",
"patterns": [
{
"include": "#command_name"
}
]
}
]
},The purpose of this is to select between what might be a numeric value, which in PowerShell is a fairly complicated set of regex, or the beginning of a command name that just looks like a numeric value. The problem is that a numeric value also uses a begin-end rule, so that it can also check for special operator circumstances, so when it returns, the anchor is left sitting at the end of the numeric value, even though it 'popped' to return. Instead of the rule with the negative lookahead for \G matching, the non-negative \G rule matches and sends the grammar to the command name path. JSON of this grammar can be found: https://github.com/msftrncs/PowerShell.tmLanguage/tree/argumentmode_2ndtry Pattern that scopes erroneously: ($i=-5kb, $c, ${true} )
($i=-5kb-$c, ${true} )In both lines, the I am not sure I can find any other reliable workaround in this particular case, though I have ultimately worked around every single other places with this sort of thing has occurred, but that's just making the regex more complicated, in each case that a work around can be made reliable, and I don't think that is the route that should be taken, as it seems the other TextMate compatible editors do not require these workarounds. If not in this update cycle, maybe shortly afterwards? The wildcard I am unclear about is if this solution, which modifies the constructor for |
|
@msftrncs Thank you for the great analysis and the PR! I have decided to go in a similar direction, but with a simplification:
This has as a "side effect" the desired behaviour that the anchor position is not matched if tokenization has advanced. IMHO, this capturing/restoring is easier to comprehend. |
|
Thanks for getting to this. I am sure there are lots more ways to tackle the problem. I was worrying about a rule pop occurring on a different line than the push did, and how to detect that, so I stayed away from pushing the actual anchor position. |
|
Ah, I had looked over the stackelement.reset() method being used to reset the previous element each time a new line is tokenized. |
This should fix #82 (the first half of microsoft/vscode#65983) and #49, and maybe others.
I save a
hasAdvancedflag to thestack(StackElement) when pushing a rule and when popping the rule I use this flag to reset theanchorPos(in_tokenizeLine) back to -1 to disable further anchor matching.I have been running in to similar issues trying to change the PowerShell/EditorSyntax grammer, and I believe that this is the correct behavior. I have only so far 'inspect'ed my PowerShell with this change and it seems to work how I think it should. I will test at another location the pug, and if it still exists, the HTML issue as well.
I do not know what affect this might have on projects dependent on this one.