uulib 0.9.20 → 0.9.21
raw patch · 3 files changed
+17/−9 lines, 3 files
Files
- examples/parser/Example.hs +8/−8
- examples/parser/Scanner.x +8/−0
- uulib.cabal +1/−1
examples/parser/Example.hs view
@@ -45,23 +45,23 @@ -- (by introducing priority levels for the operators) --- Term -> let var = Expr in Expr+-- Term -> let var = Expr in Expr | Add pExpr :: TokenParser Expr pExpr = (\_ x _ e _ b -> Let x e b) <$> pKey "let" <*> pVarid <*> pKey "=" <*> pExpr <*> pKey "in" <*> pExpr- <|> pMult+ <|> pAdd --- Expr -> Factor | Factor * Expr-pMult :: TokenParser Expr-pMult+-- Add -> Factor | Factor + Expr+pAdd :: TokenParser Expr+pAdd = pFactor - <|> (\l _ r -> Times l r) <$> pFactor <*> pKey "*" <*> pExpr+ <|> (\l _ r -> Plus l r) <$> pFactor <*> pKey "+" <*> pExpr -- Factor -> Term | Term * Factor pFactor :: TokenParser Expr pFactor = pTerm- <|> (\l _ r -> Plus l r) <$> pTerm <*> pKey "+" <*> pFactor+ <|> (\l _ r -> Times l r) <$> pTerm <*> pKey "*" <*> pFactor -- Term -> var -- Term -> String@@ -78,7 +78,7 @@ -- test it main :: IO () main- = let res = parseTokens pExpr (tokenize "nofile" "let x = 3 in x+x")+ = let res = parseTokens pExpr (tokenize "nofile" "let x = 3 in x*y+z") in case res of Left errs -> mapM_ putStrLn errs Right tree -> putStrLn $ show tree
examples/parser/Scanner.x view
@@ -4,6 +4,7 @@ module Scanner(tokenize) where import UU.Scanner+import Data.Word (Word8) } $litChar = [^[\" \\]]@@ -30,6 +31,13 @@ alexInputPrevChar :: AlexInput -> Char alexInputPrevChar = error "alexInputPrevChar: there is no need to go back in the input."++-- In Alex3 alexGetByte must be defined.+alexGetByte :: AlexInput -> Maybe (Word8, AlexInput)+alexGetByte (_, []) = Nothing+alexGetByte (p, (c:cs))+ = let p' = adv p c+ in Just ((fromIntegral $ ord c), (p', cs)) alexGetChar :: AlexInput -> Maybe (Char, AlexInput) alexGetChar (_, []) = Nothing
uulib.cabal view
@@ -1,5 +1,5 @@ name: uulib-version: 0.9.20+version: 0.9.21 license: BSD3 license-file: COPYRIGHT