inchworm 1.1.1.1 → 1.1.1.2
raw patch · 9 files changed
+62/−24 lines, 9 filesdep ~base
Dependency ranges changed: base
Files
- Changelog.md +1/−1
- LICENSE +14/−11
- Readme.md +5/−5
- Text/Lexer/Inchworm.hs +19/−1
- Text/Lexer/Inchworm/Char.hs +18/−1
- Text/Lexer/Inchworm/Source.hs +2/−2
- examples/lispy/Main.hs +1/−1
- examples/mlish/Main.hs +1/−1
- inchworm.cabal +1/−1
Changelog.md view
@@ -1,4 +1,4 @@-## inchworm-1.1.1.1:+## inchworm-1.1.1: * Matching combinators now produce the range of source locations that matched, instead of just the starting location.
LICENSE view
@@ -1,13 +1,16 @@-Copyright (c) 2016 The Inchworm Development Team+-------------------------------------------------------------------------------+The Inchworm License (MIT style) - Permission is hereby granted, free of charge, to any person- obtaining a copy of this software and associated documentation- files (the "Software"), to deal in the Software without- restriction, including without limitation the rights to use,- copy, modify, merge, publish, distribute, sublicense, and/or sell- copies of the Software, and to permit persons to whom the- Software is furnished to do so, subject to the following- condition:+Copyrite (K) 2016-2018 The Inchworm Development Team+All rights reversed. - The above copyright notice and this permission notice shall be- included in all copies or substantial portions of the Software.+Permission is hereby granted, free of charge, to any person obtaining a copy+of this software and associated documentation files (the "Software"), to deal+in the Software without restriction, including without limitation the rights+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell+copies of the Software, and to permit persons to whom the Software is+furnished to do so, subject to the following condition:++The above copyrite notice and this permission notice shall be included in all+copies or substantial portions of the Software.+-------------------------------------------------------------------------------
Readme.md view
@@ -5,15 +5,15 @@ Tokens are specified via simple fold functions, and we include baked in source location handling. -If you want to parse expressions instead of performing lexical-analysis then try the `parsec` or `attoparsec` packages, which-have more general purpose combinators.- Matchers for standard tokens like comments and strings are in the `Text.Lexer.Inchworm.Char` module. No dependencies other than the Haskell `base` library. +If you want to parse expressions instead of performing lexical+analysis then try the `parsec` or `attoparsec` packages, which+have more general purpose combinators.+ ## Minimal example The following code demonstrates how to perform lexical analysis@@ -67,6 +67,6 @@ main = do let fileName = "Source.lispy" let source = "(some (Lispy like) 26 Program 93 (for you))"- toks <- scanStringIO source (scanner fileName)+ let toks = scanString source (scanner fileName) print toks ```
Text/Lexer/Inchworm.hs view
@@ -73,6 +73,7 @@ , Scanner -- * Generic Scanning+ , scanList , scanListIO -- ** Source Construction@@ -101,6 +102,7 @@ import Text.Lexer.Inchworm.Source import Text.Lexer.Inchworm.Scanner import Text.Lexer.Inchworm.Combinator+import System.IO.Unsafe -- | Scan a list of generic input tokens in the IO monad,@@ -108,8 +110,22 @@ -- along with the remaining input. -- -- NOTE: If you just want to scan a `String` of characters--- use @scanStringIO@ from "Text.Lexer.Inchworm.Char"+-- use @scanString@ from "Text.Lexer.Inchworm.Char" --+scanList + :: Eq i+ => loc -- ^ Starting source location.+ -> (i -> loc -> loc) -- ^ Function to bump the current location by one input token.+ -> [i] -- ^ List of input tokens.+ -> Scanner IO loc [i] a -- ^ Scanner to apply.+ -> ([a], loc, [i])+ +scanList loc bump input scanner+ = unsafePerformIO $ scanListIO loc bump input scanner+++ -- | Implementation for `scanList`,+-- that uses the IO monad to manage its state. scanListIO :: Eq i => loc -- ^ Starting source location.@@ -121,3 +137,5 @@ scanListIO loc bump input scanner = do src <- makeListSourceIO loc bump input scanSourceToList src scanner++
Text/Lexer/Inchworm/Char.hs view
@@ -4,6 +4,7 @@ ( module Text.Lexer.Inchworm -- * Driver+ , scanString , scanStringIO -- * Locations@@ -19,13 +20,29 @@ where import Text.Lexer.Inchworm import Text.Lexer.Inchworm.Source+import System.IO.Unsafe import qualified Data.Char as Char import qualified Data.List as List import qualified Numeric as Numeric -- Driver ------------------------------------------------------------------------ | Scan a string, using the IO monad to maintain internal state.+-- | Scan a string.+scanString+ :: String+ -> Scanner IO Location String a+ -> ([a], Location, String)++scanString str scanner+ = unsafePerformIO + $ scanListIO+ (Location 0 0)+ bumpLocationWithChar + str scanner+++-- | Implementation for `scanString`,+-- that uses the IO monad to maintain internal state. scanStringIO :: String -> Scanner IO Location String a
Text/Lexer/Inchworm/Source.hs view
@@ -203,7 +203,7 @@ -- | A range of locations in a source file. data Range loc = Range !loc !loc- deriving Show+ deriving (Show, Eq, Ord) -- | A location in a source file.@@ -215,7 +215,7 @@ = Location !Int -- Line. !Int -- Column.- deriving Show+ deriving (Show, Eq, Ord) {-# SPECIALIZE INLINE
examples/lispy/Main.hs view
@@ -35,5 +35,5 @@ main = do let fileName = "Source.lispy" let source = "(some (Lispy like) 26 Program 93 (for you))"- toks <- scanStringIO source (scanner fileName)+ let toks = scanString source (scanner fileName) print toks
examples/mlish/Main.hs view
@@ -20,7 +20,7 @@ , "'\\137'" , "\"derpo\\ntro\\BELnic\""] - result <- scanStringIO source (scanner fileName)+ let result = scanString source (scanner fileName) print result
inchworm.cabal view
@@ -1,5 +1,5 @@ name: inchworm-version: 1.1.1.1+version: 1.1.1.2 license: MIT license-file: LICENSE author: The Inchworm Development Team