|
1 # -*- coding: utf-8 -*- |
|
2 """ |
|
3 pygments.lexers.pointless |
|
4 ~~~~~~~~~~~~~~~~~~~~~~~~~ |
|
5 |
|
6 Lexers for Pointless. |
|
7 |
|
8 :copyright: Copyright 2006-2020 by the Pygments team, see AUTHORS. |
|
9 :license: BSD, see LICENSE for details. |
|
10 """ |
|
11 |
|
12 from pygments.lexer import RegexLexer, words |
|
13 from pygments.token import Comment, Error, Keyword, Name, Number, Operator, \ |
|
14 Punctuation, String, Text |
|
15 |
|
16 __all__ = ['PointlessLexer'] |
|
17 |
|
18 |
|
19 class PointlessLexer(RegexLexer): |
|
20 """ |
|
21 For `Pointless <https://ptls.dev>`_ source code. |
|
22 |
|
23 .. versionadded:: 2.7 |
|
24 """ |
|
25 |
|
26 name = 'Pointless' |
|
27 aliases = ['pointless'] |
|
28 filenames = ['*.ptls'] |
|
29 |
|
30 ops = words([ |
|
31 "+", "-", "*", "/", "**", "%", "+=", "-=", "*=", |
|
32 "/=", "**=", "%=", "|>", "=", "==", "!=", "<", ">", |
|
33 "<=", ">=", "=>", "$", "++", |
|
34 ]) |
|
35 |
|
36 keywords = words([ |
|
37 "if", "then", "else", "where", "with", "cond", |
|
38 "case", "and", "or", "not", "in", "as", "for", |
|
39 "requires", "throw", "try", "catch", "when", |
|
40 "yield", "upval", |
|
41 ], suffix=r'\b') |
|
42 |
|
43 tokens = { |
|
44 'root': [ |
|
45 (r'[ \n\r]+', Text), |
|
46 (r'--.*$', Comment.Single), |
|
47 (r'"""', String, 'multiString'), |
|
48 (r'"', String, 'string'), |
|
49 (r'[\[\](){}:;,.]', Punctuation), |
|
50 (ops, Operator), |
|
51 (keywords, Keyword), |
|
52 (r'\d+|\d*\.\d+', Number), |
|
53 (r'(true|false)\b', Name.Builtin), |
|
54 (r'[A-Z][a-zA-Z0-9]*\b', String.Symbol), |
|
55 (r'output\b', Name.Variable.Magic), |
|
56 (r'(export|import)\b', Keyword.Namespace), |
|
57 (r'[a-z][a-zA-Z0-9]*\b', Name.Variable) |
|
58 ], |
|
59 'multiString': [ |
|
60 (r'\\.', String.Escape), |
|
61 (r'"""', String, '#pop'), |
|
62 (r'"', String), |
|
63 (r'[^\\"]+', String), |
|
64 ], |
|
65 'string': [ |
|
66 (r'\\.', String.Escape), |
|
67 (r'"', String, '#pop'), |
|
68 (r'\n', Error), |
|
69 (r'[^\\"]+', String), |
|
70 ], |
|
71 } |