Earley 0.13.0.0 → 0.13.0.1
raw patch · 4 files changed
+89/−3 lines, 4 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
Files
- CHANGELOG.md +4/−0
- Earley.cabal +3/−2
- LICENSE +1/−1
- tests/UnbalancedPars.hs +81/−0
CHANGELOG.md view
@@ -1,5 +1,9 @@ # Unreleased +# 0.13.0.1++- Add a missing test module to the Cabal file+ # 0.13.0.0 - Remove the previously deprecated operators `symbol`, `namedSymbol`, and `word`
Earley.cabal view
@@ -1,5 +1,5 @@ name: Earley-version: 0.13.0.0+version: 0.13.0.1 synopsis: Parsing all context-free grammars using Earley's algorithm. description: See <https://www.github.com/ollef/Earley> for more information and@@ -9,7 +9,7 @@ license-file: LICENSE author: Olle Fredriksson maintainer: fredriksson.olle@gmail.com-copyright: (c) 2014-2018 Olle Fredriksson+copyright: (c) 2014-2019 Olle Fredriksson category: Parsing build-type: Simple cabal-version: >=1.10@@ -146,4 +146,5 @@ Mixfix, Optional, ReversedWords,+ UnbalancedPars, VeryAmbiguous
LICENSE view
@@ -1,4 +1,4 @@-Copyright (c) 2014-2015, Olle Fredriksson+Copyright (c) 2014-2019, Olle Fredriksson All rights reserved.
+ tests/UnbalancedPars.hs view
@@ -0,0 +1,81 @@+{-# LANGUAGE FlexibleContexts, RankNTypes, RecursiveDo, ScopedTypeVariables #-}+module UnbalancedPars where++import Data.Char (isAlpha)++import Control.Applicative+import Test.Tasty+import Test.Tasty.HUnit as HU++import Text.Earley++tests :: TestTree+tests = testGroup "Unbalanced parentheses"+ [ HU.testCase "Parses balanced" $+ fst (fullParses' unbalancedPars+ "((x))") @?= [(b . b) x]+ , HU.testCase "Parses one unbalanced" $+ fst (fullParses' unbalancedPars+ "((x)") @?= [(u . b) x]+ , HU.testCase "Parses two unbalanced" $+ fst (fullParses' unbalancedPars+ "((x") @?= [(u . u) x]+ ]+ where+ -- [b]alanced+ b :: Expr -> Expr+ b e = ExprInBrackets "(" e ")"++ -- [u]nbalanced+ u :: Expr -> Expr+ u e = ExprInBrackets "(" e ""++ -- [x] variable+ x :: Expr+ x = Var 'x'++data Token = EOF | Char !Char+ deriving (Eq, Ord, Show)++fullParses'+ :: (forall r. Grammar r (Prod r e Token a))+ -> String+ -> ([a], Report e String)+fullParses' g s =+ let (res, rep) = allParses (parser $ (<* eof) <$> g) $ fmap Char s ++ repeat EOF+ in+ ( fst <$> res+ , rep { unconsumed = go $ unconsumed rep }+ )+ where+ go (Char c:xs) = c : go xs+ go _ = []++data Expr =+ Var Char | ExprInBrackets String Expr String+ deriving (Eq, Ord, Show)++eof :: Prod r e Token Token+eof = token EOF++leftPar :: Prod r e Token String+leftPar = "(" <$ token (Char '(')++rightPar :: Prod r e Token String+rightPar = ")" <$ token (Char ')')++var :: Prod r e Token Expr+var = terminal $ \t -> case t of+ Char c | isAlpha c -> Just $ Var c+ _ -> Nothing++unbalancedPars :: Grammar r (Prod r String Token Expr)+unbalancedPars = mdo+ expr <- rule $ var <|> exprInBrackets+ exprInBrackets <- rule $+ ExprInBrackets+ <$> leftPar+ <*> expr+ <*> (rightPar <|> ("" <$ eof))+ <?> "parenthesized expression"+ return expr