packages feed

language-rust 0.1.0.0 → 0.1.0.26

raw patch · 10 files changed

+55/−50 lines, 10 filesPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

Files

ChangeLog.md view
@@ -1,11 +1,11 @@ # Revision history for language-rust -## 0.1.0.0  -- YYYY-mm-dd+## 0.1.0.26  -- 2018-03-01 -* First version. Released on an unsuspecting world. * Parser module (using Alex and Happy)-* Pretty printing module (using Wadler's prettier)+* Pretty printing module * Resolving module for validating ASTs * Unit testsuite * Difference testsuite-* Benchmarks+* Allocation benchmarks+* Timing benchmarks
README.md view
@@ -2,8 +2,7 @@  `language-rust` aspires to efficiently and accurately parse and pretty print the [Rust language][0]. The underlying AST structures are also intended to be as similar as possible to the [`libsyntax` AST-`rustc`][10] uses itself. When `language-rust` and `rustc` have diverging AST, the divergence should-be detailed in the documentation.+that `rustc`][10] itself uses.  A typical use looks like: @@ -52,8 +51,10 @@  ## Evolution of Rust -As Rust evolves, so will `language-rust`. We will make a best effort to support unstable features-from nightly as they come out, but in general will only target compatibility with stable.+As Rust evolves, so will `language-rust`. A best effort will be made to support unstable features+from nightly as they come out, but only compatibility with stable is guaranteed. The last component+of the version number indicates the nightly Rust compiler version against which tests were run. For+example, `0.1.0.26` is tested against `rustc 1.26.0-nightly`.  ## Bugs @@ -62,7 +63,7 @@ ### Parser  Any difference between what is accepted by the `rustc` parser and the `language-rust` parser-indicates+indicates one of    * a bug in `language-rust` (this is almost always the case)   * a bug in `rustc`
dist/build/Language/Rust/Parser/Internal.hs view
@@ -16292,19 +16292,19 @@ -- | Parser for token trees. parseTt :: P TokenTree --- | Parser for token streams+-- | Parser for token streams. parseTokenStream :: P TokenStream --- | Parser for lifetime definitions+-- | Parser for lifetime definitions. parseLifetimeDef :: P (LifetimeDef Span) --- | Parser for a type parameter+-- | Parser for a type parameter. parseTyParam :: P (TyParam Span) --- | Parser for a where clause+-- | Parser for a where clause. parseWhereClause :: P (WhereClause Span) --- | Parser for generics (although 'WhereClause' is always empty here)+-- | Parser for generics (although 'WhereClause' is always empty here). parseGenerics :: P (Generics Span)  -- | Generate a nice looking error message based on expected tokens
language-rust.cabal view
@@ -1,5 +1,5 @@ name:                language-rust-version:             0.1.0.0+version:             0.1.0.26  synopsis:            Parsing and pretty printing of Rust code description:         Language Rust is a library for the analysis of Rust code. It includes a@@ -48,6 +48,7 @@                        Language.Rust.Parser                        Language.Rust.Parser.ParseMonad                        Language.Rust.Parser.Lexer+                       Language.Rust.Parser.Internal                        Language.Rust.Pretty                        Language.Rust.Pretty.Internal                        Language.Rust.Data.Position@@ -56,8 +57,7 @@   if flag(enableQuasiquotes)     exposed-modules:   Language.Rust.Quote  -  other-modules:       Language.Rust.Parser.Internal-                       Language.Rust.Parser.Literals+  other-modules:       Language.Rust.Parser.Literals                        Language.Rust.Parser.Reversed                        Language.Rust.Pretty.Resolve                        Language.Rust.Pretty.Literals
src/Language/Rust/Parser/Internal.y view
@@ -1744,19 +1744,19 @@ -- | Parser for token trees. parseTt :: P TokenTree --- | Parser for token streams+-- | Parser for token streams. parseTokenStream :: P TokenStream --- | Parser for lifetime definitions+-- | Parser for lifetime definitions. parseLifetimeDef :: P (LifetimeDef Span) --- | Parser for a type parameter+-- | Parser for a type parameter. parseTyParam :: P (TyParam Span) --- | Parser for a where clause+-- | Parser for a where clause. parseWhereClause :: P (WhereClause Span) --- | Parser for generics (although 'WhereClause' is always empty here)+-- | Parser for generics (although 'WhereClause' is always empty here). parseGenerics :: P (Generics Span)  -- | Generate a nice looking error message based on expected tokens
src/Language/Rust/Pretty.hs view
@@ -137,14 +137,14 @@  -- | Given a handle to a file, write a 'SourceFile' in with a desired width of 100 characters. ----- The 'Span' associated with the tokens (if present) will be used as a hint to for spacing--- out the tokens.+-- The 'Span' associated with the tokens (if present) will be used as a hint for laying out and+-- spacing the tokens. writeTokens :: Handle -> [Spanned Token] -> IO () writeTokens hdl = renderIO hdl . PP.layoutPretty layout . pretty' . Stream . map mkTT   where layout = PP.LayoutOptions (PP.AvailablePerLine 100 1.0)         mkTT (Spanned s t) = Tree (Token t s) --- | Describes things that can be pretty printed+-- | Describes things that can be pretty printed. class Pretty a where   -- | Pretty print the given value without resolving it.   prettyUnresolved :: a -> Doc b
src/Language/Rust/Pretty/Resolve.hs view
@@ -93,7 +93,7 @@ --  * See where attributes are not allowed --  * resolve in a better monad (`type ResolveM a = ReaderT [Doc] (Except ErrorType a)`) --- | Diagnostic for how severe an 'Issue' is +-- | Diagnostic for how severe an 'Issue' is. data Severity   = Clean      -- ^ Everything is normal (this variant is returned when there was nothing to resolve)   | Warning    -- ^ There is something fishy looking (AST is valid, but may not be what you expect)@@ -101,7 +101,7 @@   | Error      -- ^ The AST was invalid in some way that could not be automatically fixed   deriving (Eq, Ord, Enum, Bounded, Show) --- | Localized information about an issue in a syntax tree+-- | Localized information about an issue in a syntax tree. data Issue = Issue   { description :: String   -- ^ Description of the issue
src/Language/Rust/Quote.hs view
@@ -173,7 +173,7 @@ implItem :: QuasiQuoter implItem = quoter parseImplItem --- | Quasiquoter for trait item (see 'Language.Rust.Syntax.TraitItem')+-- | Quasiquoter for trait items (see 'Language.Rust.Syntax.TraitItem') -- -- >>> void [traitItem| type Item; |] -- TypeT [] "Item" [] Nothing ()
src/Language/Rust/Syntax/AST.hs view
@@ -113,6 +113,7 @@ import Data.Typeable                             ( Typeable )  import Data.Char                                 ( ord )+import Data.List                                 ( partition ) import Data.List.NonEmpty                        ( NonEmpty(..) ) import Data.Word                                 ( Word8 ) @@ -216,9 +217,10 @@   spanOf (Attribute _ _ _ s) = spanOf s   spanOf (SugaredDoc _ _ _ s) = spanOf s --- | Distinguishes between attributes that decorate what follows them and attributes that are--- describe the node that contains them (@syntax::ast::AttrStyle@). These two cases need to be--- distinguished only for pretty printing - they are otherwise fundamentally equivalent.+-- | Distinguishes between attributes that are associated with the node that follows them and+-- attributes that are associated with the node that contains them (@syntax::ast::AttrStyle@).+-- These two cases need to be distinguished only for pretty printing - they are otherwise+-- fundamentally equivalent. -- -- Example: @#[repr(C)]@ is an outer attribute while @#![feature(slice_patterns)]@ is an inner one data AttrStyle = Outer | Inner deriving (Eq, Ord, Enum, Bounded, Show, Typeable, Data, Generic, NFData)@@ -279,7 +281,7 @@ -- Example: @const@ in @const fn inc(x: i32) -> i32 { x + 1 }@ data Constness = Const | NotConst deriving (Eq, Ord, Enum, Bounded, Show, Typeable, Data, Generic, NFData) --- | 'ImplItem's can be marked @default@ (@syntax::ast::Defaultness@).  +-- | An 'ImplItem' can be marked @default@ (@syntax::ast::Defaultness@).   data Defaultness = Default | Final deriving (Eq, Ord, Enum, Bounded, Show, Typeable, Data, Generic, NFData)  -- | Expression (@syntax::ast::Expr@). Note that Rust pushes into expressions an unusual number@@ -364,7 +366,7 @@   | ParenExpr [Attribute a] (Expr a) a   -- | sugar for error handling with @Result@ (example: @parsed_result?@)   | Try [Attribute a] (Expr a) a-  -- | a @yield@ with an optional value to yielf (example: @yield 1@)+  -- | @yield@ with an optional value to yield (example: @yield 1@)   | Yield [Attribute a] (Maybe (Expr a)) a   deriving (Eq, Ord, Functor, Show, Typeable, Data, Generic, Generic1, NFData) @@ -468,8 +470,8 @@ -- traits, etc. (@syntax::ast::Generics@). Note that lifetime definitions are always required to be -- before the type parameters. ----- This one AST node is also a bit weird: it is the only node that whose source representation is--- not compact - the lifetimes and type parameters occur by themselves between @\<@ and @\>@ then a+-- This one AST node is also a bit weird: it is the only node whose source representation is not+-- compact - the lifetimes and type parameters occur by themselves between @\<@ and @\>@ then a -- bit further the where clause occurs after a @where@. -- -- Example: @\<\'a, \'b: \'c, T: \'a\>@ and @where Option\<T\>: Copy@ as in@@ -683,11 +685,11 @@   spanOf (Float _ _ s) = spanOf s   spanOf (Bool _ _ s) = spanOf s --- | Smart constructor for 'ByteStr'+-- | Smart constructor for 'ByteStr'. byteStr :: String -> StrStyle -> Suffix -> a -> Lit a byteStr s = ByteStr (map (fromIntegral . ord) s) --- | Extract the suffix from a 'Lit'+-- | Extract the suffix from a 'Lit'. suffix :: Lit a -> Suffix suffix (Str _ _ s _) = s suffix (ByteStr _ _ s _) = s@@ -697,8 +699,8 @@ suffix (Float _ s _) = s suffix (Bool _ s _) = s  --- | The base of the number in an @Int@ literal can be binary (like @0b1100@), octal (like @0o14@),--- decimal (like @12@), or hexadecimal (like @0xc@).+-- | The base of the number in an @Int@ literal can be binary (e.g. @0b1100@), octal (e.g. @0o14@),+-- decimal (e.g. @12@), or hexadecimal (e.g. @0xc@). data IntRep = Bin | Oct | Dec | Hex deriving (Eq, Ord, Show, Enum, Bounded, Typeable, Data, Generic, NFData)  -- | Represents a macro invocation (@syntax::ast::Mac@). The 'Path' indicates which macro is being@@ -886,8 +888,8 @@  instance Located a => Located (StructField a) where spanOf (StructField _ _ _ _ s) = spanOf s --- | An abstract sequence of tokens, organized into a sequence (e.g. stream) of 'TokenTree's, which--- are themselves a single 'Token' or a 'Delimited' subsequence of tokens.+-- | An abstract sequence of tokens, organized into a sequence (e.g. stream) of 'TokenTree', each of+-- which is a single 'Token' or a 'Delimited' subsequence of tokens. data TokenStream   = Tree TokenTree              -- ^ a single token or a single set of delimited tokens   | Stream [TokenStream]        -- ^ stream of streams of tokens@@ -910,7 +912,7 @@  -- | When the parser encounters a macro call, it parses what follows as a 'Delimited' token tree. -- Basically, token trees let you store raw tokens or 'Sequence' forms inside of balanced--- parens or braces or brackets. This is a very loose structure, such that all sorts of different+-- parens, braces, or brackets. This is a very loose structure, such that all sorts of different -- AST-fragments can be passed to syntax extensions using a uniform type. data TokenTree   -- | A single token@@ -978,7 +980,7 @@  -- | Types (@syntax::ast::Ty@). data Ty a-  -- | variable-length slice (example: @[T]@)+  -- | variable length slice (example: @[T]@)   = Slice (Ty a) a   -- | fixed length array (example: @[T; n]@)   | Array (Ty a) (Expr a) a@@ -1026,7 +1028,7 @@   spanOf (Infer s) = spanOf s   spanOf (MacTy _ s) = spanOf s --- | type parameter definition used in 'Generics' (@syntax::ast::TyParam@). Note that each+-- | Type parameter definition used in 'Generics' (@syntax::ast::TyParam@). Note that each -- parameter can have any number of (lifetime or trait) bounds, as well as possibly a default type. data TyParam a = TyParam [Attribute a] Ident [TyParamBound a] (Maybe (Ty a)) a    deriving (Eq, Ord, Functor, Show, Typeable, Data, Generic, Generic1, NFData)@@ -1044,11 +1046,13 @@   spanOf (TraitTyParamBound _ _ s) = spanOf s   spanOf (RegionTyParamBound _ s) = spanOf s --- | Partion a list of 'TyParamBound' into a tuple of the 'TraitTyParamBound' and 'RegionTyParamBound' variants.+-- | Partition a list of 'TyParamBound' into a tuple of the 'TraitTyParamBound' and+-- 'RegionTyParamBound' variants. partitionTyParamBounds :: [TyParamBound a] -> ([TyParamBound a], [TyParamBound a])-partitionTyParamBounds [] = ([],[])-partitionTyParamBounds (tpb@TraitTyParamBound{} : ts) = let ~(tpbs,rpbs) = partitionTyParamBounds ts in (tpb:tpbs,rpbs)-partitionTyParamBounds (rpb@RegionTyParamBound{} : ts) = let ~(tpbs,rpbs) = partitionTyParamBounds ts in (tpbs,rpb:rpbs)+partitionTyParamBounds = partition isTraitBound+  where+    isTraitBound TraitTyParamBound{} = True+    isTraitBound RegionTyParamBound{} = False  -- | Unary operators, used in the 'Unary' constructor of 'Expr' (@syntax::ast::UnOp@). --
src/Language/Rust/Syntax/Token.hs view
@@ -119,7 +119,7 @@   deriving (Eq, Ord, Show, Enum, Bounded, Data, Typeable, Generic, NFData)  -- TODO: BANISH NoDelim! (or rather: distinguish DelimToken from Delim, as rustc does)--- | A delimiter token (@syntax::parse::token::DelimToken@)+-- | A delimiter token (@syntax::parse::token::DelimToken@). data Delim   = Paren   -- ^ round parenthesis: @(@ or @)@   | Bracket -- ^ square bracket: @[@ or @]@@@ -140,7 +140,7 @@   deriving (Eq, Ord, Show, Data, Typeable, Generic, NFData)  --- | Check whether a space is needed between two tokens to avoid confusion+-- | Check whether a space is needed between two tokens to avoid confusion. spaceNeeded :: Token -> Token -> Bool -- conflicts with 'GreaterEqual' spaceNeeded Greater Equal = True