Skip to content

Commit

Permalink
Merge pull request #5 from MichaHoffmann/add_field_names_where_approp…
Browse files Browse the repository at this point in the history
…riate

Fix some highlighting issues
  • Loading branch information
MichaHoffmann authored Jul 2, 2021
2 parents 7cf85f1 + 380571c commit 515db10
Show file tree
Hide file tree
Showing 15 changed files with 696 additions and 429 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
11 changes: 7 additions & 4 deletions example/example.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 {
Expand Down
24 changes: 12 additions & 12 deletions grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
],

Expand Down Expand Up @@ -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,
)),


Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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(
Expand All @@ -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
Expand Down
36 changes: 22 additions & 14 deletions src/grammar.json
Original file line number Diff line number Diff line change
Expand Up @@ -310,15 +310,15 @@
"members": [
{
"type": "SYMBOL",
"name": "_quoted_template_start"
"name": "quoted_template_start"
},
{
"type": "SYMBOL",
"name": "template_literal"
},
{
"type": "SYMBOL",
"name": "_quoted_template_end"
"name": "quoted_template_end"
}
]
}
Expand Down Expand Up @@ -492,8 +492,12 @@
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "expression"
"type": "FIELD",
"name": "key",
"content": {
"type": "SYMBOL",
"name": "expression"
}
},
{
"type": "CHOICE",
Expand All @@ -509,8 +513,12 @@
]
},
{
"type": "SYMBOL",
"name": "expression"
"type": "FIELD",
"name": "val",
"content": {
"type": "SYMBOL",
"name": "expression"
}
}
]
},
Expand Down Expand Up @@ -1179,7 +1187,7 @@
"members": [
{
"type": "SYMBOL",
"name": "_quoted_template_start"
"name": "quoted_template_start"
},
{
"type": "CHOICE",
Expand Down Expand Up @@ -1211,7 +1219,7 @@
},
{
"type": "SYMBOL",
"name": "_quoted_template_end"
"name": "quoted_template_end"
}
]
}
Expand Down Expand Up @@ -1294,7 +1302,7 @@
"members": [
{
"type": "SYMBOL",
"name": "_template_interpolation_start"
"name": "template_interpolation_start"
},
{
"type": "CHOICE",
Expand Down Expand Up @@ -1334,7 +1342,7 @@
},
{
"type": "SYMBOL",
"name": "_template_interpolation_end"
"name": "template_interpolation_end"
}
]
},
Expand Down Expand Up @@ -1416,23 +1424,23 @@
"externals": [
{
"type": "SYMBOL",
"name": "_quoted_template_start"
"name": "quoted_template_start"
},
{
"type": "SYMBOL",
"name": "_quoted_template_end"
"name": "quoted_template_end"
},
{
"type": "SYMBOL",
"name": "_template_literal_chunk"
},
{
"type": "SYMBOL",
"name": "_template_interpolation_start"
"name": "template_interpolation_start"
},
{
"type": "SYMBOL",
"name": "_template_interpolation_end"
"name": "template_interpolation_end"
},
{
"type": "SYMBOL",
Expand Down
77 changes: 64 additions & 13 deletions src/node-types.json
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
]
}
}
},
{
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -669,7 +696,7 @@
"fields": {},
"children": {
"multiple": true,
"required": false,
"required": true,
"types": [
{
"type": "expression",
Expand All @@ -678,6 +705,14 @@
{
"type": "strip_marker",
"named": true
},
{
"type": "template_interpolation_end",
"named": true
},
{
"type": "template_interpolation_start",
"named": true
}
]
}
Expand Down Expand Up @@ -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
Expand Down
Loading

0 comments on commit 515db10

Please sign in to comment.