lambdapi icon indicating copy to clipboard operation
lambdapi copied to clipboard

Allowed characters in identifiers

Open gabrielhdt opened this issue 4 years ago • 6 comments

The following line does not typecheck:

symbol foo/bar: TYPE;

and yield the following error message

[...] The proof is not finished.

gabrielhdt avatar Jan 18 '22 23:01 gabrielhdt

Perhaps, because of the comments, we must not allow / in identifiers.

gabrielhdt avatar Jan 18 '22 23:01 gabrielhdt

It seems to me that the following does what we want

https://gist.github.com/gabrielhdt/e687e60f2eb14c14282e310f556e2230

it allows $, ? but still parses $foo as a pattern, it forbids / and allows *.

gabrielhdt avatar Jan 19 '22 00:01 gabrielhdt

The pull request #818 solves the issue

gabrielhdt avatar Jan 19 '22 00:01 gabrielhdt

The problem is that foo/bar is parsed as 3 separate identifiers foo / bar because / is not allowed in identifiers except as a single-letter identifier. I agree that the message is not nice. A way to get a better message is to ask the lexer to output an error message in case an identifier containing / (but reduced to /) is parsed.

fblanqui avatar Jan 19 '22 06:01 fblanqui

To solve this issue, I would rather suggest to do:

let separ_letter = [%sedlex.regexp? Chars " ,;.:\r\t\n(){}[]\""]
let special_letter = [%sedlex.regexp? Chars "`@/|$?"]
let forbidden_letter = [%sedlex.regexp? separ_letter | special_letter]
let allowed_letter = [%sedlex.regexp? Compl forbidden_letter]
let regid = [%sedlex.regexp? Plus allowed_letter]
let badid = [%sedlex.regexp? Plus allowed_letter, Plus (special_letter, Star allowed_letter)]
[...]
| '/' | regid -> UID(Utf8.lexeme lb)
| badid -> fail lb "Forbidden identifier"

fblanqui avatar Jan 19 '22 06:01 fblanqui

My concern is rather that the syntax of identifiers is not really clear. It seems odd to me to allow / by itself but not in anything else. IMO nobody will remember or use that, even when writing translators.

gabrielhdt avatar Jan 25 '22 01:01 gabrielhdt