Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.8/site-packages/pygments/lexers/slash.py: 76%
21 statements
« prev ^ index » next coverage.py v7.2.7, created at 2023-07-01 06:54 +0000
« prev ^ index » next coverage.py v7.2.7, created at 2023-07-01 06:54 +0000
1"""
2 pygments.lexers.slash
3 ~~~~~~~~~~~~~~~~~~~~~
5 Lexer for the `Slash <https://github.com/arturadib/Slash-A>`_ programming
6 language.
8 :copyright: Copyright 2006-2023 by the Pygments team, see AUTHORS.
9 :license: BSD, see LICENSE for details.
10"""
12from pygments.lexer import ExtendedRegexLexer, bygroups, DelegatingLexer
13from pygments.token import Name, Number, String, Comment, Punctuation, \
14 Other, Keyword, Operator, Whitespace
16__all__ = ['SlashLexer']
19class SlashLanguageLexer(ExtendedRegexLexer):
20 _nkw = r'(?=[^a-zA-Z_0-9])'
22 def move_state(new_state):
23 return ("#pop", new_state)
25 def right_angle_bracket(lexer, match, ctx):
26 if len(ctx.stack) > 1 and ctx.stack[-2] == "string":
27 ctx.stack.pop()
28 yield match.start(), String.Interpol, '}'
29 ctx.pos = match.end()
30 pass
32 tokens = {
33 "root": [
34 (r"<%=", Comment.Preproc, move_state("slash")),
35 (r"<%!!", Comment.Preproc, move_state("slash")),
36 (r"<%#.*?%>", Comment.Multiline),
37 (r"<%", Comment.Preproc, move_state("slash")),
38 (r".|\n", Other),
39 ],
40 "string": [
41 (r"\\", String.Escape, move_state("string_e")),
42 (r"\"", String, move_state("slash")),
43 (r"#\{", String.Interpol, "slash"),
44 (r'.|\n', String),
45 ],
46 "string_e": [
47 (r'n', String.Escape, move_state("string")),
48 (r't', String.Escape, move_state("string")),
49 (r'r', String.Escape, move_state("string")),
50 (r'e', String.Escape, move_state("string")),
51 (r'x[a-fA-F0-9]{2}', String.Escape, move_state("string")),
52 (r'.', String.Escape, move_state("string")),
53 ],
54 "regexp": [
55 (r'}[a-z]*', String.Regex, move_state("slash")),
56 (r'\\(.|\n)', String.Regex),
57 (r'{', String.Regex, "regexp_r"),
58 (r'.|\n', String.Regex),
59 ],
60 "regexp_r": [
61 (r'}[a-z]*', String.Regex, "#pop"),
62 (r'\\(.|\n)', String.Regex),
63 (r'{', String.Regex, "regexp_r"),
64 ],
65 "slash": [
66 (r"%>", Comment.Preproc, move_state("root")),
67 (r"\"", String, move_state("string")),
68 (r"'[a-zA-Z0-9_]+", String),
69 (r'%r{', String.Regex, move_state("regexp")),
70 (r'/\*.*?\*/', Comment.Multiline),
71 (r"(#|//).*?\n", Comment.Single),
72 (r'-?[0-9]+e[+-]?[0-9]+', Number.Float),
73 (r'-?[0-9]+\.[0-9]+(e[+-]?[0-9]+)?', Number.Float),
74 (r'-?[0-9]+', Number.Integer),
75 (r'nil'+_nkw, Name.Builtin),
76 (r'true'+_nkw, Name.Builtin),
77 (r'false'+_nkw, Name.Builtin),
78 (r'self'+_nkw, Name.Builtin),
79 (r'(class)(\s+)([A-Z][a-zA-Z0-9_\']*)',
80 bygroups(Keyword, Whitespace, Name.Class)),
81 (r'class'+_nkw, Keyword),
82 (r'extends'+_nkw, Keyword),
83 (r'(def)(\s+)(self)(\s*)(\.)(\s*)([a-z_][a-zA-Z0-9_\']*=?|<<|>>|==|<=>|<=|<|>=|>|\+|-(self)?|~(self)?|\*|/|%|^|&&|&|\||\[\]=?)',
84 bygroups(Keyword, Whitespace, Name.Builtin, Whitespace, Punctuation, Whitespace, Name.Function)),
85 (r'(def)(\s+)([a-z_][a-zA-Z0-9_\']*=?|<<|>>|==|<=>|<=|<|>=|>|\+|-(self)?|~(self)?|\*|/|%|^|&&|&|\||\[\]=?)',
86 bygroups(Keyword, Whitespace, Name.Function)),
87 (r'def'+_nkw, Keyword),
88 (r'if'+_nkw, Keyword),
89 (r'elsif'+_nkw, Keyword),
90 (r'else'+_nkw, Keyword),
91 (r'unless'+_nkw, Keyword),
92 (r'for'+_nkw, Keyword),
93 (r'in'+_nkw, Keyword),
94 (r'while'+_nkw, Keyword),
95 (r'until'+_nkw, Keyword),
96 (r'and'+_nkw, Keyword),
97 (r'or'+_nkw, Keyword),
98 (r'not'+_nkw, Keyword),
99 (r'lambda'+_nkw, Keyword),
100 (r'try'+_nkw, Keyword),
101 (r'catch'+_nkw, Keyword),
102 (r'return'+_nkw, Keyword),
103 (r'next'+_nkw, Keyword),
104 (r'last'+_nkw, Keyword),
105 (r'throw'+_nkw, Keyword),
106 (r'use'+_nkw, Keyword),
107 (r'switch'+_nkw, Keyword),
108 (r'\\', Keyword),
109 (r'λ', Keyword),
110 (r'__FILE__'+_nkw, Name.Builtin.Pseudo),
111 (r'__LINE__'+_nkw, Name.Builtin.Pseudo),
112 (r'[A-Z][a-zA-Z0-9_\']*'+_nkw, Name.Constant),
113 (r'[a-z_][a-zA-Z0-9_\']*'+_nkw, Name),
114 (r'@[a-z_][a-zA-Z0-9_\']*'+_nkw, Name.Variable.Instance),
115 (r'@@[a-z_][a-zA-Z0-9_\']*'+_nkw, Name.Variable.Class),
116 (r'\(', Punctuation),
117 (r'\)', Punctuation),
118 (r'\[', Punctuation),
119 (r'\]', Punctuation),
120 (r'\{', Punctuation),
121 (r'\}', right_angle_bracket),
122 (r';', Punctuation),
123 (r',', Punctuation),
124 (r'<<=', Operator),
125 (r'>>=', Operator),
126 (r'<<', Operator),
127 (r'>>', Operator),
128 (r'==', Operator),
129 (r'!=', Operator),
130 (r'=>', Operator),
131 (r'=', Operator),
132 (r'<=>', Operator),
133 (r'<=', Operator),
134 (r'>=', Operator),
135 (r'<', Operator),
136 (r'>', Operator),
137 (r'\+\+', Operator),
138 (r'\+=', Operator),
139 (r'-=', Operator),
140 (r'\*\*=', Operator),
141 (r'\*=', Operator),
142 (r'\*\*', Operator),
143 (r'\*', Operator),
144 (r'/=', Operator),
145 (r'\+', Operator),
146 (r'-', Operator),
147 (r'/', Operator),
148 (r'%=', Operator),
149 (r'%', Operator),
150 (r'^=', Operator),
151 (r'&&=', Operator),
152 (r'&=', Operator),
153 (r'&&', Operator),
154 (r'&', Operator),
155 (r'\|\|=', Operator),
156 (r'\|=', Operator),
157 (r'\|\|', Operator),
158 (r'\|', Operator),
159 (r'!', Operator),
160 (r'\.\.\.', Operator),
161 (r'\.\.', Operator),
162 (r'\.', Operator),
163 (r'::', Operator),
164 (r':', Operator),
165 (r'(\s|\n)+', Whitespace),
166 (r'[a-z_][a-zA-Z0-9_\']*', Name.Variable),
167 ],
168 }
171class SlashLexer(DelegatingLexer):
172 """
173 Lexer for the Slash programming language.
175 .. versionadded:: 2.4
176 """
178 name = 'Slash'
179 aliases = ['slash']
180 filenames = ['*.sla']
182 def __init__(self, **options):
183 from pygments.lexers.web import HtmlLexer
184 super().__init__(HtmlLexer, SlashLanguageLexer, **options)