Skip to content

Commit e94bc86

Browse files
committed
Fixed unicode support in the source code
Closes #56, #62
1 parent 16076d9 commit e94bc86

File tree

5 files changed

+238
-2
lines changed

5 files changed

+238
-2
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/)
55
and this project adheres to [Semantic Versioning](http://semver.org/).
66

77
## [Unreleased]
8+
### Fixed
9+
- Fixed unicode support in the source code
10+
[#62](https://github.com/phalcon/php-zephir-parser/issues/62),
11+
[#56](https://github.com/phalcon/php-zephir-parser/issues/56)
812

913
## [1.2.0] - 2019-01-14
1014
### Added

parser/scanner.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
#include "scanner.h"
2121

2222
// for re2c
23-
#define YYCTYPE char
23+
#define YYCTYPE unsigned char
2424
#define YYCURSOR (s->cursor)
2525
#define YYLIMIT (s->limit)
2626
#define YYMARKER (s->marker)

parser/scanner.re

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
#include "scanner.h"
1919

2020
// for re2c
21-
#define YYCTYPE char
21+
#define YYCTYPE unsigned char
2222
#define YYCURSOR (s->cursor)
2323
#define YYLIMIT (s->limit)
2424
#define YYMARKER (s->marker)

tests/unicode/bug56.phpt

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
--TEST--
2+
Using Cyrillic characters in the source code
3+
--SKIPIF--
4+
<?php include(__DIR__ . '/../skipif.inc'); ?>
5+
--FILE--
6+
<?php
7+
8+
$code =<<<ZEP
9+
namespace Test;
10+
11+
class test {
12+
13+
public function testUTF8() {
14+
return "сдфггхх";
15+
}
16+
}
17+
ZEP;
18+
19+
var_dump(zephir_parse_file($code, '(eval code)'));
20+
?>
21+
--EXPECT--
22+
array(2) {
23+
[0]=>
24+
array(5) {
25+
["type"]=>
26+
string(9) "namespace"
27+
["name"]=>
28+
string(4) "Test"
29+
["file"]=>
30+
string(11) "(eval code)"
31+
["line"]=>
32+
int(3)
33+
["char"]=>
34+
int(5)
35+
}
36+
[1]=>
37+
array(8) {
38+
["type"]=>
39+
string(5) "class"
40+
["name"]=>
41+
string(4) "test"
42+
["abstract"]=>
43+
int(0)
44+
["final"]=>
45+
int(0)
46+
["definition"]=>
47+
array(4) {
48+
["methods"]=>
49+
array(1) {
50+
[0]=>
51+
array(8) {
52+
["visibility"]=>
53+
array(1) {
54+
[0]=>
55+
string(6) "public"
56+
}
57+
["type"]=>
58+
string(6) "method"
59+
["name"]=>
60+
string(8) "testUTF8"
61+
["statements"]=>
62+
array(1) {
63+
[0]=>
64+
array(5) {
65+
["type"]=>
66+
string(6) "return"
67+
["expr"]=>
68+
array(5) {
69+
["type"]=>
70+
string(6) "string"
71+
["value"]=>
72+
string(14) "сдфггхх"
73+
["file"]=>
74+
string(11) "(eval code)"
75+
["line"]=>
76+
int(6)
77+
["char"]=>
78+
int(30)
79+
}
80+
["file"]=>
81+
string(11) "(eval code)"
82+
["line"]=>
83+
int(7)
84+
["char"]=>
85+
int(5)
86+
}
87+
}
88+
["file"]=>
89+
string(11) "(eval code)"
90+
["line"]=>
91+
int(5)
92+
["last-line"]=>
93+
int(8)
94+
["char"]=>
95+
int(19)
96+
}
97+
}
98+
["file"]=>
99+
string(11) "(eval code)"
100+
["line"]=>
101+
int(3)
102+
["char"]=>
103+
int(5)
104+
}
105+
["file"]=>
106+
string(11) "(eval code)"
107+
["line"]=>
108+
int(3)
109+
["char"]=>
110+
int(5)
111+
}
112+
}

tests/unicode/bug62.phpt

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
--TEST--
2+
Using Chinese characters in the source code
3+
--SKIPIF--
4+
<?php include(__DIR__ . '/../skipif.inc'); ?>
5+
--FILE--
6+
<?php
7+
8+
$code =<<<ZEP
9+
namespace Utils;
10+
11+
class Greeting
12+
{
13+
14+
public static function say()
15+
{
16+
echo "中文";
17+
}
18+
19+
}
20+
ZEP;
21+
22+
var_dump(zephir_parse_file($code, '(eval code)'));
23+
?>
24+
--EXPECT--
25+
array(2) {
26+
[0]=>
27+
array(5) {
28+
["type"]=>
29+
string(9) "namespace"
30+
["name"]=>
31+
string(5) "Utils"
32+
["file"]=>
33+
string(11) "(eval code)"
34+
["line"]=>
35+
int(3)
36+
["char"]=>
37+
int(5)
38+
}
39+
[1]=>
40+
array(8) {
41+
["type"]=>
42+
string(5) "class"
43+
["name"]=>
44+
string(8) "Greeting"
45+
["abstract"]=>
46+
int(0)
47+
["final"]=>
48+
int(0)
49+
["definition"]=>
50+
array(4) {
51+
["methods"]=>
52+
array(1) {
53+
[0]=>
54+
array(8) {
55+
["visibility"]=>
56+
array(2) {
57+
[0]=>
58+
string(6) "public"
59+
[1]=>
60+
string(6) "static"
61+
}
62+
["type"]=>
63+
string(6) "method"
64+
["name"]=>
65+
string(3) "say"
66+
["statements"]=>
67+
array(1) {
68+
[0]=>
69+
array(5) {
70+
["type"]=>
71+
string(4) "echo"
72+
["expressions"]=>
73+
array(1) {
74+
[0]=>
75+
array(5) {
76+
["type"]=>
77+
string(6) "string"
78+
["value"]=>
79+
string(6) "中文"
80+
["file"]=>
81+
string(11) "(eval code)"
82+
["line"]=>
83+
int(8)
84+
["char"]=>
85+
int(20)
86+
}
87+
}
88+
["file"]=>
89+
string(11) "(eval code)"
90+
["line"]=>
91+
int(9)
92+
["char"]=>
93+
int(5)
94+
}
95+
}
96+
["file"]=>
97+
string(11) "(eval code)"
98+
["line"]=>
99+
int(6)
100+
["last-line"]=>
101+
int(11)
102+
["char"]=>
103+
int(26)
104+
}
105+
}
106+
["file"]=>
107+
string(11) "(eval code)"
108+
["line"]=>
109+
int(3)
110+
["char"]=>
111+
int(5)
112+
}
113+
["file"]=>
114+
string(11) "(eval code)"
115+
["line"]=>
116+
int(3)
117+
["char"]=>
118+
int(5)
119+
}
120+
}

0 commit comments

Comments
 (0)