feat: add queries for highlighting (#13)
This commit is contained in:
parent
560a04f84d
commit
64da30ce70
|
@ -27,12 +27,22 @@ key
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
|
|
||||||
(document
|
(document
|
||||||
|
(ERROR
|
||||||
|
(quoted_key)
|
||||||
|
(bare_key)
|
||||||
|
(bare_key)
|
||||||
|
(bare_key))
|
||||||
(pair
|
(pair
|
||||||
(key)
|
(bare_key)
|
||||||
(ERROR)
|
(ERROR)
|
||||||
(boolean))
|
(boolean))
|
||||||
|
(ERROR
|
||||||
|
(quoted_key)
|
||||||
|
(bare_key)
|
||||||
|
(bare_key)
|
||||||
|
(bare_key))
|
||||||
(pair
|
(pair
|
||||||
(key)
|
(bare_key)
|
||||||
(ERROR)
|
(ERROR)
|
||||||
(boolean)))
|
(boolean)))
|
||||||
|
|
||||||
|
@ -48,8 +58,18 @@ invalid_both = 1 .0 e 2
|
||||||
|
|
||||||
(document
|
(document
|
||||||
(ERROR
|
(ERROR
|
||||||
(key)
|
(bare_key)
|
||||||
(integer)))
|
(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
|
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
|
(document
|
||||||
(ERROR
|
(ERROR
|
||||||
(key)
|
(bare_key)
|
||||||
(local_date)
|
(local_date)
|
||||||
(local_time)
|
(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
|
INVALID - local date time - whitespaces between its components are not allowed
|
||||||
|
@ -78,9 +103,12 @@ invalid2 = 1979-05-27 T 07:32:00
|
||||||
|
|
||||||
(document
|
(document
|
||||||
(ERROR
|
(ERROR
|
||||||
(key)
|
(bare_key)
|
||||||
(local_date)
|
(local_date)
|
||||||
(local_time)
|
(local_time)
|
||||||
|
(bare_key)
|
||||||
|
(bare_key)
|
||||||
|
(bare_key)
|
||||||
(local_time)))
|
(local_time)))
|
||||||
|
|
||||||
================================================================================
|
================================================================================
|
||||||
|
@ -93,7 +121,7 @@ valid = 1979-05-27
|
||||||
|
|
||||||
(document
|
(document
|
||||||
(pair
|
(pair
|
||||||
(key)
|
(bare_key)
|
||||||
(local_date)))
|
(local_date)))
|
||||||
|
|
||||||
================================================================================
|
================================================================================
|
||||||
|
@ -118,10 +146,20 @@ key
|
||||||
|
|
||||||
(document
|
(document
|
||||||
(table
|
(table
|
||||||
(key)
|
(ERROR
|
||||||
|
(quoted_key)
|
||||||
|
(bare_key)
|
||||||
|
(bare_key)
|
||||||
|
(bare_key))
|
||||||
|
(bare_key)
|
||||||
(ERROR))
|
(ERROR))
|
||||||
(table
|
(table
|
||||||
(key)
|
(ERROR
|
||||||
|
(quoted_key)
|
||||||
|
(bare_key)
|
||||||
|
(bare_key)
|
||||||
|
(bare_key))
|
||||||
|
(bare_key)
|
||||||
(ERROR)))
|
(ERROR)))
|
||||||
|
|
||||||
================================================================================
|
================================================================================
|
||||||
|
@ -136,11 +174,11 @@ key = {
|
||||||
|
|
||||||
(document
|
(document
|
||||||
(pair
|
(pair
|
||||||
(key)
|
(bare_key)
|
||||||
(inline_table
|
(inline_table
|
||||||
(ERROR)
|
(ERROR)
|
||||||
(pair
|
(pair
|
||||||
(key)
|
(bare_key)
|
||||||
(boolean))
|
(boolean))
|
||||||
(ERROR))))
|
(ERROR))))
|
||||||
|
|
||||||
|
@ -166,7 +204,16 @@ key
|
||||||
|
|
||||||
(document
|
(document
|
||||||
(ERROR
|
(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
|
VALID - table - empty content separated by comments
|
||||||
|
@ -180,7 +227,7 @@ VALID - table - empty content separated by comments
|
||||||
|
|
||||||
(document
|
(document
|
||||||
(table
|
(table
|
||||||
(key)
|
(bare_key)
|
||||||
(comment)))
|
(comment)))
|
||||||
|
|
||||||
================================================================================
|
================================================================================
|
||||||
|
@ -195,7 +242,7 @@ VALID - array of tables - empty content separated by comments
|
||||||
|
|
||||||
(document
|
(document
|
||||||
(table_array_element
|
(table_array_element
|
||||||
(key)
|
(bare_key)
|
||||||
(comment)))
|
(comment)))
|
||||||
|
|
||||||
================================================================================
|
================================================================================
|
||||||
|
@ -214,13 +261,13 @@ b = 2
|
||||||
|
|
||||||
(document
|
(document
|
||||||
(table
|
(table
|
||||||
(key)
|
(bare_key)
|
||||||
(pair
|
(pair
|
||||||
(key)
|
(bare_key)
|
||||||
(integer))
|
(integer))
|
||||||
(comment)
|
(comment)
|
||||||
(pair
|
(pair
|
||||||
(key)
|
(bare_key)
|
||||||
(integer))))
|
(integer))))
|
||||||
|
|
||||||
================================================================================
|
================================================================================
|
||||||
|
@ -239,11 +286,11 @@ b = 2
|
||||||
|
|
||||||
(document
|
(document
|
||||||
(table_array_element
|
(table_array_element
|
||||||
(key)
|
(bare_key)
|
||||||
(pair
|
(pair
|
||||||
(key)
|
(bare_key)
|
||||||
(integer))
|
(integer))
|
||||||
(comment)
|
(comment)
|
||||||
(pair
|
(pair
|
||||||
(key)
|
(bare_key)
|
||||||
(integer))))
|
(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: $ =>
|
table: $ =>
|
||||||
seq(
|
seq(
|
||||||
"[",
|
"[",
|
||||||
choice($.dotted_key, $.key),
|
choice($.dotted_key, $._key),
|
||||||
"]",
|
"]",
|
||||||
$._line_ending_or_eof,
|
$._line_ending_or_eof,
|
||||||
repeat(choice($.pair, newline)),
|
repeat(choice($.pair, newline)),
|
||||||
|
@ -54,19 +54,19 @@ module.exports = grammar({
|
||||||
table_array_element: $ =>
|
table_array_element: $ =>
|
||||||
seq(
|
seq(
|
||||||
"[[",
|
"[[",
|
||||||
choice($.dotted_key, $.key),
|
choice($.dotted_key, $._key),
|
||||||
"]]",
|
"]]",
|
||||||
$._line_ending_or_eof,
|
$._line_ending_or_eof,
|
||||||
repeat(choice($.pair, newline)),
|
repeat(choice($.pair, newline)),
|
||||||
),
|
),
|
||||||
|
|
||||||
pair: $ => seq($._inline_pair, $._line_ending_or_eof),
|
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),
|
_key: $ => choice($.bare_key, $.quoted_key),
|
||||||
dotted_key: $ => seq(choice($.dotted_key, $.key), ".", $.key),
|
dotted_key: $ => seq(choice($.dotted_key, $._key), ".", $._key),
|
||||||
_bare_key: $ => /[A-Za-z0-9_-]+/,
|
bare_key: $ => /[A-Za-z0-9_-]+/,
|
||||||
_quoted_key: $ => choice($._basic_string, $._literal_string),
|
quoted_key: $ => choice($._basic_string, $._literal_string),
|
||||||
|
|
||||||
_inline_value: $ =>
|
_inline_value: $ =>
|
||||||
choice(
|
choice(
|
||||||
|
|
13
package.json
13
package.json
|
@ -36,8 +36,21 @@
|
||||||
},
|
},
|
||||||
"files": [
|
"files": [
|
||||||
"/src/",
|
"/src/",
|
||||||
|
"/queries/",
|
||||||
"/binding.gyp",
|
"/binding.gyp",
|
||||||
"/grammar.js",
|
"/grammar.js",
|
||||||
"/index.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");
|
const generatePlayground = require("../tree-sitter/script/generate-playground");
|
||||||
|
|
||||||
generatePlayground("docs", {
|
generatePlayground("docs", {
|
||||||
name: "TOML",
|
name: "TOML",
|
||||||
example: `
|
codeExample: fs.readFileSync(
|
||||||
# This is a TOML document.
|
path.resolve(__dirname, "../examples/toml-lang.toml"),
|
||||||
|
"utf8",
|
||||||
title = "TOML Example"
|
),
|
||||||
|
queryExample: fs.readFileSync(
|
||||||
[owner]
|
path.resolve(__dirname, "../queries/highlights.scm"),
|
||||||
name = "Tom Preston-Werner"
|
"utf8",
|
||||||
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()
|
|
||||||
});
|
});
|
||||||
|
|
20
src/grammar.json
generated
20
src/grammar.json
generated
|
@ -73,7 +73,7 @@
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"type": "SYMBOL",
|
"type": "SYMBOL",
|
||||||
"name": "key"
|
"name": "_key"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
@ -119,7 +119,7 @@
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"type": "SYMBOL",
|
"type": "SYMBOL",
|
||||||
"name": "key"
|
"name": "_key"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
@ -174,7 +174,7 @@
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"type": "SYMBOL",
|
"type": "SYMBOL",
|
||||||
"name": "key"
|
"name": "_key"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
@ -188,16 +188,16 @@
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"key": {
|
"_key": {
|
||||||
"type": "CHOICE",
|
"type": "CHOICE",
|
||||||
"members": [
|
"members": [
|
||||||
{
|
{
|
||||||
"type": "SYMBOL",
|
"type": "SYMBOL",
|
||||||
"name": "_bare_key"
|
"name": "bare_key"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"type": "SYMBOL",
|
"type": "SYMBOL",
|
||||||
"name": "_quoted_key"
|
"name": "quoted_key"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
@ -213,7 +213,7 @@
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"type": "SYMBOL",
|
"type": "SYMBOL",
|
||||||
"name": "key"
|
"name": "_key"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
@ -223,15 +223,15 @@
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"type": "SYMBOL",
|
"type": "SYMBOL",
|
||||||
"name": "key"
|
"name": "_key"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"_bare_key": {
|
"bare_key": {
|
||||||
"type": "PATTERN",
|
"type": "PATTERN",
|
||||||
"value": "[A-Za-z0-9_-]+"
|
"value": "[A-Za-z0-9_-]+"
|
||||||
},
|
},
|
||||||
"_quoted_key": {
|
"quoted_key": {
|
||||||
"type": "CHOICE",
|
"type": "CHOICE",
|
||||||
"members": [
|
"members": [
|
||||||
{
|
{
|
||||||
|
|
68
src/node-types.json
generated
68
src/node-types.json
generated
|
@ -81,12 +81,16 @@
|
||||||
"multiple": true,
|
"multiple": true,
|
||||||
"required": true,
|
"required": true,
|
||||||
"types": [
|
"types": [
|
||||||
|
{
|
||||||
|
"type": "bare_key",
|
||||||
|
"named": true
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"type": "dotted_key",
|
"type": "dotted_key",
|
||||||
"named": true
|
"named": true
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"type": "key",
|
"type": "quoted_key",
|
||||||
"named": true
|
"named": true
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
@ -117,21 +121,6 @@
|
||||||
"named": true,
|
"named": true,
|
||||||
"fields": {}
|
"fields": {}
|
||||||
},
|
},
|
||||||
{
|
|
||||||
"type": "key",
|
|
||||||
"named": true,
|
|
||||||
"fields": {},
|
|
||||||
"children": {
|
|
||||||
"multiple": true,
|
|
||||||
"required": false,
|
|
||||||
"types": [
|
|
||||||
{
|
|
||||||
"type": "escape_sequence",
|
|
||||||
"named": true
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"type": "pair",
|
"type": "pair",
|
||||||
"named": true,
|
"named": true,
|
||||||
|
@ -144,6 +133,10 @@
|
||||||
"type": "array",
|
"type": "array",
|
||||||
"named": true
|
"named": true
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"type": "bare_key",
|
||||||
|
"named": true
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"type": "boolean",
|
"type": "boolean",
|
||||||
"named": true
|
"named": true
|
||||||
|
@ -164,10 +157,6 @@
|
||||||
"type": "integer",
|
"type": "integer",
|
||||||
"named": true
|
"named": true
|
||||||
},
|
},
|
||||||
{
|
|
||||||
"type": "key",
|
|
||||||
"named": true
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"type": "local_date",
|
"type": "local_date",
|
||||||
"named": true
|
"named": true
|
||||||
|
@ -184,6 +173,10 @@
|
||||||
"type": "offset_date_time",
|
"type": "offset_date_time",
|
||||||
"named": true
|
"named": true
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"type": "quoted_key",
|
||||||
|
"named": true
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"named": true
|
"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",
|
"type": "string",
|
||||||
"named": true,
|
"named": true,
|
||||||
|
@ -214,16 +222,20 @@
|
||||||
"multiple": true,
|
"multiple": true,
|
||||||
"required": true,
|
"required": true,
|
||||||
"types": [
|
"types": [
|
||||||
|
{
|
||||||
|
"type": "bare_key",
|
||||||
|
"named": true
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"type": "dotted_key",
|
"type": "dotted_key",
|
||||||
"named": true
|
"named": true
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"type": "key",
|
"type": "pair",
|
||||||
"named": true
|
"named": true
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"type": "pair",
|
"type": "quoted_key",
|
||||||
"named": true
|
"named": true
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
@ -237,16 +249,20 @@
|
||||||
"multiple": true,
|
"multiple": true,
|
||||||
"required": true,
|
"required": true,
|
||||||
"types": [
|
"types": [
|
||||||
|
{
|
||||||
|
"type": "bare_key",
|
||||||
|
"named": true
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"type": "dotted_key",
|
"type": "dotted_key",
|
||||||
"named": true
|
"named": true
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"type": "key",
|
"type": "pair",
|
||||||
"named": true
|
"named": true
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"type": "pair",
|
"type": "quoted_key",
|
||||||
"named": true
|
"named": true
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
@ -296,6 +312,10 @@
|
||||||
"type": "]]",
|
"type": "]]",
|
||||||
"named": false
|
"named": false
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"type": "bare_key",
|
||||||
|
"named": true
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"type": "boolean",
|
"type": "boolean",
|
||||||
"named": true
|
"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