Skip to content

Commit b39a6f3

Browse files
committed
Add support for user function namespace to have underscore prefix
1 parent cf01ba4 commit b39a6f3

File tree

3 files changed

+16
-3
lines changed

3 files changed

+16
-3
lines changed

dsc/tests/dsc_user_functions.tests.ps1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@
33

44
Describe 'user function tests' {
55
It 'user function working with expression: <expression>' -TestCases @(
6-
@{ expression = "[MyFunction.ComboFunction('test', 42, true)]"; expected = 'test-42-True' }
6+
@{ expression = "[__MyFunction.ComboFunction('test', 42, true)]"; expected = 'test-42-True' }
77
@{ expression = "[MyOtherNamespace.ArrayFunction(createArray('a','b','c','d'))]"; expected = @('["b","c","d"]-a') }
88
) {
99
param($expression, $expected)
1010

1111
$configYaml = @"
1212
`$schema: https://aka.ms/dsc/schemas/v3/bundled/config/document.json
1313
functions:
14-
- namespace: MyFunction
14+
- namespace: __MyFunction
1515
members:
1616
ComboFunction:
1717
parameters:

grammars/tree-sitter-dscexpression/grammar.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ module.exports = grammar({
2424

2525
function: $ => prec(PREC.FUNCTION, seq(field('name', $.functionName), '(', field('args', optional($.arguments)), ')')),
2626
functionName: $ => choice(
27-
/[a-zA-Z][a-zA-Z0-9]*(\.[a-zA-Z0-9]+)?/,
27+
/[_a-zA-Z][_a-zA-Z0-9]*(\.[a-zA-Z0-9]+)?/,
2828
$._booleanLiteral
2929
),
3030
arguments: $ => seq($._argument, repeat(seq(',', $._argument))),

grammars/tree-sitter-dscexpression/test/corpus/valid_expressions.txt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -370,3 +370,16 @@ User Function with nested function
370370
(function
371371
(functionName)))
372372
(boolean)))))
373+
374+
=====
375+
User Function with namespace prefixed by underscores
376+
=====
377+
[__bicep.myFunction('param1')]
378+
---
379+
380+
(statement
381+
(expression
382+
(function
383+
(functionName)
384+
(arguments
385+
(string)))))

0 commit comments

Comments
 (0)