-- Hoogle documentation, generated by Haddock
-- See Hoogle, http://www.haskell.org/hoogle/
-- | Yi editor javascript mode
--
-- Yi editor javascript mode
@package yi-mode-javascript
@version 0.16.0
module Yi.Lexer.JavaScript
initState :: HlState
-- | Scan one token. Return (maybe) a token and a new state.
alexScanToken :: (AlexState HlState, AlexInput) -> Maybe (Tok Token, (AlexState HlState, AlexInput))
-- | Takes a Token and returns a style to be used for that type of
-- token.
--
-- TODO: The elem check is potentially unnecessarily slow. We
-- could split the Const constructor into two different ones, one for
-- builtins and one for others.
tokenToStyle :: Token -> UIStyle -> Style
type TT = Tok Token
-- | The different tokens.
data Token
Unknown :: Token
Res :: !Reserved -> Token
Str :: !String -> Token
Rex :: !String -> Token
Op :: !Operator -> Token
Special :: !Char -> Token
Number :: !String -> Token
ValidName :: !String -> Token
Comment :: !CommentType -> Token
Const :: !String -> Token
-- | The constructors for Reserved have an apostrophe as a suffix
-- because Default is already used. Also note that
-- Undefined' is not intended as some sort of "backup" reserved
-- word for things we don't care about -- it really means the "undefined"
-- built-in in JavaScript.
data Reserved
Break' :: Reserved
Case' :: Reserved
Catch' :: Reserved
Continue' :: Reserved
Default' :: Reserved
Delete' :: Reserved
Do' :: Reserved
Else' :: Reserved
Finally' :: Reserved
For' :: Reserved
Function' :: Reserved
If' :: Reserved
In' :: Reserved
InstanceOf' :: Reserved
New' :: Reserved
Return' :: Reserved
Switch' :: Reserved
This' :: Reserved
Throw' :: Reserved
Try' :: Reserved
TypeOf' :: Reserved
Var' :: Reserved
Void' :: Reserved
While' :: Reserved
With' :: Reserved
True' :: Reserved
False' :: Reserved
Null' :: Reserved
Undefined' :: Reserved
-- | The constructors for Operator have an apostrophe as a suffix
-- because e.g. LT is already used by Prelude.
data Operator
Add' :: Operator
Subtract' :: Operator
Multiply' :: Operator
Divide' :: Operator
Modulo' :: Operator
Increment' :: Operator
Decrement' :: Operator
Assign' :: Operator
AddAssign' :: Operator
SubtractAssign' :: Operator
MultiplyAssign' :: Operator
DivideAssign' :: Operator
ModuloAssign' :: Operator
Equals' :: Operator
NotEquals' :: Operator
GT' :: Operator
GTE' :: Operator
LT' :: Operator
LTE' :: Operator
EqualsType' :: Operator
NotEqualsType' :: Operator
And' :: Operator
Or' :: Operator
Not' :: Operator
BitAnd' :: Operator
BitOr' :: Operator
BitXor' :: Operator
LeftShift' :: Operator
RightShift' :: Operator
RightShiftZ' :: Operator
BitNot' :: Operator
Qualify' :: Operator
-- | HlState is 0 when outside of a multi-line comment and -1 when
-- inside one.
type HlState = Int
-- | Prefix operators. NOTE: Add' is also a valid prefix operator, but
-- since it's completely useless in the real world, we don't care about
-- it here. Doing this makes parsing much, much easier.
prefixOperators :: [Operator]
-- | Infix operators.
infixOperators :: [Operator]
-- | Postfix operators.
postfixOperators :: [Operator]
instance GHC.Classes.Eq Yi.Lexer.JavaScript.Token
instance GHC.Show.Show Yi.Lexer.JavaScript.Token
instance GHC.Classes.Eq Yi.Lexer.JavaScript.Operator
instance GHC.Show.Show Yi.Lexer.JavaScript.Operator
instance GHC.Classes.Eq Yi.Lexer.JavaScript.Reserved
instance GHC.Show.Show Yi.Lexer.JavaScript.Reserved
instance GHC.Classes.Eq Yi.Lexer.JavaScript.CommentType
instance GHC.Show.Show Yi.Lexer.JavaScript.CommentType
instance GHC.Base.Functor Yi.Lexer.JavaScript.AlexLastAcc
-- | Parser for the JavaScript language as described at Dogan 2009.
--
-- The mode using this parser can be found at Yi.Mode.JavaScript.
module Yi.Syntax.JavaScript
-- | Instances of Strokable are datatypes which can be syntax
-- highlighted.
class Strokable a
toStrokes :: Strokable a => a -> Endo [Stroke]
-- | Instances of Failable can represent failure. This is a useful
-- class for future work, since then we can make stroking much easier.
class Failable f
stupid :: Failable f => t -> f t
hasFailed :: Failable f => f t -> Bool
type BList a = [a]
type Tree t = BList (Statement t)
type Semicolon t = Maybe t
data Statement t
FunDecl :: t -> t -> (Parameters t) -> (Block t) -> Statement t
VarDecl :: t -> (BList (VarDecAss t)) -> (Semicolon t) -> Statement t
Return :: t -> (Maybe (Expr t)) -> (Semicolon t) -> Statement t
While :: t -> (ParExpr t) -> (Block t) -> Statement t
DoWhile :: t -> (Block t) -> t -> (ParExpr t) -> (Semicolon t) -> Statement t
For :: t -> t -> (Expr t) -> (ForContent t) -> t -> (Block t) -> Statement t
If :: t -> (ParExpr t) -> (Block t) -> (Maybe (Statement t)) -> Statement t
Else :: t -> (Block t) -> Statement t
With :: t -> (ParExpr t) -> (Block t) -> Statement t
Comm :: t -> Statement t
Expr :: (Expr t) -> (Semicolon t) -> Statement t
data Parameters t
Parameters :: t -> (BList t) -> t -> Parameters t
ParErr :: t -> Parameters t
data ParExpr t
ParExpr :: t -> (BList (Expr t)) -> t -> ParExpr t
ParExprErr :: t -> ParExpr t
data ForContent t
ForNormal :: t -> (Expr t) -> t -> (Expr t) -> ForContent t
ForIn :: t -> (Expr t) -> ForContent t
ForErr :: t -> ForContent t
data Block t
Block :: t -> (BList (Statement t)) -> t -> Block t
BlockOne :: (Statement t) -> Block t
BlockErr :: t -> Block t
-- | Represents either a variable name or a variable name assigned to an
-- expression. AssBeg is a variable name maybe followed
-- by an assignment. AssRst is an equals sign and an expression.
-- (AssBeg x (Just (AssRst '=' '5'))) means x =
-- 5.
data VarDecAss t
AssBeg :: t -> (Maybe (VarDecAss t)) -> VarDecAss t
AssRst :: t -> (Expr t) -> VarDecAss t
AssErr :: t -> VarDecAss t
data Expr t
ExprObj :: t -> (BList (KeyValue t)) -> t -> Expr t
ExprPrefix :: t -> (Expr t) -> Expr t
ExprNew :: t -> (Expr t) -> Expr t
ExprSimple :: t -> (Maybe (Expr t)) -> Expr t
ExprParen :: t -> (Expr t) -> t -> (Maybe (Expr t)) -> Expr t
ExprAnonFun :: t -> (Parameters t) -> (Block t) -> Expr t
ExprTypeOf :: t -> (Expr t) -> Expr t
ExprFunCall :: t -> (ParExpr t) -> (Maybe (Expr t)) -> Expr t
OpExpr :: t -> (Expr t) -> Expr t
ExprCond :: t -> (Expr t) -> t -> (Expr t) -> Expr t
ExprArr :: t -> (Maybe (Array t)) -> t -> (Maybe (Expr t)) -> Expr t
PostExpr :: t -> Expr t
ExprErr :: t -> Expr t
data Array t
ArrCont :: (Expr t) -> (Maybe (Array t)) -> Array t
ArrRest :: t -> (Array t) -> (Maybe (Array t)) -> Array t
ArrErr :: t -> Array t
data KeyValue t
KeyValue :: t -> t -> (Expr t) -> KeyValue t
KeyValueErr :: t -> KeyValue t
-- | TODO: This code is *screaming* for some generic programming.
--
-- TODO: Somehow fix Failable and failStroker to be more "generic". This
-- will make these instances much nicer and we won't have to make ad-hoc
-- stuff like this.
-- | Normal stroker.
normal :: TT -> Endo [Stroke]
-- | Error stroker.
error :: TT -> Endo [Stroke]
one :: (t -> a) -> t -> Endo [a]
-- | Given a new style and a stroke, return a stroke with the new style
-- appended to the old one.
modStroke :: StyleName -> Stroke -> Stroke
-- | Given a list of tokens to check for errors (xs) and a list of
-- tokens to stroke (xs'), returns normal strokes for
-- xs' if there were no errors. Otherwise returns error strokes
-- for xs'.
nError :: [TT] -> [TT] -> Endo [Stroke]
-- | Given a list of TT, if any of them is an error, returns an
-- error stroker, otherwise a normal stroker. Using e.g. existentials, we
-- could make this more general and have support for heterogeneous lists
-- of elements which implement Failable, but I haven't had the time to
-- fix this.
failStroker :: [TT] -> TT -> Endo [Stroke]
-- | Given a TT, return a Stroke for it.
tokenToStroke :: TT -> Stroke
-- | The main stroking function.
getStrokes :: Tree TT -> Point -> Point -> Point -> [Stroke]
-- | Main parser.
parse :: P TT (Tree TT)
-- | Parser for statements such as "return", "while", "do-while", "for",
-- etc.
statement :: P TT (Statement TT)
-- | Parser for "blocks", i.e. a bunch of statements wrapped in curly
-- brackets or just a single statement.
--
-- Note that this works for JavaScript 1.8 "lambda" style function bodies
-- as well, e.g. "function hello() 5", since expressions are also
-- statements and we don't require a trailing semi-colon.
--
-- TODO: function hello() var x; is not a valid program.
block :: P TT (Block TT)
-- | Parser for expressions which may be statements. In reality, any
-- expression is also a valid statement, but this is a slight compromise
-- to get rid of the massive performance loss which is introduced when
-- allowing JavaScript objects to be valid statements.
stmtExpr :: P TT (Expr TT)
-- | The basic idea here is to parse "the rest" of expressions, e.g. +
-- 3 in x + 3 or [i] in x[i]. Anything
-- which is useful in such a scenario goes here. TODO: This accepts [],
-- but shouldn't, since x[] is invalid.
opExpr :: P TT (Expr TT)
-- | Parser for expressions.
expression :: P TT (Expr TT)
-- | Parses both empty and non-empty arrays. Should probably be split up
-- into further parts to allow for the separation of [] and
-- [1, 2, 3].
array :: P TT (Expr TT)
-- | Parses a semicolon if it's there.
semicolon :: P TT (Maybe TT)
-- | Parses a comma-separated list of valid identifiers.
parameters :: P TT (Parameters TT)
parExpr :: P TT (ParExpr TT)
-- | Parses a comment.
comment :: P TT TT
-- | Parses a prefix operator.
preOp :: P TT TT
-- | Parses a infix operator.
inOp :: P TT TT
-- | Parses a postfix operator.
postOp :: P TT TT
-- | Parses any literal.
opTok :: P TT TT
-- | Parses any literal.
simpleTok :: P TT TT
-- | Parses any string.
strTok :: P TT TT
-- | Parses any valid number.
numTok :: P TT TT
-- | Parses any valid identifier.
name :: P TT TT
-- | Parses any boolean.
boolean :: P TT TT
-- | Parses a reserved word.
res :: Reserved -> P TT TT
-- | Parses a special token.
spc :: Char -> P TT TT
-- | Parses an operator.
oper :: Operator -> P TT TT
-- | Expects a token x, recovers with errorToken.
plzTok :: P TT TT -> P TT TT
-- | Expects a special token.
plzSpc :: Char -> P TT TT
-- | Expects an expression.
plzExpr :: P TT (Expr TT)
plz :: Failable f => P TT (f TT) -> P TT (f TT)
-- | General recovery parser, inserts an error token.
anything :: P s TT
-- | Weighted recovery.
hate :: Int -> P s a -> P s a
fromBlock :: Block t -> [Statement t]
firstTok :: Foldable f => f t -> t
errorToken :: TT
isError :: TT -> Bool
-- | Better name for tokFromT.
toTT :: t -> Tok t
-- | Better name for tokT.
fromTT :: Tok t -> t
instance Data.Foldable.Foldable Yi.Syntax.JavaScript.ParExpr
instance Data.Data.Data t => Data.Data.Data (Yi.Syntax.JavaScript.ParExpr t)
instance GHC.Show.Show t => GHC.Show.Show (Yi.Syntax.JavaScript.ParExpr t)
instance Data.Foldable.Foldable Yi.Syntax.JavaScript.ForContent
instance Data.Data.Data t => Data.Data.Data (Yi.Syntax.JavaScript.ForContent t)
instance GHC.Show.Show t => GHC.Show.Show (Yi.Syntax.JavaScript.ForContent t)
instance Data.Foldable.Foldable Yi.Syntax.JavaScript.VarDecAss
instance Data.Data.Data t => Data.Data.Data (Yi.Syntax.JavaScript.VarDecAss t)
instance GHC.Show.Show t => GHC.Show.Show (Yi.Syntax.JavaScript.VarDecAss t)
instance Data.Foldable.Foldable Yi.Syntax.JavaScript.Statement
instance Data.Data.Data t => Data.Data.Data (Yi.Syntax.JavaScript.Statement t)
instance GHC.Show.Show t => GHC.Show.Show (Yi.Syntax.JavaScript.Statement t)
instance Data.Foldable.Foldable Yi.Syntax.JavaScript.Block
instance Data.Data.Data t => Data.Data.Data (Yi.Syntax.JavaScript.Block t)
instance GHC.Show.Show t => GHC.Show.Show (Yi.Syntax.JavaScript.Block t)
instance Data.Foldable.Foldable Yi.Syntax.JavaScript.Array
instance Data.Data.Data t => Data.Data.Data (Yi.Syntax.JavaScript.Array t)
instance GHC.Show.Show t => GHC.Show.Show (Yi.Syntax.JavaScript.Array t)
instance Data.Foldable.Foldable Yi.Syntax.JavaScript.Expr
instance Data.Data.Data t => Data.Data.Data (Yi.Syntax.JavaScript.Expr t)
instance GHC.Show.Show t => GHC.Show.Show (Yi.Syntax.JavaScript.Expr t)
instance Data.Foldable.Foldable Yi.Syntax.JavaScript.KeyValue
instance Data.Data.Data t => Data.Data.Data (Yi.Syntax.JavaScript.KeyValue t)
instance GHC.Show.Show t => GHC.Show.Show (Yi.Syntax.JavaScript.KeyValue t)
instance Data.Foldable.Foldable Yi.Syntax.JavaScript.Parameters
instance Data.Data.Data t => Data.Data.Data (Yi.Syntax.JavaScript.Parameters t)
instance GHC.Show.Show t => GHC.Show.Show (Yi.Syntax.JavaScript.Parameters t)
instance Yi.Syntax.Tree.IsTree Yi.Syntax.JavaScript.Statement
instance Yi.Syntax.JavaScript.Failable Yi.Syntax.JavaScript.ForContent
instance Yi.Syntax.JavaScript.Failable Yi.Syntax.JavaScript.Block
instance Yi.Syntax.JavaScript.Failable Yi.Syntax.JavaScript.VarDecAss
instance Yi.Syntax.JavaScript.Failable Yi.Syntax.JavaScript.Parameters
instance Yi.Syntax.JavaScript.Failable Yi.Syntax.JavaScript.ParExpr
instance Yi.Syntax.JavaScript.Failable Yi.Syntax.JavaScript.Expr
instance Yi.Syntax.JavaScript.Failable Yi.Syntax.JavaScript.KeyValue
instance Yi.Syntax.JavaScript.Strokable (Yi.Syntax.JavaScript.Statement Yi.Lexer.JavaScript.TT)
instance Yi.Syntax.JavaScript.Strokable (Yi.Syntax.JavaScript.ForContent Yi.Lexer.JavaScript.TT)
instance Yi.Syntax.JavaScript.Strokable (Yi.Syntax.JavaScript.Block Yi.Lexer.JavaScript.TT)
instance Yi.Syntax.JavaScript.Strokable (Yi.Syntax.JavaScript.VarDecAss Yi.Lexer.JavaScript.TT)
instance Yi.Syntax.JavaScript.Strokable (Yi.Syntax.JavaScript.Expr Yi.Lexer.JavaScript.TT)
instance Yi.Syntax.JavaScript.Strokable (Yi.Syntax.JavaScript.Parameters Yi.Lexer.JavaScript.TT)
instance Yi.Syntax.JavaScript.Strokable (Yi.Syntax.JavaScript.ParExpr Yi.Lexer.JavaScript.TT)
instance Yi.Syntax.JavaScript.Strokable (Yi.Syntax.JavaScript.KeyValue Yi.Lexer.JavaScript.TT)
instance Yi.Syntax.JavaScript.Strokable (Yi.Lexer.Alex.Tok Yi.Lexer.JavaScript.Token)
instance Yi.Syntax.JavaScript.Strokable (Yi.Syntax.JavaScript.Array Yi.Lexer.JavaScript.TT)
module Yi.Verifier.JavaScript
data Error
MultipleFunctionDeclaration :: String -> [Posn] -> Error
data Warning
UnreachableCode :: Posn -> Warning
data Report
Err :: Error -> Report
Warn :: Warning -> Report
-- | The main verifier which calls the sub-verifiers.
verify :: Tree TT -> Writer (DList Report) ()
-- | Given a list of function declarations, checks for multiple function
-- declarations, including the functions' subfunctions.
checkMultipleFuns :: [Statement TT] -> Writer (DList Report) ()
checkUnreachable :: [Statement TT] -> Writer (DList Report) ()
-- | Given two Tok t, compares the ts.
ttEq :: Eq t => Tok t -> Tok t -> Bool
say :: MonadWriter (DList a) m => a -> m ()
isReturn :: Statement t -> Bool
-- | Returns a list of the functions in the given block.
findFunctions :: [Statement t] -> [Statement t]
-- | Given a FunDecl, returns the token representing the name.
funName :: Statement t -> t
-- | Given a FunDecl, returns its inner body as a list.
funBody :: Statement t -> [Statement t]
-- | Given a ValidName returns the string representing the name.
nameOf :: Token -> String
-- | Like dropWhile but drops the first element in the result.
dropWhile' :: (a -> Bool) -> [a] -> [a]
dupsBy :: (a -> a -> Bool) -> [a] -> [a]
instance GHC.Classes.Eq Yi.Verifier.JavaScript.Report
instance GHC.Classes.Eq Yi.Verifier.JavaScript.Warning
instance GHC.Classes.Eq Yi.Verifier.JavaScript.Error
instance GHC.Show.Show Yi.Verifier.JavaScript.Error
instance GHC.Show.Show Yi.Verifier.JavaScript.Warning
instance GHC.Show.Show Yi.Verifier.JavaScript.Report
-- | Module defining the Mode for JavaScript. javaScriptMode
-- uses the parser defined at Yi.Syntax.JavaScript.
module Yi.Mode.JavaScript
javaScriptMode :: Mode (Tree TT)
-- | Hooks for the JavaScript mode.
hooks :: Mode (Tree TT) -> Mode (Tree TT)
instance Data.Binary.Class.Binary Yi.Mode.JavaScript.JSBuffer
instance Data.Default.Class.Default Yi.Mode.JavaScript.JSBuffer
instance Yi.Types.YiVariable Yi.Mode.JavaScript.JSBuffer
module Yi.Config.Default.JavaScriptMode
configureJavaScriptMode :: ConfigM ()