summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatth?us G. Chajdas <dev@anteru.net>2019-04-28 17:14:55 +0200
committerMatth?us G. Chajdas <dev@anteru.net>2019-04-28 17:14:55 +0200
commit075e65ed4e4424c121f7c70e0db9d2ff9e7895f8 (patch)
tree96a0258bb183c47904d10b61d478f51bd9916a64
parent373d770eae7682a785fa3417f96979789199393d (diff)
downloadpygments-075e65ed4e4424c121f7c70e0db9d2ff9e7895f8.tar.gz
Add TOML example file and improve the lexer a bit.
-rw-r--r--pygments/lexers/configs.py9
-rw-r--r--tests/examplefiles/example.toml15
2 files changed, 23 insertions, 1 deletions
diff --git a/pygments/lexers/configs.py b/pygments/lexers/configs.py
index 7c9bd655..bf9cb0bb 100644
--- a/pygments/lexers/configs.py
+++ b/pygments/lexers/configs.py
@@ -894,12 +894,19 @@ class TOMLLexer(RegexLexer):
# Basics, comments, strings
(r'\s+', Text),
(r'#.*?$', Comment.Single),
+ # Basic string
(r'"(\\\\|\\"|[^"])*"', String),
+ # Literal string
+ (r'\'[^\']*\'', String),
(r'(true|false)$', Keyword.Constant),
('[a-zA-Z_][a-zA-Z0-9_\-]*', Name),
+ (r'\[.*?\]$', Keyword),
+
# Datetime
- (r'\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}Z', Number.Integer),
+ # TODO this needs to be expanded, as TOML is rather flexible:
+ # https://github.com/toml-lang/toml#offset-date-time
+ (r'\d{4}-\d{2}-\d{2}(?:T| )\d{2}:\d{2}:\d{2}(?:Z|[-+]\d{2}:\d{2})', Number.Integer),
# Numbers
(r'(\d+\.\d*|\d*\.\d+)([eE][+-]?[0-9]+)?j?', Number.Float),
diff --git a/tests/examplefiles/example.toml b/tests/examplefiles/example.toml
new file mode 100644
index 00000000..40832c22
--- /dev/null
+++ b/tests/examplefiles/example.toml
@@ -0,0 +1,15 @@
+name = "TOML sample file"
+
+[section]
+key = "value"
+literal_string = 'C:\test'
+other_string = '''value'''
+list = [1, 2, 3]
+nested_list = [ [1, 2], [3, 4] ]
+float_variable = 13.37
+
+ [section.nested]
+ boolean_variable = false
+ date_variable = 1969-97-24T16:50:35-00:00
+
+# Comment \ No newline at end of file