Merge pull request #1528 from jdalegonzalez/master
Added parser support for traits, namespace declarations, namespace refer...
This commit is contained in:
commit
7294a35b3f
1 changed files with 168 additions and 11 deletions
|
|
@ -24,8 +24,6 @@ var PHP = {Constants:{}};
|
|||
|
||||
|
||||
|
||||
|
||||
|
||||
PHP.Constants.T_INCLUDE = 262;
|
||||
PHP.Constants.T_INCLUDE_ONCE = 261;
|
||||
PHP.Constants.T_EVAL = 260;
|
||||
|
|
@ -123,7 +121,7 @@ PHP.Constants.T_ISSET = 350;
|
|||
PHP.Constants.T_EMPTY = 351;
|
||||
PHP.Constants.T_HALT_COMPILER = 352;
|
||||
PHP.Constants.T_CLASS = 353;
|
||||
//PHP.Constants.T_TRAIT = ;
|
||||
PHP.Constants.T_TRAIT = 382;
|
||||
PHP.Constants.T_INTERFACE = 354;
|
||||
PHP.Constants.T_EXTENDS = 355;
|
||||
PHP.Constants.T_IMPLEMENTS = 356;
|
||||
|
|
@ -172,6 +170,10 @@ PHP.Lexer = function( src, ini ) {
|
|||
openTag = (ini === undefined || (/^(on|true|1)$/i.test(ini.short_open_tag) ) ? /(\<\?php\s|\<\?|\<\%|\<script language\=('|")?php('|")?\>)/i : /(\<\?php\s|<\?=|\<script language\=('|")?php('|")?\>)/i),
|
||||
openTagStart = (ini === undefined || (/^(on|true|1)$/i.test(ini.short_open_tag)) ? /^(\<\?php\s|\<\?|\<\%|\<script language\=('|")?php('|")?\>)/i : /^(\<\?php\s|<\?=|\<script language\=('|")?php('|")?\>)/i),
|
||||
tokens = [
|
||||
{
|
||||
value: PHP.Constants.T_NAMESPACE,
|
||||
re: /^namespace(?=\s)/i
|
||||
},
|
||||
{
|
||||
value: PHP.Constants.T_USE,
|
||||
re: /^use(?=\s)/i
|
||||
|
|
@ -465,6 +467,10 @@ PHP.Lexer = function( src, ini ) {
|
|||
re: /^class(?=[\s\{])/i,
|
||||
afterWhitespace: true
|
||||
},
|
||||
{
|
||||
value: PHP.Constants.T_TRAIT,
|
||||
re: /^trait(?=[\s]+[A-Za-z])/i,
|
||||
},
|
||||
{
|
||||
value: PHP.Constants.T_PUBLIC,
|
||||
re: /^public(?=[\s])/i
|
||||
|
|
@ -724,7 +730,7 @@ PHP.Lexer = function( src, ini ) {
|
|||
|
||||
results.push([
|
||||
parseInt(( curlyOpen > 0 ) ? PHP.Constants.T_CONSTANT_ENCAPSED_STRING : PHP.Constants.T_ENCAPSED_AND_WHITESPACE, 10),
|
||||
match[ 0 ],
|
||||
match[ 0 ].replace(/\n/g,"\\n").replace(/\r/g,""),
|
||||
line
|
||||
]);
|
||||
|
||||
|
|
@ -756,6 +762,8 @@ PHP.Lexer = function( src, ini ) {
|
|||
|
||||
return undefined;
|
||||
|
||||
} else {
|
||||
result = result.replace(/\n/g,"\\n").replace(/\r/g,"");
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
@ -769,6 +777,10 @@ PHP.Lexer = function( src, ini ) {
|
|||
return result;
|
||||
}
|
||||
},
|
||||
{
|
||||
value: PHP.Constants.T_NS_SEPARATOR,
|
||||
re: /^\\(?=[a-zA-Z_])/
|
||||
},
|
||||
{
|
||||
value: PHP.Constants.T_STRING,
|
||||
re: /^[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*/
|
||||
|
|
@ -929,7 +941,6 @@ PHP.Lexer = function( src, ini ) {
|
|||
|
||||
};
|
||||
|
||||
|
||||
/*
|
||||
* @author Niklas von Hertzen <niklas at hertzen.com>
|
||||
* @created 15.6.2012
|
||||
|
|
@ -1179,8 +1190,14 @@ PHP.Parser.prototype.getNextToken = function( ) {
|
|||
this.startAttributes['startLine'] = this.line;
|
||||
this.endAttributes['endLine'] = this.line;
|
||||
|
||||
this.tokenValue = token;
|
||||
return token.charCodeAt(0);
|
||||
// bug in token_get_all
|
||||
if ('b"' === token) {
|
||||
this.tokenValue = 'b"';
|
||||
return '"'.charCodeAt(0);
|
||||
} else {
|
||||
this.tokenValue = token;
|
||||
return token.charCodeAt(0);
|
||||
}
|
||||
} else {
|
||||
|
||||
|
||||
|
|
@ -1260,14 +1277,79 @@ PHP.Parser.prototype.createTokenMap = function() {
|
|||
} else if( PHP.Constants.T_CLOSE_TAG === i ) {
|
||||
tokenMap[ i ] = 59;
|
||||
// and the others can be mapped directly
|
||||
} else if ( 'UNKNOWN' !== (name = this.tokenName( i ) ) ) {
|
||||
|
||||
} else if ( 'UNKNOWN' !== (name = this.tokenName( i ) ) ) {
|
||||
tokenMap[ i ] = this[name];
|
||||
}
|
||||
}
|
||||
return tokenMap;
|
||||
};
|
||||
|
||||
var yynStandard = function () {
|
||||
this.yyval = this.yyastk[ this.stackPos-(1-1) ];
|
||||
};
|
||||
// todo fix
|
||||
|
||||
PHP.Parser.prototype.MakeArray = function( arr ) {
|
||||
return Array.isArray( arr ) ? arr : [ arr ];
|
||||
}
|
||||
|
||||
|
||||
PHP.Parser.prototype.parseString = function( str ) {
|
||||
var bLength = 0;
|
||||
if ('b' === str[0]) {
|
||||
bLength = 1;
|
||||
}
|
||||
|
||||
if ('\'' === str[ bLength ]) {
|
||||
str = str.replace(
|
||||
['\\\\', '\\\''],
|
||||
[ '\\', '\'']);
|
||||
} else {
|
||||
|
||||
str = this.parseEscapeSequences( str, '"');
|
||||
|
||||
}
|
||||
|
||||
return str;
|
||||
|
||||
};
|
||||
|
||||
PHP.Parser.prototype.parseEscapeSequences = function( str, quote ) {
|
||||
|
||||
|
||||
|
||||
if (undefined !== quote) {
|
||||
str = str.replace(new RegExp('\\' + quote, "g"), quote);
|
||||
}
|
||||
|
||||
var replacements = {
|
||||
'\\': '\\',
|
||||
'$': '$',
|
||||
'n': "\n",
|
||||
'r': "\r",
|
||||
't': "\t",
|
||||
'f': "\f",
|
||||
'v': "\v",
|
||||
'e': "\x1B"
|
||||
};
|
||||
|
||||
return str.replace(
|
||||
/~\\\\([\\\\$nrtfve]|[xX][0-9a-fA-F]{1,2}|[0-7]{1,3})~/g,
|
||||
function ( matches ){
|
||||
var str = matches[1];
|
||||
|
||||
if ( replacements[ str ] !== undefined ) {
|
||||
return replacements[ str ];
|
||||
} else if ('x' === str[ 0 ] || 'X' === str[ 0 ]) {
|
||||
return chr(hexdec(str));
|
||||
} else {
|
||||
return chr(octdec(str));
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
return str;
|
||||
};
|
||||
|
||||
/* This is an automatically GENERATED file, which should not be manually edited.
|
||||
* Instead edit one of the following:
|
||||
|
|
@ -3699,7 +3781,6 @@ PHP.Parser.prototype.yyn379 = function ( attributes ) {
|
|||
this.yyval = this.Node_Expr_Variable(this.yyastk[ this.stackPos-(1-1) ].substring( 1 ), attributes);
|
||||
};
|
||||
|
||||
|
||||
/*
|
||||
* @author Niklas von Hertzen <niklas at hertzen.com>
|
||||
* @created 20.7.2012
|
||||
|
|
@ -3765,6 +3846,63 @@ PHP.Parser.prototype.Stmt_Class_verifyModifier = function() {
|
|||
|
||||
};
|
||||
|
||||
PHP.Parser.prototype.Node_Stmt_Namespace = function() {
|
||||
return {
|
||||
type: "Node_Stmt_Namespace",
|
||||
name: arguments[ 0 ],
|
||||
attributes: arguments[ 2 ]
|
||||
};
|
||||
};
|
||||
|
||||
PHP.Parser.prototype.Node_Stmt_Use = function() {
|
||||
return {
|
||||
type: "Node_Stmt_Use",
|
||||
name: arguments[ 0 ],
|
||||
attributes: arguments[ 2 ]
|
||||
};
|
||||
};
|
||||
|
||||
PHP.Parser.prototype.Node_Stmt_UseUse = function() {
|
||||
return {
|
||||
type: "Node_Stmt_UseUse",
|
||||
name: arguments[ 0 ],
|
||||
as: arguments[1],
|
||||
attributes: arguments[ 2 ]
|
||||
};
|
||||
};
|
||||
|
||||
PHP.Parser.prototype.Node_Stmt_TraitUseAdaptation_Precedence = function() {
|
||||
return {
|
||||
type: "Node_Stmt_TraitUseAdaptation_Precedence",
|
||||
name: arguments[ 0 ],
|
||||
attributes: arguments[ 2 ]
|
||||
};
|
||||
};
|
||||
|
||||
PHP.Parser.prototype.Node_Stmt_TraitUseAdaptation_Alias = function() {
|
||||
return {
|
||||
type: "Node_Stmt_TraitUseAdaptation_Alias",
|
||||
name: arguments[ 0 ],
|
||||
attributes: arguments[ 2 ]
|
||||
};
|
||||
};
|
||||
|
||||
PHP.Parser.prototype.Node_Stmt_Trait = function() {
|
||||
return {
|
||||
type: "Node_Stmt_Trait",
|
||||
name: arguments[ 0 ],
|
||||
attributes: arguments[ 2 ]
|
||||
};
|
||||
};
|
||||
|
||||
PHP.Parser.prototype.Node_Stmt_TraitUse = function() {
|
||||
return {
|
||||
type: "Node_Stmt_TraitUse",
|
||||
name: arguments[ 0 ],
|
||||
attributes: arguments[ 2 ]
|
||||
};
|
||||
};
|
||||
|
||||
PHP.Parser.prototype.Node_Stmt_Class = function() {
|
||||
return {
|
||||
type: "Node_Stmt_Class",
|
||||
|
|
@ -4802,6 +4940,26 @@ PHP.Parser.prototype.Node_Name = function() {
|
|||
|
||||
};
|
||||
|
||||
PHP.Parser.prototype.Node_Name_FullyQualified = function() {
|
||||
|
||||
return {
|
||||
type: "Node_Name_FullyQualified",
|
||||
parts: arguments[ 0 ],
|
||||
attributes: arguments[ 1 ]
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
PHP.Parser.prototype.Node_Name_Relative = function() {
|
||||
|
||||
return {
|
||||
type: "Node_Name_Relative",
|
||||
parts: arguments[ 0 ],
|
||||
attributes: arguments[ 1 ]
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
PHP.Parser.prototype.Node_Param = function() {
|
||||
|
||||
return {
|
||||
|
|
@ -4826,7 +4984,6 @@ PHP.Parser.prototype.Node_Arg = function() {
|
|||
|
||||
};
|
||||
|
||||
|
||||
PHP.Parser.prototype.Node_Const = function() {
|
||||
|
||||
return {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue