Update the parser to allow prefix operators in more places.

This allows us to define (~) as a prefix operator symbol synonym
for `complement`.

Fixes #296.
This commit is contained in:
Robert Dockins 2016-05-04 16:26:36 -07:00
parent 59cfe03e54
commit c620cbf237
8 changed files with 20 additions and 9 deletions

View File

@ -94,10 +94,16 @@ primitive False : Bit
primitive negate : {a} (Arith a) => a -> a
/**
* Binary complement
* Binary complement.
*/
primitive complement : {a} a -> a
/**
* Operator form of binary complement.
*/
(~) : {a} a -> a
(~) = complement
/**
* Less-than. Only works on comparable arguments.
*/

View File

@ -267,7 +267,8 @@ mbDoc :: { Maybe (Located String) }
decl :: { Decl PName }
: vars_comma ':' schema { at (head $1,$3) $ DSignature (reverse $1) $3 }
| ipat '=' expr { at ($1,$3) $ DPatBind $1 $3 }
| name apats '=' expr { at ($1,$4) $
| '(' op ')' '=' expr { at ($1,$5) $ DPatBind (PVar $2) $5 }
| var apats '=' expr { at ($1,$4) $
DBind $ Bind { bName = $1
, bParams = reverse $2
, bDef = at $4 (Located emptyRange (DExpr $4))

View File

@ -5,12 +5,12 @@ Loading module Main
Defaulting type parameter 'bits'
of literal or demoted expression
at ./issue148.cry:4:34--4:35
to max 2 (width a`193)
to max 2 (width a`195)
[warning] at ./issue148.cry:2:1--9:10:
Defaulting 2nd type parameter
of expression take
at ./issue148.cry:6:10--6:14
to 16 * a`193
to 16 * a`195
[warning] at <interactive>:1:1--1:36:
Defaulting type parameter 'bits'
of finite enumeration

View File

@ -5,15 +5,15 @@ Loading module Main
Defaulting type parameter 'bits'
of literal or demoted expression
at ./simon.cry2:87:34--87:35
to max 3 (width a`569)
to max 3 (width a`571)
[warning] at ./simon.cry2:83:1--92:15:
Defaulting type parameter 'bits'
of literal or demoted expression
at ./simon.cry2:90:29--90:31
to width a`571
to width a`573
[warning] at ./simon.cry2:83:1--92:15:
Defaulting type parameter 'bits'
of literal or demoted expression
at ./simon.cry2:89:36--89:38
to max 6 (max (width a`569) (width (a`570 - 1)))
to max 6 (max (width a`571) (width (a`572 - 1)))
True

View File

@ -5,9 +5,9 @@ Loading module Main
Defaulting type parameter 'bits'
of finite enumeration
at ./issue214.cry:2:14--2:26
to max 2 (width (2 * a`193 - 2))
to max 2 (width (2 * a`195 - 2))
[warning] at ./issue214.cry:2:1--2:49:
Defaulting type parameter 'bits'
of finite enumeration
at ./issue214.cry:2:36--2:48
to max 2 (width (2 * a`193 - 1))
to max 2 (width (2 * a`195 - 1))

View File

@ -86,4 +86,5 @@ Symbols
bits >= width len) => [len]elem -> [bits]
zero : {a} a
(||) : {a} a -> a -> a
(~) : {a} a -> a

View File

@ -0,0 +1 @@
:t (~)

View File

@ -0,0 +1,2 @@
Loading module Cryptol
(~) : {a} a -> a