Sublime Forum

Newline Syntax Highlighting Bug

#1

It seems that a comment terminated by a newline is causing the syntax highlighting to fail
image
image
You can find a minimalistic .tmLanguage to reproduce this here: https://gist.github.com/Sainan/dd35d23ffe36fc5713ad97c3f9437cc5
Which I have based on https://github.com/sumneko/lua.tmbundle

0 Likes

#2

Because you consume the \n in https://gist.github.com/Sainan/dd35d23ffe36fc5713ad97c3f9437cc5#file-bug-tmlanguage-L72

Also curious about why you need another Lua syntax? Is the builtin one too lame?

https://gist.github.com/Sainan/dd35d23ffe36fc5713ad97c3f9437cc5#file-bug-tmlanguage-L84 should be </array> by the way.


The following is OP’s corresponding sublime-syntax for those who don’t want to read tmlanguage.

%YAML 1.2
---
# http://www.sublimetext.com/docs/syntax.html
name: Bug
file_extensions:
  - lua
scope: source.lua
contexts:
  main:
    - match: '(^[ \t]+)?(?=--)'
      captures:
        1: punctuation.whitespace.comment.leading.lua
      push:
        - match: '(?!\G)((?!^)[ \t]+\n)?'
          captures:
            1: punctuation.whitespace.comment.trailing.lua
          pop: true
        - match: '--\[(=*)\['
          captures:
            0: punctuation.definition.comment.begin.lua
          push:
            - meta_scope: comment.block.lua
            - match: '\]\1\]'
              captures:
                0: punctuation.definition.comment.end.lua
              pop: true
        - match: '--'
          captures:
            0: punctuation.definition.comment.lua
          push:
            - meta_scope: comment.line.double-dash.lua
            - match: \n
              pop: true
    - match: \b(break|do|else|for|if|elseif|goto|return|then|repeat|while|until|end|function|local|in|)\b
      scope: keyword.control.lua
1 Like

#3

Because you consume the \n […]

That is quite confusing, I assume “end” would only set the end-point, not consume it. Also, using the same tmLanguage in a different text editor does not have this behaviour, that’s why I report it as a bug with ST.

[Why another] Lua syntax?

For a Lua fork that adds lots of stuff.

P.S. Sorry for late response, thought I would get an email, and this thread just completely fell out of my mind.

0 Likes

#4

I am neither familiar with tmLanguage nor interested in it. My previous statement was purely basing on the converted sublime-syntax file by an official command provided in Sublime Text. If you believe this is wrong, you can submit an bug report on https://github.com/sublimehq/Packages with (hopefully minimal) reproduceable codes.

0 Likes

#5

\n is a character and thus consumed. To match eol without consuming the linefeed, you probably want to use $. That’s how regexp works.

0 Likes

#6

Hmm, I was trying to reproduce it now, and it seems fine, so I guess they fixed it, but thanks for the recommendation about using $ — if the issue happens again, I will try it.

0 Likes