gren-lang / gren-lang/compiler-common

Parser misparses postfix record access after parens, record literals, record updates, and qualified variables

Open
#27 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
No language data
Stars
1
Forks
1
PR merge metrics
No merged PRs in 30d

Description

Summary

The expression parser only recognizes a postfix .field access chain after a
plain lowercase variable (record.field). After every other kind of term that
can legally take a field access, the .field is instead parsed as a separate
accessor function term, turning the whole expression into a function
application
:

Source Parsed as Should be
(f x).field Call (Parens (f x)) [Accessor .field] Access (Parens (f x)) "field"
{ a = 1 }.a Call (Record …) [Accessor .a] Access (Record …) "a"
{ r | a = 1 }.a Call (Update …) [Accessor .a] Access (Update …) "a"
Config.default.timeout Call (VarQual Config.default) [Accessor .timeout] Access (VarQual Config.default) "timeout"

The reference compiler (the Haskell gren binary) parses all four as field
access, and treats them differently from the space-separated forms
((f x) .field is an application of the accessor function). With this
parser, both spellings collapse into the same (application) AST, so the
distinction between two different programs is lost at parse time.

Reproduction

  1. Save as Repro.gren:

    module Repro exposing (..)
    
    
    a r =
        (get r).field
    
    
    b =
        { x = 1 }.x
    
    
    c r =
        { r | x = 1 }.x
    
    
    d =
        Config.default.timeout
    
  2. Inspect the parse (e.g. gren format --pre-ast Repro.gren). Every body is
    {"type": "call", ..., "args": [..., {"type": "accessor", ...}]} where it
    should be {"type": "access", ...}.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the expression parser and reproduce the issue using the Repro.gren example and gren format --pre-ast Repro.gren. Compare the four postfix-access cases with the spaced forms, using the reference AST shapes in the issue. Done means each no-space form is parsed as field access while the space-separated accessor remains a function application.

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
Quiet
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.