Skip to content

Commit 96df75a

Browse files
authored
fix: Parse REFERENCE TO STRING (#1267)
Previously a string REFERENCE TO pointer variable would fail to parse when a REF= operator was present. This commit fixes this by checking if a REF= operator can be consumed when parsing a STRING variable.
1 parent 50dc477 commit 96df75a

File tree

2 files changed

+41
-2
lines changed

2 files changed

+41
-2
lines changed

src/parser.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -854,7 +854,10 @@ fn parse_string_type_definition(
854854
}),
855855
_ => Some(DataTypeDeclaration::DataTypeReference { referenced_type: text, location }),
856856
}
857-
.zip(Some(lexer.try_consume(&KeywordAssignment).then(|| parse_expression(lexer))))
857+
.zip(Some(
858+
(lexer.try_consume(&KeywordAssignment) || lexer.try_consume(&KeywordReferenceAssignment))
859+
.then(|| parse_expression(lexer)),
860+
))
858861
}
859862

860863
fn parse_enum_type_definition(

src/parser/tests/statement_parser_tests.rs

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ fn ref_assignment() {
291291
}
292292

293293
#[test]
294-
fn reference_to_declaration() {
294+
fn reference_to_dint_declaration() {
295295
let (result, diagnostics) = parse(
296296
r"
297297
FUNCTION foo
@@ -340,6 +340,42 @@ fn reference_to_declaration() {
340340
"###);
341341
}
342342

343+
#[test]
344+
fn reference_to_string_declaration() {
345+
let (result, diagnostics) = parse(
346+
r"
347+
FUNCTION foo
348+
VAR
349+
foo : REFERENCE TO STRING;
350+
END_VAR
351+
END_FUNCTION
352+
",
353+
);
354+
355+
assert!(diagnostics.is_empty());
356+
insta::assert_debug_snapshot!(result.units[0].variable_blocks[0], @r###"
357+
VariableBlock {
358+
variables: [
359+
Variable {
360+
name: "foo",
361+
data_type: DataTypeDefinition {
362+
data_type: PointerType {
363+
name: None,
364+
referenced_type: DataTypeReference {
365+
referenced_type: "STRING",
366+
},
367+
auto_deref: Some(
368+
Reference,
369+
),
370+
},
371+
},
372+
},
373+
],
374+
variable_block_type: Local,
375+
}
376+
"###);
377+
}
378+
343379
#[test]
344380
fn aliasing_dint_variable() {
345381
let (result, diagnostics) = parse(

0 commit comments

Comments
 (0)