Merge pull request #5 from MichaHoffmann/add_field_names_where_appropriate

Fix some highlighting issues
This commit is contained in:
Michael Hoffmann
2021-07-02 08:36:45 +02:00
committed by GitHub
15 changed files with 696 additions and 429 deletions

View File

@@ -1,5 +1,11 @@
# Changelog
## 0.4.0 - not yet released
feature:
* add named "key" and "val" fields to left and right side of object elements
* unhide the `template_interpolation_(start|end)` and `quoted_template_(start|end)` tokens
## 0.3.2 - 2021-07-01
fix:

View File

@@ -8,7 +8,7 @@ resource_1 "strlit1" "strlit2" {
attr1 = "val1"
tupl1 = [ 1, 2, 3.4, "foo" ]
tupl2 = []
obj1 = { foo = "baz" }
obj1 = { foo = "bar", baz = quoz }
null1 = null
bool1 = true
bool2 = false
@@ -28,15 +28,18 @@ resource_1 "strlit1" "strlit2" {
tpl1 = "prefix-${var.bar}"
tpl2 = "prefix-${func("bar")}"
tpl3 = "prefix-${func("nested-${var.bar}")}"
tpl4 = <<EOF
prefix
${func("foo${ var.bar }")}
suffix
EOF
func_of_object = func({
"foo": 2,
bar: 1,
fizz: buzz,
"foo" : 2,
"bar" : baz
key : val,
fizz : buzz,
})
nested_resource_1 {

View File

@@ -20,11 +20,11 @@ module.exports = grammar({
],
externals: $ => [
$._quoted_template_start,
$._quoted_template_end,
$.quoted_template_start,
$.quoted_template_end,
$._template_literal_chunk,
$._template_interpolation_start,
$._template_interpolation_end,
$.template_interpolation_start,
$.template_interpolation_end,
$.heredoc_identifier,
],
@@ -105,9 +105,9 @@ module.exports = grammar({
null_lit: $ => 'null',
string_lit: $ => prec(PREC.string_lit, seq(
$._quoted_template_start,
$.quoted_template_start,
$.template_literal,
$._quoted_template_end,
$.quoted_template_end,
)),
@@ -155,9 +155,9 @@ module.exports = grammar({
),
object_elem: $ => seq(
$.expression,
field("key", $.expression),
choice('=', ':'),
$.expression,
field("val", $.expression),
),
index: $ => choice($.new_index, $.legacy_index),
@@ -268,13 +268,13 @@ module.exports = grammar({
),
quoted_template: $ => prec(PREC.quoted_template, seq(
$._quoted_template_start,
$.quoted_template_start,
optional(repeat(choice(
$.template_literal,
$.template_interpolation,
$.template_directive,
))),
$._quoted_template_end,
$.quoted_template_end,
)),
heredoc_template: $ => seq(
@@ -297,11 +297,11 @@ module.exports = grammar({
)),
template_interpolation: $ => seq(
$._template_interpolation_start,
$.template_interpolation_start,
optional($.strip_marker),
optional($.expression),
optional($.strip_marker),
$._template_interpolation_end,
$.template_interpolation_end,
),
// TODO

View File

@@ -310,7 +310,7 @@
"members": [
{
"type": "SYMBOL",
"name": "_quoted_template_start"
"name": "quoted_template_start"
},
{
"type": "SYMBOL",
@@ -318,7 +318,7 @@
},
{
"type": "SYMBOL",
"name": "_quoted_template_end"
"name": "quoted_template_end"
}
]
}
@@ -492,8 +492,12 @@
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "expression"
"type": "FIELD",
"name": "key",
"content": {
"type": "SYMBOL",
"name": "expression"
}
},
{
"type": "CHOICE",
@@ -509,8 +513,12 @@
]
},
{
"type": "SYMBOL",
"name": "expression"
"type": "FIELD",
"name": "val",
"content": {
"type": "SYMBOL",
"name": "expression"
}
}
]
},
@@ -1179,7 +1187,7 @@
"members": [
{
"type": "SYMBOL",
"name": "_quoted_template_start"
"name": "quoted_template_start"
},
{
"type": "CHOICE",
@@ -1211,7 +1219,7 @@
},
{
"type": "SYMBOL",
"name": "_quoted_template_end"
"name": "quoted_template_end"
}
]
}
@@ -1294,7 +1302,7 @@
"members": [
{
"type": "SYMBOL",
"name": "_template_interpolation_start"
"name": "template_interpolation_start"
},
{
"type": "CHOICE",
@@ -1334,7 +1342,7 @@
},
{
"type": "SYMBOL",
"name": "_template_interpolation_end"
"name": "template_interpolation_end"
}
]
},
@@ -1416,11 +1424,11 @@
"externals": [
{
"type": "SYMBOL",
"name": "_quoted_template_start"
"name": "quoted_template_start"
},
{
"type": "SYMBOL",
"name": "_quoted_template_end"
"name": "quoted_template_end"
},
{
"type": "SYMBOL",
@@ -1428,11 +1436,11 @@
},
{
"type": "SYMBOL",
"name": "_template_interpolation_start"
"name": "template_interpolation_start"
},
{
"type": "SYMBOL",
"name": "_template_interpolation_end"
"name": "template_interpolation_end"
},
{
"type": "SYMBOL",

View File

@@ -551,16 +551,27 @@
{
"type": "object_elem",
"named": true,
"fields": {},
"children": {
"multiple": true,
"required": true,
"types": [
{
"type": "expression",
"named": true
}
]
"fields": {
"key": {
"multiple": false,
"required": true,
"types": [
{
"type": "expression",
"named": true
}
]
},
"val": {
"multiple": false,
"required": true,
"types": [
{
"type": "expression",
"named": true
}
]
}
}
},
{
@@ -588,8 +599,16 @@
"fields": {},
"children": {
"multiple": true,
"required": false,
"required": true,
"types": [
{
"type": "quoted_template_end",
"named": true
},
{
"type": "quoted_template_start",
"named": true
},
{
"type": "template_directive",
"named": true
@@ -629,9 +648,17 @@
"named": true,
"fields": {},
"children": {
"multiple": false,
"multiple": true,
"required": true,
"types": [
{
"type": "quoted_template_end",
"named": true
},
{
"type": "quoted_template_start",
"named": true
},
{
"type": "template_literal",
"named": true
@@ -669,7 +696,7 @@
"fields": {},
"children": {
"multiple": true,
"required": false,
"required": true,
"types": [
{
"type": "expression",
@@ -678,6 +705,14 @@
{
"type": "strip_marker",
"named": true
},
{
"type": "template_interpolation_end",
"named": true
},
{
"type": "template_interpolation_start",
"named": true
}
]
}
@@ -916,10 +951,26 @@
"type": "null_lit",
"named": true
},
{
"type": "quoted_template_end",
"named": true
},
{
"type": "quoted_template_start",
"named": true
},
{
"type": "strip_marker",
"named": true
},
{
"type": "template_interpolation_end",
"named": true
},
{
"type": "template_interpolation_start",
"named": true
},
{
"type": "true",
"named": false

File diff suppressed because it is too large Load Diff

View File

@@ -13,7 +13,9 @@ foo = "bar"
(expression
(literal_value
(string_lit
(template_literal)))))))
(quoted_template_start)
(template_literal)
(quoted_template_end)))))))
================================================================================
attribute with variable

View File

@@ -40,16 +40,22 @@ block_1 "strlit1" "strlit2" {
(block
(identifier)
(string_lit
(template_literal))
(quoted_template_start)
(template_literal)
(quoted_template_end))
(string_lit
(template_literal))
(quoted_template_start)
(template_literal)
(quoted_template_end))
(body
(attribute
(identifier)
(expression
(literal_value
(string_lit
(template_literal)))))))))
(quoted_template_start)
(template_literal)
(quoted_template_end)))))))))
================================================================================
nested block
@@ -135,7 +141,11 @@ locals { timestamp = regex_replace(timestamp(), "[- TZ:]", "") }
(expression
(literal_value
(string_lit
(template_literal))))
(quoted_template_start)
(template_literal)
(quoted_template_end))))
(expression
(template_expr
(quoted_template)))))))))))
(quoted_template
(quoted_template_start)
(quoted_template_end))))))))))))

View File

@@ -22,7 +22,9 @@ foo = [1, 2, "foo"]
(expression
(literal_value
(string_lit
(template_literal))))))))))
(quoted_template_start)
(template_literal)
(quoted_template_end))))))))))
================================================================================
multiline tuple
@@ -52,7 +54,9 @@ foo = [
(expression
(literal_value
(string_lit
(template_literal))))))))))
(quoted_template_start)
(template_literal)
(quoted_template_end))))))))))
================================================================================
empty tuple
@@ -113,11 +117,15 @@ foo = {1: 2, "foo"="bar"}
(expression
(literal_value
(string_lit
(template_literal))))
(quoted_template_start)
(template_literal)
(quoted_template_end))))
(expression
(literal_value
(string_lit
(template_literal)))))))))))
(quoted_template_start)
(template_literal)
(quoted_template_end)))))))))))
================================================================================
multiline object
@@ -148,11 +156,15 @@ foo = {
(expression
(literal_value
(string_lit
(template_literal))))
(quoted_template_start)
(template_literal)
(quoted_template_end))))
(expression
(literal_value
(string_lit
(template_literal)))))))))))
(quoted_template_start)
(template_literal)
(quoted_template_end)))))))))))
================================================================================
empty object
@@ -216,11 +228,15 @@ foo = { 1: 2,
(expression
(literal_value
(string_lit
(template_literal))))
(quoted_template_start)
(template_literal)
(quoted_template_end))))
(expression
(literal_value
(string_lit
(template_literal)))))))))))
(quoted_template_start)
(template_literal)
(quoted_template_end)))))))))))
================================================================================
complex object
@@ -247,7 +263,9 @@ foo = {
(expression
(literal_value
(string_lit
(template_literal)))))
(quoted_template_start)
(template_literal)
(quoted_template_end)))))
(object_elem
(expression
(variable_expr
@@ -255,7 +273,9 @@ foo = {
(expression
(literal_value
(string_lit
(template_literal)))))))))))
(quoted_template_start)
(template_literal)
(quoted_template_end)))))))))))
================================================================================
complex from real world
@@ -295,7 +315,9 @@ worker_groups = [
(expression
(literal_value
(string_lit
(template_literal)))))
(quoted_template_start)
(template_literal)
(quoted_template_end)))))
(object_elem
(expression
(variable_expr
@@ -303,7 +325,9 @@ worker_groups = [
(expression
(literal_value
(string_lit
(template_literal)))))
(quoted_template_start)
(template_literal)
(quoted_template_end)))))
(object_elem
(expression
(variable_expr
@@ -335,7 +359,9 @@ worker_groups = [
(expression
(literal_value
(string_lit
(template_literal)))))
(quoted_template_start)
(template_literal)
(quoted_template_end)))))
(object_elem
(expression
(variable_expr
@@ -343,7 +369,9 @@ worker_groups = [
(expression
(literal_value
(string_lit
(template_literal)))))
(quoted_template_start)
(template_literal)
(quoted_template_end)))))
(object_elem
(expression
(variable_expr
@@ -365,4 +393,3 @@ worker_groups = [
(expression
(literal_value
(numeric_lit)))))))))))))

View File

@@ -51,11 +51,15 @@ foo = ( true ? false : true ) ? "yes" : "no"
(expression
(literal_value
(string_lit
(template_literal))))
(quoted_template_start)
(template_literal)
(quoted_template_end))))
(expression
(literal_value
(string_lit
(template_literal)))))))))
(quoted_template_start)
(template_literal)
(quoted_template_end)))))))))
================================================================================
nested conditional expression expression without parentheses
@@ -85,8 +89,12 @@ foo = true ? false : true ? "yes" : "no"
(expression
(literal_value
(string_lit
(template_literal))))
(quoted_template_start)
(template_literal)
(quoted_template_end))))
(expression
(literal_value
(string_lit
(template_literal)))))))))
(quoted_template_start)
(template_literal)
(quoted_template_end)))))))))

View File

@@ -21,11 +21,15 @@ foo = [for v in ["a", "b"]: v]
(expression
(literal_value
(string_lit
(template_literal))))
(quoted_template_start)
(template_literal)
(quoted_template_end))))
(expression
(literal_value
(string_lit
(template_literal))))))))
(quoted_template_start)
(template_literal)
(quoted_template_end))))))))
(expression
(variable_expr
(identifier)))))))))
@@ -54,11 +58,15 @@ foo = [for i, v in ["a", "b"]: i]
(expression
(literal_value
(string_lit
(template_literal))))
(quoted_template_start)
(template_literal)
(quoted_template_end))))
(expression
(literal_value
(string_lit
(template_literal))))))))
(quoted_template_start)
(template_literal)
(quoted_template_end))))))))
(expression
(variable_expr
(identifier)))))))))
@@ -87,15 +95,21 @@ foo = [for i, v in ["a", "b", "c"]: v if pred(i)]
(expression
(literal_value
(string_lit
(template_literal))))
(quoted_template_start)
(template_literal)
(quoted_template_end))))
(expression
(literal_value
(string_lit
(template_literal))))
(quoted_template_start)
(template_literal)
(quoted_template_end))))
(expression
(literal_value
(string_lit
(template_literal))))))))
(quoted_template_start)
(template_literal)
(quoted_template_end))))))))
(expression
(variable_expr
(identifier)))
@@ -132,11 +146,15 @@ foo = {for i, v in ["a", "b"]: v => i}
(expression
(literal_value
(string_lit
(template_literal))))
(quoted_template_start)
(template_literal)
(quoted_template_end))))
(expression
(literal_value
(string_lit
(template_literal))))))))
(quoted_template_start)
(template_literal)
(quoted_template_end))))))))
(expression
(variable_expr
(identifier)))
@@ -168,11 +186,15 @@ foo = {for i, v in ["a", "b"]: v => i...}
(expression
(literal_value
(string_lit
(template_literal))))
(quoted_template_start)
(template_literal)
(quoted_template_end))))
(expression
(literal_value
(string_lit
(template_literal))))))))
(quoted_template_start)
(template_literal)
(quoted_template_end))))))))
(expression
(variable_expr
(identifier)))

View File

@@ -33,7 +33,9 @@ foo = bar("foo")
(expression
(literal_value
(string_lit
(template_literal))))))))))
(quoted_template_start)
(template_literal)
(quoted_template_end))))))))))
================================================================================
variadic function call
@@ -79,12 +81,18 @@ foo = bar(
(expression
(literal_value
(string_lit
(template_literal))))
(quoted_template_start)
(template_literal)
(quoted_template_end))))
(expression
(literal_value
(string_lit
(template_literal))))
(quoted_template_start)
(template_literal)
(quoted_template_end))))
(expression
(literal_value
(string_lit
(template_literal))))))))))
(quoted_template_start)
(template_literal)
(quoted_template_end))))))))))

View File

@@ -15,7 +15,9 @@ provider "kubernetes" {
(block
(identifier)
(string_lit
(template_literal))
(quoted_template_start)
(template_literal)
(quoted_template_end))
(body
(attribute
(identifier)
@@ -122,7 +124,9 @@ resource "azurerm_storage_blob" "proxy_cert" {
(get_attr
(identifier))
(template_expr
(quoted_template)))))
(quoted_template
(quoted_template_start)
(quoted_template_end))))))
(expression
(variable_expr
(identifier))
@@ -152,7 +156,9 @@ resource "azurerm_storage_blob" "proxy_cert" {
(get_attr
(identifier))
(template_expr
(quoted_template)))))
(quoted_template
(quoted_template_start)
(quoted_template_end))))))
(expression
(variable_expr
(identifier))
@@ -173,9 +179,13 @@ resource "azurerm_storage_blob" "proxy_cert" {
(block
(identifier)
(string_lit
(template_literal))
(quoted_template_start)
(template_literal)
(quoted_template_end))
(string_lit
(template_literal))
(quoted_template_start)
(template_literal)
(quoted_template_end))
(body
(attribute
(identifier)
@@ -189,7 +199,9 @@ resource "azurerm_storage_blob" "proxy_cert" {
(get_attr
(identifier))
(template_expr
(quoted_template)))))
(quoted_template
(quoted_template_start)
(quoted_template_end))))))
(expression
(literal_value
(numeric_lit)))
@@ -215,13 +227,19 @@ resource "azurerm_storage_blob" "proxy_cert" {
(expression
(literal_value
(string_lit
(template_literal)))))))
(quoted_template_start)
(template_literal)
(quoted_template_end)))))))
(block
(identifier)
(string_lit
(template_literal))
(quoted_template_start)
(template_literal)
(quoted_template_end))
(string_lit
(template_literal))
(quoted_template_start)
(template_literal)
(quoted_template_end))
(body
(attribute
(identifier)
@@ -235,7 +253,9 @@ resource "azurerm_storage_blob" "proxy_cert" {
(get_attr
(identifier))
(template_expr
(quoted_template)))))
(quoted_template
(quoted_template_start)
(quoted_template_end))))))
(expression
(literal_value
(numeric_lit)))
@@ -261,13 +281,19 @@ resource "azurerm_storage_blob" "proxy_cert" {
(expression
(literal_value
(string_lit
(template_literal)))))))
(quoted_template_start)
(template_literal)
(quoted_template_end)))))))
(block
(identifier)
(string_lit
(template_literal))
(quoted_template_start)
(template_literal)
(quoted_template_end))
(string_lit
(template_literal))
(quoted_template_start)
(template_literal)
(quoted_template_end))
(body
(attribute
(identifier)
@@ -281,7 +307,9 @@ resource "azurerm_storage_blob" "proxy_cert" {
(get_attr
(identifier))
(template_expr
(quoted_template)))))
(quoted_template
(quoted_template_start)
(quoted_template_end))))))
(expression
(literal_value
(numeric_lit)))
@@ -328,13 +356,19 @@ resource "azurerm_storage_blob" "proxy_cert" {
(expression
(literal_value
(string_lit
(template_literal)))))))
(quoted_template_start)
(template_literal)
(quoted_template_end)))))))
(block
(identifier)
(string_lit
(template_literal))
(quoted_template_start)
(template_literal)
(quoted_template_end))
(string_lit
(template_literal))
(quoted_template_start)
(template_literal)
(quoted_template_end))
(body
(attribute
(identifier)
@@ -352,13 +386,17 @@ resource "azurerm_storage_blob" "proxy_cert" {
(get_attr
(identifier))
(template_expr
(quoted_template))))
(quoted_template
(quoted_template_start)
(quoted_template_end)))))
(variable_expr
(identifier))))
(get_attr
(identifier))
(template_expr
(quoted_template)))))
(quoted_template
(quoted_template_start)
(quoted_template_end))))))
(expression
(literal_value
(numeric_lit)))
@@ -405,7 +443,9 @@ resource "azurerm_storage_blob" "proxy_cert" {
(expression
(literal_value
(string_lit
(template_literal)))))))))
(quoted_template_start)
(template_literal)
(quoted_template_end)))))))))
================================================================================
example 3
@@ -460,7 +500,9 @@ locals {
(expression
(template_expr
(quoted_template
(quoted_template_start)
(template_interpolation
(template_interpolation_start)
(expression
(conditional
(expression
@@ -486,4 +528,6 @@ locals {
(get_attr
(identifier))
(get_attr
(identifier))))))))))))))
(identifier)))))
(template_interpolation_end))
(quoted_template_end)))))))))

View File

@@ -13,7 +13,9 @@ foo = "foo bar"
(expression
(literal_value
(string_lit
(template_literal)))))))
(quoted_template_start)
(template_literal)
(quoted_template_end)))))))
================================================================================
escaped backslash at end
@@ -30,7 +32,9 @@ foo = "foo\\"
(expression
(literal_value
(string_lit
(template_literal)))))))
(quoted_template_start)
(template_literal)
(quoted_template_end)))))))
================================================================================
string literal escaped template interpolation
@@ -47,7 +51,9 @@ foo = "$${foo.bar}"
(expression
(literal_value
(string_lit
(template_literal)))))))
(quoted_template_start)
(template_literal)
(quoted_template_end)))))))
================================================================================
template chars but no template 1
@@ -64,7 +70,9 @@ foo = "$$$"
(expression
(literal_value
(string_lit
(template_literal)))))))
(quoted_template_start)
(template_literal)
(quoted_template_end)))))))
================================================================================
template chars but no template 2
@@ -81,7 +89,9 @@ foo = "100%"
(expression
(literal_value
(string_lit
(template_literal)))))))
(quoted_template_start)
(template_literal)
(quoted_template_end)))))))
================================================================================
template chars but no template 3
@@ -98,7 +108,9 @@ foo = "%\n\t"
(expression
(literal_value
(string_lit
(template_literal)))))))
(quoted_template_start)
(template_literal)
(quoted_template_end)))))))
================================================================================
template chars but no template 4
@@ -115,7 +127,9 @@ foo = "%%\n\t"
(expression
(literal_value
(string_lit
(template_literal)))))))
(quoted_template_start)
(template_literal)
(quoted_template_end)))))))
================================================================================
template chars but no template 5
@@ -132,7 +146,9 @@ foo = "$$"
(expression
(literal_value
(string_lit
(template_literal)))))))
(quoted_template_start)
(template_literal)
(quoted_template_end)))))))
================================================================================
template chars but no template 6
@@ -149,7 +165,9 @@ foo = "%%{\n\t"
(expression
(literal_value
(string_lit
(template_literal)))))))
(quoted_template_start)
(template_literal)
(quoted_template_end)))))))
================================================================================
escaped template
@@ -166,4 +184,6 @@ foo = "$${ var.bar }"
(expression
(literal_value
(string_lit
(template_literal)))))))
(quoted_template_start)
(template_literal)
(quoted_template_end)))))))

View File

@@ -13,12 +13,16 @@ foo = "${ var.bar }"
(expression
(template_expr
(quoted_template
(quoted_template_start)
(template_interpolation
(template_interpolation_start)
(expression
(variable_expr
(identifier))
(get_attr
(identifier))))))))))
(identifier)))
(template_interpolation_end))
(quoted_template_end)))))))
================================================================================
empty template interpolation
@@ -35,7 +39,11 @@ foo = "${}"
(expression
(template_expr
(quoted_template
(template_interpolation)))))))
(quoted_template_start)
(template_interpolation
(template_interpolation_start)
(template_interpolation_end))
(quoted_template_end)))))))
================================================================================
empty heredoc template
@@ -94,11 +102,17 @@ foo = "${ " ~ " }"
(expression
(template_expr
(quoted_template
(quoted_template_start)
(template_interpolation
(template_interpolation_start)
(expression
(literal_value
(string_lit
(template_literal)))))))))))
(quoted_template_start)
(template_literal)
(quoted_template_end))))
(template_interpolation_end))
(quoted_template_end)))))))
================================================================================
quoted template with nested quoted template
@@ -115,8 +129,10 @@ foo = "p-${ foo("v-${a.b}") }"
(expression
(template_expr
(quoted_template
(quoted_template_start)
(template_literal)
(template_interpolation
(template_interpolation_start)
(expression
(function_call
(identifier)
@@ -124,13 +140,19 @@ foo = "p-${ foo("v-${a.b}") }"
(expression
(template_expr
(quoted_template
(quoted_template_start)
(template_literal)
(template_interpolation
(template_interpolation_start)
(expression
(variable_expr
(identifier))
(get_attr
(identifier)))))))))))))))))
(identifier)))
(template_interpolation_end))
(quoted_template_end)))))))
(template_interpolation_end))
(quoted_template_end)))))))
================================================================================
quoted template interpolation with strip markers
@@ -147,15 +169,21 @@ foo = "hello ${~ "world" ~} hello"
(expression
(template_expr
(quoted_template
(quoted_template_start)
(template_literal)
(template_interpolation
(template_interpolation_start)
(strip_marker)
(expression
(literal_value
(string_lit
(template_literal))))
(strip_marker))
(template_literal)))))))
(quoted_template_start)
(template_literal)
(quoted_template_end))))
(strip_marker)
(template_interpolation_end))
(template_literal)
(quoted_template_end)))))))
================================================================================
quoted template object expression in template
@@ -172,7 +200,9 @@ foo = "${ {a=b}[a] }"
(expression
(template_expr
(quoted_template
(quoted_template_start)
(template_interpolation
(template_interpolation_start)
(expression
(collection_value
(object
@@ -187,7 +217,9 @@ foo = "${ {a=b}[a] }"
(new_index
(expression
(variable_expr
(identifier)))))))))))))
(identifier))))))
(template_interpolation_end))
(quoted_template_end)))))))
================================================================================
escaped template interpolation start
@@ -204,7 +236,9 @@ foo = "hello $${ world"
(expression
(literal_value
(string_lit
(template_literal)))))))
(quoted_template_start)
(template_literal)
(quoted_template_end)))))))
================================================================================
tricky heredoc