packages feed

Kawaii-Parser 1.0.1 → 2.0.0

raw patch · 3 files changed

+12/−6 lines, 3 filesPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

- Parser.Tokeniser: add_token :: Line_and_char -> token -> Tokeniser' char_class token err ()
+ Parser.Tokeniser: add_token :: token -> Tokeniser' char_class token err ()

Files

Kawaii-Parser.cabal view
@@ -14,7 +14,7 @@ maintainer: liisikerik@hotmail.com
 name: Kawaii-Parser
 synopsis: A simple parsing library.
-version: 1.0.1
+version: 2.0.0
 library
   build-depends: base < 4.15, containers, mtl
   default-language: Haskell2010
Parser/Line_and_char.hs view
@@ -16,7 +16,7 @@   write_line_and_char) where
   -- | Add a location to any type.
   data L t = L Line_and_char t
-  -- | Location
+  -- | Locations.
   data Line_and_char = Line_and_char Integer Integer
   deriving instance Eq Line_and_char
   deriving instance Ord Line_and_char
Parser/Tokeniser.hs view
@@ -42,9 +42,15 @@     Tokeniser tokenise' >>= f = Tokeniser (tokenise' >>= run_tokeniser <$> f)
   deriving instance Show char_class => Show (State char_class)
   deriving instance Show token => Show (Tokens' token)
-  -- | Add the token to the output. Note that the order of adding tokens is important.
-  add_token :: Line_and_char -> token -> Tokeniser' char_class token err ()
-  add_token line_and_char token = Tokeniser (tell [L line_and_char token])
+  -- | Add the token to the output. Note that the order of adding tokens is important and you have to add the token before
+  -- deleting the respective characters to get the correct location.
+  add_token :: token -> Tokeniser' char_class token err ()
+  add_token token =
+    do
+      line_and_char <- state_line_and_char <$> Tokeniser get
+      add_token' line_and_char token
+  add_token' :: Line_and_char -> token -> Tokeniser' char_class token err ()
+  add_token' line_and_char token = Tokeniser (tell [L line_and_char token])
   -- | Get the location of the first token or, if there are none, the end of file. For internal use in the parser.
   current_line_and_char :: Tokens' token -> Line_and_char
   current_line_and_char (Tokens tokens end_line_and_char) =
@@ -67,7 +73,7 @@     do
       line_and_char <- state_line_and_char <$> Tokeniser get
       token <- gather_token' recognise_char
-      add_token line_and_char (string_to_token token)
+      add_token' line_and_char (string_to_token token)
   gather_token' :: (char_class -> Maybe Char) -> Tokeniser' char_class token err String
   gather_token' recognise_char =
     let