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

Lookahead not evaluated for first word after pushing with (?=\S) #3158

Closed
deathaxe opened this issue Dec 22, 2019 · 2 comments
Closed

Lookahead not evaluated for first word after pushing with (?=\S) #3158

deathaxe opened this issue Dec 22, 2019 · 2 comments

Comments

@deathaxe
Copy link
Collaborator

Description

If a context is pushed onto the stack by (?=\S) a lookahead which points to a word (e.g.: (?=import\b)) is ignored when evaluating the next nonwhitespace character.

Note: If the (?=import\b) was replaced by import\b it was evaluated, but then breaking the syntax due to popping without pushing back into the context.

Steps to reproduce

  1. Open a vanilla ST.
  2. Create a new syntax and past the snippet below.
  3. Create an empty file and assign it the new syntax.
  4. Type several lines of import.
%YAML 1.2
---
# http://www.sublimetext.com/docs/3/syntax.html
name: Lookahead
scope: source.lookahead

contexts:
  main:
    - match: import\b
      scope: keyword.control.directive
      push:
        - meta_scope: meta.preprocessor.import
        - match: (?=\S)
          push:
            - meta_content_scope: meta.path
            - match: (?=import\b)  # not evaluated for the first word after "import"!
              pop: 2
            - match: ;
              scope: punctuation.terminator
              pop: 2
            - match: \w+\b
              scope: entity.name.class

Expected behavior

Each import keyword should be scoped as keyword.control.directive

grafik

Actual behavior

Each 2nd import keyword is scoped/highlighted as entity.name.class, because the (?=import\b) lookahread in line 15 is not evaluated and therefore the bail out does not work.

grafik

Environment

  • Build: 4061
  • Operating system and version: Windows 10 x64 1903
@wbond
Copy link
Member

wbond commented Jan 7, 2020

This is a feature that prevents infinite recursion. If a zero-width push is followed by a zero-width pop, it will result in an infinite loop.

However, with the ability to pop multiple levels, we may now have to tweak the rules to allow things that weren't possible before.

@wbond wbond self-assigned this Jun 12, 2020
@wbond
Copy link
Member

wbond commented Jul 10, 2020

This has been added in build 4075. There is now more complex logic to handle situations where pushes and pops are asymmetrical, and thus can be allowed even though both are zero-width.

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

No branches or pull requests

2 participants