Skip to content

Commit 1cf541b

Browse files
committed
glayzzle#133 - add a quote & raw property on nowdoc
1 parent f4f21cd commit 1cf541b

File tree

7 files changed

+65
-50
lines changed

7 files changed

+65
-50
lines changed

dist/php-parser.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2069,11 +2069,13 @@ var KIND = "nowdoc";
20692069
* @constructor String
20702070
* @extends {Literal}
20712071
* @property {String} label
2072-
2072+
* @property {String} raw
2073+
* @property {Boolean} quote
20732074
*/
2074-
var Nowdoc = Literal.extends(function Nowdoc(value, raw, label, docs, location) {
2075+
var Nowdoc = Literal.extends(function Nowdoc(value, raw, label, quote, docs, location) {
20752076
Literal.apply(this, [KIND, value, raw, docs, location]);
20762077
this.label = label;
2078+
this.quote = quote;
20772079
});
20782080

20792081
module.exports = Nowdoc;
@@ -6839,7 +6841,8 @@ module.exports = {
68396841
value = value.substring(0, value.length - 1);
68406842
}
68416843
this.expect(this.tok.T_ENCAPSED_AND_WHITESPACE) && this.next();
6842-
node = node(value, this.lexer._input.substring(start, this.lexer.yylloc.last_offset), this.lexer.heredoc_label);
6844+
var raw = this.lexer._input.substring(start, this.lexer.yylloc.last_offset);
6845+
node = node(value, raw, this.lexer.heredoc_label, raw[3] === '"' || raw[3] === "'");
68436846
this.expect(this.tok.T_END_HEREDOC) && this.next();
68446847
return node;
68456848
} else {

dist/php-parser.min.js

Lines changed: 8 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/php-parser.min.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/AST.md

Lines changed: 37 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -2,41 +2,6 @@
22

33
## AST
44

5-
The AST builder class
6-
7-
**Parameters**
8-
9-
- `withPositions`
10-
- `withSource`
11-
12-
**Properties**
13-
14-
- `withPositions` **[Boolean](#boolean)** Should locate any node (by default false)
15-
- `withSource` **[Boolean](#boolean)** Should extract the node original code (by default false)
16-
17-
### resolvePrecedence
18-
19-
Check and fix precence, by default using right
20-
21-
**Parameters**
22-
23-
- `result`
24-
25-
### prepare
26-
27-
Prepares an AST node
28-
29-
**Parameters**
30-
31-
- `kind` **([String](#string) | null)** Defines the node type
32-
(if null, the kind must be passed at the function call)
33-
- `parser` **Parser** The parser instance (use for extracting locations)
34-
- `docs`
35-
36-
Returns **[Function](#function)**
37-
38-
## AST
39-
405
## Class hierarchy
416

427
- [Location](#location)
@@ -155,6 +120,41 @@ Prepares an AST node
155120

156121
Returns **[Function](#function)**
157122

123+
## AST
124+
125+
The AST builder class
126+
127+
**Parameters**
128+
129+
- `withPositions`
130+
- `withSource`
131+
132+
**Properties**
133+
134+
- `withPositions` **[Boolean](#boolean)** Should locate any node (by default false)
135+
- `withSource` **[Boolean](#boolean)** Should extract the node original code (by default false)
136+
137+
### resolvePrecedence
138+
139+
Check and fix precence, by default using right
140+
141+
**Parameters**
142+
143+
- `result`
144+
145+
### prepare
146+
147+
Prepares an AST node
148+
149+
**Parameters**
150+
151+
- `kind` **([String](#string) | null)** Defines the node type
152+
(if null, the kind must be passed at the function call)
153+
- `parser` **Parser** The parser instance (use for extracting locations)
154+
- `docs`
155+
156+
Returns **[Function](#function)**
157+
158158
## Array
159159

160160
**Extends Expression**
@@ -887,6 +887,8 @@ Defines a nowdoc string
887887
**Properties**
888888

889889
- `label` **[String](#string)**
890+
- `raw` **[String](#string)**
891+
- `quote` **[Boolean](#boolean)**
890892

891893
## String
892894

src/ast/nowdoc.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,20 @@ const KIND = "nowdoc";
1212
* @constructor String
1313
* @extends {Literal}
1414
* @property {String} label
15-
15+
* @property {String} raw
16+
* @property {Boolean} quote
1617
*/
1718
const Nowdoc = Literal.extends(function Nowdoc(
1819
value,
1920
raw,
2021
label,
22+
quote,
2123
docs,
2224
location
2325
) {
2426
Literal.apply(this, [KIND, value, raw, docs, location]);
2527
this.label = label;
28+
this.quote = quote;
2629
});
2730

2831
module.exports = Nowdoc;

src/parser/scalar.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,10 +90,15 @@ module.exports = {
9090
value = value.substring(0, value.length - 1);
9191
}
9292
this.expect(this.tok.T_ENCAPSED_AND_WHITESPACE) && this.next();
93+
const raw = this.lexer._input.substring(
94+
start,
95+
this.lexer.yylloc.last_offset
96+
);
9397
node = node(
9498
value,
95-
this.lexer._input.substring(start, this.lexer.yylloc.last_offset),
96-
this.lexer.heredoc_label
99+
raw,
100+
this.lexer.heredoc_label,
101+
raw[3] === '"' || raw[3] === "'"
97102
);
98103
this.expect(this.tok.T_END_HEREDOC) && this.next();
99104
return node;

test/stringTests.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,8 @@ describe("Test strings", function() {
295295
expr.kind.should.be.exactly("nowdoc");
296296
expr.label.should.be.exactly("EOF");
297297
expr.value.should.be.exactly(" }");
298+
expr.quote.should.be.exactly(true);
299+
expr.raw.should.be.exactly("<<<'EOF'\r\n }\r\nEOF;");
298300
});
299301
it("heredoc ...", function() {
300302
var ast = parser.parseEval(

0 commit comments

Comments
 (0)