gruebel/pycep

Handle variable names matching built-in functions

Closed this issue · 3 comments

If you should happen to match a (ANY!) built-in function with your variable or parameter naming, parsing errors can arise. Example:

param environment string = 'something'
var match = environment == 'something' ? true : false

Yields:

2022-06-07 14:50:42,341 [MainThread  ] [ERROR]  [bicep] Couldn't parse function-names-test.bicep                                                                                                                                            
Traceback (most recent call last):                                                                                                                                                                                                          
  File "/home/user/.local/lib/python3.10/site-packages/lark/lexer.py", line 528, in lex                                                                                                                                                 
    yield lexer.next_token(lexer_state, parser_state)      
  File "/home/user/.local/lib/python3.10/site-packages/lark/lexer.py", line 466, in next_token                    
    raise UnexpectedCharacters(lex_state.text, line_ctr.char_pos, line_ctr.line, line_ctr.column,
lark.exceptions.UnexpectedCharacters: No terminal matches '=' in the current parser context, at line 2 col 25      
                                                           
var match = environment == 'something' ? true : false                                                                  
                       ^                                   
Expected one of:                                                                                                      
        * LPAR                                             
                                                                                                                      
Previous tokens: Token('ENVIRONMENT', 'environment')

BTW: it appears that not even words like "if" are reserved from using as variable names!!! They're not making it easy for you 😃

hey @johannesclaesson sorry for my late answer. yeah, I really was not happy that they decided to support shadowing of their built in functions. I can definitely try to support a couple of them, but for sure not everything, too ridiculous for my taste 😄 do you have any specific ones, which I should work on?

Thanks! Think you've covered the worst pitfalls. "environment", "subscription", "min", "max", "length" are likely those that people tend to use without thinking.

ok, great. Closing it for now, if you come up with some others, just open a new issue. Will create a new release this weekend.