Skip to content

Commit d85a64a

Browse files
C: Added char token (#3207)
1 parent ee7ab56 commit d85a64a

10 files changed

+126
-21
lines changed

components/prism-arduino.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

components/prism-arduino.min.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

components/prism-c.js

+18-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@ Prism.languages.c = Prism.languages.extend('clike', {
33
pattern: /\/\/(?:[^\r\n\\]|\\(?:\r\n?|\n|(?![\r\n])))*|\/\*[\s\S]*?(?:\*\/|$)/,
44
greedy: true
55
},
6+
'string': {
7+
// https://en.cppreference.com/w/c/language/string_literal
8+
pattern: /"(?:\\(?:\r\n|[\s\S])|[^"\\\r\n])*"/,
9+
greedy: true
10+
},
611
'class-name': {
712
pattern: /(\b(?:enum|struct)\s+(?:__attribute__\s*\(\([\s\S]*?\)\)\s*)?)\w+|\b[a-z]\w*_t\b/,
813
lookbehind: true
@@ -13,6 +18,14 @@ Prism.languages.c = Prism.languages.extend('clike', {
1318
'operator': />>=?|<<=?|->|([-+&|:])\1|[?:~]|[-+*/%&|^!=<>]=?/
1419
});
1520

21+
Prism.languages.insertBefore('c', 'string', {
22+
'char': {
23+
// https://en.cppreference.com/w/c/language/character_constant
24+
pattern: /'(?:\\(?:\r\n|[\s\S])|[^'\\\r\n]){0,32}'/,
25+
greedy: true
26+
}
27+
});
28+
1629
Prism.languages.insertBefore('c', 'string', {
1730
'macro': {
1831
// allow for multiline macro definitions
@@ -30,6 +43,7 @@ Prism.languages.insertBefore('c', 'string', {
3043
},
3144
Prism.languages.c['string']
3245
],
46+
'char': Prism.languages.c['char'],
3347
'comment': Prism.languages.c['comment'],
3448
'macro-name': [
3549
{
@@ -55,7 +69,10 @@ Prism.languages.insertBefore('c', 'string', {
5569
inside: Prism.languages.c
5670
}
5771
}
58-
},
72+
}
73+
});
74+
75+
Prism.languages.insertBefore('c', 'function', {
5976
// highlight predefined macros as constants
6077
'constant': /\b(?:EOF|NULL|SEEK_CUR|SEEK_END|SEEK_SET|__DATE__|__FILE__|__LINE__|__TIMESTAMP__|__TIME__|__func__|stderr|stdin|stdout)\b/
6178
});

components/prism-c.min.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
'+'
2+
'\''
3+
4+
----------------------------------------------------
5+
6+
[
7+
["char", "'+'"],
8+
["char", "'\\''"]
9+
]
+14-7
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,28 @@
11
%%
2-
foo: 'foo' "foo";
3-
bar: '\'' "\"";
2+
foo: "foo";
3+
bar: "\"";
44
%%
55

66
----------------------------------------------------
77

88
[
99
["bison", [
1010
["punctuation", "%%"],
11-
["property", "foo"], ["punctuation", ":"],
12-
["string", "'foo'"], ["string", "\"foo\""], ["punctuation", ";"],
13-
["property", "bar"], ["punctuation", ":"],
14-
["string", "'\\''"], ["string", "\"\\\"\""], ["punctuation", ";"],
11+
12+
["property", "foo"],
13+
["punctuation", ":"],
14+
["string", "\"foo\""],
15+
["punctuation", ";"],
16+
17+
["property", "bar"],
18+
["punctuation", ":"],
19+
["string", "\"\\\"\""],
20+
["punctuation", ";"],
21+
1522
["punctuation", "%%"]
1623
]]
1724
]
1825

1926
----------------------------------------------------
2027

21-
Checks for strings.
28+
Checks for strings.

tests/languages/c/char_feature.test

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
'a'
2+
'\n'
3+
'\13'
4+
'🍌'
5+
'ab'
6+
7+
u'a'
8+
u'¢'
9+
u'猫'
10+
U'猫'
11+
L'猫'
12+
13+
'\1\2\3\4'
14+
'\xFF'
15+
u'\U0001f34c'
16+
17+
----------------------------------------------------
18+
19+
[
20+
["char", "'a'"],
21+
["char", "'\\n'"],
22+
["char", "'\\13'"],
23+
["char", "'🍌'"],
24+
["char", "'ab'"],
25+
26+
"\r\n\r\nu", ["char", "'a'"],
27+
"\r\nu", ["char", "'¢'"],
28+
"\r\nu", ["char", "'猫'"],
29+
"\r\nU", ["char", "'猫'"],
30+
"\r\nL", ["char", "'猫'"],
31+
32+
["char", "'\\1\\2\\3\\4'"],
33+
["char", "'\\xFF'"],
34+
"\r\nu", ["char", "'\\U0001f34c'"]
35+
]

tests/languages/c/string_feature.test

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
""
2+
"foo"
3+
"\x12"
4+
"3"
5+
6+
"\xff""f"
7+
8+
"foo\
9+
bar"
10+
11+
"a猫🍌"
12+
u8"a猫🍌"
13+
u"a猫🍌"
14+
U"a猫🍌"
15+
L"a猫🍌"
16+
17+
----------------------------------------------------
18+
19+
[
20+
["string", "\"\""],
21+
["string", "\"foo\""],
22+
["string", "\"\\x12\""],
23+
["string", "\"3\""],
24+
25+
["string", "\"\\xff\""], ["string", "\"f\""],
26+
27+
["string", "\"foo\\\r\nbar\""],
28+
29+
["string", "\"a猫🍌\""],
30+
"\r\nu8", ["string", "\"a猫🍌\""],
31+
"\r\nu", ["string", "\"a猫🍌\""],
32+
"\r\nU", ["string", "\"a猫🍌\""],
33+
"\r\nL", ["string", "\"a猫🍌\""]
34+
]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
''
2+
'fo\'o'
3+
'foo\
4+
bar'
5+
6+
----------------------------------------------------
7+
8+
[
9+
["char", "''"],
10+
["char", "'fo\\'o'"],
11+
["char", "'foo\\\r\nbar'"]
12+
]

tests/languages/objectivec/string_feature.test

+1-10
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,6 @@
33
"foo\
44
bar"
55

6-
''
7-
'fo\'o'
8-
'foo\
9-
bar'
10-
116
@""
127
@"fo\"o"
138
@"foo\
@@ -20,15 +15,11 @@ bar"
2015
["string", "\"fo\\\"o\""],
2116
["string", "\"foo\\\r\nbar\""],
2217

23-
["string", "''"],
24-
["string", "'fo\\'o'"],
25-
["string", "'foo\\\r\nbar'"],
26-
2718
["string", "@\"\""],
2819
["string", "@\"fo\\\"o\""],
2920
["string", "@\"foo\\\r\nbar\""]
3021
]
3122

3223
----------------------------------------------------
3324

34-
Checks for strings.
25+
Checks for strings.

0 commit comments

Comments
 (0)