make object, block and tuple delimiters visible

This commit is contained in:
mhoffm
2021-07-04 10:40:40 +02:00
committed by Michael Hoffmann
parent 88c7c031d1
commit 7a12dfe711
11 changed files with 9168 additions and 8674 deletions

View File

@@ -1,5 +1,10 @@
# Changelog
## 0.5.0 - not yet released
feature:
* unhide `(block|object|tuple)_(start|end)` tokens
## 0.4.0 - 2021-07-02
feature:

View File

@@ -37,7 +37,7 @@ resource_1 "strlit1" "strlit2" {
func_of_object = func({
"foo" : 2,
"bar" : baz
"bar" : baz,
key : val,
fizz : buzz,
})

View File

@@ -53,13 +53,13 @@ module.exports = grammar({
block: $ => seq(
$.identifier,
repeat(choice($.string_lit, $.identifier)),
$._block_start,
$.block_start,
optional($.body),
$._block_end,
$.block_end,
),
_block_start: $ => '{',
_block_end: $ => '}',
block_start: $ => '{',
block_end: $ => '}',
identifier: $ => token(seq(
choice(/\p{ID_Start}/, '_'),
@@ -119,13 +119,13 @@ module.exports = grammar({
_comma: $ => ',',
tuple: $ => seq(
$._tuple_start,
$.tuple_start,
optional($._tuple_elems),
$._tuple_end,
$.tuple_end,
),
_tuple_start: $ => '[',
_tuple_end: $ => ']',
tuple_start: $ => '[',
tuple_end: $ => ']',
_tuple_elems: $ => seq(
$.expression,
@@ -137,13 +137,13 @@ module.exports = grammar({
),
object: $ => seq(
$._object_start,
$.object_start,
optional($._object_elems),
$._object_end,
$.object_end,
),
_object_start: $ => '{',
_object_end: $ => '}',
object_start: $ => '{',
object_end: $ => '}',
_object_elems: $ => seq(
$.object_elem,
@@ -182,22 +182,22 @@ module.exports = grammar({
for_expr: $ => choice($.for_tuple_expr, $.for_object_expr),
for_tuple_expr: $ => seq(
$._tuple_start,
$.tuple_start,
$.for_intro,
$.expression,
optional($.for_cond),
$._tuple_end,
$.tuple_end,
),
for_object_expr: $ => seq(
$._object_start,
$.object_start,
$.for_intro,
$.expression,
'=>',
$.expression,
optional($.ellipsis),
optional($.for_cond),
$._object_end,
$.object_end,
),
for_intro: $ => seq(

View File

@@ -80,7 +80,7 @@
},
{
"type": "SYMBOL",
"name": "_block_start"
"name": "block_start"
},
{
"type": "CHOICE",
@@ -96,15 +96,15 @@
},
{
"type": "SYMBOL",
"name": "_block_end"
"name": "block_end"
}
]
},
"_block_start": {
"block_start": {
"type": "STRING",
"value": "{"
},
"_block_end": {
"block_end": {
"type": "STRING",
"value": "}"
},
@@ -345,7 +345,7 @@
"members": [
{
"type": "SYMBOL",
"name": "_tuple_start"
"name": "tuple_start"
},
{
"type": "CHOICE",
@@ -361,15 +361,15 @@
},
{
"type": "SYMBOL",
"name": "_tuple_end"
"name": "tuple_end"
}
]
},
"_tuple_start": {
"tuple_start": {
"type": "STRING",
"value": "["
},
"_tuple_end": {
"tuple_end": {
"type": "STRING",
"value": "]"
},
@@ -415,7 +415,7 @@
"members": [
{
"type": "SYMBOL",
"name": "_object_start"
"name": "object_start"
},
{
"type": "CHOICE",
@@ -431,15 +431,15 @@
},
{
"type": "SYMBOL",
"name": "_object_end"
"name": "object_end"
}
]
},
"_object_start": {
"object_start": {
"type": "STRING",
"value": "{"
},
"_object_end": {
"object_end": {
"type": "STRING",
"value": "}"
},
@@ -667,7 +667,7 @@
"members": [
{
"type": "SYMBOL",
"name": "_tuple_start"
"name": "tuple_start"
},
{
"type": "SYMBOL",
@@ -691,7 +691,7 @@
},
{
"type": "SYMBOL",
"name": "_tuple_end"
"name": "tuple_end"
}
]
},
@@ -700,7 +700,7 @@
"members": [
{
"type": "SYMBOL",
"name": "_object_start"
"name": "object_start"
},
{
"type": "SYMBOL",
@@ -744,7 +744,7 @@
},
{
"type": "SYMBOL",
"name": "_object_end"
"name": "object_end"
}
]
},

View File

@@ -100,6 +100,14 @@
"multiple": true,
"required": true,
"types": [
{
"type": "block_end",
"named": true
},
{
"type": "block_start",
"named": true
},
{
"type": "body",
"named": true
@@ -115,6 +123,16 @@
]
}
},
{
"type": "block_end",
"named": true,
"fields": {}
},
{
"type": "block_start",
"named": true,
"fields": {}
},
{
"type": "body",
"named": true,
@@ -327,6 +345,14 @@
{
"type": "for_intro",
"named": true
},
{
"type": "object_end",
"named": true
},
{
"type": "object_start",
"named": true
}
]
}
@@ -350,6 +376,14 @@
{
"type": "for_intro",
"named": true
},
{
"type": "tuple_end",
"named": true
},
{
"type": "tuple_start",
"named": true
}
]
}
@@ -539,11 +573,19 @@
"fields": {},
"children": {
"multiple": true,
"required": false,
"required": true,
"types": [
{
"type": "object_elem",
"named": true
},
{
"type": "object_end",
"named": true
},
{
"type": "object_start",
"named": true
}
]
}
@@ -574,6 +616,16 @@
}
}
},
{
"type": "object_end",
"named": true,
"fields": {}
},
{
"type": "object_start",
"named": true,
"fields": {}
},
{
"type": "operation",
"named": true,
@@ -728,15 +780,33 @@
"fields": {},
"children": {
"multiple": true,
"required": false,
"required": true,
"types": [
{
"type": "expression",
"named": true
},
{
"type": "tuple_end",
"named": true
},
{
"type": "tuple_start",
"named": true
}
]
}
},
{
"type": "tuple_end",
"named": true,
"fields": {}
},
{
"type": "tuple_start",
"named": true,
"fields": {}
},
{
"type": "unary_operation",
"named": true,

17531
src/parser.c

File diff suppressed because it is too large Load Diff

View File

@@ -10,7 +10,9 @@ block_1 {
(config_file
(body
(block
(identifier))))
(identifier)
(block_start)
(block_end))))
================================================================================
basic block on one line
@@ -23,7 +25,9 @@ block_1 {}
(config_file
(body
(block
(identifier))))
(identifier)
(block_start)
(block_end))))
================================================================================
block with attribute
@@ -47,6 +51,7 @@ block_1 "strlit1" "strlit2" {
(quoted_template_start)
(template_literal)
(quoted_template_end))
(block_start)
(body
(attribute
(identifier)
@@ -55,7 +60,8 @@ block_1 "strlit1" "strlit2" {
(string_lit
(quoted_template_start)
(template_literal)
(quoted_template_end)))))))))
(quoted_template_end))))))
(block_end))))
================================================================================
nested block
@@ -72,9 +78,13 @@ block_1 {
(body
(block
(identifier)
(block_start)
(body
(block
(identifier))))))
(identifier)
(block_start)
(block_end)))
(block_end))))
================================================================================
nested block on one line
@@ -90,9 +100,13 @@ block_1 {
(body
(block
(identifier)
(block_start)
(body
(block
(identifier))))))
(identifier)
(block_start)
(block_end)))
(block_end))))
================================================================================
nested blocks
@@ -109,11 +123,17 @@ block_1 {
(body
(block
(identifier)
(block_start)
(body
(block
(identifier))
(identifier)
(block_start)
(block_end))
(block
(identifier))))))
(identifier)
(block_start)
(block_end)))
(block_end))))
================================================================================
one line block
@@ -128,6 +148,7 @@ locals { timestamp = regex_replace(timestamp(), "[- TZ:]", "") }
(body
(block
(identifier)
(block_start)
(body
(attribute
(identifier)
@@ -148,4 +169,5 @@ locals { timestamp = regex_replace(timestamp(), "[- TZ:]", "") }
(template_expr
(quoted_template
(quoted_template_start)
(quoted_template_end))))))))))))
(quoted_template_end)))))))))
(block_end))))

View File

@@ -13,6 +13,7 @@ foo = [1, 2, "foo"]
(expression
(collection_value
(tuple
(tuple_start)
(expression
(literal_value
(numeric_lit)))
@@ -24,7 +25,8 @@ foo = [1, 2, "foo"]
(string_lit
(quoted_template_start)
(template_literal)
(quoted_template_end))))))))))
(quoted_template_end))))
(tuple_end)))))))
================================================================================
multiline tuple
@@ -45,6 +47,7 @@ foo = [
(expression
(collection_value
(tuple
(tuple_start)
(expression
(literal_value
(numeric_lit)))
@@ -56,7 +59,8 @@ foo = [
(string_lit
(quoted_template_start)
(template_literal)
(quoted_template_end))))))))))
(quoted_template_end))))
(tuple_end)))))))
================================================================================
empty tuple
@@ -72,7 +76,9 @@ foo = []
(identifier)
(expression
(collection_value
(tuple))))))
(tuple
(tuple_start)
(tuple_end)))))))
================================================================================
multiline empty tuple
@@ -89,7 +95,9 @@ foo = [
(identifier)
(expression
(collection_value
(tuple))))))
(tuple
(tuple_start)
(tuple_end)))))))
================================================================================
object
@@ -106,6 +114,7 @@ foo = {1: 2, "foo"="bar"}
(expression
(collection_value
(object
(object_start)
(object_elem
(expression
(literal_value
@@ -125,7 +134,8 @@ foo = {1: 2, "foo"="bar"}
(string_lit
(quoted_template_start)
(template_literal)
(quoted_template_end)))))))))))
(quoted_template_end)))))
(object_end)))))))
================================================================================
multiline object
@@ -145,6 +155,7 @@ foo = {
(expression
(collection_value
(object
(object_start)
(object_elem
(expression
(literal_value
@@ -164,7 +175,8 @@ foo = {
(string_lit
(quoted_template_start)
(template_literal)
(quoted_template_end)))))))))))
(quoted_template_end)))))
(object_end)))))))
================================================================================
empty object
@@ -180,7 +192,9 @@ foo = { }
(identifier)
(expression
(collection_value
(object))))))
(object
(object_start)
(object_end)))))))
================================================================================
multiline empty object
@@ -197,7 +211,9 @@ foo = {
(identifier)
(expression
(collection_value
(object))))))
(object
(object_start)
(object_end)))))))
================================================================================
multiline object weird newlines
@@ -217,6 +233,7 @@ foo = { 1: 2,
(expression
(collection_value
(object
(object_start)
(object_elem
(expression
(literal_value
@@ -236,7 +253,8 @@ foo = { 1: 2,
(string_lit
(quoted_template_start)
(template_literal)
(quoted_template_end)))))))))))
(quoted_template_end)))))
(object_end)))))))
================================================================================
complex object
@@ -256,6 +274,7 @@ foo = {
(expression
(collection_value
(object
(object_start)
(object_elem
(expression
(variable_expr
@@ -275,7 +294,8 @@ foo = {
(string_lit
(quoted_template_start)
(template_literal)
(quoted_template_end)))))))))))
(quoted_template_end)))))
(object_end)))))))
================================================================================
complex from real world
@@ -305,9 +325,11 @@ worker_groups = [
(expression
(collection_value
(tuple
(tuple_start)
(expression
(collection_value
(object
(object_start)
(object_elem
(expression
(variable_expr
@@ -342,16 +364,20 @@ worker_groups = [
(expression
(collection_value
(tuple
(tuple_start)
(expression
(variable_expr
(identifier))
(get_attr
(identifier))
(get_attr
(identifier))))))))))
(identifier)))
(tuple_end)))))
(object_end))))
(expression
(collection_value
(object
(object_start)
(object_elem
(expression
(variable_expr
@@ -379,17 +405,21 @@ worker_groups = [
(expression
(collection_value
(tuple
(tuple_start)
(expression
(variable_expr
(identifier))
(get_attr
(identifier))
(get_attr
(identifier)))))))
(identifier)))
(tuple_end)))))
(object_elem
(expression
(variable_expr
(identifier)))
(expression
(literal_value
(numeric_lit)))))))))))))
(numeric_lit))))
(object_end))))
(tuple_end)))))))

View File

@@ -13,11 +13,13 @@ foo = [for v in ["a", "b"]: v]
(expression
(for_expr
(for_tuple_expr
(tuple_start)
(for_intro
(identifier)
(expression
(collection_value
(tuple
(tuple_start)
(expression
(literal_value
(string_lit
@@ -29,10 +31,12 @@ foo = [for v in ["a", "b"]: v]
(string_lit
(quoted_template_start)
(template_literal)
(quoted_template_end))))))))
(quoted_template_end))))
(tuple_end)))))
(expression
(variable_expr
(identifier)))))))))
(identifier)))
(tuple_end)))))))
================================================================================
for tuple expression with index
@@ -49,12 +53,14 @@ foo = [for i, v in ["a", "b"]: i]
(expression
(for_expr
(for_tuple_expr
(tuple_start)
(for_intro
(identifier)
(identifier)
(expression
(collection_value
(tuple
(tuple_start)
(expression
(literal_value
(string_lit
@@ -66,10 +72,12 @@ foo = [for i, v in ["a", "b"]: i]
(string_lit
(quoted_template_start)
(template_literal)
(quoted_template_end))))))))
(quoted_template_end))))
(tuple_end)))))
(expression
(variable_expr
(identifier)))))))))
(identifier)))
(tuple_end)))))))
================================================================================
for tuple expression with predicate
@@ -86,12 +94,14 @@ foo = [for i, v in ["a", "b", "c"]: v if pred(i)]
(expression
(for_expr
(for_tuple_expr
(tuple_start)
(for_intro
(identifier)
(identifier)
(expression
(collection_value
(tuple
(tuple_start)
(expression
(literal_value
(string_lit
@@ -109,7 +119,8 @@ foo = [for i, v in ["a", "b", "c"]: v if pred(i)]
(string_lit
(quoted_template_start)
(template_literal)
(quoted_template_end))))))))
(quoted_template_end))))
(tuple_end)))))
(expression
(variable_expr
(identifier)))
@@ -120,7 +131,8 @@ foo = [for i, v in ["a", "b", "c"]: v if pred(i)]
(function_arguments
(expression
(variable_expr
(identifier)))))))))))))
(identifier)))))))
(tuple_end)))))))
================================================================================
for object expression
@@ -137,12 +149,14 @@ foo = {for i, v in ["a", "b"]: v => i}
(expression
(for_expr
(for_object_expr
(object_start)
(for_intro
(identifier)
(identifier)
(expression
(collection_value
(tuple
(tuple_start)
(expression
(literal_value
(string_lit
@@ -154,13 +168,15 @@ foo = {for i, v in ["a", "b"]: v => i}
(string_lit
(quoted_template_start)
(template_literal)
(quoted_template_end))))))))
(quoted_template_end))))
(tuple_end)))))
(expression
(variable_expr
(identifier)))
(expression
(variable_expr
(identifier)))))))))
(identifier)))
(object_end)))))))
================================================================================
for object expression 2
@@ -177,12 +193,14 @@ foo = {for i, v in ["a", "b"]: v => i...}
(expression
(for_expr
(for_object_expr
(object_start)
(for_intro
(identifier)
(identifier)
(expression
(collection_value
(tuple
(tuple_start)
(expression
(literal_value
(string_lit
@@ -194,11 +212,13 @@ foo = {for i, v in ["a", "b"]: v => i...}
(string_lit
(quoted_template_start)
(template_literal)
(quoted_template_end))))))))
(quoted_template_end))))
(tuple_end)))))
(expression
(variable_expr
(identifier)))
(expression
(variable_expr
(identifier)))
(ellipsis)))))))
(ellipsis)
(object_end)))))))

View File

@@ -18,6 +18,7 @@ provider "kubernetes" {
(quoted_template_start)
(template_literal)
(quoted_template_end))
(block_start)
(body
(attribute
(identifier)
@@ -59,7 +60,8 @@ provider "kubernetes" {
(index
(legacy_index))
(get_attr
(identifier)))))))))))
(identifier))))))))
(block_end))))
================================================================================
example 2
@@ -111,6 +113,7 @@ resource "azurerm_storage_blob" "proxy_cert" {
(body
(block
(identifier)
(block_start)
(body
(attribute
(identifier)
@@ -175,7 +178,8 @@ resource "azurerm_storage_blob" "proxy_cert" {
(variable_expr
(identifier))
(get_attr
(identifier))))))))
(identifier)))))))
(block_end))
(block
(identifier)
(string_lit
@@ -186,6 +190,7 @@ resource "azurerm_storage_blob" "proxy_cert" {
(quoted_template_start)
(template_literal)
(quoted_template_end))
(block_start)
(body
(attribute
(identifier)
@@ -229,7 +234,8 @@ resource "azurerm_storage_blob" "proxy_cert" {
(string_lit
(quoted_template_start)
(template_literal)
(quoted_template_end)))))))
(quoted_template_end))))))
(block_end))
(block
(identifier)
(string_lit
@@ -240,6 +246,7 @@ resource "azurerm_storage_blob" "proxy_cert" {
(quoted_template_start)
(template_literal)
(quoted_template_end))
(block_start)
(body
(attribute
(identifier)
@@ -283,7 +290,8 @@ resource "azurerm_storage_blob" "proxy_cert" {
(string_lit
(quoted_template_start)
(template_literal)
(quoted_template_end)))))))
(quoted_template_end))))))
(block_end))
(block
(identifier)
(string_lit
@@ -294,6 +302,7 @@ resource "azurerm_storage_blob" "proxy_cert" {
(quoted_template_start)
(template_literal)
(quoted_template_end))
(block_start)
(body
(attribute
(identifier)
@@ -358,7 +367,8 @@ resource "azurerm_storage_blob" "proxy_cert" {
(string_lit
(quoted_template_start)
(template_literal)
(quoted_template_end)))))))
(quoted_template_end))))))
(block_end))
(block
(identifier)
(string_lit
@@ -369,6 +379,7 @@ resource "azurerm_storage_blob" "proxy_cert" {
(quoted_template_start)
(template_literal)
(quoted_template_end))
(block_start)
(body
(attribute
(identifier)
@@ -445,7 +456,8 @@ resource "azurerm_storage_blob" "proxy_cert" {
(string_lit
(quoted_template_start)
(template_literal)
(quoted_template_end)))))))))
(quoted_template_end))))))
(block_end))))
================================================================================
example 3
@@ -494,6 +506,7 @@ locals {
(body
(block
(identifier)
(block_start)
(body
(attribute
(identifier)
@@ -530,4 +543,5 @@ locals {
(get_attr
(identifier)))))
(template_interpolation_end))
(quoted_template_end)))))))))
(quoted_template_end))))))
(block_end))))

View File

@@ -206,13 +206,15 @@ foo = "${ {a=b}[a] }"
(expression
(collection_value
(object
(object_start)
(object_elem
(expression
(variable_expr
(identifier)))
(expression
(variable_expr
(identifier))))))
(identifier))))
(object_end)))
(index
(new_index
(expression