Skip to content
This repository was archived by the owner on Mar 29, 2023. It is now read-only.

Commit e6752a9

Browse files
authored
Merge pull request glayzzle#231 from glayzzle/feat-encapsed-part
feat: `EncapsedPart` node
2 parents 9754930 + f4767e1 commit e6752a9

File tree

11 files changed

+3474
-953
lines changed

11 files changed

+3474
-953
lines changed

src/ast.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ const Position = require("./ast/position");
1414
* - [Location](#location)
1515
* - [Position](#position)
1616
* - [Node](#node)
17+
* - [EncapsedPart](#encapsedpart)
1718
* - [Constant](#constant)
1819
* - [Identifier](#identifier)
1920
* - [Reference](#reference)
@@ -368,6 +369,7 @@ AST.prototype.prepare = function(kind, docs, parser) {
368369
require("./ast/echo"),
369370
require("./ast/empty"),
370371
require("./ast/encapsed"),
372+
require("./ast/encapsedpart"),
371373
require("./ast/entry"),
372374
require("./ast/error"),
373375
require("./ast/eval"),

src/ast/encapsedpart.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/**
2+
* Copyright (C) 2018 Glayzzle (BSD3 License)
3+
* @authors https://github.com/glayzzle/php-parser/graphs/contributors
4+
* @url http://glayzzle.com
5+
*/
6+
"use strict";
7+
8+
const Expression = require("./expression");
9+
const KIND = "encapsedpart";
10+
11+
/**
12+
* Part of `Encapsed` node
13+
* @constructor EncapsedPart
14+
* @extends {Expression}
15+
* @property {Expression} what
16+
*/
17+
module.exports = Expression.extends(KIND, function EncapsedPart(
18+
expression,
19+
curly,
20+
docs,
21+
location
22+
) {
23+
Expression.apply(this, [KIND, docs, location]);
24+
this.expression = expression;
25+
this.curly = curly;
26+
});

src/parser/scalar.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,8 @@ module.exports = {
176176
* @see https://github.com/php/php-src/blob/master/Zend/zend_language_parser.y#L1219
177177
*/
178178
read_encapsed_string_item: function(isDoubleQuote) {
179+
const encapsedPart = this.node("encapsedpart");
180+
let curly = false;
179181
let result = this.node(),
180182
offset,
181183
node,
@@ -220,11 +222,9 @@ module.exports = {
220222
} else if (this.token === this.tok.T_CURLY_OPEN) {
221223
// expression
222224
// https://github.com/php/php-src/blob/master/Zend/zend_language_parser.y#L1246
225+
curly = true;
223226
result.destroy();
224227
result = this.next().read_variable(false, false, false);
225-
if (result.kind === "variable") {
226-
result.curly = true;
227-
}
228228
this.expect("}") && this.next();
229229
} else if (this.token === this.tok.T_VARIABLE) {
230230
// plain variable
@@ -260,7 +260,7 @@ module.exports = {
260260
result = result("string", false, value, false, value);
261261
}
262262

263-
return result;
263+
return encapsedPart(result, curly);
264264
},
265265
/**
266266
* Reads an encapsed string

0 commit comments

Comments
 (0)