Skip to content
This repository was archived by the owner on Jul 24, 2024. It is now read-only.

Commit 04462d0

Browse files
parser: add doc string opener to nodes
1 parent 9a4c864 commit 04462d0

File tree

11 files changed

+58
-2
lines changed

11 files changed

+58
-2
lines changed

schema.json

+44
Original file line numberDiff line numberDiff line change
@@ -1705,6 +1705,24 @@
17051705
"$ref": "#/definitions/ClassishConstant"
17061706
}
17071707
}
1708+
},
1709+
{
1710+
"type": "object",
1711+
"required": [
1712+
"type",
1713+
"value"
1714+
],
1715+
"properties": {
1716+
"type": {
1717+
"type": "string",
1718+
"enum": [
1719+
"TraitUsage"
1720+
]
1721+
},
1722+
"value": {
1723+
"$ref": "#/definitions/TraitUsage"
1724+
}
1725+
}
17081726
}
17091727
]
17101728
},
@@ -6101,9 +6119,13 @@
61016119
"HeredocExpression": {
61026120
"type": "object",
61036121
"required": [
6122+
"label",
61046123
"parts"
61056124
],
61066125
"properties": {
6126+
"label": {
6127+
"$ref": "#/definitions/ByteString"
6128+
},
61076129
"parts": {
61086130
"type": "array",
61096131
"items": {
@@ -7620,9 +7642,13 @@
76207642
"NowdocExpression": {
76217643
"type": "object",
76227644
"required": [
7645+
"label",
76237646
"value"
76247647
],
76257648
"properties": {
7649+
"label": {
7650+
"$ref": "#/definitions/ByteString"
7651+
},
76267652
"value": {
76277653
"$ref": "#/definitions/ByteString"
76287654
}
@@ -10106,6 +10132,24 @@
1010610132
"$ref": "#/definitions/ClassishConstant"
1010710133
}
1010810134
}
10135+
},
10136+
{
10137+
"type": "object",
10138+
"required": [
10139+
"type",
10140+
"value"
10141+
],
10142+
"properties": {
10143+
"type": {
10144+
"type": "string",
10145+
"enum": [
10146+
"TraitUsage"
10147+
]
10148+
},
10149+
"value": {
10150+
"$ref": "#/definitions/TraitUsage"
10151+
}
10152+
}
1010910153
}
1011010154
]
1011110155
},

src/parser/ast/mod.rs

+2
Original file line numberDiff line numberDiff line change
@@ -842,6 +842,7 @@ impl Node for InterpolatedStringExpression {
842842

843843
#[derive(Debug, PartialEq, Eq, Clone, Deserialize, Serialize, JsonSchema)]
844844
pub struct HeredocExpression {
845+
pub label: ByteString,
845846
pub parts: Vec<StringPart>,
846847
}
847848

@@ -856,6 +857,7 @@ impl Node for HeredocExpression {
856857

857858
#[derive(Debug, PartialEq, Eq, Clone, Deserialize, Serialize, JsonSchema)]
858859
pub struct NowdocExpression {
860+
pub label: ByteString,
859861
pub value: ByteString,
860862
}
861863

src/parser/internal/strings.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ pub fn shell_exec(state: &mut State) -> ParseResult<Expression> {
6161
#[inline(always)]
6262
pub fn heredoc(state: &mut State) -> ParseResult<Expression> {
6363
let span = state.stream.current().span;
64+
let label = state.stream.current().value.clone();
6465
state.stream.next();
6566

6667
let mut parts = Vec::new();
@@ -140,12 +141,13 @@ pub fn heredoc(state: &mut State) -> ParseResult<Expression> {
140141
}
141142
}
142143

143-
Ok(Expression::Heredoc(HeredocExpression { parts }))
144+
Ok(Expression::Heredoc(HeredocExpression { label, parts }))
144145
}
145146

146147
#[inline(always)]
147148
pub fn nowdoc(state: &mut State) -> ParseResult<Expression> {
148149
let span = state.stream.current().span;
150+
let label = state.stream.current().value.clone();
149151

150152
state.stream.next();
151153

@@ -221,7 +223,7 @@ pub fn nowdoc(state: &mut State) -> ParseResult<Expression> {
221223
string_part = bytes.into();
222224
}
223225

224-
Ok(Expression::Nowdoc(NowdocExpression { value: string_part }))
226+
Ok(Expression::Nowdoc(NowdocExpression { label, value: string_part }))
225227
}
226228

227229
fn part(state: &mut State) -> ParseResult<Option<StringPart>> {

tests/fixtures/0224/ast.txt

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
ExpressionStatement {
1313
expression: Heredoc(
1414
HeredocExpression {
15+
label: "<<<EOF",
1516
parts: [
1617
Literal(
1718
LiteralStringPart {

tests/fixtures/0225/ast.txt

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
ExpressionStatement {
1313
expression: Heredoc(
1414
HeredocExpression {
15+
label: "<<< TXT",
1516
parts: [
1617
Literal(
1718
LiteralStringPart {

tests/fixtures/0228/ast.txt

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
ExpressionStatement {
1313
expression: Heredoc(
1414
HeredocExpression {
15+
label: "<<<EOF",
1516
parts: [
1617
Literal(
1718
LiteralStringPart {

tests/fixtures/0229/ast.txt

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
ExpressionStatement {
1313
expression: Heredoc(
1414
HeredocExpression {
15+
label: "<<<EOF",
1516
parts: [
1617
Literal(
1718
LiteralStringPart {

tests/fixtures/0230/ast.txt

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
ExpressionStatement {
1313
expression: Heredoc(
1414
HeredocExpression {
15+
label: "<<<EOF",
1516
parts: [
1617
Literal(
1718
LiteralStringPart {

tests/fixtures/0231/ast.txt

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
ExpressionStatement {
1313
expression: Nowdoc(
1414
NowdocExpression {
15+
label: "<<<'EOF'",
1516
value: " Hello, world!\n Hello, world!",
1617
},
1718
),

tests/fixtures/0232/ast.txt

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
ExpressionStatement {
1313
expression: Nowdoc(
1414
NowdocExpression {
15+
label: "<<<'EOF'",
1516
value: "Hello, world!\nHello, world!",
1617
},
1718
),

tests/fixtures/0235/ast.txt

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
ExpressionStatement {
1313
expression: Nowdoc(
1414
NowdocExpression {
15+
label: "<<<'EOF'",
1516
value: "Hello, {$name}!",
1617
},
1718
),

0 commit comments

Comments
 (0)