Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gawk built-in functions shadowing #70

Open
xonixx opened this issue Jul 5, 2021 · 0 comments
Open

Gawk built-in functions shadowing #70

xonixx opened this issue Jul 5, 2021 · 0 comments
Assignees

Comments

@xonixx
Copy link
Owner

xonixx commented Jul 5, 2021

Relates to #69

Understand what to do:

$ ./soft/gawk51 'function foo(gsub) { print gsub } BEGIN { foo(123) }'
gawk51: cmd. line:1: function foo(gsub) { print gsub } BEGIN { foo(123) }
gawk51: cmd. line:1:              ^ syntax error
gawk51: cmd. line:1: function foo(gsub) { print gsub } BEGIN { foo(123) }
gawk51: cmd. line:1:                                 ^ syntax error

 $ ./soft/gawk51 'function foo(gensub) { print gensub } BEGIN { foo(123) }'
123

$ awk 'function foo(gensub) { print gensub } BEGIN { foo(123) }'
awk: cmd. line:1: function foo(gensub) { print gensub } BEGIN { foo(123) }
awk: cmd. line:1:              ^ syntax error
awk: cmd. line:1: function foo(gensub) { print gensub } BEGIN { foo(123) }
awk: cmd. line:1:                                     ^ syntax error

$ awk --version
GNU Awk 4.1.3, API: 1.1 (GNU MPFR 3.1.4, GNU MP 6.1.0)

$ ./soft/gawk51 --posix 'BEGIN { and = 123; print and }'
123

 $ ./soft/gawk51 'BEGIN { and = 123; print and }'
gawk51: cmd. line:1: BEGIN { and = 123; print and }
gawk51: cmd. line:1:             ^ syntax error
gawk51: cmd. line:1: BEGIN { and = 123; print and }
gawk51: cmd. line:1:                              ^ syntax error

$ ./soft/bwk 'BEGIN { and = 123; print and }'
123

$ ./soft/gawk51 'BEGIN { gensub = 123; print gensub }'
gawk51: cmd. line:1: BEGIN { gensub = 123; print gensub }
gawk51: cmd. line:1:                ^ syntax error
gawk51: cmd. line:1: BEGIN { gensub = 123; print gensub }
gawk51: cmd. line:1:                                    ^ syntax error

$ ./soft/gawk51 '@namespace "a" ; BEGIN { gensub = 123; print gensub }'
123

$ ./soft/gawk51 '@namespace "a" ; BEGIN { gsub = 123; print gsub }'
gawk51: cmd. line:1: @namespace "a" ; BEGIN { gsub = 123; print gsub }
gawk51: cmd. line:1:                               ^ syntax error
gawk51: cmd. line:1: @namespace "a" ; BEGIN { gsub = 123; print gsub }
gawk51: cmd. line:1:                                                 ^ syntax error

Parsing rules change depending on namespace:

$ ./soft/gawk51 'BEGIN { print mktime ("2021 01 01 01 01 01") }'
1609455661

$ ./soft/gawk51 '@namespace "a"; BEGIN { print mktime ("2021 01 01 01 01 01") }'
2021 01 01 01 01 01

$ ./soft/gawk51 '@namespace "awk"; BEGIN { print mktime ("2021 01 01 01 01 01") }'
1609455661

It's clear why this is done for Gawk - to not break the old scripts intended to work on Posix Awk. But how can we handle this better? In the naive approach we'll just fail to parse function f(and) {} because and is a Gawk bitwise function.

Relevant doc https://www.gnu.org/software/gawk/manual/html_node/Naming-Rules.html

@xonixx xonixx self-assigned this Jul 5, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant