Skip to content

Commit 14fa71d

Browse files
committed
glayzzle#147 : introducing an unicode property on texts
1 parent 4c45a17 commit 14fa71d

14 files changed

+153
-1
lines changed

src/ast/string.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,20 @@ const KIND = "string";
1212
* Defines a string (simple ou double quoted) - chars are already escaped
1313
* @constructor String
1414
* @extends {Literal}
15+
* @property {boolean} unicode
1516
* @property {boolean} isDoubleQuote
1617
* @see {Encapsed}
1718
*/
1819
const String = Literal.extends(function String(
1920
isDoubleQuote,
2021
value,
22+
unicode,
2123
raw,
2224
docs,
2325
location
2426
) {
2527
Literal.apply(this, [KIND, value, raw, docs, location]);
28+
this.unicode = unicode;
2629
this.isDoubleQuote = isDoubleQuote;
2730
});
2831

src/parser/scalar.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ module.exports = {
6565
text.substring(offset + 1, text.length - 1),
6666
isDoubleQuote
6767
),
68+
offset === 1, // unicode flag
6869
text
6970
);
7071
if (this.token === this.tok.T_DOUBLE_COLON) {
@@ -191,6 +192,7 @@ module.exports = {
191192
"string",
192193
false,
193194
this.resolve_special_chars(text, isDoubleQuote),
195+
false,
194196
text
195197
);
196198
} else if (this.token === this.tok.T_DOLLAR_OPEN_CURLY_BRACES) {
@@ -254,7 +256,7 @@ module.exports = {
254256
const value = this.text();
255257
this.next();
256258
// consider it as string
257-
result = result("string", false, value, value);
259+
result = result("string", false, value, false, value);
258260
}
259261

260262
return result;

test/snapshot/__snapshots__/acid.test.js.snap

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ Program {
149149
},
150150
},
151151
"raw": "'foo.php'",
152+
"unicode": false,
152153
"value": "foo.php",
153154
},
154155
},
@@ -391,6 +392,7 @@ Program {
391392
},
392393
},
393394
"raw": "'foo & bar'",
395+
"unicode": false,
394396
"value": "foo & bar",
395397
},
396398
},
@@ -620,6 +622,7 @@ Program {
620622
},
621623
},
622624
"raw": "'BARFOO'",
625+
"unicode": false,
623626
"value": "BARFOO",
624627
},
625628
"visibility": "",
@@ -666,6 +669,7 @@ Program {
666669
},
667670
},
668671
"raw": "'sneezy'",
672+
"unicode": false,
669673
"value": "sneezy",
670674
},
671675
"kind": "entry",
@@ -699,6 +703,7 @@ Program {
699703
},
700704
},
701705
"raw": "'achoum'",
706+
"unicode": false,
702707
"value": "achoum",
703708
},
704709
},
@@ -720,6 +725,7 @@ Program {
720725
},
721726
},
722727
"raw": "'bashful'",
728+
"unicode": false,
723729
"value": "bashful",
724730
},
725731
"kind": "entry",
@@ -753,6 +759,7 @@ Program {
753759
},
754760
},
755761
"raw": "'tadah'",
762+
"unicode": false,
756763
"value": "tadah",
757764
},
758765
},
@@ -822,6 +829,7 @@ Program {
822829
},
823830
},
824831
"raw": "Hey ho ",
832+
"unicode": false,
825833
"value": "Hey ho ",
826834
},
827835
Variable {
@@ -860,6 +868,7 @@ Program {
860868
},
861869
},
862870
"raw": ", ",
871+
"unicode": false,
863872
"value": ", ",
864873
},
865874
Variable {
@@ -898,6 +907,7 @@ Program {
898907
},
899908
},
900909
"raw": " !",
910+
"unicode": false,
901911
"value": " !",
902912
},
903913
],
@@ -1137,6 +1147,7 @@ Program {
11371147
},
11381148
},
11391149
"raw": "'Thats it'",
1150+
"unicode": false,
11401151
"value": "Thats it",
11411152
},
11421153
],
@@ -1523,6 +1534,7 @@ Program {
15231534
},
15241535
},
15251536
"raw": "'ator'",
1537+
"unicode": false,
15261538
"value": "ator",
15271539
},
15281540
"kind": "yield",
@@ -1765,6 +1777,7 @@ Program {
17651777
},
17661778
},
17671779
"raw": "'dot'",
1780+
"unicode": false,
17681781
"value": "dot",
17691782
},
17701783
},
@@ -1823,6 +1836,7 @@ Program {
18231836
},
18241837
},
18251838
"raw": "'......'",
1839+
"unicode": false,
18261840
"value": "......",
18271841
},
18281842
},
@@ -1893,6 +1907,7 @@ Program {
18931907
},
18941908
},
18951909
"raw": "'point'",
1910+
"unicode": false,
18961911
"value": "point",
18971912
},
18981913
},
@@ -1951,6 +1966,7 @@ Program {
19511966
},
19521967
},
19531968
"raw": "'-----'",
1969+
"unicode": false,
19541970
"value": "-----",
19551971
},
19561972
},
@@ -2160,6 +2176,7 @@ Program {
21602176
},
21612177
},
21622178
"raw": "''",
2179+
"unicode": false,
21632180
"value": "",
21642181
},
21652182
"kind": "retif",
@@ -2212,6 +2229,7 @@ Program {
22122229
},
22132230
},
22142231
"raw": "'>'",
2232+
"unicode": false,
22152233
"value": ">",
22162234
},
22172235
},
@@ -3752,6 +3770,7 @@ next:
37523770
},
37533771
},
37543772
"raw": "'noo!'",
3773+
"unicode": false,
37553774
"value": "noo!",
37563775
},
37573776
"kind": "retif",
@@ -3891,6 +3910,7 @@ next:
38913910
},
38923911
},
38933912
"raw": "'yes!'",
3913+
"unicode": false,
38943914
"value": "yes!",
38953915
},
38963916
},
@@ -4513,6 +4533,7 @@ next:
45134533
},
45144534
},
45154535
"raw": "\\"meeeh\\"",
4536+
"unicode": false,
45164537
"value": "meeeh",
45174538
},
45184539
"kind": "return",
@@ -6043,6 +6064,7 @@ next:
60436064
},
60446065
},
60456066
"raw": "ls -larth",
6067+
"unicode": false,
60466068
"value": "ls -larth",
60476069
},
60486070
],
@@ -6155,6 +6177,7 @@ next:
61556177
},
61566178
},
61576179
"raw": "bar&",
6180+
"unicode": false,
61586181
"value": "bar&",
61596182
},
61606183
],
@@ -6612,6 +6635,7 @@ BAZ
66126635
},
66136636
"raw": " Hello world
66146637
",
6638+
"unicode": false,
66156639
"value": " Hello world
66166640
",
66176641
},
@@ -6807,6 +6831,7 @@ FOO
68076831
},
68086832
"raw": " return 'This is madness!';
68096833
",
6834+
"unicode": false,
68106835
"value": " return 'This is madness!';
68116836
",
68126837
},

test/snapshot/__snapshots__/array.test.js.snap

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,12 +63,14 @@ Program {
6363
"isDoubleQuote": true,
6464
"kind": "string",
6565
"raw": "\\"a\\"",
66+
"unicode": false,
6667
"value": "a",
6768
},
6869
String {
6970
"isDoubleQuote": true,
7071
"kind": "string",
7172
"raw": "\\"b\\"",
73+
"unicode": false,
7274
"value": "b",
7375
},
7476
],
@@ -155,6 +157,7 @@ Program {
155157
"isDoubleQuote": true,
156158
"kind": "string",
157159
"raw": "\\"foobar\\"",
160+
"unicode": false,
158161
"value": "foobar",
159162
},
160163
},
@@ -179,12 +182,14 @@ Program {
179182
"isDoubleQuote": true,
180183
"kind": "string",
181184
"raw": "\\"item1\\"",
185+
"unicode": false,
182186
"value": "item1",
183187
},
184188
String {
185189
"isDoubleQuote": true,
186190
"kind": "string",
187191
"raw": "\\"item2\\"",
192+
"unicode": false,
188193
"value": "item2",
189194
},
190195
],
@@ -197,12 +202,14 @@ Program {
197202
"isDoubleQuote": true,
198203
"kind": "string",
199204
"raw": "\\"item3\\"",
205+
"unicode": false,
200206
"value": "item3",
201207
},
202208
String {
203209
"isDoubleQuote": true,
204210
"kind": "string",
205211
"raw": "\\"item4\\"",
212+
"unicode": false,
206213
"value": "item4",
207214
},
208215
],
@@ -215,12 +222,14 @@ Program {
215222
"isDoubleQuote": true,
216223
"kind": "string",
217224
"raw": "\\"item5\\"",
225+
"unicode": false,
218226
"value": "item5",
219227
},
220228
String {
221229
"isDoubleQuote": true,
222230
"kind": "string",
223231
"raw": "\\"item6\\"",
232+
"unicode": false,
224233
"value": "item6",
225234
},
226235
],
@@ -315,18 +324,21 @@ Program {
315324
"isDoubleQuote": true,
316325
"kind": "string",
317326
"raw": "\\"item1\\"",
327+
"unicode": false,
318328
"value": "item1",
319329
},
320330
String {
321331
"isDoubleQuote": true,
322332
"kind": "string",
323333
"raw": "\\"item2\\"",
334+
"unicode": false,
324335
"value": "item2",
325336
},
326337
String {
327338
"isDoubleQuote": true,
328339
"kind": "string",
329340
"raw": "\\"item3\\"",
341+
"unicode": false,
330342
"value": "item3",
331343
},
332344
],
@@ -352,6 +364,7 @@ Program {
352364
"isDoubleQuote": true,
353365
"kind": "string",
354366
"raw": "\\"item2\\"",
367+
"unicode": false,
355368
"value": "item2",
356369
},
357370
Number {
@@ -362,6 +375,7 @@ Program {
362375
"isDoubleQuote": true,
363376
"kind": "string",
364377
"raw": "\\"item4\\"",
378+
"unicode": false,
365379
"value": "item4",
366380
},
367381
],

0 commit comments

Comments
 (0)