Skip to content

Commit

Permalink
Permit newline in lambda arguments and function definition arguments (A…
Browse files Browse the repository at this point in the history
…zure#13043)

Permit newline in lambda arguments and function definition arguments

Closes Azure#12913 
###### Microsoft Reviewers: [Open in
CodeFlow](https://microsoft.github.io/open-pr/?codeflow=https://github.com/Azure/bicep/pull/13043)
  • Loading branch information
anthony-c-martin committed Jan 24, 2024
1 parent 12cb7b8 commit e321ef8
Show file tree
Hide file tree
Showing 50 changed files with 2,085 additions and 760 deletions.
4 changes: 2 additions & 2 deletions docs/grammar.md
Original file line number Diff line number Diff line change
Expand Up @@ -136,11 +136,11 @@ functionCall -> IDENTIFIER "(" argumentList? ")"
parenthesizedExpression -> "(" expression ")"
localVariable -> IDENTIFIER
variableBlock -> "(" ( localVariable ("," localVariable)* )? ")"
variableBlock -> "(" NL* ( localVariable NL* ("," NL* localVariable NL*)* )? ")"
lambdaExpression -> ( variableBlock | localVariable ) "=>" expression
typedLocalVariable -> IDENTIFIER primaryTypeExpression
typedVariableBlock -> "(" ( typedLocalVariable ("," typedLocalVariable)* )? ")"
typedVariableBlock -> "(" NL* ( typedLocalVariable NL* ("," NL* typedLocalVariable NL*)* )? ")"
typedLambdaExpression -> typedVariableBlock primaryTypeExpression "=>" expression
ifCondition -> "if" parenthesizedExpression object
Expand Down
10 changes: 10 additions & 0 deletions src/Bicep.Core.Samples/Files/baselines/Functions_LF/main.bicep
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,13 @@ func test() object => loadJsonContent('./repro-data.json')
func test2() string => loadTextContent('./repro-data.json')
func test3() object => loadYamlContent('./repro-data.json')
func test4() string => loadFileAsBase64('./repro-data.json')

// validate formatter works (https://github.com/Azure/bicep/issues/12913)
func a(____________________________________________________________________________________________ string) string => 'a'
func b(longParameterName1 string, longParameterName2 string, longParameterName3 string, longParameterName4 string) string => 'b'

func buildUrlMultiLine(
https bool,
hostname string,
path string
) string => '${https ? 'https' : 'http'}:https://${hostname}${empty(path) ? '' : '/${path}'}'
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,13 @@ func test2() string => loadTextContent('./repro-data.json')
func test3() object => loadYamlContent('./repro-data.json')
func test4() string => loadFileAsBase64('./repro-data.json')

// validate formatter works (https://github.com/Azure/bicep/issues/12913)
func a(____________________________________________________________________________________________ string) string => 'a'
func b(longParameterName1 string, longParameterName2 string, longParameterName3 string, longParameterName4 string) string => 'b'

func buildUrlMultiLine(
https bool,
hostname string,
path string
) string => '${https ? 'https' : 'http'}:https://${hostname}${empty(path) ? '' : '/${path}'}'

Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,13 @@ func test() object => loadJsonContent('./repro-data.json')
func test2() string => loadTextContent('./repro-data.json')
func test3() object => loadYamlContent('./repro-data.json')
func test4() string => loadFileAsBase64('./repro-data.json')

// validate formatter works (https://github.com/Azure/bicep/issues/12913)
func a(____________________________________________________________________________________________ string) string => 'a'
func b(longParameterName1 string, longParameterName2 string, longParameterName3 string, longParameterName4 string) string => 'b'

func buildUrlMultiLine(
https bool,
hostname string,
path string
) string => '${https ? 'https' : 'http'}:https://${hostname}${empty(path) ? '' : '/${path}'}'
251 changes: 146 additions & 105 deletions src/Bicep.Core.Samples/Files/baselines/Functions_LF/main.ir.bicep

Large diffs are not rendered by default.

58 changes: 57 additions & 1 deletion src/Bicep.Core.Samples/Files/baselines/Functions_LF/main.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"_generator": {
"name": "bicep",
"version": "dev",
"templateHash": "12432202576544985285"
"templateHash": "2216132208843131284"
}
},
"definitions": {
Expand Down Expand Up @@ -153,6 +153,62 @@
"type": "string",
"value": "e30="
}
},
"a": {
"parameters": [
{
"type": "string",
"name": "____________________________________________________________________________________________"
}
],
"output": {
"type": "string",
"value": "a"
}
},
"b": {
"parameters": [
{
"type": "string",
"name": "longParameterName1"
},
{
"type": "string",
"name": "longParameterName2"
},
{
"type": "string",
"name": "longParameterName3"
},
{
"type": "string",
"name": "longParameterName4"
}
],
"output": {
"type": "string",
"value": "b"
}
},
"buildUrlMultiLine": {
"parameters": [
{
"type": "bool",
"name": "https"
},
{
"type": "string",
"name": "hostname"
},
{
"type": "string",
"name": "path"
}
],
"output": {
"type": "string",
"value": "[format('{0}:https://{1}{2}', if(parameters('https'), 'https', 'http'), parameters('hostname'), if(empty(parameters('path')), '', format('/{0}', parameters('path'))))]"
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,17 @@ func test() object => loadJsonContent('./repro-data.json')
func test2() string => loadTextContent('./repro-data.json')
func test3() object => loadYamlContent('./repro-data.json')
func test4() string => loadFileAsBase64('./repro-data.json')

// validate formatter works (https://github.com/Azure/bicep/issues/12913)
func a(
____________________________________________________________________________________________ string
) string => 'a'
func b(
longParameterName1 string,
longParameterName2 string,
longParameterName3 string,
longParameterName4 string
) string => 'b'

func buildUrlMultiLine(https bool, hostname string, path string) string =>
'${https ? 'https' : 'http'}:https://${hostname}${empty(path) ? '' : '/${path}'}'
Original file line number Diff line number Diff line change
Expand Up @@ -183,5 +183,71 @@ func test4() string => loadFileAsBase64('./repro-data.json')
//@ "type": "string",
//@ "value": "e30="
//@ }
//@ },

// validate formatter works (https://github.com/Azure/bicep/issues/12913)
func a(____________________________________________________________________________________________ string) string => 'a'
//@ "a": {
//@ "parameters": [
//@ {
//@ "type": "string",
//@ "name": "____________________________________________________________________________________________"
//@ }
//@ ],
//@ "output": {
//@ "type": "string",
//@ "value": "a"
//@ }
//@ },
func b(longParameterName1 string, longParameterName2 string, longParameterName3 string, longParameterName4 string) string => 'b'
//@ "b": {
//@ "parameters": [
//@ {
//@ "type": "string",
//@ "name": "longParameterName1"
//@ },
//@ {
//@ "type": "string",
//@ "name": "longParameterName2"
//@ },
//@ {
//@ "type": "string",
//@ "name": "longParameterName3"
//@ },
//@ {
//@ "type": "string",
//@ "name": "longParameterName4"
//@ }
//@ ],
//@ "output": {
//@ "type": "string",
//@ "value": "b"
//@ }
//@ },

func buildUrlMultiLine(
//@ "buildUrlMultiLine": {
//@ "parameters": [
//@ {
//@ "name": "https"
//@ },
//@ {
//@ "name": "hostname"
//@ },
//@ {
//@ "name": "path"
//@ }
//@ ],
//@ "output": {
//@ }
//@ }
https bool,
//@ "type": "bool",
hostname string,
//@ "type": "string",
path string
//@ "type": "string",
) string => '${https ? 'https' : 'http'}:https://${hostname}${empty(path) ? '' : '/${path}'}'
//@ "type": "string",
//@ "value": "[format('{0}:https://{1}{2}', if(parameters('https'), 'https', 'http'), parameters('hostname'), if(empty(parameters('path')), '', format('/{0}', parameters('path'))))]"

Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"_generator": {
"name": "bicep",
"version": "dev",
"templateHash": "12432202576544985285"
"templateHash": "2216132208843131284"
}
},
"definitions": {
Expand Down Expand Up @@ -153,6 +153,62 @@
"type": "string",
"value": "e30="
}
},
"a": {
"parameters": [
{
"type": "string",
"name": "____________________________________________________________________________________________"
}
],
"output": {
"type": "string",
"value": "a"
}
},
"b": {
"parameters": [
{
"type": "string",
"name": "longParameterName1"
},
{
"type": "string",
"name": "longParameterName2"
},
{
"type": "string",
"name": "longParameterName3"
},
{
"type": "string",
"name": "longParameterName4"
}
],
"output": {
"type": "string",
"value": "b"
}
},
"buildUrlMultiLine": {
"parameters": [
{
"type": "bool",
"name": "https"
},
{
"type": "string",
"name": "hostname"
},
{
"type": "string",
"name": "path"
}
],
"output": {
"type": "string",
"value": "[format('{0}:https://{1}{2}', if(parameters('https'), 'https', 'http'), parameters('hostname'), if(empty(parameters('path')), '', format('/{0}', parameters('path'))))]"
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,62 +1,83 @@
func buildUrl(https bool, hostname string, path string) string => '${https ? 'https' : 'http'}:https://${hostname}${empty(path) ? '' : '/${path}'}'
//@[14:19) Local https. Type: bool. Declaration start char: 14, length: 10
//@[26:34) Local hostname. Type: string. Declaration start char: 26, length: 15
//@[43:47) Local path. Type: string. Declaration start char: 43, length: 11
//@[05:13) Function buildUrl. Type: (bool, string, string) => string. Declaration start char: 0, length: 141
//@[14:019) Local https. Type: bool. Declaration start char: 14, length: 10
//@[26:034) Local hostname. Type: string. Declaration start char: 26, length: 15
//@[43:047) Local path. Type: string. Declaration start char: 43, length: 11
//@[05:013) Function buildUrl. Type: (bool, string, string) => string. Declaration start char: 0, length: 141

output foo string = buildUrl(true, 'google.com', 'search')
//@[07:10) Output foo. Type: string. Declaration start char: 0, length: 58
//@[07:010) Output foo. Type: string. Declaration start char: 0, length: 58

func sayHello(name string) string => 'Hi ${name}!'
//@[14:18) Local name. Type: string. Declaration start char: 14, length: 11
//@[05:13) Function sayHello. Type: string => string. Declaration start char: 0, length: 50
//@[14:018) Local name. Type: string. Declaration start char: 14, length: 11
//@[05:013) Function sayHello. Type: string => string. Declaration start char: 0, length: 50

output hellos array = map(['Evie', 'Casper'], name => sayHello(name))
//@[46:50) Local name. Type: 'Casper' | 'Evie'. Declaration start char: 46, length: 4
//@[07:13) Output hellos. Type: array. Declaration start char: 0, length: 69
//@[46:050) Local name. Type: 'Casper' | 'Evie'. Declaration start char: 46, length: 4
//@[07:013) Output hellos. Type: array. Declaration start char: 0, length: 69

func objReturnType(name string) object => {
//@[19:23) Local name. Type: string. Declaration start char: 19, length: 11
//@[05:18) Function objReturnType. Type: string => object. Declaration start char: 0, length: 68
//@[19:023) Local name. Type: string. Declaration start char: 19, length: 11
//@[05:018) Function objReturnType. Type: string => object. Declaration start char: 0, length: 68
hello: 'Hi ${name}!'
}

func arrayReturnType(name string) array => [
//@[21:25) Local name. Type: string. Declaration start char: 21, length: 11
//@[05:20) Function arrayReturnType. Type: string => [string]. Declaration start char: 0, length: 53
//@[21:025) Local name. Type: string. Declaration start char: 21, length: 11
//@[05:020) Function arrayReturnType. Type: string => [string]. Declaration start char: 0, length: 53
name
]

func asdf(name string) array => [
//@[10:14) Local name. Type: string. Declaration start char: 10, length: 11
//@[05:09) Function asdf. Type: string => ['asdf', string]. Declaration start char: 0, length: 51
//@[10:014) Local name. Type: string. Declaration start char: 10, length: 11
//@[05:009) Function asdf. Type: string => ['asdf', string]. Declaration start char: 0, length: 51
'asdf'
name
]

@minValue(0)
type positiveInt = int
//@[05:16) TypeAlias positiveInt. Type: Type<int>. Declaration start char: 0, length: 35
//@[05:016) TypeAlias positiveInt. Type: Type<int>. Declaration start char: 0, length: 35

func typedArg(input string[]) positiveInt => length(input)
//@[14:19) Local input. Type: string[]. Declaration start char: 14, length: 14
//@[05:13) Function typedArg. Type: string[] => int. Declaration start char: 0, length: 58
//@[14:019) Local input. Type: string[]. Declaration start char: 14, length: 14
//@[05:013) Function typedArg. Type: string[] => int. Declaration start char: 0, length: 58

func barTest() array => ['abc', 'def']
//@[05:12) Function barTest. Type: () => ['abc', 'def']. Declaration start char: 0, length: 38
//@[05:012) Function barTest. Type: () => ['abc', 'def']. Declaration start char: 0, length: 38
func fooTest() array => map(barTest(), a => 'Hello ${a}!')
//@[39:40) Local a. Type: any. Declaration start char: 39, length: 1
//@[05:12) Function fooTest. Type: () => string[]. Declaration start char: 0, length: 58
//@[39:040) Local a. Type: any. Declaration start char: 39, length: 1
//@[05:012) Function fooTest. Type: () => string[]. Declaration start char: 0, length: 58

output fooValue array = fooTest()
//@[07:15) Output fooValue. Type: array. Declaration start char: 0, length: 33
//@[07:015) Output fooValue. Type: array. Declaration start char: 0, length: 33

func test() object => loadJsonContent('./repro-data.json')
//@[05:09) Function test. Type: () => object. Declaration start char: 0, length: 58
//@[05:009) Function test. Type: () => object. Declaration start char: 0, length: 58
func test2() string => loadTextContent('./repro-data.json')
//@[05:10) Function test2. Type: () => '{}'. Declaration start char: 0, length: 59
//@[05:010) Function test2. Type: () => '{}'. Declaration start char: 0, length: 59
func test3() object => loadYamlContent('./repro-data.json')
//@[05:10) Function test3. Type: () => object. Declaration start char: 0, length: 59
//@[05:010) Function test3. Type: () => object. Declaration start char: 0, length: 59
func test4() string => loadFileAsBase64('./repro-data.json')
//@[05:10) Function test4. Type: () => repro-data.json. Declaration start char: 0, length: 60
//@[05:010) Function test4. Type: () => repro-data.json. Declaration start char: 0, length: 60

// validate formatter works (https://github.com/Azure/bicep/issues/12913)
func a(____________________________________________________________________________________________ string) string => 'a'
//@[07:099) Local ____________________________________________________________________________________________. Type: string. Declaration start char: 7, length: 99
//@[05:006) Function a. Type: string => 'a'. Declaration start char: 0, length: 121
func b(longParameterName1 string, longParameterName2 string, longParameterName3 string, longParameterName4 string) string => 'b'
//@[07:025) Local longParameterName1. Type: string. Declaration start char: 7, length: 25
//@[34:052) Local longParameterName2. Type: string. Declaration start char: 34, length: 25
//@[61:079) Local longParameterName3. Type: string. Declaration start char: 61, length: 25
//@[88:106) Local longParameterName4. Type: string. Declaration start char: 88, length: 25
//@[05:006) Function b. Type: (string, string, string, string) => 'b'. Declaration start char: 0, length: 128

func buildUrlMultiLine(
//@[05:022) Function buildUrlMultiLine. Type: (bool, string, string) => string. Declaration start char: 0, length: 158
https bool,
//@[02:007) Local https. Type: bool. Declaration start char: 2, length: 10
hostname string,
//@[02:010) Local hostname. Type: string. Declaration start char: 2, length: 15
path string
//@[02:006) Local path. Type: string. Declaration start char: 2, length: 11
) string => '${https ? 'https' : 'http'}:https://${hostname}${empty(path) ? '' : '/${path}'}'

Loading

0 comments on commit e321ef8

Please sign in to comment.