Permalink
Browse files

namespace BrownPLT

  • Loading branch information...
1 parent 83366e5 commit 1e6e526eacc342458dc694abaaca8a91b0edc1ae Arjun Guha committed Apr 3, 2009
View
@@ -16,16 +16,16 @@ Description:
WebBits is a collection of libraries for working with JavaScript embeded in
HTML files. Highlights include:
.
- * @WebBits.JavaScript.Crawl@ returns all JavaScript in an HTML page, including
+ * @BrownPLT.JavaScript.Crawl@ returns all JavaScript in an HTML page, including
JavaScript from imported script files (@\<script src=...\>@).
.
- * @WebBits.JavaScript.Env@ annotates JavaScript syntax with its static
+ * @BrownPLT.JavaScript.Env@ annotates JavaScript syntax with its static
environment and returns a list of free identifiers.
.
- * @WebBits.JavaScript.Parser@ is a JavaScript parser that is largely based on
+ * @BrownPLT.JavaScript.Parser@ is a JavaScript parser that is largely based on
JavaScript 1.5.
.
- * @WebBits.Html.Parser@ is a permissive HTML parser.
+ * @BrownPLT.Html.Parser@ is a permissive HTML parser.
Library
Hs-Source-Dirs:
@@ -37,20 +37,20 @@ Library
Extensions:
Generics TypeSynonymInstances DeriveDataTypeable
Exposed-Modules:
- WebBits.Html.Html
- WebBits.Html.Syntax
- WebBits.Html.PermissiveParser
- WebBits.Html.PrettyPrint
- WebBits.Html.Instances
- WebBits.Common
- WebBits.Html.RawScript
- WebBits.JavaScript.Combinators
- WebBits.JavaScript.HtmlEmbedding
- WebBits.JavaScript.Instances
- WebBits.JavaScript
- WebBits.JavaScript.Lexer
- WebBits.JavaScript.Parser
- WebBits.JavaScript.PrettyPrint
- WebBits.JavaScript.Syntax
- WebBits.JavaScript.Crawl
- WebBits.JavaScript.Environment
+ BrownPLT.Html.Html
+ BrownPLT.Html.Syntax
+ BrownPLT.Html.PermissiveParser
+ BrownPLT.Html.PrettyPrint
+ BrownPLT.Html.Instances
+ BrownPLT.Common
+ BrownPLT.Html.RawScript
+ BrownPLT.JavaScript.Combinators
+ BrownPLT.JavaScript.HtmlEmbedding
+ BrownPLT.JavaScript.Instances
+ BrownPLT.JavaScript
+ BrownPLT.JavaScript.Lexer
+ BrownPLT.JavaScript.Parser
+ BrownPLT.JavaScript.PrettyPrint
+ BrownPLT.JavaScript.Syntax
+ BrownPLT.JavaScript.Crawl
+ BrownPLT.JavaScript.Environment
@@ -1,5 +1,5 @@
-- | Defines commonly used datatypes and functions.
-module WebBits.Common
+module BrownPLT.Common
( PrettyPrintable(..)
, L.isPrefixOf
, initialPos
@@ -23,7 +23,7 @@ import qualified Data.Traversable as Traversable
import Data.Traversable (Traversable, traverse)
import qualified Text.PrettyPrint.HughesPJ as Pp
import Text.ParserCombinators.Parsec.Pos (SourcePos, initialPos, sourceName)
-import WebBits.JavaScript.Syntax
+import BrownPLT.JavaScript.Syntax
-- |For generics, this type cannot be quantified.
isNotFuncExpr :: Expression SourcePos -> Bool
@@ -0,0 +1,14 @@
+-- |Rexports various modules of the HTML library. It's best to use this in lieu
+-- of selectively importing the following libraries.
+module BrownPLT.Html.Html
+ ( module BrownPLT.Html.Syntax
+ -- PermissiveParser
+ , html
+ , parseHtmlFromFile
+ , parseHtmlFromString
+ ) where
+
+import BrownPLT.Html.Syntax
+import BrownPLT.Html.PermissiveParser
+import BrownPLT.Html.PrettyPrint -- no names, only instances
+import BrownPLT.Html.Instances -- no names, only instances
@@ -1,4 +1,4 @@
-module WebBits.Html.Instances() where
+module BrownPLT.Html.Instances() where
import qualified Prelude as Prelude
import Prelude (Functor,map,fmap)
@@ -8,7 +8,7 @@ import Data.Foldable
import Data.Traversable
import Control.Applicative
-import WebBits.Html.Syntax
+import BrownPLT.Html.Syntax
ltraverse:: (Traversable t, Applicative f) => (a -> f b) -> [t a] -> f [t b]
ltraverse f [] = pure []
@@ -11,7 +11,7 @@
-- merchantability or fitness for a particular purpose. See
-- <http://www.gnu.org/copyleft/lesser.html> for details. For other license
-- options and consulting, contact the author.
-module WebBits.Html.PermissiveParser
+module BrownPLT.Html.PermissiveParser
( html
, parseHtmlFromFile
, parseHtmlFromString
@@ -26,8 +26,8 @@ import qualified Text.ParserCombinators.Parsec as Parsec
import Data.Char (toLower)
import Data.List (intersperse)
-import qualified WebBits.Html.Syntax as Html
-import WebBits.Html.Syntax (HtmlId,Attribute,Script(..))
+import qualified BrownPLT.Html.Syntax as Html
+import BrownPLT.Html.Syntax (HtmlId,Attribute,Script(..))
type ParsedHtml s = Html.Html SourcePos s
type ParsedAttribute s = Html.Attribute SourcePos s
@@ -1,16 +1,16 @@
-- |Pretty-printer for HTML. This modules exports no names. It only defines
-- instances of 'PrettyPrintable' for HTML.
-module WebBits.Html.PrettyPrint
+module BrownPLT.Html.PrettyPrint
( -- this module exports no names
) where
import qualified Data.List as List
import qualified Data.Char as Char
import Text.PrettyPrint.HughesPJ
-import WebBits.Common (PrettyPrintable(..))
+import BrownPLT.Common (PrettyPrintable(..))
-import WebBits.Html.Syntax
+import BrownPLT.Html.Syntax
vert [] = empty
vert [doc] = doc
@@ -1,4 +1,4 @@
-module WebBits.Html.RawScript
+module BrownPLT.Html.RawScript
( RawScript (..)
, parseFromFile
, parseFromString
@@ -9,8 +9,8 @@ import Data.Generics (Data)
import Data.Generics (Typeable)
import Text.PrettyPrint.HughesPJ (text)
import Text.ParserCombinators.Parsec
-import WebBits.Common
-import WebBits.Html.Html
+import BrownPLT.Common
+import BrownPLT.Html.Html
type RawHtml = Html SourcePos RawScript
@@ -1,84 +1,84 @@
--- |Datatypes for HTML parameterized over an annotation type and a script type.
-module WebBits.Html.Syntax (
- -- * HTML Data Structures
- HtmlId,AttributeValue,Attribute(..),Html(..)
- -- * The Script class
- , Script(..)
- -- * Miscellaneous Functions
- , attributeValue,attributeUpdate,attributeSet,isAttributeExpr
- ) where
-
-import Text.ParserCombinators.Parsec(CharParser,SourcePos)
-import Data.Generics(Data)
-import Data.Typeable(Typeable)
-
---------------------------------------------------------------------------------
--- Types
-
-type HtmlId = String
-type AttributeValue = String
-
-data Attribute a s
- = Attribute HtmlId AttributeValue a
- | AttributeExpr a HtmlId s String
- deriving (Show,Eq,Typeable,Data)
-
-data Html a sc
- = Element HtmlId [Attribute a sc] [Html a sc] a
- | Text String a
- | Comment String a
- | HtmlSeq [Html a sc] -- ^must be a non-empty list
- | ProcessingInstruction String a
- | InlineScript sc a String
- | Script sc a
- deriving (Show,Eq,Typeable,Data)
-
---------------------------------------------------------------------------------
--- The Script class
-
--- |A type 't' of the 'Script' class can be parsed using 'Parsec'. 't' is of
--- kind '* -> *', as the parsed AST should be annotated with souce locations
--- (see 'Text.ParserCombinators.Parsec.SourcePos').
---
--- The big deal here is that we can embed a parser for some scripting language,
--- (e.g. Javascript) into this HTML parser with ease, while preserving source
--- locations. The Html datatype is parameterized over a script parser (an
--- instance of Script).
-class Script t where
- parseScriptBlock:: [Attribute SourcePos t] -> CharParser a t
- -- An inline script parser, which may be Nothing if the scripting language
- -- does not support inline scripts.
- parseInlineScript:: Maybe (CharParser a t)
- -- A parser for script-expressions defined inline as attribute values.
- parseAttributeScript:: Maybe (CharParser a t)
-
---------------------------------------------------------------------------------
--- HTML navigation
-
-isAttributeExpr (AttributeExpr _ _ _ _) = True
-isAttributeExpr _ = False
-
--- |Returns the value of the attribute in the list, or 'Nothing' if it doesn't
--- exist of the value is an inline-expression.
-attributeValue:: HtmlId -> [Attribute a s] -> Maybe String
-attributeValue name [] = Nothing
-attributeValue name ((AttributeExpr pos name' expr init):rest) =
- if name == name' then Nothing
- else attributeValue name rest
-attributeValue name ((Attribute name' value _):rest) =
- if name == name' then Just value
- else attributeValue name rest
-
-attributeSet:: HtmlId -> String -> [Attribute a s] -> [Attribute a s]
-attributeSet n v attrs = attributeUpdate n (\_ -> v) attrs
-
-attributeUpdate:: HtmlId -> (String -> String) -> [Attribute a s]
- -> [Attribute a s]
-attributeUpdate n f [] =
- [Attribute n (f "") (error "attributeUpdate--no value")] -- TODO: undefined?!
-attributeUpdate n _ ((AttributeExpr _ _ _ _):_) =
- error $ "attributeUpdate: " ++ n ++ " is an expression-attribute."
-attributeUpdate n f ((Attribute n' v p):attrs) =
- if n' == n then (Attribute n (f v) p):attrs
- else (Attribute n' v p):(attributeUpdate n f attrs)
-
+-- |Datatypes for HTML parameterized over an annotation type and a script type.
+module BrownPLT.Html.Syntax (
+ -- * HTML Data Structures
+ HtmlId,AttributeValue,Attribute(..),Html(..)
+ -- * The Script class
+ , Script(..)
+ -- * Miscellaneous Functions
+ , attributeValue,attributeUpdate,attributeSet,isAttributeExpr
+ ) where
+
+import Text.ParserCombinators.Parsec(CharParser,SourcePos)
+import Data.Generics(Data)
+import Data.Typeable(Typeable)
+
+--------------------------------------------------------------------------------
+-- Types
+
+type HtmlId = String
+type AttributeValue = String
+
+data Attribute a s
+ = Attribute HtmlId AttributeValue a
+ | AttributeExpr a HtmlId s String
+ deriving (Show,Eq,Typeable,Data)
+
+data Html a sc
+ = Element HtmlId [Attribute a sc] [Html a sc] a
+ | Text String a
+ | Comment String a
+ | HtmlSeq [Html a sc] -- ^must be a non-empty list
+ | ProcessingInstruction String a
+ | InlineScript sc a String
+ | Script sc a
+ deriving (Show,Eq,Typeable,Data)
+
+--------------------------------------------------------------------------------
+-- The Script class
+
+-- |A type 't' of the 'Script' class can be parsed using 'Parsec'. 't' is of
+-- kind '* -> *', as the parsed AST should be annotated with souce locations
+-- (see 'Text.ParserCombinators.Parsec.SourcePos').
+--
+-- The big deal here is that we can embed a parser for some scripting language,
+-- (e.g. Javascript) into this HTML parser with ease, while preserving source
+-- locations. The Html datatype is parameterized over a script parser (an
+-- instance of Script).
+class Script t where
+ parseScriptBlock:: [Attribute SourcePos t] -> CharParser a t
+ -- An inline script parser, which may be Nothing if the scripting language
+ -- does not support inline scripts.
+ parseInlineScript:: Maybe (CharParser a t)
+ -- A parser for script-expressions defined inline as attribute values.
+ parseAttributeScript:: Maybe (CharParser a t)
+
+--------------------------------------------------------------------------------
+-- HTML navigation
+
+isAttributeExpr (AttributeExpr _ _ _ _) = True
+isAttributeExpr _ = False
+
+-- |Returns the value of the attribute in the list, or 'Nothing' if it doesn't
+-- exist of the value is an inline-expression.
+attributeValue:: HtmlId -> [Attribute a s] -> Maybe String
+attributeValue name [] = Nothing
+attributeValue name ((AttributeExpr pos name' expr init):rest) =
+ if name == name' then Nothing
+ else attributeValue name rest
+attributeValue name ((Attribute name' value _):rest) =
+ if name == name' then Just value
+ else attributeValue name rest
+
+attributeSet:: HtmlId -> String -> [Attribute a s] -> [Attribute a s]
+attributeSet n v attrs = attributeUpdate n (\_ -> v) attrs
+
+attributeUpdate:: HtmlId -> (String -> String) -> [Attribute a s]
+ -> [Attribute a s]
+attributeUpdate n f [] =
+ [Attribute n (f "") (error "attributeUpdate--no value")] -- TODO: undefined?!
+attributeUpdate n _ ((AttributeExpr _ _ _ _):_) =
+ error $ "attributeUpdate: " ++ n ++ " is an expression-attribute."
+attributeUpdate n f ((Attribute n' v p):attrs) =
+ if n' == n then (Attribute n (f v) p):attrs
+ else (Attribute n' v p):(attributeUpdate n f attrs)
+
@@ -0,0 +1,19 @@
+-- |Re-exports commonly used modules.
+module BrownPLT.JavaScript
+ ( module BrownPLT.JavaScript.Syntax
+ , module BrownPLT.JavaScript.HtmlEmbedding
+ , module BrownPLT.JavaScript.Parser
+ , module BrownPLT.JavaScript.Combinators
+ , module BrownPLT.Common
+ -- JavaScript.Instances exports nothing
+ ) where
+
+import BrownPLT.Common
+
+import BrownPLT.JavaScript.Syntax
+import BrownPLT.JavaScript.Parser
+import BrownPLT.JavaScript.PrettyPrint
+import BrownPLT.JavaScript.HtmlEmbedding
+import BrownPLT.JavaScript.Combinators
+
+import BrownPLT.JavaScript.Instances
@@ -1,4 +1,4 @@
-module WebBits.JavaScript.Combinators
+module BrownPLT.JavaScript.Combinators
( scriptStatements
, isParenExpr
, syntaxAt
@@ -10,9 +10,9 @@ import Data.Generics (Data,Typeable, everything, mkQ)
import Text.ParserCombinators.Parsec (SourcePos)
import qualified Data.Foldable as F
import Data.Foldable (Foldable)
-import WebBits.JavaScript.Syntax
-import WebBits.JavaScript.Instances ()
-import WebBits.Common ()
+import BrownPLT.JavaScript.Syntax
+import BrownPLT.JavaScript.Instances ()
+import BrownPLT.Common ()
scriptStatements:: JavaScript a -> [Statement a]
scriptStatements (Script _ ss) = ss
@@ -1,17 +1,17 @@
-- |Crawls an HTML page for JavaScript
-module WebBits.JavaScript.Crawl
+module BrownPLT.JavaScript.Crawl
( getPageJavaScript
) where
-import WebBits.Common
+import BrownPLT.Common
import Control.Monad
import Data.Char (toLower)
import Data.Generics
import System.IO
import Text.ParserCombinators.Parsec(parse,setPosition,incSourceColumn,Column,sourceLine,sourceColumn)
-import WebBits.Html.Syntax
-import qualified WebBits.JavaScript as Js
+import BrownPLT.Html.Syntax
+import qualified BrownPLT.JavaScript as Js
-- |Returns the source of the script.
scriptSrc:: Js.ParsedJsHtml -> [String]
Oops, something went wrong.

0 comments on commit 1e6e526

Please sign in to comment.