gren-lang / gren-lang/compiler-common
A top-level declaration is accepted at any column; the Haskell-based compiler requires column 1
Nobody has claimed this yet.
- Dominant language
- No language data
- Stars
- 1
- Forks
- 1
- PR merge metrics
- No merged PRs in 30d
Description
Summary
Once a top-level declaration's body has ended, the new parser will accept the
next declaration's head starting at any column. The Haskell-based compiler
requires every top-level declaration to begin in column 1 and reports an error
otherwise.
On its own this is only a permissiveness difference between the two parsers.
But, combined with #14 it is worse than that.
#14 ends a body early at a stray same-column row, and the missing column
check then hands that row to the declaration parser, which reads it as the head
of a new declaration. The result is a file that parses successfully into a
different program from the one the Haskell-based compiler reads. So, this is related to #14,
but separate.
Reproduction
src/M.gren:
module M exposing (a, b)
one : Int
one =
1
a =
one
b =
2
b is a top-level declaration starting in column 9.
The new parser accepts it
gren-format --show M.gren exits 0, and normalizes both declarations to
column 1 — so the parser did read b as a declaration of its own, not as
part of a:
module M exposing (a, b)
one : Int
one =
1
a =
one
b =
2
The Haskell-based compiler (gren 0.6.6) rejects it
-- UNEXPECTED EQUALS ------------------------------------------------ src/M.gren
I was not expecting to see this equals sign:
13| b =
^
Maybe you want == instead? To check if two values are equal?
Note: I may be getting confused by your indentation. I think I am still parsing
the `a` definition. Is this supposed to be part of a definition after that? If
so, the problem may be a bit before the equals sign. I need all definitions to
be indented exactly the same amount, so the problem may be that this new
definition has too many spaces in front of it.
The same holds for the first declaration in a module: indent it and the
Haskell compiler stops with SYNTAX PROBLEM ... Note: This can also happen when something is indented too much!.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the src/M.gren reproduction and run gren-format --show M.gren, then compare its result with the Haskell-based compiler's rejection. Trace the declaration parser's handling of top-level column positions and add a regression test for an indented first or subsequent declaration. Done means declarations not starting in column 1 are rejected consistently.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- haskell
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 68/100