brimdata / zed

A novel data lake based on super-structured data
https://zed.brimdata.io/
BSD 3-Clause "New" or "Revised" License
1.34k stars 67 forks source link

possible parser error if user-defined op or func starts with an internal operator name #5160

Closed chrismo closed 2 days ago

chrismo commented 2 days ago

v1.16.0

❯ zq -z 'func headfunc(): ( 1 ) headfunc()'  
zq: could not invoke zq with a single argument because:
 - a file could not be found with the name "func headfunc(): ( 1..."
 - the argument could not be compiled as a valid Zed query:
   error parsing Zed at line 1, column 28:
   func headfunc(): ( 1 ) headfunc()
                          === ^ ===

❯ zq -z 'func _headfunc(): ( 1 ) _headfunc()' 
1
❯ echo '{}' | zq -z 'op headop(): ( pass ) headop()' - 
zq: error parsing Zed at line 1, column 27:
op headop(): ( pass ) headop()
                      === ^ ===

❯ echo '{}' | zq -z 'op _headop(): ( pass ) _headop()' -
{}

It seems the parser isn't grabbing the entire name of the user-defined op as one thing.

mattnibs commented 2 days ago

Good catch. Did some digging this is caused by the parser getting tripped up when parsing operators that can have zero arguments:

(There are already guards for this for fuse and shape)

philrz commented 2 days ago

Verified in Zed commit f497079.

Repeating the user's original program, it now parses and produces the expected result regardless of its name.

$ zq -version
Version: v1.16.0-6-gf4970799

$ zq -z 'func headfunc(): ( 1 ) headfunc()'
1

Thanks @mattnibs!