BNFC-meta 0.4.0.2 → 0.4.0.3
raw patch · 3 files changed
+12/−31 lines, 3 filesdep ~template-haskell
Dependency ranges changed: template-haskell
Files
- BNFC-meta.cabal +2/−2
- Language/LBNF/CFtoHappy.hs +4/−27
- Language/LBNF/Runtime.hs +6/−2
BNFC-meta.cabal view
@@ -1,5 +1,5 @@ Name: BNFC-meta-version: 0.4.0.2+version: 0.4.0.3 cabal-Version: >= 1.6 build-type: Simple license: GPL-2@@ -41,7 +41,7 @@ Build-Depends: base>=4.2&&<5 , array>=0.4&&<0.6- , template-haskell >=2.4&&<2.10+ , template-haskell >=2.4&&<2.11 , haskell-src-meta >= 0.5 && < 1.0 , happy-meta >= 0.2.0.4 && < 0.3 , alex-meta >= 0.3.0.5 && < 0.4
Language/LBNF/CFtoHappy.hs view
@@ -109,8 +109,6 @@ prTokens tk oneTok t k = "PT _ (TS _ " ++ show k ++ ")" --- Happy doesn't allow characters such as åäö to occur in the happy file. This--- is however not a restriction, just a naming paradigm in the happy source file. convert :: String -> String convert "\\" = concat ['\'':"\\\\","\'"] convert xs = concat ['\'':(escape xs),"\'"]@@ -122,11 +120,7 @@ rulesForHappy cf = map mkOne $ ruleGroups cf where mkOne (cat,rules) = constructRule cf rules cat --- For every non-terminal, we construct a set of rules. A rule is a sequence of--- terminals and non-terminals, and an action to be performed--- As an optimization, a pair of list rules [C] ::= "" | C k [C]--- is left-recursivized into [C] ::= "" | [C] C k.--- This could be generalized to cover other forms of list rules.+ constructRule :: CF -> [Rule] -> NonTerminal -> (NonTerminal,[(Rule,Pattern,Action)]) constructRule cf rules nt = (nt,[(r,p,generateAction nt (revF b r) m) | r0 <- rules,@@ -140,9 +134,7 @@ underscore f | isDefinedRule f = f ++ "_" | otherwise = f --- Generates a string containing the semantic action.--- An action can for example be: Sum $1 $2, that is, construct an AST--- with the constructor Sum applied to the two metavariables $1 and $2.+ generateAction :: NonTerminal -> (Fun) -> [(Bool,Cat,MetaVar)] -> Action generateAction nt f ms = MkAction (if isCoercion f then Nothing else Just f) ms @@ -237,14 +229,8 @@ "(:[])" -> appEPAllL _ -> appEPAll ++"\""++f++"\" " - {-- expspats - | isTokenRule rul = fromToken ++ "\""++f++"\" $1"- | otherwise = constr++" ["++- (concat $ intersperse "," [m1|(_,c,m1) <- ms])- ++ "]" --}+ isAqAction (MkAction mf _) = maybe False isAqFun mf prPattern = prPatternQ True@@ -282,10 +268,7 @@ | otherwise = App x $ map underscore es underscore e = e --- aarne's modifs 8/1/2002:--- Markus's modifs 11/02/2002 --- GF literals specialToks :: CF -> String specialToks cf = unlines $ (map aux (literals cf))@@ -308,13 +291,7 @@ -- m = loc_module l aux (fun,cat) = case cat of--- "Ident" -> "Ident :: { (Ident } : L_ident { (Ident $1,fromToken \"Ident\" $1) }" --- "String" -> "String :: { (String,BNFC_QQType) } : L_quoted { fromString $1 }" -- FIXME: Why not read?--- "Integer" -> "Integer :: { (Integer,BNFC_QQType) } \nInteger : "++iaq++"L_integ { fromLit (read $1) }"--- "Double" -> "Double :: { (Double,BNFC_QQType) } : L_doubl { fromLit (read $1) }"--- "Char" -> "Char :: { (Char,BNFC_QQType) } : L_charac { fromLit (read $1) }"--- own -> own ++ " :: { (" ++ own ++ ",BNFC_QQType) } : L_" ++ own ++ --- " { (" ++ own ++ " ("++ posn ++ "$1),fromToken \""++own++"\" $1)}"+ "Ident" -> unlines [ "Ident :: { Ident } : L_ident { Ident $1 }" , "QQ_Ident :: { BNFC_QQType } : L_ident { "++fromToken ++"\"Ident\" $1 }"
Language/LBNF/Runtime.hs view
@@ -25,8 +25,8 @@ -import Control.Monad (MonadPlus(..), liftM, foldM, (>=>))-+import Control.Monad (MonadPlus(..), liftM, foldM, (>=>), ap)+import Control.Applicative ( Applicative(..) ) import Data.Char@@ -49,6 +49,10 @@ instance Functor ParseMonad where fmap = liftM++instance Applicative ParseMonad where+ (<*>) = ap+ pure = return --instance MonadPlus ParseMonad where -- mzero = Bad "Err.mzero"