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

Lexer deficiencies with numbers #2177

Open
sauclovian-g opened this issue Jan 14, 2025 · 1 comment
Open

Lexer deficiencies with numbers #2177

sauclovian-g opened this issue Jan 14, 2025 · 1 comment
Assignees
Labels
topics: error-handling Issues involving the way SAW responds to an error condition type: bug Issues reporting bugs or unexpected/unwanted behavior usability An issue that impedes efficient understanding and use
Milestone

Comments

@sauclovian-g
Copy link
Contributor

This does not strike me as user-friendly behavior:

sawscript> :t 0b1
Int
sawscript> :t 0b2

Type errors:
  <stdin>:1:1-1:2: Type mismatch.
    Term is not a function. (Maybe a function is applied to too many arguments?)
    <stdin>:1:1-1:2: The type t.0 -> t.1 arises from the context of the term
    <stdin>:1:1-1:2: The type Int arises from the type of this term
    
    Expected: t.0 -> t.1
    Found:    Int
    
    within "_" (<stdin>:1:1-1:4)

  <stdin>:1:2-1:4: Unbound variable: "b2" (<stdin>:1:2-1:4)
Note that some built-in commands are available only after running
either `enable_deprecated` or `enable_experimental`.

Observe that it treats 0b2 as 0 followed by the identifier b2 rather than as a malformed binary constant. Similar things happen with 0xg and 0o8.

I think it would be better to match [digit]alnum* as number first and then reject malformed ones, as that's what people generally expect in this day and age.

@sauclovian-g sauclovian-g added type: bug Issues reporting bugs or unexpected/unwanted behavior usability An issue that impedes efficient understanding and use topics: error-handling Issues involving the way SAW responds to an error condition labels Jan 14, 2025
@sauclovian-g sauclovian-g added this to the 2025T1 milestone Jan 14, 2025
@sauclovian-g sauclovian-g self-assigned this Jan 14, 2025
@sauclovian-g
Copy link
Contributor Author

On a similar front, string constants with malformed contents are dropped by the lexer, resulting in a confusing error message:

sawscript> return "abc\tdef"
[03:05:18.731] "abc\tdef"
sawscript> return "abc\qdef"
Parse error at <stdin>:1:8-1:9: Unexpected `"'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topics: error-handling Issues involving the way SAW responds to an error condition type: bug Issues reporting bugs or unexpected/unwanted behavior usability An issue that impedes efficient understanding and use
Projects
None yet
Development

No branches or pull requests

1 participant