richardhundt / shine

A Shiny Lua Dialect
Other
231 stars 18 forks source link

Identifier starting with '!' is definable but unusable #68

Closed leonidborisenko closed 9 years ago

leonidborisenko commented 9 years ago
--- example1.shn
!var = "shine"
$ shinec -o example1.shn
;TvmJIT opcode tree:

(!line "@example1.shn" 1)(!define __magic__ (!index (!call1 require "core") "__magic__"))(!call (!index _G "module") !vararg (!index __magic__ "environ"))
(!line 1) (!define (!var) (!nil))(!massign (!var) ("shine"))

--- example2.shn
!var = "shine"
print(!var)
$ shinec -o example2.shn
Error: [string "shine.lang.translator"]:0: shine: example2.shn:2: "var" used but not defined

stack traceback:
    [C]: in function 'error'
    [string "shine.lang.translator"]: in function 'abort'
    [string "shine.lang.translator"]: in function 'close'
    [string "shine.lang.translator"]: in function 'translate'
    [string "shinec"]: in main chunk

! and ? in identifiers are very useful for Ruby-style accessors/methods naming: empty?, sort!. But, maybe, starting ! and ? should be forbidden in identifiers?

richardhundt commented 9 years ago

I agree that ! as a first character doesn't work. However, I like the idea of having ? as a prefix too. For example if you were to create nilable predicates then you could name it ?String which would assert that it's either nil or a string. This is different to the "questioning" style in which it is used in the postfix position.

So I guess I should tighten up the parser for ! as prefix.

richardhundt commented 9 years ago

Done.

leonidborisenko commented 9 years ago

Thanks. Also README.md now contains outdated information about valid identifiers.