on a164051 help sign in
12 files changed+42−58
since splitsnapshots
unifiedsplit
.ghci+1−1 .github/workflows/ci.yml−33 .travis.yml+12 LICENSE+1−1 README.md+1−1 appveyor.yml+5 cbits/hexml.c+2−2 gen/Lib.hs+3−3 gen/Main.hs+2−2 hexml.cabal+2−2 src/Main.hs+4−4 src/Text/XML/Hexml.hs+9−9
.ghci+1−1
@@ -1,4 +1,4 @@
1−:set -Wunused-binds -Wunused-imports -Worphans
1+:set -fwarn-unused-binds -fwarn-unused-imports -fwarn-orphans
22:set -isrc
33:load Main
44
.github/workflows/ci.ymldeleted−33
@@ -1,33 +0,0 @@
1−name: ci
2−on:
3− push:
4− pull_request:
5− schedule:
6− - cron: '0 3 * * 6' # 3am Saturday
7−jobs:
8− test:
9− runs-on: ${{ matrix.os }}
10−
11− strategy:
12− fail-fast: false
13− matrix:
14− os: [ubuntu-latest]
15− ghc: ['9.6', '9.4', '9.2', '9.0', '8.10', '8.8']
16− include:
17− - os: windows-latest
18− - os: macOS-latest
19−
20− steps:
21− - run: git config --global core.autocrlf false
22− - uses: actions/checkout@v2
23− - uses: haskell/actions/setup@v2
24− id: setup-haskell
25− with:
26− ghc-version: ${{ matrix.ghc }}
27− - run: cabal v2-freeze --enable-tests
28− - uses: actions/cache@v2
29− with:
30− path: ${{ steps.setup-haskell.outputs.cabal-store }}
31− key: ${{ runner.os }}-${{ matrix.ghc }}-${{ hashFiles('cabal.project.freeze') }}
32− restore-keys: ${{ runner.os }}-${{ matrix.ghc }}-
33− - uses: ndmitchell/neil@master
.travis.ymlnew file+12
@@ -0,0 +1,12 @@
1+sudo: required
2+env:
3+- GHCVER=7.10
4+- GHCVER=8.0
5+- GHCVER=8.2
6+- GHCVER=8.4
7+- GHCVER=8.6
8+- GHCVER=head
9+
10+script:
11+- curl -sSL https://raw.github.com/ndmitchell/neil/master/travis.sh | sh
12+- sh afl.sh
LICENSE+1−1
@@ -1,4 +1,4 @@
1−Copyright Neil Mitchell 2016-2023.
1+Copyright Neil Mitchell 2016-2019.
22
33Licensed under either of:
44
README.md+1−1
@@ -1,4 +1,4 @@
1−# Hexml [![Hackage version](https://img.shields.io/hackage/v/hexml.svg?label=Hackage)](https://hackage.haskell.org/package/hexml) [![Stackage version](https://www.stackage.org/package/hexml/badge/nightly?label=Stackage)](https://www.stackage.org/package/hexml) [![Build status](https://img.shields.io/github/actions/workflow/status/ndmitchell/hexml/ci.yml?branch=master)](https://github.com/ndmitchell/hexml/actions)
1+# Hexml [![Hackage version](https://img.shields.io/hackage/v/hexml.svg?label=Hackage)](https://hackage.haskell.org/package/hexml) [![Stackage version](https://www.stackage.org/package/hexml/badge/nightly?label=Stackage)](https://www.stackage.org/package/hexml) [![Linux build status](https://img.shields.io/travis/ndmitchell/hexml/master.svg?label=Linux%20build)](https://travis-ci.org/ndmitchell/hexml) [![Windows build status](https://img.shields.io/appveyor/ci/ndmitchell/hexml/master.svg?label=Windows%20build)](https://ci.appveyor.com/project/ndmitchell/hexml)
22
33An XML DOM-style parser, that only parses a subset of XML, but is designed to be fast. In particular:
44
appveyor.ymlnew file+5
@@ -0,0 +1,5 @@
1+build: off
2+cache: "c:\\sr -> appveyor.yml"
3+
4+test_script:
5+- ps: Invoke-Expression (Invoke-WebRequest 'https://raw.githubusercontent.com/ndmitchell/neil/master/appveyor.ps1')
cbits/hexml.c+2−2
@@ -40,7 +40,7 @@ typedef struct
4040 // have a cursor at the end, which is stack scoped, so children write out, then I do
4141 // when you commit, you copy over from end to front
4242
43− // nodes
43+ // nodes
4444 int size;
4545 int used_front; // front entries, stored for good
4646 int used_back; // back entries, stack based, copied into front
@@ -539,7 +539,7 @@ document* hexml_document_parse(const char* s, int slen)
539539 d->nodes.nodes[0].outer = start_length(0, slen);
540540 d->nodes.nodes[0].inner = start_length(0, slen);
541541 d->nodes.nodes[0].attrs = start_length(0, 0);
542−
542+
543543 // Introduce an intermediate result, otherwise behaviour is undefined
544544 // because there is no guaranteed ordering between LHS and RHS evaluation
545545 str content = parse_content(d);
gen/Lib.hs+3−3
@@ -10,7 +10,7 @@ module Lib(
1010import Control.Monad.Extra
1111import Control.Monad.Trans.Writer
1212import Data.Maybe
13−import Data.List.Extra
13+import Data.List
1414import Data.Bits
1515import Data.Monoid
1616import Numeric
@@ -67,7 +67,7 @@ choices :: [Parser o ()] -> Parser o ()
6767choices = foldr1 choice
6868
6969optional :: Parser o () -> Parser o ()
70−optional x = choice x $ pure ()
70+optional x = choice x $ return ()
7171
7272
7373---------------------------------------------------------------------
@@ -106,7 +106,7 @@ charSetC sets =
106106 ,\x -> fromMaybe ("table[(int) *p] & " ++ showBit (bit $ fromJust $ elemIndex x hard)) $ simple x)
107107 where
108108 showBit x = "0x" ++ showHex (x :: Int) ""
109− disp c = showBit $ foldr (.|.) 0 [bit i | (i, h) <- zipFrom 0 hard, fromCharSet h c]
109+ disp c = showBit $ foldr (.|.) 0 [bit i | (i, h) <- zip [0..] hard, fromCharSet h c]
110110
111111 hard = nub $ filter (isNothing . simple) sets
112112
gen/Main.hs+2−2
@@ -28,13 +28,13 @@ main = do
2828
2929writeFileChanged :: FilePath -> String -> IO ()
3030writeFileChanged file new = do
31− old <- ifM (doesFileExist file) (readFile' file) (pure "")
31+ old <- ifM (doesFileExist file) (readFile' file) (return "")
3232 when (old /= new) $
3333 writeFile file new
3434
3535buildRule :: [FilePath] -> [FilePath] -> IO () -> IO ()
3636buildRule from to act = do
37− let modTime x = ifM (doesFileExist x) (Just <$> getModificationTime x) (pure Nothing)
37+ let modTime x = ifM (doesFileExist x) (Just <$> getModificationTime x) (return Nothing)
3838 from <- mapM modTime from
3939 to <- mapM modTime to
4040 when (any isNothing (from ++ to) || maximum from >= minimum to)
hexml.cabal+2−2
@@ -8,13 +8,13 @@ license-file: LICENSE
88category: XML
99author: Neil Mitchell <ndmitchell@gmail.com>
1010maintainer: Neil Mitchell <ndmitchell@gmail.com>
11−copyright: Neil Mitchell 2016-2023
11+copyright: Neil Mitchell 2016-2019
1212synopsis: XML subset DOM parser
1313description:
1414 An XML DOM-style parser, that only parses a subset of XML, but is designed to be fast.
1515homepage: https://github.com/ndmitchell/hexml#readme
1616bug-reports: https://github.com/ndmitchell/hexml/issues
17−tested-with: GHC==9.6, GHC==9.4, GHC==9.2, GHC==9.0, GHC==8.10, GHC==8.8
17+tested-with: GHC==8.6.4, GHC==8.4.4, GHC==8.2.2, GHC==8.0.2, GHC==7.10.3
1818extra-doc-files:
1919 README.md
2020 CHANGES.txt
src/Main.hs+4−4
@@ -44,12 +44,12 @@ main = do
4444 attributes (head $ children doc) === [Attribute "id" "1", Attribute "extra" "2"]
4545 map (`attributeBy` "id") (childrenBy doc "test") === map (fmap (Attribute "id")) [Just "1", Just "2", Just "4", Nothing]
4646
47− Right _ <- pure $ parse $ "<test " <> BS.unwords [BS.pack $ "x" ++ show i ++ "='value'" | i <- [1..10000]] <> " />"
48− Right _ <- pure $ parse $ BS.unlines $ replicate 10000 "<test x='value' />"
47+ Right _ <- return $ parse $ "<test " <> BS.unwords [BS.pack $ "x" ++ show i ++ "='value'" | i <- [1..10000]] <> " />"
48+ Right _ <- return $ parse $ BS.unlines $ replicate 10000 "<test x='value' />"
4949
5050 let attrs = ["usd:jpy","test","extra","more","stuff","jpy:usd","xxx","xxxx"]
51− Right doc <- pure $ parse $ "<test " <> BS.unwords [x <> "='" <> x <> "'" | x <- attrs] <> ">middle</test>"
52− [c] <- pure $ childrenBy doc "test"
51+ Right doc <- return $ parse $ "<test " <> BS.unwords [x <> "='" <> x <> "'" | x <- attrs] <> ">middle</test>"
52+ [c] <- return $ childrenBy doc "test"
5353 forM_ attrs $ \a -> attributeBy c a === Just (Attribute a a)
5454 forM_ ["missing","gone","nothing"] $ \a -> attributeBy c a === Nothing
5555 putStrLn "\nSuccess"
src/Text/XML/Hexml.hs+9−9
@@ -90,11 +90,11 @@ parse src = do
9090 if err /= nullPtr then do
9191 bs <- BS.packCString =<< hexml_document_error doc
9292 hexml_document_free doc
93− pure $ Left bs
93+ return $ Left bs
9494 else do
9595 node <- hexml_document_node doc
9696 doc <- newForeignPtr hexml_document_free_funptr doc
97− pure $ Right $ Node src0 doc node
97+ return $ Right $ Node src0 doc node
9898
9999-- | Given a node, rerender it to something with an equivalent parse tree.
100100-- Mostly useful for debugging - if you want the real source document use 'outer' instead.
@@ -103,7 +103,7 @@ render (Node src doc n) = unsafePerformIO $ withForeignPtr doc $ \d -> do
103103 i <- hexml_node_render d n nullPtr 0
104104 res <- BS.create (fromIntegral i) $ \ptr -> void $ hexml_node_render d n (castPtr ptr) i
105105 touchBS src
106− pure res
106+ return res
107107
108108applyStr :: BS.ByteString -> Str -> BS.ByteString
109109applyStr bs Str{..} = BS.take (fromIntegral strLength) $ BS.drop (fromIntegral strStart) bs
@@ -118,7 +118,7 @@ attrPeek :: BS.ByteString -> ForeignPtr CDocument -> Ptr CAttr -> Attribute
118118attrPeek src doc a = unsafePerformIO $ withForeignPtr doc $ \_ -> do
119119 name <- applyStr src <$> peekElemOff (castPtr a) 0
120120 val <- applyStr src <$> peekElemOff (castPtr a) 1
121− pure $ Attribute name val
121+ return $ Attribute name val
122122
123123-- | Get the name of a node, e.g. @\<test /\>@ produces @\"test\"@.
124124name :: Node -> BS.ByteString
@@ -142,7 +142,7 @@ outer = nodeBS 2
142142contents :: Node -> [Either BS.ByteString Node]
143143contents n@(Node src _ _) = f (strStart inner) outers
144144 where
145− f i [] = string i (strEnd inner)
145+ f i [] = string i (strEnd inner) ++ []
146146 f i ((x, n):xs) = string i (strStart x) ++ Right n : f (strEnd x) xs
147147
148148 string start end | start == end = []
@@ -156,7 +156,7 @@ children (Node src doc n) = unsafePerformIO $ withForeignPtr doc $ \d ->
156156 alloca $ \count -> do
157157 res <- hexml_node_children d n count
158158 count <- fromIntegral <$> peek count
159− pure [Node src doc $ plusPtr res $ i*szNode | i <- [0..count-1]]
159+ return [Node src doc $ plusPtr res $ i*szNode | i <- [0..count-1]]
160160
161161-- | Get the attributes of this node.
162162attributes :: Node -> [Attribute]
@@ -164,7 +164,7 @@ attributes (Node src doc n) = unsafePerformIO $ withForeignPtr doc $ \d ->
164164 alloca $ \count -> do
165165 res <- hexml_node_attributes d n count
166166 count <- fromIntegral <$> peek count
167− pure [attrPeek src doc $ plusPtr res $ i*szAttr | i <- [0..count-1]]
167+ return [attrPeek src doc $ plusPtr res $ i*szAttr | i <- [0..count-1]]
168168
169169-- | Get the direct children of this node which have a specific name.
170170-- A more efficient version of:
@@ -177,7 +177,7 @@ childrenBy (Node src doc n) str = go nullPtr
177177 BS.unsafeUseAsCStringLen str $ \(bs, len) -> do
178178 r <- hexml_node_child d n old bs $ fromIntegral len
179179 touchBS src
180− pure $ if r == nullPtr then [] else Node src doc r : go r
180+ return $ if r == nullPtr then [] else Node src doc r : go r
181181
182182-- | Get the first attribute of this node which has a specific name, if there is one.
183183-- A more efficient version of:
@@ -188,7 +188,7 @@ attributeBy (Node src doc n) str = unsafePerformIO $ withForeignPtr doc $ \d ->
188188 BS.unsafeUseAsCStringLen str $ \(bs, len) -> do
189189 r <- hexml_node_attribute d n bs $ fromIntegral len
190190 touchBS src
191− pure $ if r == nullPtr then Nothing else Just $ attrPeek src doc r
191+ return $ if r == nullPtr then Nothing else Just $ attrPeek src doc r
192192
193193-- | Find the starting location of a node, the @<@ character.
194194-- The first character will be reported as @(line 1,column 1)@, because thats