Skip to content

Commit 1fd17d0

Browse files
authored
Fix the bug where a period in a variable name generates a syntax error when using it in a string template. (#72)
Fixes #71
1 parent 7c15455 commit 1fd17d0

File tree

4 files changed

+39
-2
lines changed

4 files changed

+39
-2
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
# v0.13.4
2+
3+
## Bug Fixes
4+
5+
* ([#71](https://github.com/harrisont/fastbuild-vscode/issues/71)) Fix the bug where a period in a variable name generates a syntax error when using it in a string template.
6+
17
# v0.13.3
28

39
## Bug Fixes

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "fastbuild-support",
33
"displayName": "FASTBuild Support",
44
"description": "FASTBuild language support. Includes go-to definition, find references, variable evaluation, syntax errors, etc.",
5-
"version": "0.13.3",
5+
"version": "0.13.4",
66
"preview": true,
77
"publisher": "HarrisonT",
88
"author": {

server/src/fbuild-grammar.ne

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ const lexer = moo.states({
120120
},
121121
templatedVariable: {
122122
endTemplatedVariable: { match: '$', pop: 1 },
123-
variableName: /[a-zA-Z_][a-zA-Z0-9_]*/,
123+
variableName: /[a-zA-Z_.][a-zA-Z0-9_.]*/,
124124
},
125125
variableReferenceName: {
126126
// Literal variable name

server/src/test/2-evaluator.test.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,14 @@ describe('evaluator', () => {
182182
assertEvaluatedVariablesValueEqual(input, ['MyValue', 'MyValue']);
183183
});
184184

185+
it('should be detected in a string with a variable whose name contains a period', () => {
186+
const input = `
187+
.'My.Var' = 'MyValue'
188+
Print('pre-$My.Var$-post')
189+
`;
190+
assertEvaluatedVariablesValueEqual(input, ['MyValue', 'MyValue']);
191+
});
192+
185193
it('should be detected in a string with multiple variables', () => {
186194
const input = `
187195
.MyVar1 = 'MyValue1'
@@ -199,6 +207,14 @@ describe('evaluator', () => {
199207
assertEvaluatedVariablesValueEqual(input, [1, 1, 1]);
200208
});
201209

210+
it('should be detected in the RHS when assigning the value of another variable whose name contains a period', () => {
211+
const input = `
212+
.'My.Var' = 1
213+
.Copy = .'My.Var'
214+
`;
215+
assertEvaluatedVariablesValueEqual(input, [1, 1, 1]);
216+
});
217+
202218
it('should be detected in the RHS when assigning the value of another variable in the parent scope', () => {
203219
const input = `
204220
.MyVar = 1
@@ -741,6 +757,21 @@ describe('evaluator', () => {
741757
]);
742758
});
743759

760+
it('should evaluate dynamic variable names with periods in them on the RHS in the current scope', () => {
761+
const input = `
762+
.A_B_C = 'foo'
763+
.'Mid.dle' = 'B'
764+
.MyVar = ."A_$Mid.dle$_C"
765+
`;
766+
assertEvaluatedVariablesValueEqual(input, [
767+
'foo',
768+
'B',
769+
'B',
770+
'foo',
771+
'foo',
772+
]);
773+
});
774+
744775
it('should evaluate dynamic variable names on the RHS in the parent scope', () => {
745776
const input = `
746777
.A_B_C = 'foo'

0 commit comments

Comments
 (0)