Skip to content

Commit

Permalink
apply code reviews
Browse files Browse the repository at this point in the history
Signed-off-by: Outsider <outsideris@gmail.com>
  • Loading branch information
outsideris committed Dec 16, 2018
1 parent 625a795 commit 40c4578
Show file tree
Hide file tree
Showing 6 changed files with 97 additions and 66 deletions.
8 changes: 1 addition & 7 deletions components.js

Large diffs are not rendered by default.

51 changes: 21 additions & 30 deletions components/prism-hcl.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,73 +2,64 @@ Prism.languages.hcl = {
'comment': /(?:\/\/|#).*|\/\*[\s\S]*?(?:\*\/|$)/,
'keyword': [
{
pattern: /(resource|data)\s+([\w-]+|"[\w-]+")(?=\s+"[\w-]+"\s+{)/i,
pattern: /(?:resource|data)\s+(?:[\w-]+|"[\w-]+")(?=\s+"[\w-]+"\s+{)/i,
inside: {
'type': [
{
pattern: /(resource|data|\s+)([\w-]+|"[\w-]+")/i,
pattern: /(resource|data|\s+)(?:[\w-]+|"[\w-]+")/i,
lookbehind: true,
alias: 'variable'
}
]
]
}
},
{
pattern: /(provider|provisioner|variable|output|module|backend)\s+(")?([\w-]+)(")?\s+(?={)/i,
pattern: /(?:provider|provisioner|variable|output|module|backend)\s+"?[\w-]+"?\s+(?={)/i,
inside: {
'type': [
{
pattern: /(provider|provisioner|variable|output|module|backend)\s+(")?([\w-]+)(")?\s+/i,
pattern: /(provider|provisioner|variable|output|module|backend)\s+"?[\w-]+"?\s+/i,
lookbehind: true,
alias: 'variable'
}
]
]
}
},
{
pattern: /([\w-]+)(?=\s+{)/
pattern: /[\w-]+(?=\s+{)/
}
],
'interpolation': [
{
pattern: /\${([\w[\](+)\-*%^"',?=:/\s]+\.?)+}/i,
pattern: /\${(?:[\w[\](+)\-*%^"',?=:/\s\\]+\.?)+}/i,
inside: {
'type': [
{
pattern: /((terraform|var|self|count|module|path|data|local)\.)[\w\*]+/i,
pattern: /((?:terraform|var|self|count|module|path|data|local)\.)[\w\*]+/i,
lookbehind: true,
alias: 'variable'
}
],
'keyword': /(terraform|var|self|count|module|path|data|local)/i,
'operator': /\$\{|[}.]/,
'function': [
{
pattern: /[\w]+(?=\()/,
alias: 'variable'
}
],
'string': /".*"/,
'punctuation': /[!"#%&'()*+,.\/;<=>@\[\\\]^`{|}~]/,
'keyword': /(?:terraform|var|self|count|module|path|data|local)/i,
'function': /\w+(?=\()/,
'string': /"(?:\\(?:\r\n|[\s\S])|(?!\1)[^\\\r\n])*"/,
'punctuation': /[!"\$#%&'()*+,.\/;<=>@\[\\\]^`{|}~]/,
'number': /-?\d+\.?\d*/,
'others': [
{
pattern: /[\w\*]+/,
alias: 'string'
}
],
},
]
}
}
],
'property': [
{
pattern: /[\w-\.]+(?=\s*=)/i,
},
{
pattern: /"[\w-\.]+"(?=\s*:)/i
}
/[^\\\r\n]+(?=\s*=)/,
/"[^\\\r\n]+"(?=\s*:)/
],
'string': /"(?:[^\n\r\\"]|\\.)*"/,
'number': /(?:\d+e[+-]?\d+|0[0-7]+|0x[\da-f]+|\d+\.?\d*)/i,
'boolean': /\b(?:true|false)\b/i
'string': /"(?:\\(?:\r\n|[\s\S])|(?!\1)[^\\\r\n])*"/,
'number': /(?:\d+.?\d*e[+-]?\d+|0[0-7]+|0x[\da-f]+|\d+\.?\d*)/i,
'boolean': /\b(?:true|false)\b/i,
'punctuation': /[=\[\]]/,
};
2 changes: 1 addition & 1 deletion components/prism-hcl.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

71 changes: 44 additions & 27 deletions tests/languages/hcl/interpolation_feature.test
Original file line number Diff line number Diff line change
Expand Up @@ -4,98 +4,115 @@
"${length(var.hostnames)}"
"${format("web-%03d", count.index + 1)}"
"${file("templates/web_init.tpl")}"
"${replace(var.sub_domain, ".", "\\\\\\\\.")}"

----------------------------------------------------

[
"\"",
["interpolation",
[
["operator", "${"],
["punctuation", "$"],
["punctuation", "{"],
["keyword", "data"],
["operator", "."],
["punctuation", "."],
["type", "aws_availability_zones"],
["operator", "."],
["punctuation", "."],
["others", "available"],
["operator", "."],
["punctuation", "."],
["others", "names"],
["punctuation", "["],
["number", "0"],
["punctuation", "]"],
["operator", "}"]
["punctuation", "}"]
]
],
"\"\r\n\"",
["interpolation",
[
["operator", "${"],
["punctuation", "$"],
["punctuation", "{"],
["others", "aws_db_subnet_group"],
["operator", "."],
["punctuation", "."],
["others", "default"],
["operator", "."],
["punctuation", "."],
["others", "id"],
["operator", "}"]
["punctuation", "}"]
]
],
"\"\r\n\"",
["interpolation",
[
["operator", "${"],
["punctuation", "$"],
["punctuation", "{"],
["keyword", "var"],
["operator", "."],
["punctuation", "."],
["type", "something"],
" ? ",
["number", "1"],
" : ",
["number", "0"],
["operator", "}"]
["punctuation", "}"]
]
],
"\"\r\n\"",
["interpolation",
[
["operator", "${"],
["punctuation", "$"],
["punctuation", "{"],
["function", "length"],
["punctuation", "("],
["keyword", "var"],
["operator", "."],
["punctuation", "."],
["type", "hostnames"],
["punctuation", ")"],
["operator", "}"]
["punctuation", "}"]
]
],
"\"\r\n\"",
["interpolation",
[
["operator", "${"],
["punctuation", "$"],
["punctuation", "{"],
["function", "format"],
["punctuation", "("],
["string", "\"web-%03d\""],
["punctuation", ","],
["keyword", "count"],
["operator", "."],
["punctuation", "."],
["type", "index"],
["punctuation", "+"],
["number", "1"],
["punctuation", ")"],
["operator", "}"]
["punctuation", "}"]
]
],
"\"\r\n\"",
["interpolation",
[
["operator", "${"],
["punctuation", "$"],
["punctuation", "{"],
["function", "file"],
["punctuation", "("],
["punctuation", "\""],
["others", "templates"],
["punctuation", "/"],
["others", "web_init"],
["operator", "."],
["others", "tpl"],
["punctuation", "\""],
["string", "\"templates/web_init.tpl\""],
["punctuation", ")"],
["operator", "}"]
["punctuation", "}"]
]
],
"\"\r\n\"",
["interpolation",
[
["punctuation", "$"],
["punctuation", "{"],
["function", "replace"],
["punctuation", "("],
["keyword", "var"],
["punctuation", "."],
["type", "sub_domain"],
["punctuation", ","],
["string", "\".\", \"\\\\\\\\\\\\\\\\.\""],
["punctuation", ")"],
["punctuation", "}"]
]
],
"\""
Expand Down
4 changes: 3 additions & 1 deletion tests/languages/hcl/number_feature.test
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
0x1a
027
1e10
3.1e4

----------------------------------------------------

Expand All @@ -11,7 +12,8 @@
["number", "1.02"],
["number", "0x1a"],
["number", "027"],
["number", "1e10"]
["number", "1e10"],
["number", "3.1e4"]
]

----------------------------------------------------
Expand Down
27 changes: 27 additions & 0 deletions tests/languages/hcl/property_feature.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
foo = "bar"
c = 1e10
FOO = "bar"
"bool" = [false]

----------------------------------------------------

[
["property", "foo "],
["punctuation", "="],
["string", "\"bar\""],
["property", "c "],
["punctuation", "="],
["number", "1e10"],
["property", "FOO "],
["punctuation", "="],
["string", "\"bar\""],
["property", "\"bool\" "],
["punctuation", "="],
["punctuation", "["],
["boolean", "false"],
["punctuation", "]"]
]

----------------------------------------------------

Checks for all keywords.

0 comments on commit 40c4578

Please sign in to comment.