Help with grammar matching


#1

EDIT: After working on it I’m fairly convinced the regex is correct, and the issue lies in the grammar system, the package code, or Atom.

EDIT2: Further testing: I disabled all the patterns in the grammar file except the variable.other.lua. What I’ve discovered is that the grammar is working: the syntax highlighting shows all the places which are variable.other.lua in the relevant colour, even while the scope the package sees is reported as undefined.
What’s happening is the scope being delivered to the package (via a scopeDescriptor parameter) is being sent for the character to the right of the cursor, instead of the one preceding it. Alternatively the cursor exists after the scope and before the next character.
What I don’t know is if this is what it’s supposed to be doing (and I need a match pattern which extends to the right of the cursor?), or if this is a bug somewhere.


I’m working on a package that uses a lua grammar to enable autocompletion. I’m new to how grammar files work, but I think I have the gist of it. I’m running into a problem where a match isn’t being made even though I think it should, and I don’t know enough to know if its an issue with the code I’m looking at, how grammars work, or maybe (unlikelily) a bug in atom, so I’m hoping someone with more knowledge can help me:

The match in question is this one:
‘match’: ‘(?<=[^.]\.|:)\b([A-Za-z_]\w*)’
‘name’: ‘variable.other.lua’

Which (I think) means: not a ‘.’ then a ‘.’ OR ‘:’ -> word break -> standard variable characters.

Anyway, what I’m seeing in the console is if I type any of the following it’ll match and the scope at the cursor will be variable.other.lua (I’ll use ‘¦’ to represent the cursor):

foo(bar.baz.get¦
foo(bar.baz[bob].get¦
foo(bar.baz.get¦)

BUT

foo(bar.baz[bob].get¦)

does not match; the scope remains undefined. If another scope was matching it first I’d understand, but because its undefined I don’t get it. How does adding a bracket at the end invalidate the above regexp?

The entire grammar is here:


#2

It shouldn’t. I don’t have time right now to test and see if I can make it work, but try this:

foo( bar.baz[bob].get¦ )

Does it break on any non-word character following get, or just )?


#3

It breaks on everything, even whitespce


#4

Can you remove the \b? I don’t think that’s needed because of your lookbehind.


#5

Removing \b doesn’t fix it


#6

Use regexr.com and put the regex in there. it should help. Also, look behinds aren’t supported in JavaScript.


#7

The grammar system uses Ruby regexs, which do support look behinds.


#8

I’ve editted in my progress to the top of the post.