Skip to content

Commit

Permalink
Fix a bug introduced by the parens fix
Browse files Browse the repository at this point in the history
  The fix for #81 ignored a case where a layout block was started by ParenL
symbol.  In that case, the layout level wouldn't be pushed on the stack, and a
parse error would eventually result.  This adds the check into the ParenL
special case, starting an explicit block terminated by a ParenR, as well as a
new virtual layout block.

  Also missing from the original patch was the full offsides check, which must
be repeated in the ParenL special case.  I think that we should probably do some
refactoring of the layout processor, as I doubt that this is the only case that
will produce this behavior.

  Additionally, the BraceL/BraceR cases were removed, as explicitly delimited
layout is not currently supported.
  • Loading branch information
elliottt committed Sep 3, 2014
1 parent 9ed8523 commit 56028ec
Showing 1 changed file with 7 additions and 10 deletions.
17 changes: 7 additions & 10 deletions src/Cryptol/Parser/LexerUtils.hs
Original file line number Diff line number Diff line change
Expand Up @@ -236,22 +236,16 @@ layout cfg ts0
-- If we find the EOF, we close all open blocks, and then we stop.
| EOF <- ty = extra ++ [ virt cfg (to pos) VCurlyR | _ <- stack ] ++ [t]

-- Left parens and braces start new explicit blocks
| Sym ParenL <- ty = t : loop False (Explicit (Sym ParenR) : stack) ts
| Sym CurlyL <- ty = t : loop False (Explicit (Sym CurlyR) : stack) ts
-- Left parens start new explicit blocks
| Sym ParenL <- ty = t : loop False (Explicit (Sym ParenR) : parensStack) ts

-- Right parens and braces close to the nearest explicit block, failing if
-- they don't properly close it
-- Right parens close to the nearest explicit block, failing if they don't
-- properly close it
| Sym ParenR <- ty
, Explicit (Sym ParenR) : ps' <- ps = [ virt cfg (to pos) VCurlyR | _ <- es ]
++ t
: loop False ps' ts

| Sym CurlyR <- ty
, Explicit (Sym CurlyR) : ps' <- ps = [ virt cfg (to pos) VCurlyR | _ <- es ]
++ t
: loop False ps' ts

-- If we see the keyword `where`, we start a new virtual block
| KW KW_where <- ty = t : virt cfg (to pos) VCurlyL
: loop True stack ts
Expand All @@ -270,6 +264,9 @@ layout cfg ts0
punc | startBlock = []
| otherwise = [virt cfg (to pos) VSemi]

parensStack | startBlock = Virtual (col (from pos)) : stack
| otherwise = stack

(es,ps) = span isVirtual stack

-- We are the first token in a new block, push our column on the stack.
Expand Down

0 comments on commit 56028ec

Please sign in to comment.