packages feed

language-python 0.2 → 0.3.0

raw patch · 9 files changed

+43/−31 lines, 9 filesdep ~arraydep ~basedep ~containers

Dependency ranges changed: array, base, containers, monads-tf, pretty, transformers

Files

LICENSE view
@@ -1,4 +1,4 @@-Copyright (c) 2008-2009 Bernard James Pope +Copyright (c) 2009-2010 Bernard James Pope (also known as Bernie Pope).  All rights reserved. 
language-python.cabal view
@@ -1,16 +1,16 @@ name:                language-python-version:             0.2-cabal-version:       >= 1.2+version:             0.3.0+cabal-version:       >= 1.6 synopsis:            Parsing and pretty printing of Python code.  description:         language-python is a Haskell library for lexical analysis, parsing                       and pretty printing Python code. It supports versions 2.x and 3.x of Python.  category:            Language license:             BSD3 license-file:        LICENSE-copyright:           (c) 2008-2009 Bernard James Pope-author:              Bernard James Pope -maintainer:          bjpop@csse.unimelb.edu.au-homepage:            http://projects.haskell.org/language-python/+copyright:           (c) 2008-2010 Bernard James Pope+author:              Bernard James Pope (Bernie Pope)+maintainer:          florbitous@gmail.com+homepage:            http://github.com/bjpop/language-python  build-depends:       base build-type:          Simple stability:           experimental@@ -19,7 +19,8 @@  Library    hs-source-dirs:   src-   build-depends:    base >= 4 && < 5, containers, pretty, array, transformers, monads-tf+   build-depends:    base == 4.*, containers == 0.2.*, pretty == 1.0.*, array == 0.2.*, transformers == 0.2.*, +                     monads-tf == 0.1.*    build-tools:      happy, alex    exposed-modules:       Language.Python.Common@@ -27,6 +28,7 @@       Language.Python.Common.SrcLocation       Language.Python.Common.Pretty       Language.Python.Common.Token+      Language.Python.Common.ParserMonad       Language.Python.Common.PrettyToken       Language.Python.Common.AST       Language.Python.Common.PrettyAST@@ -39,7 +41,6 @@       Language.Python.Common.PrettyParseError       Language.Python.Common.StringEscape    other-modules:-      Language.Python.Common.ParserMonad       Language.Python.Common.ParserUtils       Language.Python.Common.LexerUtils       Language.Python.Version3.Parser.Parser
src/Language/Python/Common/AST.hs view
@@ -590,7 +590,7 @@      , expr_annot :: annot      }    -- | Subscription, for example \'x [y]\'. -   | Subscript { subscriptee :: Expr annot, subscript_exprs :: [Expr annot], expr_annot :: annot }+   | Subscript { subscriptee :: Expr annot, subscript_expr :: Expr annot, expr_annot :: annot }    -- | Slicing, for example \'w [x:y:z]\'.     | SlicedExpr { slicee :: Expr annot, slices :: [Slice annot], expr_annot :: annot }     -- | Conditional expresison. 
src/Language/Python/Common/LexerUtils.hs view
@@ -47,7 +47,8 @@ dedentation :: P Token -> Action dedentation lexToken span _len _str = do    topIndent <- getIndent-   case compare (endCol span) topIndent of+   -- case compare (endCol span) topIndent of+   case compare (startCol span) topIndent of       EQ -> do popStartCode                lexToken        LT -> do popIndent@@ -69,16 +70,18 @@       then lexToken       else do           topIndent <- getIndent-         case compare (endCol span) topIndent of+         -- case compare (endCol span) topIndent of+         case compare (startCol span) topIndent of             EQ -> case bo of                      BOF -> lexToken                      BOL -> newlineToken                LT -> do pushStartCode dedentCode                       newlineToken -            GT -> do pushIndent (endCol span)-                     return indentToken +            -- GT -> do pushIndent (endCol span)+            GT -> do pushIndent (startCol span)+                     return indentToken    where-   indentToken = IndentToken span +   indentToken = IndentToken span  symbolToken :: (SrcSpan -> Token) -> Action  symbolToken mkToken location _ _ = return (mkToken location)
src/Language/Python/Common/ParserMonad.hs view
@@ -74,6 +74,7 @@    , lastEOL :: !SrcSpan      -- location of the most recent end-of-line encountered    , comments :: [Token]      -- accumulated comments     }+   deriving Show  initToken :: Token initToken = NewlineToken SpanEmpty 
src/Language/Python/Common/ParserUtils.hs view
@@ -44,7 +44,7 @@   getSpan = trailer_span  data Subscript-   = SubscriptExpr { subscript_expr :: ExprSpan, subscript_span :: SrcSpan }+   = SubscriptExpr { subscription :: ExprSpan, subscript_span :: SrcSpan }    | SubscriptSlice       { subscript_slice_span1 :: Maybe ExprSpan      , subscript_slice_span2 :: Maybe ExprSpan@@ -69,11 +69,15 @@    = SliceEllipsis span  subscriptToExpr :: Subscript -> ExprSpan-subscriptToExpr sub@(SubscriptExpr {}) = subscript_expr sub --- this should never happen:-subscriptToExpr (SubscriptSlice {}) -   = error "subscriptToExpr applied to a proper slice"+subscriptToExpr (SubscriptExpr { subscription = s }) = s+subscriptToExpr other = error "subscriptToExpr applied to non subscript" +subscriptsToExpr :: [Subscript] -> ExprSpan+subscriptsToExpr subs+   | length subs > 1 = Tuple (map subscriptToExpr subs) (getSpan subs)+   | length subs == 1 = subscriptToExpr $ head subs+   | otherwise = error "subscriptsToExpr: empty subscript list"+ {-    = TrailerCall { trailer_call_args :: [ArgumentSpan], trailer_span :: SrcSpan }    | TrailerSubscript { trailer_subs :: [Subscript], trailer_span :: SrcSpan }@@ -91,7 +95,7 @@       | any isProperSlice subs            = SlicedExpr e (map subscriptToSlice subs) (spanning e trail)        | otherwise -           = Subscript e (map subscriptToExpr subs) (spanning e trail) +           = Subscript e (subscriptsToExpr subs) (spanning e trail)     trail e trail@(TrailerDot { trailer_dot_ident = ident, dot_span = ds })       = BinaryOp (AST.Dot ds) e (Var ident (getSpan ident)) (spanning e trail) 
src/Language/Python/Common/PrettyAST.hs view
@@ -223,8 +223,8 @@    pretty (ByteStrings { byte_string_strings = bs }) = hcat (map pretty bs)    pretty (Strings { strings_strings = ss }) = hcat (map prettyString ss)    pretty (Call { call_fun = f, call_args = args }) = pretty f <> prettyParenList args-   pretty (Subscript { subscriptee = e, subscript_exprs = subs })-      = pretty e <> brackets (commaList subs)+   pretty (Subscript { subscriptee = e, subscript_expr = sub })+      = pretty e <> brackets (pretty sub)    pretty (SlicedExpr { slicee = e, slices = ss })       = pretty e <> brackets (commaList ss)     pretty (CondExpr { ce_true_branch = trueBranch, ce_condition = cond, ce_false_branch = falseBranch })
src/Language/Python/Common/SrcLocation.hs view
@@ -185,7 +185,7 @@ mkSrcSpan _ NoLocation = SpanEmpty  mkSrcSpan loc1 loc2   | line1 == line2 = -       if col1 == col2+       if col2 <= col1            then SpanPoint file line1 col1           else SpanCoLinear file line1 col1 col2   | otherwise = 
src/Language/Python/Version3/Lexer.hs view
@@ -15,7 +15,9 @@ module Language.Python.Version3.Lexer (    -- * Lexical analysis    lex, -   lexOneToken) where+   lexOneToken,+   lexer,+   initLexState ) where  import Prelude hiding (lex) import Language.Python.Version3.Parser.Lexer (lexToken, initStartCodeStack)@@ -24,15 +26,16 @@ import Language.Python.Common.ParserMonad         (ParseState (input), P, runParser, execParser, ParseError, initialState) +initLexState :: String -> String -> ParseState+initLexState input srcName = +   initialState (initialSrcLocation srcName) input initStartCodeStack+ -- | Parse a string into a list of Python Tokens, or return an error.  lex :: String -- ^ The input stream (python source code).      -> String -- ^ The name of the python source (filename or input device).     -> Either ParseError [Token] -- ^ An error or a list of tokens. lex input srcName =-   execParser lexer state-   where-   initLoc = initialSrcLocation srcName-   state = initialState initLoc input initStartCodeStack+   execParser lexer $ initLexState input srcName  -- | Try to lex the first token in an input string. Return either a parse error -- or a pair containing the next token and the rest of the input after the token.@@ -44,9 +47,9 @@       Left err -> Left err       Right (tok, state) -> Right (tok, input state)    where-   initLoc = initialSrcLocation srcName-   state = initialState initLoc source initStartCodeStack+   state = initLexState source srcName  +-- | Lex a sequence of tokens. lexer :: P [Token] lexer = loop []    where