From: Nathaniel Wesley Filardo Date: Thu, 16 May 2013 22:28:01 +0000 (-0400) Subject: Add "for" as another spelling of "whenever" X-Git-Url: https://hydra-www.ietfng.org/gitweb/?a=commitdiff_plain;h=e902849c52557322e5ebb0c98e9e69c3f81db37f;p=dyna2 Add "for" as another spelling of "whenever" --- diff --git a/docs/TODO.LSA b/docs/TODO.LSA index 208d080..b5936aa 100644 --- a/docs/TODO.LSA +++ b/docs/TODO.LSA @@ -9,8 +9,6 @@ Utilities for encoding plain-text files to .dyna files. Parse QMode pragmas -s/whenever/for/ in surface language - List notation ----- Frontend diff --git a/examples/papa2.dyna b/examples/papa2.dyna index ba13f92..34f383f 100644 --- a/examples/papa2.dyna +++ b/examples/papa2.dyna @@ -8,8 +8,8 @@ goal(P) max= phrase("S", 0, *length, P). best max= pair(phrase("S", 0, *length, P), P). -bestScore max= pair(Score,_) is best, Score. -bestParse max= pair(_,P) is best, P. +bestScore max= Score for pair(Score,_) is best. +bestParse max= P for pair(_,P) is best. length max= word(_, I), I+1. diff --git a/src/Dyna/Analysis/ANF.hs b/src/Dyna/Analysis/ANF.hs index 42fb6da..7ad472f 100644 --- a/src/Dyna/Analysis/ANF.hs +++ b/src/Dyna/Analysis/ANF.hs @@ -325,12 +325,14 @@ normTerm_ c ss (P.TFunctor "is" [x T.:~ sx, v T.:~ sv]) = do _ -> do NTVar `fmap` newAssign "_i" (Right ("is",[nx,nv])) --- ",/2" and "whenever/2" are also reserved words of the language and get --- handled here. +-- ",/2", "whenever/2", and "for/2" are also reserved words of the language +-- and get handled here. -- -- XXX This is wrong, too, of course; these should really be moved into a -- standard prelude. But there's no facility for that right now and no -- reason to make the backend know about them since that's also wrong! +-- +-- XXX XREF:ANFRESERVED normTerm_ (_,ADEval) ss (P.TFunctor "," [i T.:~ si, r T.:~ sr]) = do ni <- normTerm_ (ECFunctor, ADEval) (si:ss) i >>= newAssign "_e" . Left nv <- normTerm_ (ECFunctor, ADEval) (sr:ss) r >>= newAssign "_e" . Left @@ -342,6 +344,9 @@ normTerm_ (_,ADEval) ss (P.TFunctor "," [i T.:~ si, r T.:~ sr]) = do normTerm_ c@(_,ADEval) ss (P.TFunctor "whenever" [sr, si]) = normTerm_ c ss (P.TFunctor "," [si,sr]) +normTerm_ c@(_,ADEval) ss (P.TFunctor "for" [sr, si]) = + normTerm_ c ss (P.TFunctor "," [si,sr]) + -- Functors have both top-down and bottom-up dispositions on -- their handling. normTerm_ c ss (P.TFunctor f as) = do diff --git a/src/Dyna/ParserHS/Parser.hs b/src/Dyna/ParserHS/Parser.hs index 94607b1..8bc4f42 100644 --- a/src/Dyna/ParserHS/Parser.hs +++ b/src/Dyna/ParserHS/Parser.hs @@ -13,7 +13,9 @@ -- -- * Doesn't handle parenthesized aggregators -- --- * Doesn't handle shared subgoals (\"whenever ... { ... }\") +-- * Doesn't handle shared subgoals (\"for ... { ... }\") +-- (Fixing that probably means changing our idea of 'Rule'; +-- also revisit XREF:ANFRESERVED if doing so.) -- -- * Doesn't understand nullary star for gensym correctly -- (it's a available in term context but not texpr context; @@ -203,7 +205,7 @@ defPCS = PCS { _pcs_dispostab = defDisposTab -- The basic expression table for limited expressions. -- -- Notably, this excludes @,@ (which is important - -- syntactically) and @whenever@ and @is@ (which are + -- syntactically), @for@, @whenever@, and @is@ (which are -- nonsensical in local context) -- XXX right now all binops are at equal precedence and -- left-associative; that's wrong. @@ -308,7 +310,7 @@ dynaAtomStyle = IdentifierStyle { _styleName = "Atom" , _styleStart = (lower <|> oneOf "$") , _styleLetter = (alphaNum <|> oneOf "_'") - , _styleReserved = H.fromList [ "is", "new", "whenever" ] -- XXX maybe not? + , _styleReserved = H.fromList [ "for", "is", "new", "whenever" ] -- XXX maybe not? , _styleHighlight = Constant , _styleReservedHighlight = ReservedOperator } @@ -414,7 +416,8 @@ tlexpr = view pcs_opertab >>= flip buildExpressionParser term . unEOT moreETable :: DeltaParsing m => [[Operator m (Spanned Term)]] moreETable = [ [ Infix (bf (spanned $ bsf $ symbol "is" )) AssocNone ] , [ Infix (bf (spanned $ bsf $ symbol "," )) AssocRight ] - , [ Infix (bf (spanned $ bsf $ symbol "whenever")) AssocNone ] + , [ Infix (bf (spanned $ bsf $ symbol "whenever")) AssocNone + , Infix (bf (spanned $ bsf $ symbol "for" )) AssocNone ] ] -- | Full Expression