summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEnrico Tassi <Enrico.Tassi@inria.fr>2023-04-30 09:58:45 +0200
committerGitHub <noreply@github.com>2023-04-30 09:58:45 +0200
commit4575f888183c65eb50f55963b9e20f5af5757b53 (patch)
treee8fffd0b7efdf9087ed808b17e5efb5c8e3940a5
parent013193b542e9f76b799dd6d9665b3aad3cc07ba0 (diff)
downloadpygments-git-4575f888183c65eb50f55963b9e20f5af5757b53.tar.gz
[elpi] handle quotations (#2419)
Co-authored-by: Jean Abou Samra <jean@abou-samra.fr>
-rw-r--r--pygments/lexers/elpi.py10
-rw-r--r--tests/snippets/elpi/test_quotations.txt33
2 files changed, 42 insertions, 1 deletions
diff --git a/pygments/lexers/elpi.py b/pygments/lexers/elpi.py
index 91dfa0a6..6fc8b502 100644
--- a/pygments/lexers/elpi.py
+++ b/pygments/lexers/elpi.py
@@ -10,7 +10,7 @@
from pygments.lexer import RegexLexer, bygroups, include
from pygments.token import Text, Comment, Operator, Keyword, Name, String, \
- Number
+ Number, Punctuation
__all__ = ['ElpiLexer']
@@ -88,6 +88,7 @@ class ElpiLexer(RegexLexer):
(r'"', String.Double, 'elpi-string'),
(r'`', String.Double, 'elpi-btick'),
(r'\'', String.Double, 'elpi-tick'),
+ (r'\{\{', Punctuation, 'elpi-quote'),
(r'\{[^\{]', Text, 'elpi-spill'),
(r"\(", Text, 'elpi-in-parens'),
(r'\d[\d_]*', Number.Integer),
@@ -151,6 +152,13 @@ class ElpiLexer(RegexLexer):
(r'[^\"]+', String.Double),
(r'"', String.Double, '#pop'),
],
+ 'elpi-quote': [
+ (r'\{\{', Punctuation, '#push'),
+ (r'\}\}', Punctuation, '#pop'),
+ (r"(lp:)((?=[A-Z_]){})".format(constant_re), bygroups(Keyword, Name.Variable)),
+ (r"[^l\}]+", Text),
+ (r"l|\}", Text),
+ ],
'elpi-spill': [
(r'\{[^\{]', Text, '#push'),
(r'\}[^\}]', Text, '#pop'),
diff --git a/tests/snippets/elpi/test_quotations.txt b/tests/snippets/elpi/test_quotations.txt
new file mode 100644
index 00000000..05352c7b
--- /dev/null
+++ b/tests/snippets/elpi/test_quotations.txt
@@ -0,0 +1,33 @@
+---input---
+tc {{ Eq lp:A }} {{ f lp:B l } }} :- foo A B.
+
+---tokens---
+'tc' Text
+' ' Text.Whitespace
+'{{' Punctuation
+' Eq ' Text
+'lp:' Keyword
+'A' Name.Variable
+' ' Text
+'}}' Punctuation
+' ' Text.Whitespace
+'{{' Punctuation
+' f ' Text
+'lp:' Keyword
+'B' Name.Variable
+' ' Text
+'l' Text
+' ' Text
+'}' Text
+' ' Text
+'}}' Punctuation
+' ' Text.Whitespace
+':-' Keyword.Declaration
+' ' Text.Whitespace
+'foo' Text
+' ' Text.Whitespace
+'A' Name.Variable
+' ' Text.Whitespace
+'B' Name.Variable
+'.' Operator
+'\n' Text.Whitespace