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

Parens and "Unexpected end of layout block" #81

Closed
weaversa opened this issue Aug 31, 2014 · 5 comments
Closed

Parens and "Unexpected end of layout block" #81

weaversa opened this issue Aug 31, 2014 · 5 comments
Labels
bug Something not working correctly
Milestone

Comments

@weaversa
Copy link
Collaborator

It would be nice to be able to parenthesize valid cryptol statements in the interpreter. For example, the following statements give errors
(x where x = 1) + 1 and (f where f x = x+1) 10

Main> x where x = 1
Assuming a = 1
1
Main> (x where x = 1)

Parse error at 2:1, unexpected end of layout block
Main> (x where x = 1) + 1

Parse error at 1:17, unexpected +
Main> f where f x = x+1
Assuming a = 1
<function>
Main> :t f where f x = x+1
f
where
  f x = x + 1
 : {a} (a >= 1, fin a) => [a] -> [a]
Main> f where f x = x+1 10
[warning] at <interactive>:1:1--1:21:
  Defaulting type parameter 'bits'
             of literal or demoted expression
             at <interactive>:1:19--1:21
  to 4
[warning] at <interactive>:1:1--1:21:
  Defaulting type parameter 'bits'
             of literal or demoted expression
             at <interactive>:1:17--1:18
  to 1

[error] at <interactive>:1:17--1:21:
  Type mismatch:
    Expected type: [?y20] -> ?d21
    Inferred type: [?a21]
  where
  ?y20 is type parameter 'bits'
          of literal or demoted expression
          at <interactive>:1:19--1:21
  ?a21 is type parameter 'bits'
          of literal or demoted expression
          at <interactive>:1:17--1:18
  ?d21 is 1st type parameter
          of expression (+)
          at <interactive>:1:16--1:17
Main> (f where f x = x+1) 10
Parse error at 1:21, unexpected 10
acfoltzer added a commit that referenced this issue Sep 2, 2014
@acfoltzer
Copy link
Contributor

Confirmed that this doesn't only occur in the interpreter, but also if you have such expressions in files. It only seems to arise with where clauses, so something funky must be going on in the layout-handling code. For example (\x -> x + 1) 10 works fine.

Added a test case for this in 17ee75e.

@elliottt
Copy link
Contributor

elliottt commented Sep 3, 2014

The layout processor didn't account for layout blocks that were terminated by parens or braces, so this accounts for that in the context stack that is kept by the layout processor.

@brianhuffman
Copy link
Contributor

@elliottt Changeset 3487737 broke one of the regression tests, involving AES.cry. The parser now does the wrong thing if the first token after where is an open parenthesis. For example:

Cryptol> x + y where [x,y] = [3:[8], 4:[8]]
7
Cryptol> x + y where (x,y) = (3:[8], 4:[8])

Parse error at 2:1, unexpected end of input

@brianhuffman brianhuffman reopened this Sep 3, 2014
elliottt added a commit that referenced this issue Sep 3, 2014
  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.
@elliottt
Copy link
Contributor

elliottt commented Sep 3, 2014

I've fixed the AES regression, but there was another test (regression/r03.icry) that was failing for seemingly unrelated reasons. @brianhuffman, let me know if you notice anything else, otherwise I'll hopefully close this one :)

elliottt added a commit that referenced this issue Sep 3, 2014
  Accidentally didn't commit some additional changes.  This is the other half of
56028ec.
@brianhuffman
Copy link
Contributor

@elliottt Everything looks good to me now: no failed regressions, and back down to 4 failing issue tests. In particular, regression/r03.icry works for me; maybe something there is dependent on which version of cvc4 you have?

@acfoltzer acfoltzer added the bug Something not working correctly label Oct 16, 2014
@acfoltzer acfoltzer added this to the Cryptol 2.1 milestone Oct 16, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something not working correctly
Projects
None yet
Development

No branches or pull requests

4 participants