There are two highlight bugs specific to the ‘Solar2D syntax package aka Lua(Solar2D)’ for sublime text I want to fix. The colour scheme I’m using is not the problem, and it corrects these bugs when I swap to any other lua syntax package. Searching google for ‘how to edit sublime syntax package highlight’ has been an absolute rabbit hole.
Does anyone ‘know specifically’ how to make such fixes so the highlight works again? Please no untested responses, but even just how to access AND edit the right file would be helpful. The bugs which break highlighting, // denotes comments, are these:
require"test" //requires brackets OR space to work
function () --() //comments cant have a closed or unclosed )
I don’t know if @personalnadir is still active to answer your question but we might try
That’s the Github repo if you want to make changes:
You’ll need to duplicate line 69 of the syntax file and change it so that for require the regex also accepts all the valid quotation marks. For the second one you want to look at line 19 you’ll need to change the regex to look for the first closing ‘)’ rather than the last.
Your best bet will be to find the syntax file for the working Lua file and then copy them over and see what works and what breaks. A diff program is going to be your friend.
turns out require[[test]]
is also valid. The syntactic sugar that allows for brackets to be omitted inconsistently is a mistake in my opinion:
> print "1"
1
> print 1
stdin:1: '=' expected near '1'
> print(1)
1
> print{1}
table: 0x600001118300
and
> assert[[bah]]
> assert '1'
> assert 1
stdin:1: '=' expected near '1'
Weird that it will break if the argument is a number but handle everything else.
Based on the above you don’t need to duplicate line 69, you just need to edit it to accept [[, ', " in addition to the existing space, ( and {
I’m stuck trying to find where the file is. I installed from package control on windows.
The likely area:
…\AppData\Roaming\Sublime Text\Packages\Corona Editor
There’s only a menu file though, an unwritable sublime menu file.
In sublime package control I can run “view package file” and it brings up the syntax file successfully but doesn’t allow edits…and the path of the file is that same path above where there’s only a menu-file and nothing else. So I’m confused what to do. I could find and edit the syntax file of the neighboring luaLove folder.
I don’t know how to manually install from the github page I only see instructions for package control.
*edit: I downloaded the zip and transferred the syntax-file from that zip into the existing folder and now when I search it via package control it brings up that file I can now edit…I don’t understand that but okay.
Following the instructions below the quoted part, you can fork and redirect to your version where you can edit the code as you want:
If you want to help test the latest development version of Solar2D Editor you can configure Package Control to grab it instead of the official release version by following these steps:
So to make require"composer"/require’composer’/require[[composer]] work, you download the sublime-syntax file from git and toss it into the corona package file under windows roaming. And then package control: viewPackageFile now allows u to open and edit that syntax file. You go to line 69 and remove the quotes around the match regex and change the end from (?=[( {]) to (?=[( {"’[])
I don’t know what the quotes around the match regex are there for I couldn’t find explanation in the docs, is that just syntax sugar that can be removed? Cause not removing them breaks the file when I try to fix require’composer’. Was there a ’ " kind of exception character that sublime and its regex both respect so you don’t have to remove the quotes?
And the other problem of:
function() --)
Actually also extends to situations like this as well:
function() function()
On line 19. The solution I cameup with was changing…
- match: '(\w+)?(?:\s*=\s*)*(function\s*)(\w+\s*[:.]+)*(?:\s+)*(\w+)*\s*(\()(.*)(\))'
to…
- match: '(\w+)?(?:\s*=\s*)*(function\s*)(\w+\s*[:.]+)*(?:\s+)*(\w+)*\s*(\()[^)]*\)'
So changing the ending of
(.*)(\))
to
[^)]*\)
I assumed sublime had the most support since they advertised it with the stellar dracula theme in nice pictures on the front page, and sublime with this package as their rather joyful top recommendation in the docs.
I didn’t question some of the oddities since I was just learning the engine, but looking at it now, I have to say it doesn’t make any sense to me that parameters are uncoloured and function calls are uncoloured and various lua things are included in the engine yet left out of the colouring.
I really think this should be addressed. Is the dev team using lua(solar2d)? Shouldn’t they mostly be if they are recommending+advertising it as their top…? Do they mostly use the other official IDE syntax packages? Do those also use the same highlighting as the Sublime one? Can they explain these highlighting choices?
The solution of simply “just use normal lua or love2d or whatever then” isn’t fair when you are just learning the engine and how things work…Just loadup the tutorial game and swap from lua to lua(solar2d), the colouring is terribly disjointed all over the place. What does everyone reading this use?
I also don’t get why the auto-complete has alot of the same cmds listed and they generate things u don’t want or expect when u tab into them. Like display.newText vs display.newImageRect…u get two options for each completely different from eachother but named the same and display.newText’s two options are something not in the api newText(?) and the undesired display.newText(options)
I’m sorry to hear about your experience. I use Sublime Text as my daily driver but looking at your reaction, I guess I’m just used to it.
I didn’t understand what you are struggling with at the moment. Can you give me an example piece of code that’s causing you the problem? I’d really like it if you can use preformatted text button above so I can easily understand what that is and try it myself to understand the problem.
About display.newText()
and some other APIs, that’s because there are multiple ways to call those functions. You can either use the basic/legacy mode and enter all the parameters that’s shown or pass a table including the options to create that object. Both are shown as both are valid.
Can you or someone help me get function parameters colourized?
The code I made:
-match: (?<=function\s*[\w_.:]*[\('"{])[\w, ]*(?=[\)'"}])
scope: variable.parameter.function.lua
Worked in https://regexr.com/, grabbing function name(x,y,z) and colourize the x,y,z. But variable length characters * ? + don’t work inside (?<=) in sublime apparently and the solution of using \K…doesn’t seems to work either…cause it’s not doing anything in sublime. And even if all that got sorted there is overlap with the existing -match definitions preventing it from showing up.
I cameup with the simpler code
- match: (?<=\()[\w, ]*(?=\))
scope: variable.parameter.function.lua
to just grab based on (x,y,z)
I thought you could piggyback off the existing scope definitions of functions the syntax file seems to define, but I can’t figure it out and the official doc entry on these syntax files I find to be very confusing (the only other doc I found was the ‘unofficial doc’ entry which barely covered anything). And I couldn’t figureout how to take the code of the existing lua syntax files with this highlighting and copy it into the existing syntax.
I got the functions colourized, opting to generalize the definitions since most of the things you misspell with the vanilla syntax file maintain their colour anyways. If anyone wants that it’s below, just replace the -match lines for the scopes support.function.lua and support.function.library.corona like:
- match: \b([\w_.:]*)(?=[("'{].*[)"'}])(?<!function)
scope: support.function.lua
- match: '\b(ads|analytics|audio|composer|credits|crypto|display|easing|facebook|gameNetwork|global|graphics|io|json|lfs|licensing|math|mime|media|native|network|os|package|physics|socket|sprite|sqlite3|store|storyboard|string|syntax|system|table|timer|transition|widget)\.[a-zA-Z0-9]+\b'
scope: support.function.library.corona
The second match is kept for clauses like display.contentCenterY where there are no (). There’s some redundancy, so you can go through each keyword i.e. ads|analytics etc and weed it down. Similarly if u only want the exact spellings to be highlighted. I don’t find any of this straightforward so please forgive any overstating of the obvious.
I think the regex in the Sublime syntax definitions need to be inside single quotes, going off of the existing file, but I could be wrong.
You can test the regex in the standard Sublime find command panel if you enable the regex option. It uses the same matching it does for syntax.
Something I didn’t know: you can’t use anything that would make a variable length string in a lookbehind (?<= … ). If you use the https://regex101.com/ site, you can see that highlighted as a regex error.
However if you look at the existing syntax file, you can see that it is already detecting parameters (lines 19-29). It is just assigning them to ‘variable’. Perhaps you just need to change line 28?
I still can’t figureout how to make parameters colourized. The scopes overlapping and taking priority over one and another partway through the regexes is making this too confusing for me to figureout.
I also made some mistakes above, but I can’t edit any of my posts so I’m going to post here to the forum’s annoyance.
- it should be:
(?=[( {"'\[])
with a \ before the second [ to fix cases like require[[test]]. I didn’t notice but the forums removed the \ special character even within the blockquote formatting. - And for some reason I wrote " just replace the -match lines for the scopes support.function.lua and support.function.library.corona like:"
But I think I meant support.function.library.lua, although both methods might work so long as u don’t delete the existing entry for support.function.lua. Again there’s redundancy/overlap among these changes that you can spend some time cleaning up if desired.
Ohkay I got it working finally. It’s this section of the code:
- match: '(\w+)?(?:\s*=\s*)*(function\s*)(\w+\s*[:.]+)*(?:\s+)*(\w+)*\s*(\()[^)]*\)'
comment: 'Find the various kinds of function definition in Lua: for any line containing "function", match optional "local" and/or "function", match identifier with optional classname, discard optional "=", match optional "function", match "(", match everything until closing ")", match ")"'
scope: meta.function.lua #variable.parameter.function.lua will italic function, and orange brackets, and parameters...but only want parameters italic and orange
captures:
1: entity.name.function.scope.lua
2: keyword.control.lua #colours function keyword
3: entity.name.function.scope.lua
4: entity.name.function.scope.lua #colours the function name
5: punctuation.definition.parameters.begin.lua #first bracket
6: variable #broken?
7: punctuation.definition.parameters.end.lua #last bracket seems broken?
I changed it to the below…someone can correct me if I’m wrong but capture 6 and 7 literally don’t exist! So we have scopes for things that don’t exist in the syntax file? That should really be fixed.
# - match: '(\w+)?(?:\s*=\s*)*(function\s*)(\w+\s*[:.]+)*(?:\s+)*(\w+)*\s*(\()[^)]*\)'
- match: '(\w+)?(?:\s*=\s*)*(function\s*)(\w+\s*[:.]+)*(?:\s+)*(\w+)*\s*(\()([^)]*)(\))'
# - match: '(\w+) (function\s*) (\w+\s*[:.]+)* (\w+)*\s* (\() [^)] *\)'
comment: 'Find the various kinds of function definition in Lua: for any line containing "function", match optional "local" and/or "function", match identifier with optional classname, discard optional "=", match optional "function", match "(", match everything until closing ")", match ")"'
scope: meta.function.lua #variable.parameter.function.lua will italic function, and orange brackets, and parameters...but only want parameters italic and orange
captures:
1: entity.name.function.scope.lua
2: keyword.control.lua #colours function keyword
3: entity.name.function.scope.lua
4: entity.name.function.scope.lua #colours the function name
# 5: variable.parameter.function.lua #punctuation.definition.parameters.begin.lua #first bracket
# 6: variable #not doing anything
6: variable.parameter.function.lua
Yay…victory lap…nice pretty code now…the parameters r colourized, the comments on function lines r working, the user defined function calls r colourized…the func"test" style calls are working…and some other stuff not shown in the picture is working, yay. Left is before, Right is after. Hopefully someone updates the official at some point. Double+ nesters aren’t covered ‘in every case’ like in i.e. function test.pos.x()end won’t highlight test…but fixing that’s just a case of adding it into the existing match regex. And with my fixes there is overlap with function calls that should ideally be fixed I mentioned above (note overlap exists in the original too)…so good enough for me now, not perfect though.
Here’s a scruffy yet working copy if anyone like previous me was lost and just wants it to work (assuming copying into the forums didn’t destroy any / or special characters). Comments might apply to the old lines they were on, they aren’t cleaned, don’t quote them:
%YAML 1.2
---
# http://www.sublimetext.com/docs/3/syntax.html
name: Lua (Solar2D)
comment: "Lua Syntax for Solar2D: version 0.2 (after Lua Syntax: version 0.8)"
file_extensions:
- lua
scope: source.lua.corona
contexts:
main:
###################### highlights variable inside anything(var)
# - match: function (\w)* (?<=\()[a-zA-Z., ]*(?=\)) #excludes numbersshould match only niggers(whores) not showing up tho
# scope: variable.parameter.function.lua
################
- match: '--\[(=*)\['
captures:
0: punctuation.definition.comment.lua
push: string
- match: '([\s]*-{2})(?!\[\[).*$\n?'
scope: comment.line.double-dash.lua
captures:
1: punctuation.definition.comment.lua
#me: this line below is ovewritingi ur para
# - match: '(\w+)?(?:\s*=\s*)*(function\s*)(\w+\s*[:.]+)*(?:\s+)*(\w+)*\s*(\()[^)]*\)'
- match: '(\w+)?(?:\s*=\s*)*(function\s*)(\w+\s*[:.]+)*(?:\s+)*(\w+)*\s*(\()([^)]*)(\))'
# - match: '(\w+) (function\s*) (\w+\s*[:.]+)* (\w+)*\s* (\() [^)] *\)'
comment: 'Find the various kinds of function definition in Lua: for any line containing "function", match optional "local" and/or "function", match identifier with optional classname, discard optional "=", match optional "function", match "(", match everything until closing ")", match ")"'
scope: meta.function.lua #variable.parameter.function.lua will italic function, and orange brackets, and parameters...but only want parameters italic and orange
captures:
1: entity.name.function.scope.lua
2: keyword.control.lua #colours function keyword
3: entity.name.function.scope.lua
4: entity.name.function.scope.lua #colours the function name
# 5: variable.parameter.function.lua #punctuation.definition.parameters.begin.lua #first bracket
# 6: variable #not doing anything
6: variable.parameter.function.lua #last bracket seems broken
- match: '(?<![\d.])\s0x[a-fA-F\d]+|\b\d+(\.\d+)?([eE]-?\d+)?|\.\d+([eE]-?\d+)?'
scope: constant.numeric.lua
- match: "'"
captures:
0: punctuation.definition.string.begin.lua
push:
- meta_scope: string.quoted.single.lua
- match: "'"
captures:
0: punctuation.definition.string.end.lua
pop: true
- match: \\.
scope: constant.character.escape.lua
- match: '"'
captures:
0: punctuation.definition.string.begin.lua
push:
- meta_scope: string.quoted.double.lua
- match: '"'
captures:
0: punctuation.definition.string.end.lua
pop: true
- match: \\.
scope: constant.character.escape.lua
- match: '(?<!--)\[(=*)\['
captures:
0: punctuation.definition.string.begin.lua
push:
- meta_scope: string.quoted.other.multiline.lua
- match: '\]\1\]'
captures:
0: punctuation.definition.string.end.lua
pop: true
- match: \b(break|do|else|for|if|elseif|return|then|repeat|while|until|end|function|local|in)\b
scope: keyword.control.lua
- match: '(?<![^.]\.|:)\b(false|nil|true|_G|_VERSION|math\.(pi|huge))\b|(?<![.])\.{3}(?!\.)'
scope: constant.language.lua
- match: '(?<![^.]\.|:)\b(self)\b'
scope: variable.language.self.lua
#fixes require"composer"; require’composer’; require[[composer]]
# - match: '(?<![^.]\.|:)\b(assert|collectgarbage|dofile|error|getfenv|getmetatable|ipairs|loadfile|loadstring|module|next|pairs|pcall|print|rawequal|rawget|rawset|require|select|setfenv|setmetatable|tonumber|tostring|type|unpack|xpcall)\b(?=[( {])'
- match: (?<![^.]\.|:)\b(assert|collectgarbage|dofile|error|getfenv|getmetatable|ipairs|loadfile|loadstring|module|next|pairs|pcall|print|rawequal|rawget|rawset|require|select|setfenv|setmetatable|tonumber|tostring|type|unpack|xpcall)\b(?=[( {"'\[])
scope: support.function.lua
- match: \b([\w_.:]*)(?=[("'{].*[)"'}])(?<!function)
scope: support.function.lua
- match: '(?<![^.]\.|:)\b(coroutine\.(create|resume|running|status|wrap|yield)|string\.(byte|char|dump|find|format|gmatch|gsub|len|lower|match|rep|reverse|sub|upper)|table\.(concat|insert|maxn|remove|sort)|math\.(abs|acos|asin|atan2?|ceil|cosh?|deg|exp|floor|fmod|frexp|ldexp|log|log10|max|min|modf|pow|rad|random|randomseed|sinh?|sqrt|tanh?)|io\.(close|flush|input|lines|open|output|popen|read|tmpfile|type|write)|os\.(clock|date|difftime|execute|exit|getenv|remove|rename|setlocale|time|tmpname)|package\.(cpath|loaded|loadlib|path|preload|seeall)|debug\.(debug|[gs]etfenv|[gs]ethook|getinfo|[gs]etlocal|[gs]etmetatable|getregistry|[gs]etupvalue|traceback))\b(?=[( {])'
# - match: \b([\w_.:]*)(?=[("'{].*[)"'}])(?<!function)
scope: support.function.library.lua
#for some reason I wrote " just replace the -mat ch lines for the scopes support.function.lua and support.function.library.corona like:"
#But I think I meant support.function.library.lua like I have it right now (working)
# scope: support.function.lua
- match: '\b(ads|analytics|audio|composer|credits|crypto|display|easing|facebook|gameNetwork|global|graphics|io|json|lfs|licensing|math|mime|media|native|network|os|package|physics|socket|sprite|sqlite3|store|storyboard|string|syntax|system|table|timer|transition|widget)\.[a-zA-Z0-9]+\b'
scope: support.function.library.corona
- match: \b(and|or|not)\b
scope: keyword.operator.lua
- match: '\+|-|%|#|\*|\/|\^|==?|~=|<=?|>=?|(?<!\.)\.{2}(?!\.)'
scope: keyword.operator.lua
string:
- meta_scope: comment.block.lua
- match: '\]\1\]'
captures:
0: punctuation.definition.comment.lua
pop: true
And since I’m rambling for the sake of people like me: There were a ton of things I had to setup to get the sublime-corona environment cleaned up and useable (imo). I do think it useful a guide get linked somewhere in the startup tutorials on how to get things setup to viable states. Like you can’t just follow the instructions and have a working environment…you need to write snippets, change sublime’s settings, change corona’s syntax, write scripts for window formatting cause the console etc is locked at a HUGE minimum size…even the formatting of the engine window you got to mess with via scripts and inhouse setting that are confusing. I still have to weed through and delete a bunch of the included solar2d snippets cause u got the old definitions mashed with the new…with the same names…and coming up at the wrong times completely changing what I write on completion. This is insane if you are learning the engine and still don’t have all the definitions you are going to be using memorized. If someone were to gripe about it being too hard to just start working in this engine, I would +1 it and link a guide how to really set things up…and then the issue could be solved. So whoever knows all this stuff should make a video or easily found guide on it, whether that’s you now or future me please consider doing that…youtube results are currently sparse enough a simple video upload might get on page 1 to be easily found.