packages feed

indents (empty) → 0.1.0

raw patch · 4 files changed

+177/−0 lines, 4 filesdep +basedep +concatenativedep +mtlsetup-changed

Dependencies added: base, concatenative, mtl, parsec

Files

+ LICENSE view
@@ -0,0 +1,30 @@+Copyright (c)2010, Sam Anklesaria++All rights reserved.++Redistribution and use in source and binary forms, with or without+modification, are permitted provided that the following conditions are met:++    * Redistributions of source code must retain the above copyright+      notice, this list of conditions and the following disclaimer.++    * Redistributions in binary form must reproduce the above+      copyright notice, this list of conditions and the following+      disclaimer in the documentation and/or other materials provided+      with the distribution.++    * Neither the name of Sam Anklesaria nor the names of other+      contributors may be used to endorse or promote products derived+      from this software without specific prior written permission.++THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT+OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ Text/Parsec/Indent.hs view
@@ -0,0 +1,84 @@+{-# LANGUAGE FlexibleContexts #-}+module Text.Parsec.Indent (block, lineFold, runIndent) where+import Text.Parsec+import Text.Parsec.Pos+import Control.Monad.State+import Control.Concatenative++{-| ++A module to construct indentation aware parsers. Many programming+language have indentation based syntax rules e.g. python and Haskell.+This module exports combinators to create such parsers. ++The input source can be thought of as a list of tokens. Abstractly+each token occurs at a line and a column and has a width. The column+number of a token measures is indentation. If t1 and t2 are two tokens+then we say that indentation of t1 is more than t2 if the column+number of occurrence of t1 is greater than that of t2.++Currently this module supports two kind of indentation based syntactic+structures which we now describe:++[Block] A block of indentation /c/ is a sequence of tokens with+indentation at least /c/.  Examples for a block is a where clause of+Haskell with no explicit braces.++[Line fold] A line fold starting at line /l/ and indentation /c/ is a+sequence of tokens that start at line /l/ and possibly continue to+subsequent lines as long as the indentation is greater than /c/. Such+a sequence of lines need to be /folded/ to a single line. An example+is MIME headers. Line folding based binding separation is used in+Haskell as well.++-}++type IndentParserT s u m a = ParsecT s u (StateT SourcePos m) a++-- | Parses a block of lines at the same indentation level+block :: (Stream s (StateT SourcePos m) Char, Monad m) => IndentParserT s u m a -> IndentParserT s u m [a]+block p = do+    a <- setStart+    r <- many1 (checkIndent >> p)+    put a+    return r++-- | Continues parsing indented below a line+lineFold :: (Stream s (StateT SourcePos m) Char, Monad m) => IndentParserT s u m a -> IndentParserT s u m [a]+lineFold p = do+    a <- setStart+    r <- blockOrNewLine p+    put a+    return r++blockOrNewLine :: (Stream s (StateT SourcePos m) Char, Monad m) => IndentParserT s u m a -> IndentParserT s u m [a]+blockOrNewLine p = do+    s <- get+    pos <- getPosition+    liftM2 (:) p $ if biAp sourceLine (==) pos s then blockOrNewLine p else liftM concat (block (manyLine p))++-- | Parses many occurances of p without using more than one line+manyLine :: (Stream s (StateT SourcePos m) Char, Monad m) => IndentParserT s u m a -> IndentParserT s u m [a]+manyLine p = do+    s <- liftM ((+1) . sourceLine) get+    pos <- liftM sourceLine getPosition+    if pos == s then many (char ' ') >> return [] else liftM2 (:) p (manyLine p)++setStart :: (Stream s (StateT SourcePos m) Char, Monad m) => IndentParserT s u m SourcePos+setStart = do+    a <- get+    p <- getPosition+    (put p)+    return a++checkIndent :: (Stream s (StateT SourcePos m) Char, Monad m) => IndentParserT s u m ()+checkIndent = do+    s <- get+    p <- getPosition+    if biAp sourceColumn (==) p s then return () else mzero++-- | Run the result of an indentation sensative parse+runIndent :: Monad m => SourceName -> StateT SourcePos m a -> m a+runIndent s = flip evalStateT (initialPos s)++-- for tests, assemble random indent-using functions, their inputs and outputs in tandem, then test to see they all fit as planned
+ indents.cabal view
@@ -0,0 +1,61 @@+-- indents.cabal auto-generated by cabal init. For additional options,+-- see+-- http://www.haskell.org/cabal/release/cabal-latest/doc/users-guide/authors.html#pkg-descr.+-- The name of the package.+Name:                indents++-- The package version. See the Haskell package versioning policy+-- (http://www.haskell.org/haskellwiki/Package_versioning_policy) for+-- standards guiding when and how versions should be incremented.+Version:             0.1.0++-- A short (one-line) description of the package.+Synopsis:            indentation sensitive parser-combinators for parsec++-- A longer description of the package.+Description:         This library provides functions for use in parsing indentation sensitive contexts. It parses blocks of lines all indented to the same level as well as lines continued at an indented level below. ++-- URL for the project homepage or repository.+Homepage:            http://patch-tag.com/r/salazar/indents++-- The license under which the package is released.+License:             BSD3++-- The file containing the license text.+License-file:        LICENSE++-- The package author(s).+Author:              Sam Anklesaria++-- An email address to which users can send suggestions, bug reports,+-- and patches.+Maintainer:          amsay@amsay.net++-- A copyright notice.+-- Copyright:           ++Category:            Text++Build-type:          Simple++-- Extra files to be distributed with the package, such as examples or+-- a README.+-- Extra-source-files:  ++-- Constraint on the version of Cabal needed to build this package.+Cabal-version:       >=1.2+++Library+  -- Modules exported by the library.+  Exposed-modules:     Text.Parsec.Indent+  +  -- Packages needed in order to build this package.+  Build-depends: parsec >= 3 && < 4, concatenative < 2, mtl < 2, base < 4.3+  +  -- Modules not exported by this package.+  -- Other-modules:       +  +  -- Extra tools (e.g. alex, hsc2hs, ...) needed to build the source.+  -- Build-tools:         +