-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathAWK.sublime-syntax
212 lines (188 loc) · 5.69 KB
/
AWK.sublime-syntax
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
%YAML 1.2
---
# http://www.sublimetext.com/docs/3/syntax.html
name: AWK
scope: source.awk
file_extensions:
- awk
# References
# http://pubs.opengroup.org/onlinepubs/009695399/utilities/awk.html
# http://www.gnu.org/software/gawk/manual/html_node/index.html
# http://www.grymoire.com/Unix/Awk.html
# http://www.cs.mun.ca/~yzchen/bib/nawkUS.pdf
variables:
NAME: '[A-Za-z_][A-Za-z_0-9]*'
contexts:
main:
- include: comment
- include: procedure
- include: pattern
comment:
- match: '(?<!\S)(#)(?!\{).*$\n?'
scope: comment.line.number-sign.awk
captures:
1: punctuation.definition.comment.awk
procedure:
- match: '{'
scope: meta.brace.curly.awk
push:
- match: '}'
scope: meta.brace.curly.awk
pop: true
- include: comment
- include: procedure
- include: keyword
- include: expression
pattern:
- include: function-definition
- include: builtin-pattern
- include: expression
#TODO: Resolve regex / operator ambiguity
#Will probably have to split expression
#into seperate unary/binary states
#See https://github.com/sublimehq/Packages/blob/master/JavaScript/JavaScript.sublime-syntax
expression:
- include: comment
- include: command
- include: function
- include: constant
- include: variable
- include: groupings
- include: prefix-operator
- include: regexp
- match: '(?=[\S])'
pop: true
groupings:
- match: \(
scope: meta.brace.round.awk
- match: \)(?=\s*{)
scope: meta.brace.round.awk
- match: \)
scope: meta.brace.round.awk
push: infix-operator
- match: \,
scope: punctuation.separator.parameters.awk
builtin-pattern:
- match: \b(BEGINFILE|BEGIN|ENDFILE|END)\b
scope: constant.language.awk
function-definition:
- match: \b(function)\s+({{NAME}})(\()
captures:
1: storage.type.function.awk
2: entity.name.function.awk
3: punctuation.definition.parameters.begin.awk
push:
- match: \)
captures:
0: punctuation.definition.parameters.end.awk
pop: true
- match: \b(\w+)\b
scope: variable.parameter.function.awk
- match: \b(,)\b
scope: punctuation.separator.parameters.awk
constant:
- include: numeric-constant
- include: string-constant
numeric-constant:
- match: '\b[0-9]+(?:\.[0-9]+)?(?:e[+-][0-9]+)?\b'
scope: constant.numeric.awk
push: infix-operator
string-constant:
- match: '"'
scope: punctuation.definition.string.begin.awk
push:
- meta_scope: string.quoted.double.awk
- match: '"'
scope: punctuation.definition.string.end.awk
pop: true
- include: escaped-char
escaped-char:
- match: '\\(?:[\\abfnrtv/"]|x[0-9A-Fa-f]{2}|[0-7]{3})'
scope: constant.character.escape.awk
# To avoid ambiguity with division operators regexps are only
# valid in places were division is not.
regexp:
- match: /
scope: punctuation.definition.regex.begin.awk
push:
- meta_scope: string.regexp
- match: "(/)([gimy]*)"
captures:
1: punctuation.definition.regex.end.awk
2: keyword.other.awk
set: infix-operator
- match: '(?=.|\n)'
with_prototype:
- match: '(?=/)'
pop: true
push:
- include: scope:source.regexp
variable:
- match: '\$[0-9]+'
scope: variable.language.awk
push: infix-operator
- match: \b(?:FILENAME|FS|NF|NR|OFMT|OFS|ORS|RS)\b
scope: variable.language.awk
push: infix-operator
- match: \b(?:ARGC|ARGV|CONVFMT|ENVIRON|FNR|RLENGTH|RSTART|SUBSEP)\b
scope: variable.language.nawk
push: infix-operator
- match: \b(?:ARGIND|ERRNO|FIELDWIDTHS|IGNORECASE|RT)\b
scope: variable.language.gawk
push: infix-operator
- match: '\b{{NAME}}\b'
scope: variable.other.readwrite.awk
push: infix-operator
keyword:
- match: \b(?:break|continue|do|while|exit|for|if|else|return)\b
scope: keyword.control.awk
command:
- match: \b(?:next|print|printf)\b
scope: keyword.other.command.awk
- match: \b(?:close|getline|delete|system)\b
scope: keyword.other.command.nawk
- match: \b(?:fflush|nextfile)\b
scope: keyword.other.command.bell-awk
function:
- match: \b(?:exp|int|log|sqrt|index|length|split|sprintf|substr)\b
scope: support.function.awk
- match: \b(?:atan2|cos|rand|sin|srand|gsub|match|sub|tolower|toupper)\b
scope: support.function.nawk
- match: \b(?:gensub|strftime|systime)\b
scope: support.function.gawk
- match: \b{{NAME}}(?=\s*\()
scope: entity.name.function.awk
prefix-operator:
- match: '[+-]'
scope: keyword.operator.arithmetic.awk
set: expression
infix-operator:
- match: "!?~|[=<>!]=|[<>]"
scope: keyword.operator.comparison.awk
set: expression
- match: \b(in)\b
scope: keyword.operator.comparison.awk
set: expression
- match: '[+\-*/%^]=|\+\+|--|>>|='
scope: keyword.operator.assignment.awk
set: expression
- match: \|\||&&|!
scope: keyword.operator.boolean.awk
set: expression
- match: '[+\-*/%^]'
scope: keyword.operator.arithmetic.awk
set: expression
- match: '[?:]'
scope: keyword.operator.trinary.awk
set: expression
- match: '\['
scope: keyword.operator.index.awk
push:
- match: '\]'
scope: keyword.operator.index.awk
pop: true
- match: ','
scope: punctuation.separator.index.awk
- include: expression
- match: '(?=[\S])'
pop: true