Not possible to use language keywords as field names in tuple
Acton Version
0.15.3
Steps to Reproduce
I'm trying to create a tuple with named fields:
def foo():
return (type="tcp", actor=1234)
actor main(env):
pass
which doesn't work because actor is a keyword, I guess?
Expected Behavior
A tuple with a field named "actor".
Actual Behavior
kll@Boxy:~/terastream/acton$ dist/bin/actonc examples/tu.act --cgen
Building file examples/tu.act
ERROR: Error when compiling tu module: Syntax error
examples/tu.act:3:25:
|
3 | return (type="tcp", actor=1234)
| ^
unexpected 'a'
expecting "**" or a closing parenthesis
Here's where our optional quotes around tuple field names come in handy. Write (type="tcp", 'actor'=1234) and the parser will be happy!
But can't language keywords be context sensitive or is that a really bad idea?
Context-sensitive keywords complicate parsing and is therefore generally considered a bad idea. But one can alwas make exceptions on a point-to-point basis if the gains are clear.
The quoting doesn't work in type signatures
def foo() -> ("type", "actor"):
return ("type"="tcp", "actor"=1234)
actor main(env):
env.exit(0)
ERROR: Error when compiling 'tuple-keywords' module: Syntax error
test/core_lang_auto/tuple-keywords.act:2:15:
|
2 | def foo() -> ("type", "actor"):
| ^
unexpected '"'
expecting "**", "None", "Self", "action", "mut", "proc", "pure", '(', '*', '?', '[', '_', '{', a closing parenthesis, comma, or identifier