Skip to content
Browse files

Better DSL definition syntax

  • Loading branch information...
1 parent 4989b2a commit c82f06bdbd69db7e8464da5f09f8446397788b83 Edwin Brady committed Jul 5, 2011
Showing with 23 additions and 2 deletions.
  1. +23 −2 Idris/Parser.y
View
25 Idris/Parser.y
@@ -211,6 +211,11 @@ Declaration: Function { $1 }
| Namespace '{' Program '}' { PNamespace $1 $3 }
| Transform { RealDecl $1 }
| syntax Name NamesS '=' Term ';' { RealDecl (SynDef $2 $3 $5) }
+ | dsl Name File Line '{' Overloads '}'
+ { let (b,r,p,a,v,l) = $6 in
+ RealDecl (SynDef $2 [UN "x"]
+ (RDSLdef b r p a v l (RVar $3 $4 (UN "x") Unknown)))
+ }
| hide Name File Line ';'
{ RealDecl (SynDef $2 [] (RVar $3 $4 (mkhidden $2) Unknown)) }
| cinclude string { RealDecl (CInclude $2) }
@@ -590,8 +595,24 @@ DSLBlock : dsl '(' Overloads ')' NoAppTerm
RDSLdef b r p a v l $5 }
Overloads :: { (Maybe Id, Maybe Id, Maybe Id, Maybe Id, Maybe Id, Maybe Id) }
-Overloads : Name ',' Name { (Just $1, Just $3, Nothing, Nothing, Nothing, Nothing) }
- | Name ',' Name ',' Name ',' Name { (Just $1, Just $3, Nothing, Nothing, Just $5, Just $7) }
+Overloads -- : Name ',' Name { (Just $1, Just $3, Nothing, Nothing, Nothing, Nothing) }
+ -- | Name ',' Name ',' Name ',' Name { (Just $1, Just $3, Nothing, Nothing, Just $5, Just $7) }
+ : OList { (lookup (UN "bind") $1,
+ lookup (UN "return") $1,
+ lookup (UN "pure") $1,
+ lookup (UN "apply") $1,
+ lookup (UN "variable") $1,
+ lookup (UN "lambda") $1) }
+
+OList :: { [(Id, Id)] }
+OList : Obind { [$1] }
+ | Obind ',' OList { $1:$3 }
+ | Obind ';' OList { $1:$3 }
+ | Obind OList { $1:$2 }
+
+Obind :: { (Id, Id) }
+Obind : Name '=' Name { ($1, $3) }
+ | return '=' Name { (UN "return", $3) }
DoBlock :: { [Do] }
DoBlock : do '{' DoBindings '}' { $3 }

0 comments on commit c82f06b

Please sign in to comment.
Something went wrong with that request. Please try again.