1
0
mirror of https://github.com/anthonyaxenov/lite-xl-env-syntax.git synced 2024-12-25 15:40:49 +00:00

Initial commit

This commit is contained in:
Anthony Axenov 2022-06-12 15:43:07 +08:00
commit 828b42cee6
Signed by: anthony
GPG Key ID: EA9EC32FF7CCD4EC
4 changed files with 345 additions and 0 deletions

21
LICENSE Normal file
View File

@ -0,0 +1,21 @@
MIT License
Copyright (c) 2022 Антон Аксенов (aka Anthony Axenov)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

47
README.md Normal file
View File

@ -0,0 +1,47 @@
# env syntax support plugin for lite-xl
[Lite-XL](https://lite-xl.com/) is lightweight, fast and customizable open-source code editor.
This plugin adds syntax support for `*.env` files using *very simple* rules.
Unfortunately, in fact `env`-file syntax is more complicated than it seems, so current solution doesn't cover ALL possible syntax combinations.
My goal is to do so somehow in future but I think plugin is already good enought to use in most of basic cases.
Currently available highlighting:
* line and inline comments;
* keys;
* `export`;
* values:
* literals: `null`, `true`, `false`, `\n`, `\r`, `\t`, `\f`, `\b`, `\\`, `\"`, `\'`;
* numerics;
* strings:
* one-lined (inside `'...'` or `"..."`)
* multiline (inside `"""..."""` or `'''...'''`);
* string interpolation `${myvar}`;
TODO and known issues:
* unquoted string values are not highlighted as string;
* quotes inside unquoted strings are not escaped (highlighted substring inside not highlighted string);
* in unquoted string values, word + `=` are showed as inlined key;
* inside any quoted strings interpolations and literals are not highlighted;
* numeric values containing more than 1 decimal separator are not highlighted as string;
* literals used as keys must be highlighted as keys, not literals;
* quoted strings used as keys must be highlighted as keys, not strings;
* escaped literals must not be used keys;
* ...
You can use `test.env` file to check how plugin works.
## How to install
To install a plugin:
* Drop `language_env.lua` file in:
* Linux: `~/.config/lite-xl/plugins/`
* MacOS: `~/.config/lite-xl/plugins/`
* Windows: `C:\Users\(username)\.config\lite-xl\plugins\`
* If lite-xl is already opened then save files just press `Ctrl`+`Shift`+`P` => `rst` => `Enter` to reboot editor's core and load plugin immidiately.
## License
[The MIT License](LICENSE)

43
language_env.lua Normal file
View File

@ -0,0 +1,43 @@
-- mod-version:2
-- Anthony Axenov (c) 2022, The MIT License
-- https://github.com/anthonyaxenov/lite-xl-env-syntax
local syntax = require "core.syntax"
syntax.add {
name = "language_env",
files = { "%.env$" },
comment = '#',
symbols = {},
patterns = {
{type = "comment" , pattern = "#.*$"},
{type = "function", pattern = "export"},
{type = "literal", pattern = "[Nn][Uu][Ll][Ll]%s*"}, -- null
{type = "literal", pattern = "[Tt][Rr][Uu][Ee]%s*"}, -- true
{type = "literal", pattern = "[Ff][Aa][Ll][Ss][Ee]%s*"}, -- false
{type = "literal", pattern = "\\[nrtfb\\\"']"}, -- escaped chars
{type = "literal", pattern = "'\\u%x%x%x%x'"}, -- unicode sequence
-- quoted strings
{type = "string", pattern = {'"', '"', '\\'}},
{type = "string", pattern = {"'", "'", '\\'}},
{type = "string", pattern = {'"""', '"""', '\\'}},
{type = "string", pattern = {"'''", "'''", '\\'}},
-- numbers
{type = "number", pattern = "0[bB][%d]+"},
{type = "number", pattern = "0[xX][%da-fA-F]+"},
{type = "number", pattern = "[-+]?%.?%d+"},
{ -- keys
pattern = "[a-zA-Z_]+[a-zA-Z%d_]+()%s*=%s*",
type = { "keyword2", "operator" },
},
{ -- interpolated var
pattern = "%${()[a-zA-Z_]+[a-zA-Z%d_]+()}",
type = {"keyword", "keyword2", "keyword"},
},
},
}

234
test.env Normal file
View File

@ -0,0 +1,234 @@
# https://lite-xl.com/?/tutorials/syntax/highlighting
# https://www.lua.org/manual/5.3/manual.html#6.4.1
# https://hexdocs.pm/dotenvy/dotenv-file-format.html
#########################################################
lorem ipsum dolor sit amet
#########################################################
#line comment
# line comment
#line comment
# line comment
#########################################################
empty=
empty =
empty=#inline comment
empty =#inline comment
emp3ty= #inline comment
empty = #inline comment
empty=# inline comment
empty =# inline comment
empty= # inline comment
empty = # inline comment
#########################################################
export empty=
export empty =
#########################################################
null=null#inline comment
null =null #inline comment
null= null# inline comment
null = null # inline comment
NULL=NULL
NULL =NULL
NULL= NULL
NULL = NULL
NuLL=NuLL
NUlL =NUlL
nULL= nULL
NULll= NUlll
#########################################################
true=true
true =true
true= true
true = true
TRUE=TRUE
TRUE =TRUE
TRUE= TRUE
TRUE = TRUE
tRUE=tRUE
TrUE =TrUE
TRuE= TRuE
TRUe = TRUe
#########################################################
false=false
false =false
false= false
false = false
FALSE=FALSE
FALSE =FALSE
FALSE= FALSE
FALSE = FALSE
FaLSE=FaLSE
FAlSE =FAlSE
FALSe= FALSe
fALSE = fALSE
#########################################################
string_no_quotes=string value
string_no_quotes =string value
string_no_quotes= string value
string_no_quotes = string value
string_in_quotes1='string value'
string_in_quotes1 ='string value'
string_in_quotes1= 'string value'
string_in_quotes1 = 'string value'
string_in_quotes2="string value"
string_in_quotes2 ="string value"
string_in_quotes2= "string value"
string_in_quotes2 = "string value"
#########################################################
quotes1_inside_string_no_quotes=string'quotes'value
quotes1_inside_string_no_quotes =string 'quotes'value
quotes1_inside_string_no_quotes= string'quotes' value
quotes1_inside_string_no_quotes = string 'quotes' value
esc_quotes1_inside_string_no_quotes=string\'quotes\'value
esc_quotes1_inside_string_no_quotes =string \'quotes\'value
esc_quotes1_inside_string_no_quotes= string\'quotes\' value
esc_quotes1_inside_string_no_quotes = string \'quotes\' value
quotes2_inside_string_no_quotes=string"quotes"value
quotes2_inside_string_no_quotes =string "quotes"value
quotes2_inside_string_no_quotes= string"quotes" value
quotes2_inside_string_no_quotes = string "quotes" value
esc_quotes2_inside_string_no_quotes=string\"quotes\"value
esc_quotes2_inside_string_no_quotes =string \"quotes\"value
esc_quotes2_inside_string_no_quotes= string\"quotes\" value
esc_quotes2_inside_string_no_quotes = string \"quotes\" value
#########################################################
string_no_quotes_and_literals=true started this string
string_no_quotes_and_literals =false started th=is string
string_no_quotes_and_literals= null started this string
string_no_quotes_and_literals = \n started this string
string_no_quotes_and_literals=now true inside string
string_no_quotes_and_literals =now false inside string
string_no_quotes_and_literals= now null inside string
string_no_quotes_and_literals = now \n inside string
string_no_quotes_and_literals=string and null
string_no_quotes_and_literals =string and true
string_no_quotes_and_literals= string and false
string_no_quotes_and_literals = string and \n
#########################################################
string_in_quotes1_and_literals='true started this string'
string_in_quotes1_and_literals ='false started this string'
string_in_quotes1_and_literals= 'null started this string'
string_in_quotes1_and_literals = '\n started this string'
string_in_quotes1_and_literals='now true inside string'
string_in_quotes1_and_literals ='now false inside string'
string_in_quotes1_and_literals= 'now null inside string'
string_in_quotes1_and_literals = 'now \n inside string'
string_in_quotes1_and_literals='string and null'
string_in_quotes1_and_literals ='string and true'
string_in_quotes1_and_literals= 'string and false'
string_in_quotes1_and_literals = 'string and \n'
#########################################################
string_in_quotes2_and_literals="true started this string"
string_in_quotes2_and_literals ="false started this string"
string_in_quotes2_and_literals= "null started this string"
string_in_quotes2_and_literals = "\n started this string"
string_in_quotes2_and_literals="now true inside string"
string_in_quotes2_and_literals ="now false inside string"
string_in_quotes2_and_literals= "now null inside string"
string_in_quotes2_and_literals = "now \n inside string"
string_in_quotes2_and_literals="string and null"
string_in_quotes2_and_literals ="string and true"
string_in_quotes2_and_literals= "string and false"
string_in_quotes2_and_literals = "string and \n"
#########################################################
STRING="just string"
STRING ="just string"
STRING= "just string"
STRING = "just string"
#########################################################
STRING=string #comment
STRING =string #comment
STRING= string # comment
STRING = string # comment
#########################################################
STRING='#string'#comment
STRING ='#string' #comment
STRING= '#string'# comment
STRING = '#string' # comment
#########################################################
STRING="#string"#comment
STRING ="#string" #comment
STRING= "#string"# comment
STRING = "#string" # comment
#########################################################
escaped_specials=\n\r\t\f\b\\\'\"
escaped_specials =\n\r\t\f\b\\\'\"
escaped_specials= \n\r\t\f\b\\\'\"
escaped_specials = \n\r\t\f\b\\\'\"
escaped_specials=\r\t\f\b\n\\\'\"
escaped_specials =\r\t\f\b\n\\\'\"
escaped_specials= \r\t\f\b\n\\\'\"
escaped_specials = \r\t\f\b\n\\\'\"
\n\r\t\f\b\\\'\" = baaad
#########################################################
q_escaped_specials='\n\r\t\f\b\\\'\"'
q_escaped_specials ='\n\r\t\f\b\\\'\"'
q_escaped_specials= '\n\r\t\f\b\\\'\"'
q_escaped_specials = '\n\r\t\f\b\\\'\"'
#########################################################
q_escaped_specials="\n\r\t\f\b\\\'\""
q_escaped_specials ="\n\r\t\f\b\\\'\""
q_escaped_specials= "\n\r\t\f\b\\\'\""
q_escaped_specials = "\n\r\t\f\b\\\'\""
"string"=baaad
#########################################################
string_with_keys=key=key=key=key=
string_with_keys =key=sfd =key=k asdf ey=
string_with_keys= key=key=key=key=
string_with_keys = key=key=key=key=
#########################################################
interpolated=${MYVAR} #comment
interpolated= ${MYVAR}
interpolated=${MYVAR}@example.com
interpolated= ${MYVAR}@example.com
interpolated="${MYVAR}@example.com"
interpolated="This, that, ${MYVAR} and something else"
interpolated="This, that and ${MYVAR}"
interpolated_multiline="""
${MYVAR} lorem ipsum
dolor ${MYVAR} sit
amet ${MYVAR}
"""
#########################################################
not_interpolated='${MYVAR}, this and that'
not_interpolated='This, that, ${MYVAR} and something else'
not_interpolated='This, that and ${MYVAR}'
not_interpolated= 'This, that, ${MYVAR} and something else'
not_interpolated= 'This, that and ${MYVAR}' #comment
not_interpolated_multiline='''
${MYVAR} lorem ipsum
dolor ${MYVAR} sit
amet ${MYVAR}
'''
#########################################################
number=1025
number =-1025
number= +1025
number = -1025
number=+1025
number=0b1025
number=0B1025
number=0x1025
number=0XDEADbeef
number=0X01234567
number=0X12ABCDEF
number =-1025
number= +1025
number = -1025
number=+1025
number_with_delimiter= 1025.123
number_with_delimiter= -1025.1234
number_with_delimiter=+1025.1234
number_with_delimiter= .123
number_with_delimiter= -.1234
number_with_2_delimiters=+.1234
number_with_2_delimiters= 1025.123.
number_with_2_delimiters= -1025.1234.
number_with_2_delimiters=+1025.1234.
number_with_2_delimiters= .123.
number_with_2_delimiters= -.1234.
number_with_2_delimiters=+.1234.
#########################################################