Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit dc16935

Browse files
Add parser support for traits, namespace declarations and namespace qualified classnames
1 parent 87e61d9 commit dc16935

File tree

4 files changed

+92
-5
lines changed

4 files changed

+92
-5
lines changed

‎src/modules/tokenizer/constants.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ PHP.Constants.T_ISSET = 350;
9999
PHP.Constants.T_EMPTY = 351;
100100
PHP.Constants.T_HALT_COMPILER = 352;
101101
PHP.Constants.T_CLASS = 353;
102-
//PHP.Constants.T_TRAIT = ;
102+
PHP.Constants.T_TRAIT = 382;
103103
PHP.Constants.T_INTERFACE = 354;
104104
PHP.Constants.T_EXTENDS = 355;
105105
PHP.Constants.T_IMPLEMENTS = 356;
@@ -129,4 +129,4 @@ PHP.Constants.T_DOUBLE_COLON = 376;
129129
PHP.Constants.T_NAMESPACE = 377;
130130
PHP.Constants.T_NS_C = 378;
131131
PHP.Constants.T_DIR = 379;
132-
PHP.Constants.T_NS_SEPARATOR = 380;
132+
PHP.Constants.T_NS_SEPARATOR = 380;

‎src/parser/lexer.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ PHP.Lexer = function( src, ini ) {
1616
openTag = (ini === undefined || (/^(on|true|1)$/i.test(ini.short_open_tag) ) ? /(\<\?php\s|\<\?|\<\%|\<scriptlanguage\=('|")?php('|")?\>)/i : /(\<\?php\s|<\?=|\<scriptlanguage\=('|")?php('|")?\>)/i),
1717
openTagStart = (ini === undefined || (/^(on|true|1)$/i.test(ini.short_open_tag)) ? /^(\<\?php\s|\<\?|\<\%|\<scriptlanguage\=('|")?php('|")?\>)/i : /^(\<\?php\s|<\?=|\<scriptlanguage\=('|")?php('|")?\>)/i),
1818
tokens = [
19+
{
20+
value: PHP.Constants.T_NAMESPACE,
21+
re: /^namespace(?=\s)/i
22+
},
1923
{
2024
value: PHP.Constants.T_USE,
2125
re: /^use(?=\s)/i
@@ -309,6 +313,10 @@ PHP.Lexer = function( src, ini ) {
309313
re: /^class(?=[\s\{])/i,
310314
afterWhitespace: true
311315
},
316+
{
317+
value: PHP.Constants.T_TRAIT,
318+
re: /^trait(?=[\s]+[A-Za-z])/i,
319+
},
312320
{
313321
value: PHP.Constants.T_PUBLIC,
314322
re: /^public(?=[\s])/i
@@ -615,6 +623,10 @@ PHP.Lexer = function( src, ini ) {
615623
return result;
616624
}
617625
},
626+
{
627+
value: PHP.Constants.T_NS_SEPARATOR,
628+
re: /^\\(?=[a-zA-Z_])/
629+
},
618630
{
619631
value: PHP.Constants.T_STRING,
620632
re: /^[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*/

‎src/parser/yyn_scalar.js

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,26 @@ PHP.Parser.prototype.Node_Name = function() {
8383

8484
};
8585

86+
PHP.Parser.prototype.Node_Name_FullyQualified = function() {
87+
88+
return {
89+
type: "Node_Name_FullyQualified",
90+
parts: arguments[ 0 ],
91+
attributes: arguments[ 1 ]
92+
};
93+
94+
};
95+
96+
PHP.Parser.prototype.Node_Name_Relative = function() {
97+
98+
return {
99+
type: "Node_Name_Relative",
100+
parts: arguments[ 0 ],
101+
attributes: arguments[ 1 ]
102+
};
103+
104+
};
105+
86106
PHP.Parser.prototype.Node_Param = function() {
87107

88108
return {
@@ -107,7 +127,6 @@ PHP.Parser.prototype.Node_Arg = function() {
107127

108128
};
109129

110-
111130
PHP.Parser.prototype.Node_Const = function() {
112131

113132
return {
@@ -118,4 +137,3 @@ PHP.Parser.prototype.Node_Const = function() {
118137
};
119138

120139
};
121-

‎src/parser/yyn_stmt.js

Lines changed: 58 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,63 @@ PHP.Parser.prototype.Stmt_Class_verifyModifier = function() {
6363

6464
};
6565

66+
PHP.Parser.prototype.Node_Stmt_Namespace = function() {
67+
return {
68+
type: "Node_Stmt_Namespace",
69+
name: arguments[ 0 ],
70+
attributes: arguments[ 2 ]
71+
};
72+
};
73+
74+
PHP.Parser.prototype.Node_Stmt_Use = function() {
75+
return {
76+
type: "Node_Stmt_Use",
77+
name: arguments[ 0 ],
78+
attributes: arguments[ 2 ]
79+
};
80+
};
81+
82+
PHP.Parser.prototype.Node_Stmt_UseUse = function() {
83+
return {
84+
type: "Node_Stmt_UseUse",
85+
name: arguments[ 0 ],
86+
as: arguments[1],
87+
attributes: arguments[ 2 ]
88+
};
89+
};
90+
91+
PHP.Parser.prototype.Node_Stmt_TraitUseAdaptation_Precedence = function() {
92+
return {
93+
type: "Node_Stmt_TraitUseAdaptation_Precedence",
94+
name: arguments[ 0 ],
95+
attributes: arguments[ 2 ]
96+
};
97+
};
98+
99+
PHP.Parser.prototype.Node_Stmt_TraitUseAdaptation_Alias = function() {
100+
return {
101+
type: "Node_Stmt_TraitUseAdaptation_Alias",
102+
name: arguments[ 0 ],
103+
attributes: arguments[ 2 ]
104+
};
105+
};
106+
107+
PHP.Parser.prototype.Node_Stmt_Trait = function() {
108+
return {
109+
type: "Node_Stmt_Trait",
110+
name: arguments[ 0 ],
111+
attributes: arguments[ 2 ]
112+
};
113+
};
114+
115+
PHP.Parser.prototype.Node_Stmt_TraitUse = function() {
116+
return {
117+
type: "Node_Stmt_TraitUse",
118+
name: arguments[ 0 ],
119+
attributes: arguments[ 2 ]
120+
};
121+
};
122+
66123
PHP.Parser.prototype.Node_Stmt_Class = function() {
67124
return {
68125
type: "Node_Stmt_Class",
@@ -310,4 +367,4 @@ PHP.Parser.prototype.Node_Stmt_Unset = function() {
310367
attributes: arguments[ 1 ]
311368
};
312369

313-
};
370+
};

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /