summaryrefslogtreecommitdiff
path: root/pygments/lexers/configs.py
diff options
context:
space:
mode:
authorTim Hatch <tim@timhatch.com>2015-10-12 15:54:30 -0700
committerTim Hatch <tim@timhatch.com>2015-10-12 15:54:30 -0700
commitc90d76683d23412b02bdd920e57ff5092d4a89b6 (patch)
tree6cdfb374fe0eaeca52380cf2fd453bbf4ccb7f66 /pygments/lexers/configs.py
parentb51eef6aea28d7c7673767781d51151204d1790f (diff)
downloadpygments-c90d76683d23412b02bdd920e57ff5092d4a89b6.tar.gz
Move terraform lexer to configs.py
Diffstat (limited to 'pygments/lexers/configs.py')
-rw-r--r--pygments/lexers/configs.py75
1 files changed, 74 insertions, 1 deletions
diff --git a/pygments/lexers/configs.py b/pygments/lexers/configs.py
index 1bd8f55a..6b00e5f4 100644
--- a/pygments/lexers/configs.py
+++ b/pygments/lexers/configs.py
@@ -18,7 +18,8 @@ from pygments.lexers.shell import BashLexer
__all__ = ['IniLexer', 'RegeditLexer', 'PropertiesLexer', 'KconfigLexer',
'Cfengine3Lexer', 'ApacheConfLexer', 'SquidConfLexer',
- 'NginxConfLexer', 'LighttpdConfLexer', 'DockerLexer']
+ 'NginxConfLexer', 'LighttpdConfLexer', 'DockerLexer',
+ 'TerraformLexer']
class IniLexer(RegexLexer):
@@ -544,3 +545,75 @@ class DockerLexer(RegexLexer):
(r'(.*\\\n)*.+', using(BashLexer)),
],
}
+
+
+class TerraformLexer(RegexLexer):
+ """
+ Lexer for `terraformi .tf files <https://www.terraform.io/>`_
+
+ .. versionadded:: 2.1
+ """
+
+ name = 'Terraform'
+ aliases = ['terraform', 'tf']
+ filenames = ['*.tf']
+ mimetypes = ['application/x-tf', 'application/x-terraform']
+
+ tokens = {
+ 'root': [
+ include('string'),
+ include('punctuation'),
+ include('curly'),
+ include('basic'),
+ include('whitespace'),
+ (r'[0-9]+', Number),
+ ],
+ 'basic': [
+ (words(('true', 'false'), prefix=r'\b', suffix=r'\b'), Keyword.Type),
+ (r'\s*/\*', Comment.Multiline, 'comment'),
+ (r'\s*#.*\n', Comment.Single),
+ (r'(.*?)(\s*)(=)', bygroups(Name.Attribute, Text, Operator)),
+ (words(('variable', 'resource', 'provider', 'provisioner', 'module'),
+ prefix=r'\b', suffix=r'\b'), Keyword.Reserved, 'function'),
+ (words(('ingress', 'egress', 'listener', 'default', 'connection'),
+ prefix=r'\b', suffix=r'\b'), Keyword.Declaration),
+ ('\$\{', String.Interpol, 'var_builtin'),
+ ],
+ 'function': [
+ (r'(\s+)(".*")(\s+)', bygroups(Text, String, Text)),
+ include('punctuation'),
+ include('curly'),
+ ],
+ 'var_builtin': [
+ (r'\$\{', String.Interpol, '#push'),
+ (words(('concat', 'file', 'join', 'lookup', 'element'),
+ prefix=r'\b', suffix=r'\b'), Name.Builtin),
+ include('string'),
+ include('punctuation'),
+ (r'\s+', Text),
+ (r'\}', String.Interpol, '#pop'),
+ ],
+ 'string':[
+ (r'(".*")', bygroups(String.Double)),
+ ],
+ 'punctuation':[
+ (r'[\[\]\(\),.]', Punctuation),
+ ],
+ # Keep this seperate from punctuation - we sometimes want to use different
+ # Tokens for { }
+ 'curly':[
+ (r'\{', Text.Punctuation),
+ (r'\}', Text.Punctuation),
+ ],
+ 'comment': [
+ (r'[^*/]', Comment.Multiline),
+ (r'/\*', Comment.Multiline, '#push'),
+ (r'\*/', Comment.Multiline, '#pop'),
+ (r'[*/]', Comment.Multiline)
+ ],
+ 'whitespace': [
+ (r'\n', Text),
+ (r'\s+', Text),
+ (r'\\\n', Text),
+ ],
+ }