acton icon indicating copy to clipboard operation
acton copied to clipboard

Not possible to use language keywords as field names in tuple

Open plajjan opened this issue 2 years ago • 4 comments

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

plajjan avatar Jul 02 '23 21:07 plajjan

Here's where our optional quotes around tuple field names come in handy. Write (type="tcp", 'actor'=1234) and the parser will be happy!

nordlander avatar Aug 16 '23 08:08 nordlander

But can't language keywords be context sensitive or is that a really bad idea?

plajjan avatar Aug 16 '23 09:08 plajjan

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.

nordlander avatar Aug 16 '23 09:08 nordlander

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

plajjan avatar Aug 25 '23 12:08 plajjan