Skip to content

Commit

Permalink
Added support for AWK (#3374)
Browse files Browse the repository at this point in the history
RunDevelopment authored Mar 14, 2022

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent 7bda2bf commit ea8a0f4
Showing 18 changed files with 244 additions and 3 deletions.
2 changes: 1 addition & 1 deletion components.js

Large diffs are not rendered by default.

8 changes: 8 additions & 0 deletions components.json
Original file line number Diff line number Diff line change
@@ -175,6 +175,14 @@
"alias": "avdl",
"owner": "RunDevelopment"
},
"awk": {
"title": "AWK",
"alias": "gawk",
"aliasTitles": {
"gawk": "GAWK"
},
"owner": "RunDevelopment"
},
"bash": {
"title": "Bash",
"alias": "shell",
32 changes: 32 additions & 0 deletions components/prism-awk.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
Prism.languages.awk = {
'hashbang': {
pattern: /^#!.*/,
greedy: true,
alias: 'comment'
},
'comment': {
pattern: /#.*/,
greedy: true
},
'string': {
pattern: /(^|[^\\])"(?:[^\\"\r\n]|\\.)*"/,
lookbehind: true,
greedy: true
},
'regex': {
pattern: /((?:^|[^\w\s)])\s*)\/(?:[^\/\\\r\n]|\\.)*\//,
lookbehind: true,
greedy: true
},

'variable': /\$\w+/,
'keyword': /\b(?:BEGIN|BEGINFILE|END|ENDFILE|break|case|continue|default|delete|do|else|exit|for|function|getline|if|in|next|nextfile|printf?|return|switch|while)\b|@(?:include|load)\b/,

'function': /\b[a-z_]\w*(?=\s*\()/i,
'number': /\b(?:\d+(?:\.\d+)?(?:e[+-]?\d+)?|0x[a-fA-F0-9]+)\b/,

'operator': /--|\+\+|!?~|>&|>>|<<|(?:\*\*|[<>!=+\-*/%^])=?|&&|\|[|&]|[?:]/,
'punctuation': /[()[\]{},;]/
};

Prism.languages.gawk = Prism.languages.awk;
1 change: 1 addition & 0 deletions components/prism-awk.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions examples/prism-awk.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<h2>Full example</h2>
<pre><code># Source: awklang.org
BEGIN { ascetion = bsection = 0 }
$2 ~ /^[aA][0-9]+/ { asection++ }
$2 ~ /^[bB][0-9]+/ { bsection++ }
END { print asection, bsection }
</code></pre>
1 change: 1 addition & 0 deletions plugins/autoloader/prism-autoloader.js
Original file line number Diff line number Diff line change
@@ -179,6 +179,7 @@
"adoc": "asciidoc",
"avs": "avisynth",
"avdl": "avro-idl",
"gawk": "awk",
"shell": "bash",
"shortcode": "bbcode",
"rbnf": "bnf",
2 changes: 1 addition & 1 deletion plugins/autoloader/prism-autoloader.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions plugins/show-language/prism-show-language.js
Original file line number Diff line number Diff line change
@@ -49,6 +49,8 @@
"avs": "AviSynth",
"avro-idl": "Avro IDL",
"avdl": "Avro IDL",
"awk": "AWK",
"gawk": "GAWK",
"basic": "BASIC",
"bbcode": "BBcode",
"bnf": "BNF",
2 changes: 1 addition & 1 deletion plugins/show-language/prism-show-language.min.js
7 changes: 7 additions & 0 deletions tests/languages/awk/comment_feature.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# some comment

----------------------------------------------------

[
["comment", "# some comment"]
]
7 changes: 7 additions & 0 deletions tests/languages/awk/hashbang_feature.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#! /bin/awk -f

----------------------------------------------------

[
["hashbang", "#! /bin/awk -f"]
]
59 changes: 59 additions & 0 deletions tests/languages/awk/keyword_feature.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
BEGIN
BEGINFILE
END
ENDFILE
break
case
continue
default
delete
do
else
exit
for
function
getline
if
in
next
nextfile
print
printf
return
switch
while

@include
@load

----------------------------------------------------

[
["keyword", "BEGIN"],
["keyword", "BEGINFILE"],
["keyword", "END"],
["keyword", "ENDFILE"],
["keyword", "break"],
["keyword", "case"],
["keyword", "continue"],
["keyword", "default"],
["keyword", "delete"],
["keyword", "do"],
["keyword", "else"],
["keyword", "exit"],
["keyword", "for"],
["keyword", "function"],
["keyword", "getline"],
["keyword", "if"],
["keyword", "in"],
["keyword", "next"],
["keyword", "nextfile"],
["keyword", "print"],
["keyword", "printf"],
["keyword", "return"],
["keyword", "switch"],
["keyword", "while"],

["keyword", "@include"],
["keyword", "@load"]
]
13 changes: 13 additions & 0 deletions tests/languages/awk/number_feature.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
105
1.05e+2
1050e-1
0x11

----------------------------------------------------

[
["number", "105"],
["number", "1.05e+2"],
["number", "1050e-1"],
["number", "0x11"]
]
57 changes: 57 additions & 0 deletions tests/languages/awk/operator_feature.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
+ - * / % ^ **
+= -= *= /= %= ^= **=
++ --

> >= < <= != ==
&& || !

|& >& << >>

~ !~

? :
=

----------------------------------------------------

[
["operator", "+"],
["operator", "-"],
["operator", "*"],
["operator", "/"],
["operator", "%"],
["operator", "^"],
["operator", "**"],

["operator", "+="],
["operator", "-="],
["operator", "*="],
["operator", "/="],
["operator", "%="],
["operator", "^="],
["operator", "**="],

["operator", "++"],
["operator", "--"],

["operator", ">"],
["operator", ">="],
["operator", "<"],
["operator", "<="],
["operator", "!="],
["operator", "=="],

["operator", "&&"],
["operator", "||"],
["operator", "!"],

["operator", "|&"],
["operator", ">&"],
["operator", "<<"],
["operator", ">>"],

["operator", "~"], ["operator", "!~"],

["operator", "?"], ["operator", ":"],
["operator", "="]
]
16 changes: 16 additions & 0 deletions tests/languages/awk/punctuation_feature.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
( ) [ ] { }
, ;

----------------------------------------------------

[
["punctuation", "("],
["punctuation", ")"],
["punctuation", "["],
["punctuation", "]"],
["punctuation", "{"],
["punctuation", "}"],

["punctuation", ","],
["punctuation", ";"]
]
9 changes: 9 additions & 0 deletions tests/languages/awk/regex_feature.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
//;
/.*:\/home\/[[:alnum:]]+:.*/

----------------------------------------------------

[
["regex", "//"], ["punctuation", ";"],
["regex", "/.*:\\/home\\/[[:alnum:]]+:.*/"]
]
11 changes: 11 additions & 0 deletions tests/languages/awk/string_feature.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
""
"foo"
".png\">"

----------------------------------------------------

[
["string", "\"\""],
["string", "\"foo\""],
["string", "\".png\\\">\""]
]
11 changes: 11 additions & 0 deletions tests/languages/awk/variable_feature.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
$0 $1 $2
$NF
$i

----------------------------------------------------

[
["variable", "$0"], ["variable", "$1"], ["variable", "$2"],
["variable", "$NF"],
["variable", "$i"]
]

0 comments on commit ea8a0f4

Please sign in to comment.