Added support for HCL (#1594)

Adds support for HCL ([HashiCorp configuration language](https://github.com/hashicorp/hcl)).
This commit is contained in:
JeongHoon Byun (aka Outsider) 2018-12-27 20:56:24 +09:00 committed by Michael Schmidt
parent 4f6f3c7d49
commit c939df8ed8
13 changed files with 459 additions and 3 deletions

File diff suppressed because one or more lines are too long

View File

@ -337,6 +337,10 @@
"require": "clike",
"owner": "Golmote"
},
"hcl": {
"title": "HCL",
"owner": "outsideris"
},
"http": {
"title": "HTTP",
"peerDependencies": [

65
components/prism-hcl.js Normal file
View File

@ -0,0 +1,65 @@
Prism.languages.hcl = {
'comment': /(?:\/\/|#).*|\/\*[\s\S]*?(?:\*\/|$)/,
'heredoc': {
pattern: /<<-?(\w+)[\s\S]*?^\s*\1/m,
greedy: true,
alias: 'string'
},
'keyword': [
{
pattern: /(?:resource|data)\s+(?:"(?:\\[\s\S]|[^\\"])*")(?=\s+"[\w-]+"\s+{)/i,
inside: {
'type': {
pattern: /(resource|data|\s+)(?:"(?:\\[\s\S]|[^\\"])*")/i,
lookbehind: true,
alias: 'variable'
}
}
},
{
pattern: /(?:provider|provisioner|variable|output|module|backend)\s+(?:[\w-]+|"(?:\\[\s\S]|[^\\"])*")\s+(?={)/i,
inside: {
'type': {
pattern: /(provider|provisioner|variable|output|module|backend)\s+(?:[\w-]+|"(?:\\[\s\S]|[^\\"])*")\s+/i,
lookbehind: true,
alias: 'variable'
}
}
},
{
pattern: /[\w-]+(?=\s+{)/
}
],
'property': [
/[\w-\.]+(?=\s*=(?!=))/,
/"(?:\\[\s\S]|[^\\"])+"(?=\s*[:=])/,
],
'string': {
pattern: /"(?:[^\\$"]|\\[\s\S]|\$(?:(?=")|\$+|[^"${])|\$\{(?:[^{}"]|"(?:[^\\"]|\\[\s\S])*")*\})*"/,
greedy: true,
inside: {
'interpolation': {
pattern: /(^|[^$])\$\{(?:[^{}"]|"(?:[^\\"]|\\[\s\S])*")*\}/,
lookbehind: true,
inside: {
'type': {
pattern: /(\b(?:terraform|var|self|count|module|path|data|local)\b\.)[\w\*]+/i,
lookbehind: true,
alias: 'variable'
},
'keyword': /\b(?:terraform|var|self|count|module|path|data|local)\b/i,
'function': /\w+(?=\()/,
'string': {
pattern: /"(?:\\[\s\S]|[^\\"])*"/,
greedy: true,
},
'number': /\b0x[\da-f]+|\d+\.?\d*(?:e[+-]?\d+)?/i,
'punctuation': /[!\$#%&'()*+,.\/;<=>@\[\\\]^`{|}~?:]/,
}
},
}
},
'number': /\b0x[\da-f]+|\d+\.?\d*(?:e[+-]?\d+)?/i,
'boolean': /\b(?:true|false)\b/i,
'punctuation': /[=\[\]{}]/,
};

1
components/prism-hcl.min.js vendored Normal file
View File

@ -0,0 +1 @@
Prism.languages.hcl={comment:/(?:\/\/|#).*|\/\*[\s\S]*?(?:\*\/|$)/,heredoc:{pattern:/<<-?(\w+)[\s\S]*?^\s*\1/m,greedy:!0,alias:"string"},keyword:[{pattern:/(?:resource|data)\s+(?:"(?:\\[\s\S]|[^\\"])*")(?=\s+"[\w-]+"\s+{)/i,inside:{type:{pattern:/(resource|data|\s+)(?:"(?:\\[\s\S]|[^\\"])*")/i,lookbehind:!0,alias:"variable"}}},{pattern:/(?:provider|provisioner|variable|output|module|backend)\s+(?:[\w-]+|"(?:\\[\s\S]|[^\\"])*")\s+(?={)/i,inside:{type:{pattern:/(provider|provisioner|variable|output|module|backend)\s+(?:[\w-]+|"(?:\\[\s\S]|[^\\"])*")\s+/i,lookbehind:!0,alias:"variable"}}},{pattern:/[\w-]+(?=\s+{)/}],property:[/[\w-\.]+(?=\s*=(?!=))/,/"(?:\\[\s\S]|[^\\"])+"(?=\s*[:=])/],string:{pattern:/"(?:[^\\$"]|\\[\s\S]|\$(?:(?=")|\$+|[^"${])|\$\{(?:[^{}"]|"(?:[^\\"]|\\[\s\S])*")*\})*"/,greedy:!0,inside:{interpolation:{pattern:/(^|[^$])\$\{(?:[^{}"]|"(?:[^\\"]|\\[\s\S])*")*\}/,lookbehind:!0,inside:{type:{pattern:/(\b(?:terraform|var|self|count|module|path|data|local)\b\.)[\w\*]+/i,lookbehind:!0,alias:"variable"},keyword:/\b(?:terraform|var|self|count|module|path|data|local)\b/i,"function":/\w+(?=\()/,string:{pattern:/"(?:\\[\s\S]|[^\\"])*"/,greedy:!0},number:/\b0x[\da-f]+|\d+\.?\d*(?:e[+-]?\d+)?/i,punctuation:/[!\$#%&'()*+,.\/;<=>@\[\\\]^`{|}~?:]/}}}},number:/\b0x[\da-f]+|\d+\.?\d*(?:e[+-]?\d+)?/i,"boolean":/\b(?:true|false)\b/i,punctuation:/[=\[\]{}]/};

42
examples/prism-hcl.html Normal file
View File

@ -0,0 +1,42 @@
<h2>Comments</h2>
<pre><code># Configure the AWS Provider
// Configure the AWS Provider
</code></pre>
<h2>Resources</h2>
<pre><code>resource "aws_instance" "web" {
ami = "${data.aws_ami.ubuntu.id}"
instance_type = "t2.micro"
tags {
Name = "HelloWorld"
}
}</code></pre>
<h2>Provider</h2>
<pre><code>provider "aws" {
access_key = "${var.aws_access_key}"
secret_key = "${var.aws_secret_key}"
region = "us-east-1"
}</code></pre>
<h2>Variables</h2>
<pre><code>variable "images" {
type = "map"
default = {
us-east-1 = "image-1234"
us-west-2 = "image-4567"
}
}</code></pre>
<h2>Outputs</h2>
<pre><code>output "address" {
value = "${aws_instance.db.public_dns}"
}</code></pre>
<h2>Modules</h2>
<pre><code>module "consul" {
source = "hashicorp/consul/aws"
servers = 5
}</code></pre>

View File

@ -11,7 +11,7 @@ if (!Prism.plugins.toolbar) {
}
// The languages map is built automatically with gulp
var Languages = /*languages_placeholder[*/{"html":"HTML","xml":"XML","svg":"SVG","mathml":"MathML","css":"CSS","clike":"C-like","javascript":"JavaScript","abap":"ABAP","actionscript":"ActionScript","apacheconf":"Apache Configuration","apl":"APL","applescript":"AppleScript","arff":"ARFF","asciidoc":"AsciiDoc","asm6502":"6502 Assembly","aspnet":"ASP.NET (C#)","autohotkey":"AutoHotkey","autoit":"AutoIt","shell":"Shell","basic":"BASIC","csharp":"C#","cpp":"C++","cil":"CIL","coffeescript":"CoffeeScript","csp":"Content-Security-Policy","css-extras":"CSS Extras","django":"Django/Jinja2","erb":"ERB","fsharp":"F#","gcode":"G-code","gedcom":"GEDCOM","glsl":"GLSL","gml":"GameMaker Language","graphql":"GraphQL","http":"HTTP","hpkp":"HTTP Public-Key-Pins","hsts":"HTTP Strict-Transport-Security","ichigojam":"IchigoJam","inform7":"Inform 7","javastacktrace":"Java stack trace","json":"JSON","jsonp":"JSONP","latex":"LaTeX","livescript":"LiveScript","lolcode":"LOLCODE","markup-templating":"Markup templating","matlab":"MATLAB","mel":"MEL","n4js":"N4JS","nasm":"NASM","nginx":"nginx","nsis":"NSIS","objectivec":"Objective-C","ocaml":"OCaml","opencl":"OpenCL","parigp":"PARI/GP","objectpascal":"Object Pascal","php":"PHP","php-extras":"PHP Extras","plsql":"PL/SQL","powershell":"PowerShell","properties":".properties","protobuf":"Protocol Buffers","q":"Q (kdb+ database)","jsx":"React JSX","tsx":"React TSX","renpy":"Ren'py","rest":"reST (reStructuredText)","sas":"SAS","sass":"Sass (Sass)","scss":"Sass (Scss)","sql":"SQL","soy":"Soy (Closure Template)","tap":"TAP","toml":"TOML","tt2":"Template Toolkit 2","typescript":"TypeScript","vbnet":"VB.Net","vhdl":"VHDL","vim":"vim","visual-basic":"Visual Basic","wasm":"WebAssembly","wiki":"Wiki markup","xeoracube":"XeoraCube","xojo":"Xojo (REALbasic)","xquery":"XQuery","yaml":"YAML"}/*]*/;
var Languages = /*languages_placeholder[*/{"html":"HTML","xml":"XML","svg":"SVG","mathml":"MathML","css":"CSS","clike":"C-like","javascript":"JavaScript","abap":"ABAP","actionscript":"ActionScript","apacheconf":"Apache Configuration","apl":"APL","applescript":"AppleScript","arff":"ARFF","asciidoc":"AsciiDoc","asm6502":"6502 Assembly","aspnet":"ASP.NET (C#)","autohotkey":"AutoHotkey","autoit":"AutoIt","shell":"Shell","basic":"BASIC","csharp":"C#","cpp":"C++","cil":"CIL","coffeescript":"CoffeeScript","csp":"Content-Security-Policy","css-extras":"CSS Extras","django":"Django/Jinja2","erb":"ERB","fsharp":"F#","gcode":"G-code","gedcom":"GEDCOM","glsl":"GLSL","gml":"GameMaker Language","graphql":"GraphQL","hcl":"HCL","http":"HTTP","hpkp":"HTTP Public-Key-Pins","hsts":"HTTP Strict-Transport-Security","ichigojam":"IchigoJam","inform7":"Inform 7","javastacktrace":"Java stack trace","json":"JSON","jsonp":"JSONP","latex":"LaTeX","livescript":"LiveScript","lolcode":"LOLCODE","markup-templating":"Markup templating","matlab":"MATLAB","mel":"MEL","n4js":"N4JS","nasm":"NASM","nginx":"nginx","nsis":"NSIS","objectivec":"Objective-C","ocaml":"OCaml","opencl":"OpenCL","parigp":"PARI/GP","objectpascal":"Object Pascal","php":"PHP","php-extras":"PHP Extras","plsql":"PL/SQL","powershell":"PowerShell","properties":".properties","protobuf":"Protocol Buffers","q":"Q (kdb+ database)","jsx":"React JSX","tsx":"React TSX","renpy":"Ren'py","rest":"reST (reStructuredText)","sas":"SAS","sass":"Sass (Sass)","scss":"Sass (Scss)","sql":"SQL","soy":"Soy (Closure Template)","tap":"TAP","toml":"TOML","tt2":"Template Toolkit 2","typescript":"TypeScript","vbnet":"VB.Net","vhdl":"VHDL","vim":"vim","visual-basic":"Visual Basic","wasm":"WebAssembly","wiki":"Wiki markup","xeoracube":"XeoraCube","xojo":"Xojo (REALbasic)","xquery":"XQuery","yaml":"YAML"}/*]*/;
Prism.plugins.toolbar.registerButton('show-language', function(env) {
var pre = env.element.parentNode;
if (!pre || !/pre/i.test(pre.nodeName)) {

View File

@ -1 +1 @@
!function(){if("undefined"!=typeof self&&self.Prism&&self.document){if(!Prism.plugins.toolbar)return console.warn("Show Languages plugin loaded before Toolbar plugin."),void 0;var e={html:"HTML",xml:"XML",svg:"SVG",mathml:"MathML",css:"CSS",clike:"C-like",javascript:"JavaScript",abap:"ABAP",actionscript:"ActionScript",apacheconf:"Apache Configuration",apl:"APL",applescript:"AppleScript",arff:"ARFF",asciidoc:"AsciiDoc",asm6502:"6502 Assembly",aspnet:"ASP.NET (C#)",autohotkey:"AutoHotkey",autoit:"AutoIt",shell:"Shell",basic:"BASIC",csharp:"C#",cpp:"C++",cil:"CIL",coffeescript:"CoffeeScript",csp:"Content-Security-Policy","css-extras":"CSS Extras",django:"Django/Jinja2",erb:"ERB",fsharp:"F#",gcode:"G-code",gedcom:"GEDCOM",glsl:"GLSL",gml:"GameMaker Language",graphql:"GraphQL",http:"HTTP",hpkp:"HTTP Public-Key-Pins",hsts:"HTTP Strict-Transport-Security",ichigojam:"IchigoJam",inform7:"Inform 7",javastacktrace:"Java stack trace",json:"JSON",jsonp:"JSONP",latex:"LaTeX",livescript:"LiveScript",lolcode:"LOLCODE","markup-templating":"Markup templating",matlab:"MATLAB",mel:"MEL",n4js:"N4JS",nasm:"NASM",nginx:"nginx",nsis:"NSIS",objectivec:"Objective-C",ocaml:"OCaml",opencl:"OpenCL",parigp:"PARI/GP",objectpascal:"Object Pascal",php:"PHP","php-extras":"PHP Extras",plsql:"PL/SQL",powershell:"PowerShell",properties:".properties",protobuf:"Protocol Buffers",q:"Q (kdb+ database)",jsx:"React JSX",tsx:"React TSX",renpy:"Ren'py",rest:"reST (reStructuredText)",sas:"SAS",sass:"Sass (Sass)",scss:"Sass (Scss)",sql:"SQL",soy:"Soy (Closure Template)",tap:"TAP",toml:"TOML",tt2:"Template Toolkit 2",typescript:"TypeScript",vbnet:"VB.Net",vhdl:"VHDL",vim:"vim","visual-basic":"Visual Basic",wasm:"WebAssembly",wiki:"Wiki markup",xeoracube:"XeoraCube",xojo:"Xojo (REALbasic)",xquery:"XQuery",yaml:"YAML"};Prism.plugins.toolbar.registerButton("show-language",function(a){var t=a.element.parentNode;if(t&&/pre/i.test(t.nodeName)){var s=t.getAttribute("data-language")||e[a.language]||a.language&&a.language.substring(0,1).toUpperCase()+a.language.substring(1);if(s){var r=document.createElement("span");return r.textContent=s,r}}})}}();
!function(){if("undefined"!=typeof self&&self.Prism&&self.document){if(!Prism.plugins.toolbar)return console.warn("Show Languages plugin loaded before Toolbar plugin."),void 0;var e={html:"HTML",xml:"XML",svg:"SVG",mathml:"MathML",css:"CSS",clike:"C-like",javascript:"JavaScript",abap:"ABAP",actionscript:"ActionScript",apacheconf:"Apache Configuration",apl:"APL",applescript:"AppleScript",arff:"ARFF",asciidoc:"AsciiDoc",asm6502:"6502 Assembly",aspnet:"ASP.NET (C#)",autohotkey:"AutoHotkey",autoit:"AutoIt",shell:"Shell",basic:"BASIC",csharp:"C#",cpp:"C++",cil:"CIL",coffeescript:"CoffeeScript",csp:"Content-Security-Policy","css-extras":"CSS Extras",django:"Django/Jinja2",erb:"ERB",fsharp:"F#",gcode:"G-code",gedcom:"GEDCOM",glsl:"GLSL",gml:"GameMaker Language",graphql:"GraphQL",hcl:"HCL",http:"HTTP",hpkp:"HTTP Public-Key-Pins",hsts:"HTTP Strict-Transport-Security",ichigojam:"IchigoJam",inform7:"Inform 7",javastacktrace:"Java stack trace",json:"JSON",jsonp:"JSONP",latex:"LaTeX",livescript:"LiveScript",lolcode:"LOLCODE","markup-templating":"Markup templating",matlab:"MATLAB",mel:"MEL",n4js:"N4JS",nasm:"NASM",nginx:"nginx",nsis:"NSIS",objectivec:"Objective-C",ocaml:"OCaml",opencl:"OpenCL",parigp:"PARI/GP",objectpascal:"Object Pascal",php:"PHP","php-extras":"PHP Extras",plsql:"PL/SQL",powershell:"PowerShell",properties:".properties",protobuf:"Protocol Buffers",q:"Q (kdb+ database)",jsx:"React JSX",tsx:"React TSX",renpy:"Ren'py",rest:"reST (reStructuredText)",sas:"SAS",sass:"Sass (Sass)",scss:"Sass (Scss)",sql:"SQL",soy:"Soy (Closure Template)",tap:"TAP",toml:"TOML",tt2:"Template Toolkit 2",typescript:"TypeScript",vbnet:"VB.Net",vhdl:"VHDL",vim:"vim","visual-basic":"Visual Basic",wasm:"WebAssembly",wiki:"Wiki markup",xeoracube:"XeoraCube",xojo:"Xojo (REALbasic)",xquery:"XQuery",yaml:"YAML"};Prism.plugins.toolbar.registerButton("show-language",function(a){var t=a.element.parentNode;if(t&&/pre/i.test(t.nodeName)){var s=t.getAttribute("data-language")||e[a.language]||a.language&&a.language.substring(0,1).toUpperCase()+a.language.substring(1);if(s){var r=document.createElement("span");return r.textContent=s,r}}})}}();

View File

@ -0,0 +1,17 @@
# foo bar
// foo bar
/*
* multi line
*/
----------------------------------------------------
[
["comment", "# foo bar"],
["comment", "// foo bar"],
["comment", "/*\r\n * multi line\r\n */"]
]
----------------------------------------------------
Checks for comments.

View File

@ -0,0 +1,206 @@
"${data.aws_availability_zones.available.names[0]}"
"${aws_db_subnet_group.default.id}"
"${var.something ? 1 : 0}"
"${var.num ? 1.02 : 0}"
"${length(var.hostnames)}"
"${format("web-%03d", count.index + 1)}"
"${file("templates/web_init.tpl")}"
"${replace(var.sub_domain, ".", "\\\\\\\\.")}"
"${filepath.foo}"
----------------------------------------------------
[
["string",
[
"\"",
[
"interpolation",
[
["punctuation", "$"],
["punctuation", "{"],
["keyword", "data"],
["punctuation", "."],
["type", "aws_availability_zones"],
["punctuation", "."],
"available",
["punctuation", "."],
"names",
["punctuation", "["],
["number", "0"],
["punctuation", "]"],
["punctuation", "}"]
]
],
"\""
]
],
["string",
[
"\"",
[
"interpolation",
[
["punctuation", "$"],
["punctuation", "{"],
"aws_db_subnet_group",
["punctuation", "."],
"default",
["punctuation", "."],
"id",
["punctuation", "}"]
]
],
"\""
]
],
["string",
[
"\"",
[
"interpolation",
[
["punctuation", "$"],
["punctuation", "{"],
["keyword", "var"],
["punctuation", "."],
["type", "something"],
["punctuation", "?"],
["number", "1"],
["punctuation", ":"],
["number", "0"],
["punctuation", "}"]
]
],
"\""
]
],
["string",
[
"\"",
[
"interpolation",
[
["punctuation", "$"],
["punctuation", "{"],
["keyword", "var"],
["punctuation", "."],
["type", "num"],
["punctuation", "?"],
["number", "1.02"],
["punctuation", ":"],
["number", "0"],
["punctuation", "}"]
]
],
"\""
]
],
["string",
[
"\"",
[
"interpolation",
[
["punctuation", "$"],
["punctuation", "{"],
["function", "length"],
["punctuation", "("],
["keyword", "var"],
["punctuation", "."],
["type", "hostnames"],
["punctuation", ")"],
["punctuation", "}"]
]
],
"\""
]
],
["string",
[
"\"",
[
"interpolation",
[
["punctuation", "$"],
["punctuation", "{"],
["function", "format"],
["punctuation", "("],
["string", "\"web-%03d\""],
["punctuation", ","],
["keyword", "count"],
["punctuation", "."],
["type", "index"],
["punctuation", "+"],
["number", "1"],
["punctuation", ")"],
["punctuation", "}"]
]
],
"\""
]
],
["string",
[
"\"",
[
"interpolation",
[
["punctuation", "$"],
["punctuation", "{"],
["function", "file"],
["punctuation", "("],
["string", "\"templates/web_init.tpl\""],
["punctuation", ")"],
["punctuation", "}"]
]
],
"\""
]
],
["string",
[
"\"",
[
"interpolation",
[
["punctuation", "$"],
["punctuation", "{"],
["function", "replace"],
["punctuation", "("],
["keyword", "var"],
["punctuation", "."],
["type", "sub_domain"],
["punctuation", ","],
["string", "\".\""],
["punctuation", ","],
["string", "\"\\\\\\\\\\\\\\\\.\""],
["punctuation", ")"],
["punctuation", "}"]
]
],
"\""
]
],
["string",
[
"\"",
[
"interpolation",
[
["punctuation", "$"],
["punctuation", "{"],
"filepath",
["punctuation", "."],
"foo",
["punctuation", "}"]
]
],
"\""
]
]
]
----------------------------------------------------
Checks for all interpolation.

View File

@ -0,0 +1,32 @@
resource "aws_db_instance" "main" {
data "terraform_remote_state" "main" {
output "dev_vpc_id" {
config {
terraform {
----------------------------------------------------
[
["keyword",
["resource ",
["type", "\"aws_db_instance\""]]],
["string", ["\"main\""]],
["punctuation", "{"],
["keyword",
["data ",
["type", "\"terraform_remote_state\""]]],
["string", ["\"main\""]],
["punctuation", "{"],
["keyword",
["output",
["type", " \"dev_vpc_id\" "]]],
["punctuation", "{"],
["keyword", "config"],
["punctuation", "{"],
["keyword", "terraform"],
["punctuation", "{"]
]
----------------------------------------------------
Checks for all keywords.

View File

@ -0,0 +1,21 @@
42
1.02
0x1a
027
1e10
3.1e4
----------------------------------------------------
[
["number", "42"],
["number", "1.02"],
["number", "0x1a"],
["number", "027"],
["number", "1e10"],
["number", "3.1e4"]
]
----------------------------------------------------
Checks for numbers.

View File

@ -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 properties.

View File

@ -0,0 +1,41 @@
"double quoted\"' % string"
"abc // what now?"
multiline_literal = "hello
world"
foo = <<EOF
bar
baz
EOF
bar = <<-EOF_TEXT
bar
"baz"
EOF_TEXT
foo = <<FOO
# I'm not a comment
// me neither
/* this might make a good test */
This string can contain FOO but not at the start of a line.
FOO
----------------------------------------------------
[
["string", ["\"double quoted\\\"' % string\""]],
["string", ["\"abc // what now?\""]],
["property", "multiline_literal"],
["punctuation", "="],
["string", ["\"hello\r\n world\""]],
["property", "foo"],
["punctuation", "="],
["heredoc", "<<EOF\r\n bar\r\n baz\r\n EOF"],
["property", "bar"],
["punctuation", "="],
["heredoc", "<<-EOF_TEXT\r\n bar\r\n \"baz\"\r\n EOF_TEXT"],
["property", "foo"],
["punctuation", "="],
["heredoc", "<<FOO\r\n # I'm not a comment\r\n // me neither\r\n /* this might make a good test */\r\n This string can contain FOO but not at the start of a line.\r\nFOO"]
]
----------------------------------------------------
Checks for strings.