gruebel / pycep

A Python based Bicep parser
Apache License 2.0
10 stars 7 forks source link

0.4.2 failing to parse variable interpolation in mutli line string #230

Open tin-ot opened 1 month ago

tin-ot commented 1 month ago

Hello,

I am currently just trying to look into the project,

It seems that there is issues to parse bicep files with multi line strings

resource name 'Microsoft.Insights/scheduledQueryRules@2023-03-15-preview' = {

.....

    {
      query: format(
        '''l

lark.exceptions.UnexpectedCharacters: No terminal matches ''' in the current parser context, at line 35 col 13

        '''

       ( I guess the failing character might be any of the character inside to querry for metrics )
gruebel commented 1 month ago

hey @tin-ot thanks for reaching out.

Did you try the preview releases? You can find them on pypi. If it works, then great. If not, then please provide a complete example, enough to reproduce it.

tin-ot commented 1 week ago

1) Indeed I started by trying the latest Pypi version Ans it is failing as well

2) The issue is not a specific character more the interpolation in the multiline that is failing to be parsed

here are the version

pip freeze | grep pycep pycep==1.0.4 pycep-parser==0.4.2

Here are steps to reproduce :

created bicep file will a structure of a Microsoft.Insights/scheduledQueryRules

Then :

Multi line query OK

resource myalert 'Microsoft.Insights/scheduledQueryRules@2023-03-15-preview' = {
......
      allOf: [
        {
          query: '''AzureDiagnostics
          my multiline
          query without any variable
          '''
       .....

Multi line query NOK

resource myalert  'Microsoft.Insights/scheduledQueryRules@2023-03-15-preview' = {
......
      allOf: [
        {
          query: format(
          '''AzureDiagnostics
          my multilin
          query with {0} ''', myvariable
         )

       .....

Hope this help !

By the way I don't if it is supposed to be supported but looks like this function : cidrSubnet( ) https://learn.microsoft.com/en-us/azure/azure-resource-manager/bicep/bicep-functions-cidr#cidrsubnet is breaking parser as well