feat: add queries for highlighting (#13)
This commit is contained in:
parent
560a04f84d
commit
64da30ce70
|
@ -27,12 +27,22 @@ key
|
|||
--------------------------------------------------------------------------------
|
||||
|
||||
(document
|
||||
(ERROR
|
||||
(quoted_key)
|
||||
(bare_key)
|
||||
(bare_key)
|
||||
(bare_key))
|
||||
(pair
|
||||
(key)
|
||||
(bare_key)
|
||||
(ERROR)
|
||||
(boolean))
|
||||
(ERROR
|
||||
(quoted_key)
|
||||
(bare_key)
|
||||
(bare_key)
|
||||
(bare_key))
|
||||
(pair
|
||||
(key)
|
||||
(bare_key)
|
||||
(ERROR)
|
||||
(boolean)))
|
||||
|
||||
|
@ -48,8 +58,18 @@ invalid_both = 1 .0 e 2
|
|||
|
||||
(document
|
||||
(ERROR
|
||||
(key)
|
||||
(integer)))
|
||||
(bare_key)
|
||||
(integer)
|
||||
(bare_key)
|
||||
(bare_key)
|
||||
(bare_key)
|
||||
(bare_key)
|
||||
(bare_key)
|
||||
(bare_key)
|
||||
(bare_key)
|
||||
(bare_key)
|
||||
(bare_key)
|
||||
(bare_key)))
|
||||
|
||||
================================================================================
|
||||
INVALID - offset date time - whitespaces between its components are not allowed
|
||||
|
@ -62,10 +82,15 @@ invalid2 = 1979-05-27 T 07:32:00 Z
|
|||
|
||||
(document
|
||||
(ERROR
|
||||
(key)
|
||||
(bare_key)
|
||||
(local_date)
|
||||
(local_time)
|
||||
(local_time)))
|
||||
(bare_key)
|
||||
(bare_key)
|
||||
(bare_key)
|
||||
(bare_key)
|
||||
(local_time)
|
||||
(bare_key)))
|
||||
|
||||
================================================================================
|
||||
INVALID - local date time - whitespaces between its components are not allowed
|
||||
|
@ -78,9 +103,12 @@ invalid2 = 1979-05-27 T 07:32:00
|
|||
|
||||
(document
|
||||
(ERROR
|
||||
(key)
|
||||
(bare_key)
|
||||
(local_date)
|
||||
(local_time)
|
||||
(bare_key)
|
||||
(bare_key)
|
||||
(bare_key)
|
||||
(local_time)))
|
||||
|
||||
================================================================================
|
||||
|
@ -93,7 +121,7 @@ valid = 1979-05-27
|
|||
|
||||
(document
|
||||
(pair
|
||||
(key)
|
||||
(bare_key)
|
||||
(local_date)))
|
||||
|
||||
================================================================================
|
||||
|
@ -118,10 +146,20 @@ key
|
|||
|
||||
(document
|
||||
(table
|
||||
(key)
|
||||
(ERROR
|
||||
(quoted_key)
|
||||
(bare_key)
|
||||
(bare_key)
|
||||
(bare_key))
|
||||
(bare_key)
|
||||
(ERROR))
|
||||
(table
|
||||
(key)
|
||||
(ERROR
|
||||
(quoted_key)
|
||||
(bare_key)
|
||||
(bare_key)
|
||||
(bare_key))
|
||||
(bare_key)
|
||||
(ERROR)))
|
||||
|
||||
================================================================================
|
||||
|
@ -136,11 +174,11 @@ key = {
|
|||
|
||||
(document
|
||||
(pair
|
||||
(key)
|
||||
(bare_key)
|
||||
(inline_table
|
||||
(ERROR)
|
||||
(pair
|
||||
(key)
|
||||
(bare_key)
|
||||
(boolean))
|
||||
(ERROR))))
|
||||
|
||||
|
@ -166,7 +204,16 @@ key
|
|||
|
||||
(document
|
||||
(ERROR
|
||||
(key)))
|
||||
(ERROR
|
||||
(quoted_key)
|
||||
(bare_key)
|
||||
(bare_key)
|
||||
(bare_key)
|
||||
(bare_key)
|
||||
(bare_key)
|
||||
(bare_key)
|
||||
(bare_key))
|
||||
(bare_key)))
|
||||
|
||||
================================================================================
|
||||
VALID - table - empty content separated by comments
|
||||
|
@ -180,7 +227,7 @@ VALID - table - empty content separated by comments
|
|||
|
||||
(document
|
||||
(table
|
||||
(key)
|
||||
(bare_key)
|
||||
(comment)))
|
||||
|
||||
================================================================================
|
||||
|
@ -195,7 +242,7 @@ VALID - array of tables - empty content separated by comments
|
|||
|
||||
(document
|
||||
(table_array_element
|
||||
(key)
|
||||
(bare_key)
|
||||
(comment)))
|
||||
|
||||
================================================================================
|
||||
|
@ -214,13 +261,13 @@ b = 2
|
|||
|
||||
(document
|
||||
(table
|
||||
(key)
|
||||
(bare_key)
|
||||
(pair
|
||||
(key)
|
||||
(bare_key)
|
||||
(integer))
|
||||
(comment)
|
||||
(pair
|
||||
(key)
|
||||
(bare_key)
|
||||
(integer))))
|
||||
|
||||
================================================================================
|
||||
|
@ -239,11 +286,11 @@ b = 2
|
|||
|
||||
(document
|
||||
(table_array_element
|
||||
(key)
|
||||
(bare_key)
|
||||
(pair
|
||||
(key)
|
||||
(bare_key)
|
||||
(integer))
|
||||
(comment)
|
||||
(pair
|
||||
(key)
|
||||
(bare_key)
|
||||
(integer))))
|
||||
|
|
502
corpus/spec.txt
502
corpus/spec.txt
File diff suppressed because it is too large
Load diff
14
grammar.js
14
grammar.js
|
@ -45,7 +45,7 @@ module.exports = grammar({
|
|||
table: $ =>
|
||||
seq(
|
||||
"[",
|
||||
choice($.dotted_key, $.key),
|
||||
choice($.dotted_key, $._key),
|
||||
"]",
|
||||
$._line_ending_or_eof,
|
||||
repeat(choice($.pair, newline)),
|
||||
|
@ -54,19 +54,19 @@ module.exports = grammar({
|
|||
table_array_element: $ =>
|
||||
seq(
|
||||
"[[",
|
||||
choice($.dotted_key, $.key),
|
||||
choice($.dotted_key, $._key),
|
||||
"]]",
|
||||
$._line_ending_or_eof,
|
||||
repeat(choice($.pair, newline)),
|
||||
),
|
||||
|
||||
pair: $ => seq($._inline_pair, $._line_ending_or_eof),
|
||||
_inline_pair: $ => seq(choice($.dotted_key, $.key), "=", $._inline_value),
|
||||
_inline_pair: $ => seq(choice($.dotted_key, $._key), "=", $._inline_value),
|
||||
|
||||
key: $ => choice($._bare_key, $._quoted_key),
|
||||
dotted_key: $ => seq(choice($.dotted_key, $.key), ".", $.key),
|
||||
_bare_key: $ => /[A-Za-z0-9_-]+/,
|
||||
_quoted_key: $ => choice($._basic_string, $._literal_string),
|
||||
_key: $ => choice($.bare_key, $.quoted_key),
|
||||
dotted_key: $ => seq(choice($.dotted_key, $._key), ".", $._key),
|
||||
bare_key: $ => /[A-Za-z0-9_-]+/,
|
||||
quoted_key: $ => choice($._basic_string, $._literal_string),
|
||||
|
||||
_inline_value: $ =>
|
||||
choice(
|
||||
|
|
13
package.json
13
package.json
|
@ -36,8 +36,21 @@
|
|||
},
|
||||
"files": [
|
||||
"/src/",
|
||||
"/queries/",
|
||||
"/binding.gyp",
|
||||
"/grammar.js",
|
||||
"/index.js"
|
||||
],
|
||||
"tree-sitter": [
|
||||
{
|
||||
"scope": "source.toml",
|
||||
"file-types": [
|
||||
"toml"
|
||||
],
|
||||
"highlights": [
|
||||
"queries/highlights.scm"
|
||||
],
|
||||
"injection-regex": "^toml$"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
|
33
queries/highlights.scm
Normal file
33
queries/highlights.scm
Normal file
|
@ -0,0 +1,33 @@
|
|||
; Properties
|
||||
;-----------
|
||||
|
||||
(bare_key) @property
|
||||
(quoted_key) @string
|
||||
|
||||
; Literals
|
||||
;---------
|
||||
|
||||
(boolean) @constant.builtin
|
||||
(comment) @comment
|
||||
(string) @string
|
||||
(integer) @number
|
||||
(float) @number
|
||||
(offset_date_time) @string.special
|
||||
(local_date_time) @string.special
|
||||
(local_date) @string.special
|
||||
(local_time) @string.special
|
||||
|
||||
; Punctuation
|
||||
;------------
|
||||
|
||||
"." @punctuation.delimiter
|
||||
"," @punctuation.delimiter
|
||||
|
||||
"=" @operator
|
||||
|
||||
"[" @punctuation.bracket
|
||||
"]" @punctuation.bracket
|
||||
"[[" @punctuation.bracket
|
||||
"]]" @punctuation.bracket
|
||||
"{" @punctuation.bracket
|
||||
"}" @punctuation.bracket
|
|
@ -1,40 +1,15 @@
|
|||
const fs = require("fs");
|
||||
const path = require("path");
|
||||
const generatePlayground = require("../tree-sitter/script/generate-playground");
|
||||
|
||||
generatePlayground("docs", {
|
||||
name: "TOML",
|
||||
example: `
|
||||
# This is a TOML document.
|
||||
|
||||
title = "TOML Example"
|
||||
|
||||
[owner]
|
||||
name = "Tom Preston-Werner"
|
||||
dob = 1979-05-27T07:32:00-08:00 # First class dates
|
||||
|
||||
[database]
|
||||
server = "192.168.1.1"
|
||||
ports = [ 8001, 8001, 8002 ]
|
||||
connection_max = 5000
|
||||
enabled = true
|
||||
|
||||
[servers]
|
||||
|
||||
# Indentation (tabs and/or spaces) is allowed but not required
|
||||
[servers.alpha]
|
||||
ip = "10.0.0.1"
|
||||
dc = "eqdc10"
|
||||
|
||||
[servers.beta]
|
||||
ip = "10.0.0.2"
|
||||
dc = "eqdc10"
|
||||
|
||||
[clients]
|
||||
data = [ ["gamma", "delta"], [1, 2] ]
|
||||
|
||||
# Line breaks are OK when inside arrays
|
||||
hosts = [
|
||||
"alpha",
|
||||
"omega"
|
||||
]
|
||||
`.trim()
|
||||
codeExample: fs.readFileSync(
|
||||
path.resolve(__dirname, "../examples/toml-lang.toml"),
|
||||
"utf8",
|
||||
),
|
||||
queryExample: fs.readFileSync(
|
||||
path.resolve(__dirname, "../queries/highlights.scm"),
|
||||
"utf8",
|
||||
),
|
||||
});
|
||||
|
|
20
src/grammar.json
generated
20
src/grammar.json
generated
|
@ -73,7 +73,7 @@
|
|||
},
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "key"
|
||||
"name": "_key"
|
||||
}
|
||||
]
|
||||
},
|
||||
|
@ -119,7 +119,7 @@
|
|||
},
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "key"
|
||||
"name": "_key"
|
||||
}
|
||||
]
|
||||
},
|
||||
|
@ -174,7 +174,7 @@
|
|||
},
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "key"
|
||||
"name": "_key"
|
||||
}
|
||||
]
|
||||
},
|
||||
|
@ -188,16 +188,16 @@
|
|||
}
|
||||
]
|
||||
},
|
||||
"key": {
|
||||
"_key": {
|
||||
"type": "CHOICE",
|
||||
"members": [
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "_bare_key"
|
||||
"name": "bare_key"
|
||||
},
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "_quoted_key"
|
||||
"name": "quoted_key"
|
||||
}
|
||||
]
|
||||
},
|
||||
|
@ -213,7 +213,7 @@
|
|||
},
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "key"
|
||||
"name": "_key"
|
||||
}
|
||||
]
|
||||
},
|
||||
|
@ -223,15 +223,15 @@
|
|||
},
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "key"
|
||||
"name": "_key"
|
||||
}
|
||||
]
|
||||
},
|
||||
"_bare_key": {
|
||||
"bare_key": {
|
||||
"type": "PATTERN",
|
||||
"value": "[A-Za-z0-9_-]+"
|
||||
},
|
||||
"_quoted_key": {
|
||||
"quoted_key": {
|
||||
"type": "CHOICE",
|
||||
"members": [
|
||||
{
|
||||
|
|
68
src/node-types.json
generated
68
src/node-types.json
generated
|
@ -81,12 +81,16 @@
|
|||
"multiple": true,
|
||||
"required": true,
|
||||
"types": [
|
||||
{
|
||||
"type": "bare_key",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "dotted_key",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "key",
|
||||
"type": "quoted_key",
|
||||
"named": true
|
||||
}
|
||||
]
|
||||
|
@ -117,21 +121,6 @@
|
|||
"named": true,
|
||||
"fields": {}
|
||||
},
|
||||
{
|
||||
"type": "key",
|
||||
"named": true,
|
||||
"fields": {},
|
||||
"children": {
|
||||
"multiple": true,
|
||||
"required": false,
|
||||
"types": [
|
||||
{
|
||||
"type": "escape_sequence",
|
||||
"named": true
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "pair",
|
||||
"named": true,
|
||||
|
@ -144,6 +133,10 @@
|
|||
"type": "array",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "bare_key",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "boolean",
|
||||
"named": true
|
||||
|
@ -164,10 +157,6 @@
|
|||
"type": "integer",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "key",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "local_date",
|
||||
"named": true
|
||||
|
@ -184,6 +173,10 @@
|
|||
"type": "offset_date_time",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "quoted_key",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "string",
|
||||
"named": true
|
||||
|
@ -191,6 +184,21 @@
|
|||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "quoted_key",
|
||||
"named": true,
|
||||
"fields": {},
|
||||
"children": {
|
||||
"multiple": true,
|
||||
"required": false,
|
||||
"types": [
|
||||
{
|
||||
"type": "escape_sequence",
|
||||
"named": true
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "string",
|
||||
"named": true,
|
||||
|
@ -214,16 +222,20 @@
|
|||
"multiple": true,
|
||||
"required": true,
|
||||
"types": [
|
||||
{
|
||||
"type": "bare_key",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "dotted_key",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "key",
|
||||
"type": "pair",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "pair",
|
||||
"type": "quoted_key",
|
||||
"named": true
|
||||
}
|
||||
]
|
||||
|
@ -237,16 +249,20 @@
|
|||
"multiple": true,
|
||||
"required": true,
|
||||
"types": [
|
||||
{
|
||||
"type": "bare_key",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "dotted_key",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "key",
|
||||
"type": "pair",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "pair",
|
||||
"type": "quoted_key",
|
||||
"named": true
|
||||
}
|
||||
]
|
||||
|
@ -296,6 +312,10 @@
|
|||
"type": "]]",
|
||||
"named": false
|
||||
},
|
||||
{
|
||||
"type": "bare_key",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "boolean",
|
||||
"named": true
|
||||
|
|
1312
src/parser.c
generated
1312
src/parser.c
generated
File diff suppressed because it is too large
Load diff
Loading…
Reference in a new issue