packages feed

GroteTrap 0.2 → 0.3

raw patch · 5 files changed

+16/−8 lines, 5 filesdep ~parsecPVP ok

version bump matches the API change (PVP)

Dependency ranges changed: parsec

API changes (from Hackage documentation)

+ Language.GroteTrap.Language: language :: Language a
- Language.GroteTrap.Language: number :: Language a -> (Int -> a)
+ Language.GroteTrap.Language: number :: Language a -> Int -> a
- Language.GroteTrap.Language: variable :: Language a -> (String -> a)
+ Language.GroteTrap.Language: variable :: Language a -> String -> a

Files

GroteTrap.cabal view
@@ -1,5 +1,5 @@ Name:           GroteTrap-Version:        0.2+Version:        0.3 Synopsis:       GroteTrap Description:    Allows quick definition of expression languages. You get a parser for free, as well as conversion from text selection to tree selection and back. @@ -14,7 +14,7 @@ Build-type:     Simple  Library-  Build-Depends:    base, QuickCheck, parsec, mtl+  Build-Depends:    base, QuickCheck, parsec <= 2.1.0.0, mtl   Exposed-Modules:  Language.GroteTrap.Range                     Language.GroteTrap.Trees                     Language.GroteTrap.Language
Language/GroteTrap/Language.hs view
@@ -2,7 +2,7 @@ module Language.GroteTrap.Language (    -- * Language-  Language(..),+  Language(..), language,      -- * Operators   Operator(..),@@ -25,12 +25,20 @@  -- | Language connects the syntax of identifiers, numbers, operators and functions with their semantics. GroteTrap is able to derive a parser and evaluator from a Language, as well as convert between source text selections and tree selections. data Language a  =   Language-  { variable     ::  (String -> a)-  , number       ::  (Int -> a)+  { variable     ::  String -> a+  , number       ::  Int -> a   , operators    ::  [Operator a]   , functions    ::  [Function a]   } +-- | An empty language. Use this as the starting base of your languages, setting only those fields that are of importance.+language :: Language a+language = Language+  { variable    = error "variables are not supported"+  , number      = error "numbers are not supported"+  , operators   = []+  , functions   = []+  }  ------------------------------------ -- Operators
Language/GroteTrap/Lexer.hs view
@@ -33,7 +33,7 @@  type TokenPos = (Pos, Token) --- | When giver a language, transforms a list of characters into a list of tokens.+-- | When given a language, transforms a list of characters into a list of tokens. tokenize :: Language a -> Parser [TokenPos] tokenize = many . pToken 
Language/GroteTrap/Parser.hs view
@@ -34,7 +34,7 @@  -- | Given a language and a string, parses and evaluates the string. readExpression :: Language a -> String -> a-readExpression lang = evaluate lang . resultOf . parseSentence lang+readExpression lang = evaluate lang . readParseTree lang  combine :: Parser [TokenPos] -> GenParser TokenPos () c -> String -> Either ParseError c combine p1 p2 input = case runParser p1 () "characters" input of
Language/GroteTrap/Trees.hs view
@@ -155,7 +155,7 @@  -- | Selects part of a tree. select :: (Monad m, Tree t) => t -> TreeSelection -> m [t]-select t (path, offset) = (sequence . map (followM t) . take offset . iterate right) path+select t (path, offset) = (sequence . map (followM t) . take (offset + 1) . iterate right) path  -- | Computes the range of a valid selection. selectionToRange :: (Tree a, KnowsPosition a) => a -> TreeSelection -> Range