Skip to content

Commit 51e3ecc

Browse files
authoredNov 22, 2021
Crystal: Improved tokenization (#3194)
1 parent e137035 commit 51e3ecc

11 files changed

+759
-66
lines changed
 

‎components/prism-crystal.js

+37-31
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,57 @@
11
(function (Prism) {
22
Prism.languages.crystal = Prism.languages.extend('ruby', {
3-
keyword: [
4-
/\b(?:__DIR__|__END_LINE__|__FILE__|__LINE__|abstract|alias|as|asm|begin|break|case|class|def|do|else|elsif|end|ensure|enum|extend|for|fun|if|include|instance_sizeof|lib|macro|module|next|of|out|pointerof|private|protected|require|rescue|return|select|self|sizeof|struct|super|then|type|typeof|uninitialized|union|unless|until|when|while|with|yield)\b/,
3+
'keyword': [
4+
/\b(?:__DIR__|__END_LINE__|__FILE__|__LINE__|abstract|alias|annotation|as|asm|begin|break|case|class|def|do|else|elsif|end|ensure|enum|extend|for|fun|if|ifdef|include|instance_sizeof|lib|macro|module|next|of|out|pointerof|private|protected|ptr|require|rescue|return|select|self|sizeof|struct|super|then|type|typeof|undef|uninitialized|union|unless|until|when|while|with|yield)\b/,
55
{
66
pattern: /(\.\s*)(?:is_a|responds_to)\?/,
77
lookbehind: true
88
}
99
],
10-
11-
number: /\b(?:0b[01_]*[01]|0o[0-7_]*[0-7]|0x[\da-fA-F_]*[\da-fA-F]|(?:\d(?:[\d_]*\d)?)(?:\.[\d_]*\d)?(?:[eE][+-]?[\d_]*\d)?)(?:_(?:[uif](?:8|16|32|64))?)?\b/
10+
'number': /\b(?:0b[01_]*[01]|0o[0-7_]*[0-7]|0x[\da-fA-F_]*[\da-fA-F]|(?:\d(?:[\d_]*\d)?)(?:\.[\d_]*\d)?(?:[eE][+-]?[\d_]*\d)?)(?:_(?:[uif](?:8|16|32|64))?)?\b/,
11+
'operator': [
12+
/->/,
13+
Prism.languages.ruby.operator,
14+
],
15+
'punctuation': /[(){}[\].,;\\]/,
1216
});
1317

1418
Prism.languages.insertBefore('crystal', 'string-literal', {
15-
attribute: {
16-
pattern: /@\[.+?\]/,
17-
alias: 'attr-name',
19+
'attribute': {
20+
pattern: /@\[.*?\]/,
1821
inside: {
19-
delimiter: {
22+
'delimiter': {
2023
pattern: /^@\[|\]$/,
21-
alias: 'tag'
24+
alias: 'punctuation'
25+
},
26+
'attribute': {
27+
pattern: /^(\s*)\w+/,
28+
lookbehind: true,
29+
alias: 'class-name'
30+
},
31+
'args': {
32+
pattern: /\S(?:[\s\S]*\S)?/,
33+
inside: Prism.languages.crystal
2234
},
23-
rest: Prism.languages.crystal
2435
}
2536
},
26-
27-
expansion: [
28-
{
29-
pattern: /\{\{.+?\}\}/,
30-
inside: {
31-
delimiter: {
32-
pattern: /^\{\{|\}\}$/,
33-
alias: 'tag'
34-
},
35-
rest: Prism.languages.crystal
36-
}
37-
},
38-
{
39-
pattern: /\{%.+?%\}/,
40-
inside: {
41-
delimiter: {
42-
pattern: /^\{%|%\}$/,
43-
alias: 'tag'
44-
},
45-
rest: Prism.languages.crystal
37+
'expansion': {
38+
pattern: /\{(?:\{.*?\}|%.*?%)\}/,
39+
inside: {
40+
'content': {
41+
pattern: /^(\{.)[\s\S]+(?=.\}$)/,
42+
lookbehind: true,
43+
inside: Prism.languages.crystal
44+
},
45+
'delimiter': {
46+
pattern: /^\{[\{%]|[\}%]\}$/,
47+
alias: 'operator'
4648
}
4749
}
48-
]
50+
},
51+
'char': {
52+
pattern: /'(?:[^\\\r\n]{1,2}|\\(?:.|u(?:[A-Fa-f0-9]{1,4}|\{[A-Fa-f0-9]{1,6}\})))'/,
53+
greedy: true
54+
}
4955
});
5056

5157
}(Prism));

‎components/prism-crystal.min.js

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

‎tests/languages/crystal/attribute_feature.test

+32-26
Original file line numberDiff line numberDiff line change
@@ -8,47 +8,53 @@
88
[
99
["attribute", [
1010
["delimiter", "@["],
11-
"AlwaysInline",
11+
["attribute", "AlwaysInline"],
1212
["delimiter", "]"]
1313
]],
1414
["attribute", [
1515
["delimiter", "@["],
16-
"CallConvention",
17-
["punctuation", "("],
18-
["string-literal", [
19-
["string", "\"X86_StdCall\""]
16+
["attribute", "CallConvention"],
17+
["args", [
18+
["punctuation", "("],
19+
["string-literal", [
20+
["string", "\"X86_StdCall\""]
21+
]],
22+
["punctuation", ")"]
2023
]],
21-
["punctuation", ")"],
2224
["delimiter", "]"]
2325
]],
2426
["attribute", [
2527
["delimiter", "@["],
26-
"MyAnnotation",
27-
["punctuation", "("],
28-
["symbol", "key"],
29-
["operator", ":"],
30-
["string-literal", [
31-
["string", "\"value\""]
28+
["attribute", "MyAnnotation"],
29+
["args", [
30+
["punctuation", "("],
31+
["symbol", "key"],
32+
["operator", ":"],
33+
["string-literal", [
34+
["string", "\"value\""]
35+
]],
36+
["punctuation", ","],
37+
["symbol", "value"],
38+
["operator", ":"],
39+
["number", "123"],
40+
["punctuation", ")"]
3241
]],
33-
["punctuation", ","],
34-
["symbol", "value"],
35-
["operator", ":"],
36-
["number", "123"],
37-
["punctuation", ")"],
3842
["delimiter", "]"]
3943
]],
4044
["attribute", [
4145
["delimiter", "@["],
42-
"MyAnnotation",
43-
["punctuation", "("],
44-
["string-literal", [
45-
["string", "\"foo\""]
46+
["attribute", "MyAnnotation"],
47+
["args", [
48+
["punctuation", "("],
49+
["string-literal", [
50+
["string", "\"foo\""]
51+
]],
52+
["punctuation", ","],
53+
["number", "123"],
54+
["punctuation", ","],
55+
["boolean", "false"],
56+
["punctuation", ")"]
4657
]],
47-
["punctuation", ","],
48-
["number", "123"],
49-
["punctuation", ","],
50-
["boolean", "false"],
51-
["punctuation", ")"],
5258
["delimiter", "]"]
5359
]]
5460
]
+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
'a'
2+
'z'
3+
'0'
4+
'_'
5+
'あ'
6+
'\'' # single quote
7+
'\\' # backslash
8+
'\a' # alert
9+
'\b' # backspace
10+
'\e' # escape
11+
'\f' # form feed
12+
'\n' # newline
13+
'\r' # carriage return
14+
'\t' # tab
15+
'\v' # vertical tab
16+
'\0' # null character
17+
'\uFFFF' # hexadecimal unicode character
18+
'\u{10FFFF}' # hexadecimal unicode character
19+
20+
----------------------------------------------------
21+
22+
[
23+
["char", "'a'"],
24+
["char", "'z'"],
25+
["char", "'0'"],
26+
["char", "'_'"],
27+
["char", "'あ'"],
28+
["char", "'\\''"], ["comment", "# single quote"],
29+
["char", "'\\\\'"], ["comment", "# backslash"],
30+
["char", "'\\a'"], ["comment", "# alert"],
31+
["char", "'\\b'"], ["comment", "# backspace"],
32+
["char", "'\\e'"], ["comment", "# escape"],
33+
["char", "'\\f'"], ["comment", "# form feed"],
34+
["char", "'\\n'"], ["comment", "# newline"],
35+
["char", "'\\r'"], ["comment", "# carriage return"],
36+
["char", "'\\t'"], ["comment", "# tab"],
37+
["char", "'\\v'"], ["comment", "# vertical tab"],
38+
["char", "'\\0'"], ["comment", "# null character"],
39+
["char", "'\\uFFFF'"], ["comment", "# hexadecimal unicode character"],
40+
["char", "'\\u{10FFFF}'"], ["comment", "# hexadecimal unicode character"]
41+
]

‎tests/languages/crystal/expansion_feature.test

+16-8
Original file line numberDiff line numberDiff line change
@@ -8,26 +8,34 @@
88
[
99
["expansion", [
1010
["delimiter", "{{"],
11-
["number", "1_u32"],
11+
["content", [
12+
["number", "1_u32"]
13+
]],
1214
["delimiter", "}}"]
1315
]],
1416
["expansion", [
1517
["delimiter", "{%"],
16-
["number", "2_u32"],
18+
["content", [
19+
["number", "2_u32"]
20+
]],
1721
["delimiter", "%}"]
1822
]],
1923
["expansion", [
2024
["delimiter", "{{"],
21-
["punctuation", "{"],
22-
["number", "3_u32"],
23-
["punctuation", "}"],
25+
["content", [
26+
["punctuation", "{"],
27+
["number", "3_u32"],
28+
["punctuation", "}"]
29+
]],
2430
["delimiter", "}}"]
2531
]],
2632
["expansion", [
2733
["delimiter", "{%"],
28-
["operator", "%"],
29-
["number", "4_u32"],
30-
["operator", "%"],
34+
["content", [
35+
["operator", "%"],
36+
["number", "4_u32"],
37+
["operator", "%"]
38+
]],
3139
["delimiter", "%}"]
3240
]]
3341
]

‎tests/languages/crystal/keyword_feature.test

+8
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
.responds_to?
33
abstract
44
alias
5+
annotation;
56
as
67
asm
78
begin
@@ -19,6 +20,7 @@ extend
1920
for
2021
fun
2122
if
23+
ifdef
2224
include
2325
instance_sizeof
2426
lib
@@ -30,6 +32,7 @@ out
3032
pointerof
3133
private
3234
protected
35+
ptr
3336
require
3437
rescue
3538
return
@@ -41,6 +44,7 @@ super
4144
then
4245
type
4346
typeof
47+
undef
4448
uninitialized
4549
union
4650
unless
@@ -62,6 +66,7 @@ __LINE__
6266
["punctuation", "."], ["keyword", "responds_to?"],
6367
["keyword", "abstract"],
6468
["keyword", "alias"],
69+
["keyword", "annotation"], ["punctuation", ";"],
6570
["keyword", "as"],
6671
["keyword", "asm"],
6772
["keyword", "begin"],
@@ -79,6 +84,7 @@ __LINE__
7984
["keyword", "for"],
8085
["keyword", "fun"],
8186
["keyword", "if"],
87+
["keyword", "ifdef"],
8288
["keyword", "include"],
8389
["keyword", "instance_sizeof"],
8490
["keyword", "lib"],
@@ -90,6 +96,7 @@ __LINE__
9096
["keyword", "pointerof"],
9197
["keyword", "private"],
9298
["keyword", "protected"],
99+
["keyword", "ptr"],
93100
["keyword", "require"],
94101
["keyword", "rescue"],
95102
["keyword", "return"],
@@ -101,6 +108,7 @@ __LINE__
101108
["keyword", "then"],
102109
["keyword", "type"],
103110
["keyword", "typeof"],
111+
["keyword", "undef"],
104112
["keyword", "uninitialized"],
105113
["keyword", "union"],
106114
["keyword", "unless"],
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
+ - * / % **
2+
+= -= *= /= %= **=
3+
4+
== != < > <= >= <=> ===
5+
!~ =~
6+
=
7+
& | ^ ~ << >>
8+
&= |= ^= <<= >>=
9+
&& || !
10+
&&= ||=
11+
12+
=>
13+
->
14+
15+
&.
16+
17+
? :
18+
.. ...
19+
20+
and or not
21+
22+
----------------------------------------------------
23+
24+
[
25+
["operator", "+"],
26+
["operator", "-"],
27+
["operator", "*"],
28+
["operator", "/"],
29+
["operator", "%"],
30+
["operator", "**"],
31+
32+
["operator", "+="],
33+
["operator", "-="],
34+
["operator", "*="],
35+
["operator", "/="],
36+
["operator", "%="],
37+
["operator", "**="],
38+
39+
["operator", "=="],
40+
["operator", "!="],
41+
["operator", "<"],
42+
["operator", ">"],
43+
["operator", "<="],
44+
["operator", ">="],
45+
["operator", "<=>"],
46+
["operator", "==="],
47+
48+
["operator", "!~"],
49+
["operator", "=~"],
50+
51+
["operator", "="],
52+
53+
["operator", "&"],
54+
["operator", "|"],
55+
["operator", "^"],
56+
["operator", "~"],
57+
["operator", "<<"],
58+
["operator", ">>"],
59+
60+
["operator", "&="],
61+
["operator", "|="],
62+
["operator", "^="],
63+
["operator", "<<="],
64+
["operator", ">>="],
65+
66+
["operator", "&&"],
67+
["operator", "||"],
68+
["operator", "!"],
69+
70+
["operator", "&&="],
71+
["operator", "||="],
72+
73+
["operator", "=>"],
74+
["operator", "->"],
75+
76+
["operator", "&."],
77+
78+
["operator", "?"], ["operator", ":"],
79+
["operator", ".."], ["operator", "..."],
80+
81+
"\r\n\r\nand or not"
82+
]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
( ) [ ] { }
2+
, .
3+
:: \
4+
5+
----------------------------------------------------
6+
7+
[
8+
["punctuation", "("],
9+
["punctuation", ")"],
10+
["punctuation", "["],
11+
["punctuation", "]"],
12+
["punctuation", "{"],
13+
["punctuation", "}"],
14+
15+
["punctuation", ","],
16+
["punctuation", "."],
17+
18+
["double-colon", "::"],
19+
["punctuation", "\\"]
20+
]
+184
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,184 @@
1+
/foo|bar/
2+
/h(e+)llo/
3+
/\d+/
4+
/あ/
5+
6+
/\// # slash
7+
/\\/ # backslash
8+
/\b/ # backspace
9+
/\e/ # escape
10+
/\f/ # form feed
11+
/\n/ # newline
12+
/\r/ # carriage return
13+
/\t/ # tab
14+
/\v/ # vertical tab
15+
/\NNN/ # octal ASCII character
16+
/\xNN/ # hexadecimal ASCII character
17+
/\x{FFFF}/ # hexadecimal unicode character
18+
/\x{10FFFF}/ # hexadecimal unicode character
19+
20+
/foo/i.match("FOO") # => #<Regex::MatchData "FOO">
21+
/foo/m.match("bar\nfoo") # => #<Regex::MatchData "foo">
22+
/foo /x.match("foo") # => #<Regex::MatchData "foo">
23+
/foo /imx.match("bar\nFOO") # => #<Regex::MatchData "FOO">
24+
25+
%r((/)) # => /(\/)/
26+
%r[[/]] # => /[\/]/
27+
%r{{/}} # => /{\/}/
28+
%r<</>> # => /<\/>/
29+
%r|/| # => /\//
30+
31+
----------------------------------------------------
32+
33+
[
34+
["regex-literal", [
35+
["regex", "/foo|bar/"]
36+
]],
37+
["regex-literal", [
38+
["regex", "/h(e+)llo/"]
39+
]],
40+
["regex-literal", [
41+
["regex", "/\\d+/"]
42+
]],
43+
["regex-literal", [
44+
["regex", "/あ/"]
45+
]],
46+
47+
["regex-literal", [
48+
["regex", "/\\//"]
49+
]],
50+
["comment", "# slash"],
51+
52+
["regex-literal", [
53+
["regex", "/\\\\/"]
54+
]],
55+
["comment", "# backslash"],
56+
57+
["regex-literal", [
58+
["regex", "/\\b/"]
59+
]],
60+
["comment", "# backspace"],
61+
62+
["regex-literal", [
63+
["regex", "/\\e/"]
64+
]],
65+
["comment", "# escape"],
66+
67+
["regex-literal", [
68+
["regex", "/\\f/"]
69+
]],
70+
["comment", "# form feed"],
71+
72+
["regex-literal", [
73+
["regex", "/\\n/"]
74+
]],
75+
["comment", "# newline"],
76+
77+
["regex-literal", [
78+
["regex", "/\\r/"]
79+
]],
80+
["comment", "# carriage return"],
81+
82+
["regex-literal", [
83+
["regex", "/\\t/"]
84+
]],
85+
["comment", "# tab"],
86+
87+
["regex-literal", [
88+
["regex", "/\\v/"]
89+
]],
90+
["comment", "# vertical tab"],
91+
92+
["regex-literal", [
93+
["regex", "/\\NNN/"]
94+
]],
95+
["comment", "# octal ASCII character"],
96+
97+
["regex-literal", [
98+
["regex", "/\\xNN/"]
99+
]],
100+
["comment", "# hexadecimal ASCII character"],
101+
102+
["regex-literal", [
103+
["regex", "/\\x{FFFF}/"]
104+
]],
105+
["comment", "# hexadecimal unicode character"],
106+
107+
["regex-literal", [
108+
["regex", "/\\x{10FFFF}/"]
109+
]],
110+
["comment", "# hexadecimal unicode character"],
111+
112+
["regex-literal", [
113+
["regex", "/foo/i"]
114+
]],
115+
["punctuation", "."],
116+
"match",
117+
["punctuation", "("],
118+
["string-literal", [
119+
["string", "\"FOO\""]
120+
]],
121+
["punctuation", ")"],
122+
["comment", "# => #<Regex::MatchData \"FOO\">"],
123+
124+
["regex-literal", [
125+
["regex", "/foo/m"]
126+
]],
127+
["punctuation", "."],
128+
"match",
129+
["punctuation", "("],
130+
["string-literal", [
131+
["string", "\"bar\\nfoo\""]
132+
]],
133+
["punctuation", ")"],
134+
["comment", "# => #<Regex::MatchData \"foo\">"],
135+
136+
["regex-literal", [
137+
["regex", "/foo /x"]
138+
]],
139+
["punctuation", "."],
140+
"match",
141+
["punctuation", "("],
142+
["string-literal", [
143+
["string", "\"foo\""]
144+
]],
145+
["punctuation", ")"],
146+
["comment", "# => #<Regex::MatchData \"foo\">"],
147+
148+
["regex-literal", [
149+
["regex", "/foo /imx"]
150+
]],
151+
["punctuation", "."],
152+
"match",
153+
["punctuation", "("],
154+
["string-literal", [
155+
["string", "\"bar\\nFOO\""]
156+
]],
157+
["punctuation", ")"],
158+
["comment", "# => #<Regex::MatchData \"FOO\">"],
159+
160+
["regex-literal", [
161+
["regex", "%r((/))"]
162+
]],
163+
["comment", "# => /(\\/)/"],
164+
165+
["regex-literal", [
166+
["regex", "%r[[/]]"]
167+
]],
168+
["comment", "# => /[\\/]/"],
169+
170+
["regex-literal", [
171+
["regex", "%r{{/}}"]
172+
]],
173+
["comment", "# => /{\\/}/"],
174+
175+
["regex-literal", [
176+
["regex", "%r<</>>"]
177+
]],
178+
["comment", "# => /<\\/>/"],
179+
180+
["regex-literal", [
181+
["regex", "%r|/|"]
182+
]],
183+
["comment", "# => /\\//"]
184+
]
+321
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,321 @@
1+
"hello world"
2+
3+
"\"" # double quote
4+
"\\" # backslash
5+
"\#" # hash character (to escape interpolation)
6+
"\a" # alert
7+
"\b" # backspace
8+
"\e" # escape
9+
"\f" # form feed
10+
"\n" # newline
11+
"\r" # carriage return
12+
"\t" # tab
13+
"\v" # vertical tab
14+
"\377" # octal ASCII character
15+
"\xFF" # hexadecimal ASCII character
16+
"\uFFFF" # hexadecimal unicode character
17+
"\u{0}".."\u{10FFFF}" # hexadecimal unicode character
18+
19+
"\101" # => "A"
20+
"\123" # => "S"
21+
"\12" # => "\n"
22+
"\1" # string with one character with code point 1
23+
24+
"\u{48 45 4C 4C 4F}" # => "HELLO"
25+
26+
"sum: #{a} + #{b} = #{a + b}"
27+
28+
"\#{a + b}" # => "#{a + b}"
29+
%q(#{a + b}) # => "#{a + b}"
30+
31+
%(hello ("world")) # => "hello (\"world\")"
32+
%[hello ["world"]] # => "hello [\"world\"]"
33+
%{hello {"world"}} # => "hello {\"world\"}"
34+
%<hello <"world">> # => "hello <\"world\">"
35+
%|hello "world"| # => "hello \"world\""
36+
37+
name = "world"
38+
%q(hello \n #{name}) # => "hello \\n \#{name}"
39+
%Q(hello \n #{name}) # => "hello \n world"
40+
41+
%w(foo bar baz) # => ["foo", "bar", "baz"]
42+
%w(foo\nbar baz) # => ["foo\\nbar", "baz"]
43+
%w(foo(bar) baz) # => ["foo(bar)", "baz"]
44+
45+
%w(foo\ bar baz) # => ["foo bar", "baz"]
46+
47+
"hello " \
48+
"world, " \
49+
"no newlines" # same as "hello world, no newlines"
50+
51+
"hello \
52+
world, \
53+
no newlines" # same as "hello world, no newlines"
54+
55+
<<-XML
56+
<parent>
57+
<child />
58+
</parent>
59+
XML
60+
61+
----------------------------------------------------
62+
63+
[
64+
["string-literal", [
65+
["string", "\"hello world\""]
66+
]],
67+
68+
["string-literal", [
69+
["string", "\"\\\"\""]
70+
]],
71+
["comment", "# double quote"],
72+
73+
["string-literal", [
74+
["string", "\"\\\\\""]
75+
]],
76+
["comment", "# backslash"],
77+
78+
["string-literal", [
79+
["string", "\"\\#\""]
80+
]],
81+
["comment", "# hash character (to escape interpolation)"],
82+
83+
["string-literal", [
84+
["string", "\"\\a\""]
85+
]],
86+
["comment", "# alert"],
87+
88+
["string-literal", [
89+
["string", "\"\\b\""]
90+
]],
91+
["comment", "# backspace"],
92+
93+
["string-literal", [
94+
["string", "\"\\e\""]
95+
]],
96+
["comment", "# escape"],
97+
98+
["string-literal", [
99+
["string", "\"\\f\""]
100+
]],
101+
["comment", "# form feed"],
102+
103+
["string-literal", [
104+
["string", "\"\\n\""]
105+
]],
106+
["comment", "# newline"],
107+
108+
["string-literal", [
109+
["string", "\"\\r\""]
110+
]],
111+
["comment", "# carriage return"],
112+
113+
["string-literal", [
114+
["string", "\"\\t\""]
115+
]],
116+
["comment", "# tab"],
117+
118+
["string-literal", [
119+
["string", "\"\\v\""]
120+
]],
121+
["comment", "# vertical tab"],
122+
123+
["string-literal", [
124+
["string", "\"\\377\""]
125+
]],
126+
["comment", "# octal ASCII character"],
127+
128+
["string-literal", [
129+
["string", "\"\\xFF\""]
130+
]],
131+
["comment", "# hexadecimal ASCII character"],
132+
133+
["string-literal", [
134+
["string", "\"\\uFFFF\""]
135+
]],
136+
["comment", "# hexadecimal unicode character"],
137+
138+
["string-literal", [
139+
["string", "\"\\u{0}\""]
140+
]],
141+
["operator", ".."],
142+
["string-literal", [
143+
["string", "\"\\u{10FFFF}\""]
144+
]],
145+
["comment", "# hexadecimal unicode character"],
146+
147+
["string-literal", [
148+
["string", "\"\\101\""]
149+
]],
150+
["comment", "# => \"A\""],
151+
152+
["string-literal", [
153+
["string", "\"\\123\""]
154+
]],
155+
["comment", "# => \"S\""],
156+
157+
["string-literal", [
158+
["string", "\"\\12\""]
159+
]],
160+
["comment", "# => \"\\n\""],
161+
162+
["string-literal", [
163+
["string", "\"\\1\""]
164+
]],
165+
["comment", "# string with one character with code point 1"],
166+
167+
["string-literal", [
168+
["string", "\"\\u{48 45 4C 4C 4F}\""]
169+
]],
170+
["comment", "# => \"HELLO\""],
171+
172+
["string-literal", [
173+
["string", "\"sum: "],
174+
["interpolation", [
175+
["delimiter", "#{"],
176+
["content", ["a"]],
177+
["delimiter", "}"]
178+
]],
179+
["string", " + "],
180+
["interpolation", [
181+
["delimiter", "#{"],
182+
["content", ["b"]],
183+
["delimiter", "}"]
184+
]],
185+
["string", " = "],
186+
["interpolation", [
187+
["delimiter", "#{"],
188+
["content", [
189+
"a ",
190+
["operator", "+"],
191+
" b"
192+
]],
193+
["delimiter", "}"]
194+
]],
195+
["string", "\""]
196+
]],
197+
198+
["string-literal", [
199+
["string", "\"\\#{a + b}\""]
200+
]],
201+
["comment", "# => \"#{a + b}\""],
202+
203+
["string-literal", [
204+
["string", "%q("],
205+
["interpolation", [
206+
["delimiter", "#{"],
207+
["content", [
208+
"a ",
209+
["operator", "+"],
210+
" b"
211+
]],
212+
["delimiter", "}"]
213+
]],
214+
["string", ")"]
215+
]],
216+
["comment", "# => \"#{a + b}\""],
217+
218+
["string-literal", [
219+
["string", "%(hello (\"world\"))"]
220+
]],
221+
["comment", "# => \"hello (\\\"world\\\")\""],
222+
223+
["string-literal", [
224+
["string", "%[hello [\"world\"]]"]
225+
]],
226+
["comment", "# => \"hello [\\\"world\\\"]\""],
227+
228+
["string-literal", [
229+
["string", "%{hello {\"world\"}}"]
230+
]],
231+
["comment", "# => \"hello {\\\"world\\\"}\""],
232+
233+
["string-literal", [
234+
["string", "%<hello <\"world\">>"]
235+
]],
236+
["comment", "# => \"hello <\\\"world\\\">\""],
237+
238+
["string-literal", [
239+
["string", "%|hello \"world\"|"]
240+
]],
241+
["comment", "# => \"hello \\\"world\\\"\""],
242+
243+
"\r\n\r\nname ",
244+
["operator", "="],
245+
["string-literal", [
246+
["string", "\"world\""]
247+
]],
248+
249+
["string-literal", [
250+
["string", "%q(hello \\n "],
251+
["interpolation", [
252+
["delimiter", "#{"],
253+
["content", ["name"]],
254+
["delimiter", "}"]
255+
]],
256+
["string", ")"]
257+
]],
258+
["comment", "# => \"hello \\\\n \\#{name}\""],
259+
260+
["string-literal", [
261+
["string", "%Q(hello \\n "],
262+
["interpolation", [
263+
["delimiter", "#{"],
264+
["content", ["name"]],
265+
["delimiter", "}"]
266+
]],
267+
["string", ")"]
268+
]],
269+
["comment", "# => \"hello \\n world\""],
270+
271+
["string-literal", [
272+
["string", "%w(foo bar baz)"]
273+
]],
274+
["comment", "# => [\"foo\", \"bar\", \"baz\"]"],
275+
276+
["string-literal", [
277+
["string", "%w(foo\\nbar baz)"]
278+
]],
279+
["comment", "# => [\"foo\\\\nbar\", \"baz\"]"],
280+
281+
["string-literal", [
282+
["string", "%w(foo(bar) baz)"]
283+
]],
284+
["comment", "# => [\"foo(bar)\", \"baz\"]"],
285+
286+
["string-literal", [
287+
["string", "%w(foo\\ bar baz)"]
288+
]],
289+
["comment", "# => [\"foo bar\", \"baz\"]"],
290+
291+
["string-literal", [
292+
["string", "\"hello \""]
293+
]],
294+
["punctuation", "\\"],
295+
296+
["string-literal", [
297+
["string", "\"world, \""]
298+
]],
299+
["punctuation", "\\"],
300+
301+
["string-literal", [
302+
["string", "\"no newlines\""]
303+
]],
304+
["comment", "# same as \"hello world, no newlines\""],
305+
306+
["string-literal", [
307+
["string", "\"hello \\\r\n world, \\\r\n no newlines\""]
308+
]],
309+
["comment", "# same as \"hello world, no newlines\""],
310+
311+
["string-literal", [
312+
["delimiter", [
313+
["punctuation", "<<-"],
314+
["symbol", "XML"]
315+
]],
316+
["string", "\r\n<parent>\r\n <child />\r\n</parent>\r\n"],
317+
["delimiter", [
318+
["symbol", "XML"]
319+
]]
320+
]]
321+
]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
:unquoted_symbol
2+
:"quoted symbol"
3+
:"a" # identical to :a
4+
:あ
5+
:question?
6+
:exclamation!
7+
8+
----------------------------------------------------
9+
10+
[
11+
["symbol", ":unquoted_symbol"],
12+
["symbol", ":\"quoted symbol\""],
13+
["symbol", ":\"a\""], ["comment", "# identical to :a"],
14+
["symbol", ":あ"],
15+
["symbol", ":question?"],
16+
["symbol", ":exclamation!"]
17+
]

0 commit comments

Comments
 (0)
Please sign in to comment.