Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
GHC
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Terraform modules
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Reinier Maas
GHC
Commits
afca46a4
Commit
afca46a4
authored
1 year ago
by
Sebastian Graf
Committed by
Marge Bot
1 year ago
Browse files
Options
Downloads
Patches
Plain Diff
Parser: Add a Note detailing why we need happy's `error` to implement layout
parent
13503451
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
compiler/GHC/Parser.y
+32
-1
32 additions, 1 deletion
compiler/GHC/Parser.y
with
32 additions
and
1 deletion
compiler/GHC/Parser.y
+
32
−
1
View file @
afca46a4
...
...
@@ -3943,9 +3943,40 @@ literal :: { Located (HsLit GhcPs) }
-----------------------------------------------------------------------------
-- Layout
{- Note [Layout and error]
~~~~~~~~~~~~~~~~~~~~~~~~~~
The Haskell 2010 report (Section 10.3, Note 5) dictates the use of the error
token in `close`. To recall why that is necessary, consider
f x = case x of
True -> False
where y = x+1
The virtual pass L inserts vocurly, semi, vccurly to return a laid-out
token stream. It must insert a vccurly before `where` to close the layout
block introduced by `of`.
But there is no good way to do so other than L becoming aware of the grammar!
Thus, L is specified to detect the ensuing parse error (implemented via
happy's `error` token) and then insert the vccurly.
Thus in effect, L is distributed between Lexer.x and Parser.y.
There are a bunch of other, less "tricky" examples:
let x = x {- vccurly -} in x -- could just track bracketing of
-- let..in on layout stack to fix
(case x of
True -> False {- vccurly -}) -- ditto for surrounding delimiters such as ()
data T = T;{- vccurly -} -- Need insert vccurly at EOF
Many of these are not that hard to fix, but still tedious and prone to break
when the grammar changes; but the `of`/`where` example is especially gnarly,
because it demonstrates a grammatical interaction between two lexically
unrelated tokens.
-}
close :: { () }
: vccurly { () } -- context popped in lexer.
| error {% popContext }
| error {% popContext }
-- See Note [Layout and error]
-----------------------------------------------------------------------------
-- Miscellaneous (mostly renamings)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment