gll 0.4.0.12 → 0.4.0.13
raw patch · 8 files changed
+38/−58 lines, 8 filesdep −random-stringssetup-changedPVP: major bump suggested
API removals or changes: PVP suggests a major version bump
Dependencies removed: random-strings
API changes (from Hackage documentation)
- GLL.Combinators.BinaryInterface: printEvalDataWithOptions :: (Parseable t, IsSymbExpr s, Show a) => ParseOptions -> CombinatorOptions -> s t a -> [t] -> IO ()
- GLL.Combinators.Interface: printEvalDataWithOptions :: (Parseable t, IsSymbExpr s, Show a) => ParseOptions -> CombinatorOptions -> s t a -> [t] -> IO ()
+ GLL.Combinators.BinaryInterface: lexerEither :: SubsumesToken t => LexerSettings -> String -> Either String [t]
+ GLL.Combinators.Interface: lexerEither :: SubsumesToken t => LexerSettings -> String -> Either String [t]
+ GLL.Combinators.Lexer: lexerEither :: SubsumesToken t => LexerSettings -> String -> Either String [t]
- GLL.Combinators.BinaryInterface: AltIDLit :: (Maybe String) -> Token
+ GLL.Combinators.BinaryInterface: AltIDLit :: Maybe String -> Token
- GLL.Combinators.BinaryInterface: BoolLit :: (Maybe Bool) -> Token
+ GLL.Combinators.BinaryInterface: BoolLit :: Maybe Bool -> Token
- GLL.Combinators.BinaryInterface: CharLit :: (Maybe Char) -> Token
+ GLL.Combinators.BinaryInterface: CharLit :: Maybe Char -> Token
- GLL.Combinators.BinaryInterface: FloatLit :: (Maybe Double) -> Token
+ GLL.Combinators.BinaryInterface: FloatLit :: Maybe Double -> Token
- GLL.Combinators.BinaryInterface: IDLit :: (Maybe String) -> Token
+ GLL.Combinators.BinaryInterface: IDLit :: Maybe String -> Token
- GLL.Combinators.BinaryInterface: IntLit :: (Maybe Int) -> Token
+ GLL.Combinators.BinaryInterface: IntLit :: Maybe Int -> Token
- GLL.Combinators.BinaryInterface: LexerSettings :: [Char] -> [String] -> Char -> Bool -> String -> String -> String -> RE Char String -> RE Char String -> [(String, RE Char String)] -> Bool -> LexerSettings
+ GLL.Combinators.BinaryInterface: LexerSettings :: [Char] -> [String] -> (Char -> Bool) -> String -> String -> String -> RE Char String -> RE Char String -> [(String, RE Char String)] -> Bool -> LexerSettings
- GLL.Combinators.BinaryInterface: StringLit :: (Maybe String) -> Token
+ GLL.Combinators.BinaryInterface: StringLit :: Maybe String -> Token
- GLL.Combinators.BinaryInterface: Token :: String -> (Maybe String) -> Token
+ GLL.Combinators.BinaryInterface: Token :: String -> Maybe String -> Token
- GLL.Combinators.Interface: AltIDLit :: (Maybe String) -> Token
+ GLL.Combinators.Interface: AltIDLit :: Maybe String -> Token
- GLL.Combinators.Interface: BoolLit :: (Maybe Bool) -> Token
+ GLL.Combinators.Interface: BoolLit :: Maybe Bool -> Token
- GLL.Combinators.Interface: CharLit :: (Maybe Char) -> Token
+ GLL.Combinators.Interface: CharLit :: Maybe Char -> Token
- GLL.Combinators.Interface: FloatLit :: (Maybe Double) -> Token
+ GLL.Combinators.Interface: FloatLit :: Maybe Double -> Token
- GLL.Combinators.Interface: IDLit :: (Maybe String) -> Token
+ GLL.Combinators.Interface: IDLit :: Maybe String -> Token
- GLL.Combinators.Interface: IntLit :: (Maybe Int) -> Token
+ GLL.Combinators.Interface: IntLit :: Maybe Int -> Token
- GLL.Combinators.Interface: LexerSettings :: [Char] -> [String] -> Char -> Bool -> String -> String -> String -> RE Char String -> RE Char String -> [(String, RE Char String)] -> Bool -> LexerSettings
+ GLL.Combinators.Interface: LexerSettings :: [Char] -> [String] -> (Char -> Bool) -> String -> String -> String -> RE Char String -> RE Char String -> [(String, RE Char String)] -> Bool -> LexerSettings
- GLL.Combinators.Interface: StringLit :: (Maybe String) -> Token
+ GLL.Combinators.Interface: StringLit :: Maybe String -> Token
- GLL.Combinators.Interface: Token :: String -> (Maybe String) -> Token
+ GLL.Combinators.Interface: Token :: String -> Maybe String -> Token
- GLL.Combinators.Lexer: LexerSettings :: [Char] -> [String] -> Char -> Bool -> String -> String -> String -> RE Char String -> RE Char String -> [(String, RE Char String)] -> Bool -> LexerSettings
+ GLL.Combinators.Lexer: LexerSettings :: [Char] -> [String] -> (Char -> Bool) -> String -> String -> String -> RE Char String -> RE Char String -> [(String, RE Char String)] -> Bool -> LexerSettings
- GLL.Combinators.Options: maintainWith :: (Eq k) => (k -> k -> Ordering) -> [[(k, a)]] -> [[(k, a)]]
+ GLL.Combinators.Options: maintainWith :: Eq k => (k -> k -> Ordering) -> [[(k, a)]] -> [[(k, a)]]
- GLL.Parser: Prod :: (Nt) -> (Symbols t) -> Prod t
+ GLL.Parser: Prod :: Nt -> Symbols t -> Prod t
- GLL.Parser: Slot :: (Nt) -> (([Symbol t])) -> (([Symbol t])) -> Slot t
+ GLL.Parser: Slot :: Nt -> [Symbol t] -> [Symbol t] -> Slot t
- GLL.Parser: mkInput :: (Parseable t) => [t] -> Input t
+ GLL.Parser: mkInput :: Parseable t => [t] -> Input t
- GLL.Parser: parse :: (Parseable t) => Grammar t -> [t] -> ParseResult t
+ GLL.Parser: parse :: Parseable t => Grammar t -> [t] -> ParseResult t
- GLL.Parser: parseArray :: (Parseable t) => Grammar t -> Input t -> ParseResult t
+ GLL.Parser: parseArray :: Parseable t => Grammar t -> Input t -> ParseResult t
- GLL.Types.Derivations: eMapInsert :: (Ord t) => SPPFNode t -> SPPFNode t -> SPPF t -> SPPF t
+ GLL.Types.Derivations: eMapInsert :: Ord t => SPPFNode t -> SPPFNode t -> SPPF t -> SPPF t
- GLL.Types.Derivations: emptySPPF :: (Ord t) => SPPF t
+ GLL.Types.Derivations: emptySPPF :: Ord t => SPPF t
- GLL.Types.Derivations: iNodeInsert :: (Ord t) => SPPFNode t -> SPPFNode t -> SPPF t -> SPPF t
+ GLL.Types.Derivations: iNodeInsert :: Ord t => SPPFNode t -> SPPFNode t -> SPPF t -> SPPF t
- GLL.Types.Derivations: iNodeLookup :: (Ord t) => SPPF t -> (Slot t, Int, Int) -> Bool
+ GLL.Types.Derivations: iNodeLookup :: Ord t => SPPF t -> (Slot t, Int, Int) -> Bool
- GLL.Types.Derivations: iNodeRemove :: (Ord t) => SPPF t -> (Slot t, Int, Int) -> SPPF t
+ GLL.Types.Derivations: iNodeRemove :: Ord t => SPPF t -> (Slot t, Int, Int) -> SPPF t
- GLL.Types.Derivations: inU :: Ord a => (a, Key, Key) -> IntMap IntMap Set a -> Bool
+ GLL.Types.Derivations: inU :: Ord a => (a, Key, Key) -> IntMap (IntMap (Set a)) -> Bool
- GLL.Types.Derivations: pMapInsert :: (Ord t) => SPPFNode t -> SPPFNode t -> SPPF t -> SPPF t
+ GLL.Types.Derivations: pMapInsert :: Ord t => SPPFNode t -> SPPFNode t -> SPPF t -> SPPF t
- GLL.Types.Derivations: pNodeLookup :: (Ord t) => SPPF t -> ((Prod t, Int), Int, Int) -> Maybe [Int]
+ GLL.Types.Derivations: pNodeLookup :: Ord t => SPPF t -> ((Prod t, Int), Int, Int) -> Maybe [Int]
- GLL.Types.Derivations: sNodeInsert :: (Ord t) => SPPFNode t -> SPPFNode t -> SPPF t -> SPPF t
+ GLL.Types.Derivations: sNodeInsert :: Ord t => SPPFNode t -> SPPFNode t -> SPPF t -> SPPF t
- GLL.Types.Derivations: sNodeLookup :: (Ord t) => SPPF t -> (Symbol t, Int, Int) -> Bool
+ GLL.Types.Derivations: sNodeLookup :: Ord t => SPPF t -> (Symbol t, Int, Int) -> Bool
- GLL.Types.Derivations: sNodeRemove :: (Ord t) => SPPF t -> (Symbol t, Int, Int) -> SPPF t
+ GLL.Types.Derivations: sNodeRemove :: Ord t => SPPF t -> (Symbol t, Int, Int) -> SPPF t
- GLL.Types.Derivations: showP :: (Show a1, Show a2) => IntMap IntMap IntMap Map a1 a2 -> String
+ GLL.Types.Derivations: showP :: (Show a1, Show a2) => IntMap (IntMap (IntMap (Map a1 a2))) -> String
- GLL.Types.Derivations: showS :: Show a => IntMap IntMap a -> String
+ GLL.Types.Derivations: showS :: Show a => IntMap (IntMap a) -> String
- GLL.Types.Derivations: toU :: Ord a => (a, Key, Key) -> IntMap IntMap Set a -> IntMap IntMap Set a
+ GLL.Types.Derivations: toU :: Ord a => (a, Key, Key) -> IntMap (IntMap (Set a)) -> IntMap (IntMap (Set a))
- GLL.Types.Grammar: AltIDLit :: (Maybe String) -> Token
+ GLL.Types.Grammar: AltIDLit :: Maybe String -> Token
- GLL.Types.Grammar: BoolLit :: (Maybe Bool) -> Token
+ GLL.Types.Grammar: BoolLit :: Maybe Bool -> Token
- GLL.Types.Grammar: CharLit :: (Maybe Char) -> Token
+ GLL.Types.Grammar: CharLit :: Maybe Char -> Token
- GLL.Types.Grammar: FloatLit :: (Maybe Double) -> Token
+ GLL.Types.Grammar: FloatLit :: Maybe Double -> Token
- GLL.Types.Grammar: IDLit :: (Maybe String) -> Token
+ GLL.Types.Grammar: IDLit :: Maybe String -> Token
- GLL.Types.Grammar: IntLit :: (Maybe Int) -> Token
+ GLL.Types.Grammar: IntLit :: Maybe Int -> Token
- GLL.Types.Grammar: Prod :: (Nt) -> (Symbols t) -> Prod t
+ GLL.Types.Grammar: Prod :: Nt -> Symbols t -> Prod t
- GLL.Types.Grammar: Slot :: (Nt) -> (([Symbol t])) -> (([Symbol t])) -> Slot t
+ GLL.Types.Grammar: Slot :: Nt -> [Symbol t] -> [Symbol t] -> Slot t
- GLL.Types.Grammar: StringLit :: (Maybe String) -> Token
+ GLL.Types.Grammar: StringLit :: Maybe String -> Token
- GLL.Types.Grammar: Token :: String -> (Maybe String) -> Token
+ GLL.Types.Grammar: Token :: String -> Maybe String -> Token
Files
- Setup.hs +0/−2
- changelog.txt +3/−0
- gll.cabal +4/−4
- src/GLL/Combinators/BinaryInterface.hs +1/−1
- src/GLL/Combinators/Interface.hs +2/−37
- src/GLL/Combinators/Lexer.hs +18/−12
- src/GLL/GrammarCombinators.hs +8/−0
- src/GLL/Parseable/Char.hs +2/−2
− Setup.hs
@@ -1,2 +0,0 @@-import Distribution.Simple-main = defaultMain
changelog.txt view
@@ -68,3 +68,6 @@ + let 'parse' throw errors by default + changed priorities of operator tables to doubles + removed need to specify associativity of prefix operators in operator table++0.4.0.12 -> 0.4.0.13+ + export 'lexerEither' that produces an 'Either' value with either an error or a list of tokens
gll.cabal view
@@ -3,7 +3,7 @@ -- The name of the package. name: gll-version: 0.4.0.12+version: 0.4.0.13 synopsis: GLL parser with simple combinator interface license: BSD3 license-file: LICENSE@@ -12,8 +12,8 @@ category: Compilers build-type: Simple cabal-version: >=1.22-tested-with: GHC == 8.0.1, GHC == 8.0.2 -copyright: Copyright (C) 2015 L. Thomas van Binsbergen+tested-with: GHC >= 8.2.1 && <= 8.6, GHC == 8.8.3+copyright: Copyright (C) 2015-2020 L. Thomas van Binsbergen stability: experimental description: @@ -48,9 +48,9 @@ , text , regex-applicative >= 0.3 , time >= 1.8- , random-strings >= 0.1.1.0 exposed-modules : GLL.Combinators.Interface , GLL.Combinators.BinaryInterface+ , GLL.GrammarCombinators , GLL.Combinators , GLL.Combinators.Test.Interface , GLL.Combinators.Test.BinaryInterface
src/GLL/Combinators/BinaryInterface.hs view
@@ -29,7 +29,7 @@ -- * Running a parser grammarOf, parse, printParseData, evaluatorWithParseData, -- ** Running a parser with options- parseWithOptions, parseWithParseOptions, printEvalDataWithOptions, printParseDataWithOptions, evaluatorWithParseDataAndOptions,printGrammarData,+ parseWithOptions, parseWithParseOptions, printParseDataWithOptions, evaluatorWithParseDataAndOptions,printGrammarData, -- *** Possible options CombinatorOptions, CombinatorOption, GLL.Combinators.Options.maximumErrors, throwErrors,
src/GLL/Combinators/Interface.hs view
@@ -202,7 +202,7 @@ -- * Running a parser grammarOf, parse, printParseData, evaluatorWithParseData, -- ** Running a parser with options- parseWithOptions, parseWithParseOptions, printEvalDataWithOptions, printParseDataWithOptions, evaluatorWithParseDataAndOptions, printGrammarData,+ parseWithOptions, parseWithParseOptions, printParseDataWithOptions, evaluatorWithParseDataAndOptions, printGrammarData, -- *** Possible options CombinatorOptions, CombinatorOption, GLL.Combinators.Options.maximumErrors, throwErrors, @@ -217,7 +217,7 @@ -- ** Builtin lexers. default_lexer, -- *** Lexer settings- lexer, LexerSettings(..), emptyLanguage,+ lexer, lexerEither, LexerSettings(..), emptyLanguage, -- * Derived combinators mkNt, -- *** Ignoring semantic results@@ -318,41 +318,6 @@ endTime <- getCurrentTime putStrLn $ "semantic phase: " ++ show (diffUTCTime endTime startTime')-} putStrLn $ "total time: " ++ show (diffUTCTime endTime startTime)---- | Variant of 'printParseData' which can be controlled by 'ParseOption's-printEvalDataWithOptions :: (Parseable t, IsSymbExpr s, Show a) => ParseOptions -> CombinatorOptions -> s t a -> [t] -> IO ()-printEvalDataWithOptions popts opts p' input = - let SymbExpr (Nt start,vpa2,vpa3) = mkRule ("__Start" <:=> OO [id <$$> p'])- rules = vpa2 M.empty- grammar = (start, [ p | (_, alts) <- M.assocs rules, p <- alts ])- parse_res = GLL.parseWithOptions (popts ++ [packedNodesOnly,strictBinarisation]) grammar input- arr = mkInput input - (_,m) = A.bounds arr- in do let (_,prods) = grammar- nt_set = S.fromList [ x | Prod x _ <- prods ]- putStrLn $ "#production: " ++ show (length prods)- putStrLn $ "#nonterminals: " ++ show (length nt_set)- putStrLn $ "largest nonterminal: " ++ show ( - foldr (\x -> max (Data.Text.length x)) 0 nt_set)-- startTime <- getCurrentTime- putStrLn $ "#tokens: " ++ (show m)- putStrLn $ "#successes: " ++ (show $ res_successes parse_res)- endTime <- getCurrentTime- putStrLn $ "recognition time: " ++ show (diffUTCTime endTime startTime)- startTime' <- getCurrentTime- putStrLn $ "#descriptors " ++ (show $ nr_descriptors parse_res)- putStrLn $ "#EPNs " ++ (show $ nr_packed_node_attempts parse_res) - endTime <- getCurrentTime- putStrLn $ "parse-data time: " ++ show (diffUTCTime endTime startTime')- startTime' <- getCurrentTime- as <- vpa3 (runOptions opts) emptyAncestors (sppf_result parse_res) arr 0 m- putStrLn $ "ambiguous?: " ++ show (length as > 1)- when (not (null as)) (writeFile "/tmp/derivation" (show (head as)))- endTime <- getCurrentTime- putStrLn $ "semantic phase: " ++ show (diffUTCTime endTime startTime')- putStrLn $ "total time: " ++ show (diffUTCTime endTime startTime)- -- | Print some information evaluatorWithParseData :: (Parseable t, IsSymbExpr s, Show a) => s t a -> [t] -> [a]
src/GLL/Combinators/Lexer.hs view
@@ -1,6 +1,6 @@ module GLL.Combinators.Lexer (- default_lexer, lexer, LexerSettings(..), emptyLanguage,+ default_lexer, lexer, lexerEither, LexerSettings(..), emptyLanguage, oneOf, manyOf, someOf, baseToDec, ) where @@ -47,18 +47,24 @@ default_lexer :: SubsumesToken t => String -> [t] default_lexer = lexer emptyLanguage --- | A lexer parameterised by 'LexerSettings'.+-- | Variant of 'lexerEither' that throws an error or returns the result otherwise lexer :: SubsumesToken t => LexerSettings -> String -> [t]-lexer _ [] = []-lexer lexsets s+lexer set inp = case lexerEither set inp of+ Left err -> error err+ Right ts -> ts++-- | A lexer parameterised by 'LexerSettings'.+lexerEither :: SubsumesToken t => LexerSettings -> String -> Either String [t]+lexerEither _ [] = Right []+lexerEither lexsets s | start /= "" && end /= "" && start `isPrefixOf` s = blockState 1 (drop lS s) | lComm /= "" && lComm `isPrefixOf` s = case dropWhile ((/=) '\n') s of- [] -> []- (c:cs) -> lexer lexsets cs- | isWS (head s) = lexer lexsets (dropWhile isWS s)+ [] -> Right []+ (c:cs) -> lexerEither lexsets cs+ | isWS (head s) = lexerEither lexsets (dropWhile isWS s) | otherwise = case findLongestPrefix (lTokens lexsets) s of- Just (tok, rest) -> tok : lexer lexsets rest- Nothing -> error ("lexical error at: " ++ show (take 10 s))+ Just (tok, rest) -> fmap (tok :) $ lexerEither lexsets rest+ Nothing -> Left ("lexical error at: " ++ show (take 10 s)) where start = blockCommentOpen lexsets end = blockCommentClose lexsets isWS = whitespace lexsets@@ -66,9 +72,9 @@ lS = length start lE = length end - blockState :: SubsumesToken t => Int -> String -> [t] - blockState n [] = [] - blockState 0 rest = lexer lexsets rest+ blockState :: SubsumesToken t => Int -> String -> Either String [t] + blockState n [] = Right [] + blockState 0 rest = lexerEither lexsets rest blockState n cs | start `isPrefixOf` cs = blockState (n+1) (drop lS cs) | end `isPrefixOf` cs = blockState (n-1) (drop lE cs) | otherwise = blockState n (tail cs)
+ src/GLL/GrammarCombinators.hs view
@@ -0,0 +1,8 @@++-- |+-- "GLL.Combinators" imports "GLL.Combinators.Interface" as the default library.+module GLL.GrammarCombinators (+ module GLL.Combinators.Interface + ) where++import GLL.Combinators.Interface
src/GLL/Parseable/Char.hs view
@@ -1,11 +1,11 @@ -- | Exports an instance for 'Parseable' 'Char' --- that assumes '$' and '#' never appear in the inpur string.+-- that assumes '$' and '#' never appear in the input string. module GLL.Parseable.Char () where import GLL.Types.Grammar --- | Assumes '$' and '#' never appear in the inpur string.+-- | Assumes '$' and '#' never appear in the input string. instance Parseable Char where eos = '$' eps = '#'