Skip to content

Commit 7b34e65

Browse files
authoredNov 22, 2021
Concurnas: Improved tokenization (#3189)
1 parent 6af8a64 commit 7b34e65

8 files changed

+107
-38
lines changed
 

‎components/prism-concurnas.js

+28-15
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,20 @@
11
Prism.languages.concurnas = {
2-
'comment': [
3-
{
4-
pattern: /(^|[^\\])\/\*[\s\S]*?(?:\*\/|$)/,
5-
lookbehind: true
6-
},
7-
{
8-
pattern: /(^|[^\\:])\/\/.*/,
9-
lookbehind: true,
10-
greedy: true
11-
}
12-
],
2+
'comment': {
3+
pattern: /(^|[^\\])(?:\/\*[\s\S]*?(?:\*\/|$)|\/\/.*)/,
4+
lookbehind: true,
5+
greedy: true
6+
},
137
'langext': {
148
pattern: /\b\w+\s*\|\|[\s\S]+?\|\|/,
159
greedy: true,
16-
alias: 'string'
10+
inside: {
11+
'class-name': /^\w+/,
12+
'string': {
13+
pattern: /(^\s*\|\|)[\s\S]+(?=\|\|$)/,
14+
lookbehind: true
15+
},
16+
'punctuation': /\|\|/
17+
}
1718
},
1819
'function': {
1920
pattern: /((?:^|\s)def[ \t]+)[a-zA-Z_]\w*(?=\s*\()/,
@@ -23,16 +24,28 @@ Prism.languages.concurnas = {
2324
'boolean': /\b(?:false|true)\b/,
2425
'number': /\b0b[01][01_]*L?\b|\b0x(?:[\da-f_]*\.)?[\da-f_p+-]+\b|(?:\b\d[\d_]*(?:\.[\d_]*)?|\B\.\d[\d_]*)(?:e[+-]?\d[\d_]*)?[dfls]?/i,
2526
'punctuation': /[{}[\];(),.:]/,
26-
'operator': /<==|>==|=>|->|<-|<>|\^|&==|&<>|!|\?:?|\.\?|\+\+|--|[-+*/=<>]=?|\b(?:and|as|band|bor|bxor|comp|is|isnot|mod|or)\b=?/,
27+
'operator': /<==|>==|=>|->|<-|<>|&==|&<>|\?:?|\.\?|\+\+|--|[-+*/=<>]=?|[!^~]|\b(?:and|as|band|bor|bxor|comp|is|isnot|mod|or)\b=?/,
2728
'annotation': {
2829
pattern: /@(?:\w+:)?(?:\w+|\[[^\]]+\])?/,
2930
alias: 'builtin'
3031
}
3132
};
3233

3334
Prism.languages.insertBefore('concurnas', 'langext', {
34-
'string': {
35-
pattern: /[rs]?("|')(?:\\.|(?!\1)[^\\\r\n])*\1/,
35+
'regex-literal': {
36+
pattern: /\br("|')(?:\\.|(?!\1)[^\\\r\n])*\1/,
37+
greedy: true,
38+
inside: {
39+
'interpolation': {
40+
pattern: /((?:^|[^\\])(?:\\{2})*)\{(?:[^{}]|\{(?:[^{}]|\{[^}]*\})*\})+\}/,
41+
lookbehind: true,
42+
inside: Prism.languages.concurnas
43+
},
44+
'regex': /[\s\S]+/
45+
}
46+
},
47+
'string-literal': {
48+
pattern: /(?:\B|\bs)("|')(?:\\.|(?!\1)[^\\\r\n])*\1/,
3649
greedy: true,
3750
inside: {
3851
'interpolation': {

‎components/prism-concurnas.min.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// comment
2+
/*
3+
comment
4+
*/
5+
6+
----------------------------------------------------
7+
8+
[
9+
["comment", "// comment"],
10+
["comment", "/*\r\ncomment\r\n*/"]
11+
]

‎tests/languages/concurnas/function_feature.test

+11-3
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,18 @@ myfunc()
44
----------------------------------------------------
55

66
[
7-
["keyword", "def"], ["function", "myfunc"], ["punctuation", "("], ["punctuation", ")"], ["operator", "=>"], ["number", "12"],
8-
"\r\nmyfunc" , ["punctuation", "("], ["punctuation", ")"]
7+
["keyword", "def"],
8+
["function", "myfunc"],
9+
["punctuation", "("],
10+
["punctuation", ")"],
11+
["operator", "=>"],
12+
["number", "12"],
13+
14+
"\r\nmyfunc",
15+
["punctuation", "("],
16+
["punctuation", ")"]
917
]
1018

1119
----------------------------------------------------
1220

13-
Checks for functions.
21+
Checks for functions.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
myAPL || x[⍋x←6?40] ||
2+
SimpleLisp||(+ 1 2 (* 3 3 ) )||
3+
4+
|| invalid ||
5+
6+
----------------------------------------------------
7+
8+
[
9+
["langext", [
10+
["class-name", "myAPL"],
11+
["punctuation", "||"],
12+
["string", " x[⍋x←6?40] "],
13+
["punctuation", "||"]
14+
]],
15+
["langext", [
16+
["class-name", "SimpleLisp"],
17+
["punctuation", "||"],
18+
["string", "(+ 1 2 (* 3 3 ) )"],
19+
["punctuation", "||"]
20+
]],
21+
22+
"\r\n\r\n || invalid ||"
23+
]

‎tests/languages/concurnas/operator_feature.test

+15-2
Original file line numberDiff line numberDiff line change
@@ -10,42 +10,55 @@ mod mod=
1010
< <== > >==
1111
and or
1212
band bor bxor
13-
^
13+
^ ~
1414

1515
----------------------------------------------------
1616

1717
[
1818
["operator", "+"],
1919
["operator", "++"],
2020
["operator", "+="],
21+
2122
["operator", "-"],
2223
["operator", "--"],
2324
["operator", "-="],
25+
2426
["operator", "="],
2527
["operator", "=="],
2628
["operator", "<>"],
29+
2730
["operator", "&=="],
2831
["operator", "&<>"],
32+
2933
["operator", "isnot"],
34+
3035
["operator", "is"],
3136
["operator", "as"],
37+
3238
["operator", "comp"],
39+
3340
["operator", "/"],
3441
["operator", "/="],
3542
["operator", "*"],
3643
["operator", "*="],
44+
3745
["operator", "mod"],
3846
["operator", "mod="],
47+
3948
["operator", "<"],
4049
["operator", "<=="],
4150
["operator", ">"],
4251
["operator", ">=="],
52+
4353
["operator", "and"],
4454
["operator", "or"],
55+
4556
["operator", "band"],
4657
["operator", "bor"],
4758
["operator", "bxor"],
48-
["operator", "^"]
59+
60+
["operator", "^"],
61+
["operator", "~"]
4962
]
5063

5164
----------------------------------------------------
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
r'say'
2+
r"hello"
3+
4+
----------------------------------------------------
5+
6+
[
7+
["regex-literal", [
8+
["regex", "r'say'"]
9+
]],
10+
["regex-literal", [
11+
["regex", "r\"hello\""]
12+
]]
13+
]

‎tests/languages/concurnas/string_feature.test

+5-17
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,15 @@
11
"hi"
22
"addition result: {1+2}"
33
'hi'
4-
r'say'
5-
r"hello"
64
'contains: "'
7-
myAPL || x[⍋x←6?40] ||
8-
|| invalid ||
95

106
----------------------------------------------------
117

128
[
13-
["string", [
9+
["string-literal", [
1410
["string", "\"hi\""]
1511
]],
16-
["string", [
12+
["string-literal", [
1713
["string", "\"addition result: "],
1814
["interpolation", [
1915
["punctuation", "{"],
@@ -24,20 +20,12 @@ myAPL || x[⍋x←6?40] ||
2420
]],
2521
["string", "\""]
2622
]],
27-
["string", [
23+
["string-literal", [
2824
["string", "'hi'"]
2925
]],
30-
["string", [
31-
["string", "r'say'"]
32-
]],
33-
["string", [
34-
["string", "r\"hello\""]
35-
]],
36-
["string", [
26+
["string-literal", [
3727
["string", "'contains: \"'"]
38-
]],
39-
["langext", "myAPL || x[⍋x←6?40] ||"],
40-
"\r\n || invalid ||"
28+
]]
4129
]
4230

4331
----------------------------------------------------

0 commit comments

Comments
 (0)
Please sign in to comment.