Sublime Forum

How to have ` character recognized as quotes

#1

Recently, Roblox Lua (a variation of Lua) allows you to concatenate strings and variables more easily using the ` character instead of " or '.

However, currently ST does not recognize ` as a type of quote, flagging it as an error:

image

Is there any way for these quotes to be recognized without this error?

0 Likes

#2

I’d suggest to create a Lua (Roblox).sublime-syntax with following content to add support for interpolated backtick-quoted strings based on ST’s default Lua syntax:

%YAML 1.2
---
# See http://www.sublimetext.com/docs/syntax.html
scope: source.lua.roblox
version: 2

file_extensions:
  - lua

extends: Packages/Lua/Lua.sublime-syntax

contexts:
  string:
    - meta_prepend: true
    - include: interpolated-string

  interpolated-string:
    - match: \`
      scope: punctuation.definition.string.begin.lua
      set: interpolated-string-body

  interpolated-string-body:
    - meta_include_prototype: false
    - meta_scope: meta.string.lua string.quoted.backtick.lua
    - match: \`
      scope: punctuation.definition.string.end.lua
      pop: 1
    - match: \{
      scope: punctuation.section.interpolation.begin.lua
      push:
        - string-interpolation
        - expression-end
        - expression-begin
    - include: string-content

  string-interpolation:
    - clear_scopes: 1
    - meta_scope: meta.interpolation.lua
    - match: \}
      scope: punctuation.section.interpolation.end.lua
      pop: 1
2 Likes

#3

Thanks, but how to do that?
Is there any tutorial to create .sublime-syntax?

0 Likes

#4

A small introduction can be found at https://www.sublimetext.com/docs/syntax.html.

Create a file named Lua (Roblox).sublime-syntax in ST’s User package and paste content from above. That’s it. ST loads any *.sublime-syntax file which is found in any folder in Packages/ (see: Main Menu > Preferences > Browse Packages…)

1 Like

#5

Thanks for your answer, but you have to understand that I’m ignorant in ST syntax, so what might seem obvious to you isn’t to me.

What I got so far is this:

  1. I located a folder C:\Users\Rogerio\AppData\Roaming\Sublime Text\Packages\User
  2. There is Lua.sublime-settings there, so I copied it to Lua (Roblox).sublime-settings
  3. When opening the new file, I have this:
  4. When overwriting with your content, I get this:

    I don’t think these are the right steps.
    Could you please help me as a layman?
0 Likes

#6

The steps outlined above are correct, you just didn’t follow them correctly:

Create a file named Lua (Roblox).sublime-syntax in ST’s User package and paste content from above.

You found the User package, but instead of creating a file by that name, you copied an existing settings file to a new name.

You just need to do something like right click in the file explorer for the User folder and choose New > Text File and rename it to the name @deathaxe mentioned above, or Tools > Developer > New Syntax... from the menu.

In the first case you will have to also change the extension of the file (which windows will warn you about) and then open it in Sublime.

In the second case you will get an empty stub syntax file; you can replace the content with the content provided above and Save the file. Sublime will offer to put it into the appropriate place automagically; just make sure you specify the extension so that Sublime recognizes it.

1 Like

#7

Thanks for your patience, I can even create the file, but it doesn’t show up as new syntax.
Here my steps:

0 Likes

#8

You need to save it as a .sublime-syntax file. Not .sublime-settings.

1 Like

#9

You’ve still named the file as a sublime-settings file; it is a sublime-syntax file.

2 Likes

#10

Oh God, it looks like I suffer from dyslexia… :face_with_hand_over_mouth: I’m sorry!
Now the new syntax is working perfectly.
Thank you all! :+1:

0 Likes