yi-mode-javascript-0.19.1: Yi editor javascript mode

License | GPL-2
Maintainer | yi-devel@googlegroups.com
Stability | experimental
Portability | portable
Safe Haskell | None
Language | Haskell2010

Extensions

- DeriveDataTypeable
- DeriveFoldable
- TypeSynonymInstances
- FlexibleInstances

Yi.Syntax.JavaScript

Contents

- Data types, classes and instances
- Helper functions.
- Stroking functions
- The parser
- Parsing helpers
- Simple parsers
- Recovery parsers
- Utility stuff

Description

Parser for the JavaScript language as described at Dogan 2009.

The mode using this parser can be found at Yi.Mode.JavaScript.

Synopsis

- class Strokable a where
  - toStrokes :: a -> Endo [Stroke]
- class Failable (f :: Type -> Type) where
  - stupid :: t -> f t
  - hasFailed :: 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)
  - | VarDecl t (BList (VarDecAss t)) (Semicolon t)
  - | Return t (Maybe (Expr t)) (Semicolon t)
  - | While t (ParExpr t) (Block t)
  - | DoWhile t (Block t) t (ParExpr t) (Semicolon t)
  - | For t t (Expr t) (ForContent t) t (Block t)
  - | If t (ParExpr t) (Block t) (Maybe (Statement t))
  - | Else t (Block t)
  - | With t (ParExpr t) (Block t)
  - | Comm t
  - | Expr (Expr t) (Semicolon t)
- data Parameters t
  - = Parameters t (BList t) t
  - | ParErr t
- data ParExpr t
  - = ParExpr t (BList (Expr t)) t
  - | ParExprErr t
- data ForContent t
  - = ForNormal t (Expr t) t (Expr t)
  - | ForIn t (Expr t)
  - | ForErr t
- data Block t
  - = Block t (BList (Statement t)) t
  - | BlockOne (Statement t)
  - | BlockErr t
- data VarDecAss t
  - = AssBeg t (Maybe (VarDecAss t))
  - | AssRst t (Expr t)
  - | AssErr t
- data Expr t
  - = ExprObj t (BList (KeyValue t)) t
  - | ExprPrefix t (Expr t)
  - | ExprNew t (Expr t)
  - | ExprSimple t (Maybe (Expr t))
  - | ExprParen t (Expr t) t (Maybe (Expr t))
  - | ExprAnonFun t (Parameters t) (Block t)
  - | ExprTypeOf t (Expr t)
  - | ExprFunCall t (ParExpr t) (Maybe (Expr t))
  - | OpExpr t (Expr t)
  - | ExprCond t (Expr t) t (Expr t)
  - | ExprArr t (Maybe (Array t)) t (Maybe (Expr t))
  - | PostExpr t
  - | ExprErr t
- data Array t
  - = ArrCont (Expr t) (Maybe (Array t))
  - | ArrRest t (Array t) (Maybe (Array t))
  - | ArrErr t
- data KeyValue t
  - = KeyValue t t (Expr t)
  - | KeyValueErr t
- normal :: TT -> Endo [Stroke]
- error :: TT -> Endo [Stroke]
- one :: (t -> a) -> t -> Endo [a]
- modStroke :: StyleName -> Stroke -> Stroke
- nError :: [TT] -> [TT] -> Endo [Stroke]
- failStroker :: [TT] -> TT -> Endo [Stroke]
- tokenToStroke :: TT -> Stroke
- getStrokes :: Tree TT -> Point -> Point -> Point -> [Stroke]
- parse :: P TT (Tree TT)
- statement :: P TT (Statement TT)
- block :: P TT (Block TT)
- stmtExpr :: P TT (Expr TT)
- opExpr :: P TT (Expr TT)
- expression :: P TT (Expr TT)
- array :: P TT (Expr TT)
- semicolon :: P TT (Maybe TT)
- parameters :: P TT (Parameters TT)
- parExpr :: P TT (ParExpr TT)
- comment :: P TT TT
- preOp :: P TT TT
- inOp :: P TT TT
- postOp :: P TT TT
- opTok :: P TT TT
- simpleTok :: P TT TT
- strTok :: P TT TT
- numTok :: P TT TT
- name :: P TT TT
- boolean :: P TT TT
- res :: Reserved -> P TT TT
- spc :: Char -> P TT TT
- oper :: Operator -> P TT TT
- plzTok :: P TT TT -> P TT TT
- plzSpc :: Char -> P TT TT
- plzExpr :: P TT (Expr TT)
- plz :: Failable f => P TT (f TT) -> P TT (f TT)
- anything :: P s TT
- hate :: Int -> P s a -> P s a
- fromBlock :: Block t -> [Statement t]
- firstTok :: Foldable f => f t -> t
- errorToken :: TT
- isError :: TT -> Bool
- toTT :: t -> Tok t
- fromTT :: Tok t -> t

# Data types, classes and instances

class Strokable a where Source #

Instances of `Strokable` are datatypes which can be syntax highlighted.

Methods

toStrokes :: a -> Endo [Stroke] Source #

#### Instances

Instances details

Strokable (Tok Token) Source # |
Instance details Defined in Yi.Syntax.JavaScript Methods toStrokes :: Tok Token -> Endo [Stroke] Source #
Strokable (Array TT) Source # |
Instance details Defined in Yi.Syntax.JavaScript Methods toStrokes :: Array TT -> Endo [Stroke] Source #
Strokable (Block TT) Source # |
Instance details Defined in Yi.Syntax.JavaScript Methods toStrokes :: Block TT -> Endo [Stroke] Source #
Strokable (Expr TT) Source # |
Instance details Defined in Yi.Syntax.JavaScript Methods toStrokes :: Expr TT -> Endo [Stroke] Source #
Strokable (ForContent TT) Source # |
Instance details Defined in Yi.Syntax.JavaScript Methods toStrokes :: ForContent TT -> Endo [Stroke] Source #
Strokable (KeyValue TT) Source # |
Instance details Defined in Yi.Syntax.JavaScript Methods toStrokes :: KeyValue TT -> Endo [Stroke] Source #
Strokable (ParExpr TT) Source # |
Instance details Defined in Yi.Syntax.JavaScript Methods toStrokes :: ParExpr TT -> Endo [Stroke] Source #
Strokable (Parameters TT) Source # |
Instance details Defined in Yi.Syntax.JavaScript Methods toStrokes :: Parameters TT -> Endo [Stroke] Source #
Strokable (Statement TT) Source # | 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.
Instance details Defined in Yi.Syntax.JavaScript Methods toStrokes :: Statement TT -> Endo [Stroke] Source #
Strokable (VarDecAss TT) Source # |
Instance details Defined in Yi.Syntax.JavaScript Methods toStrokes :: VarDecAss TT -> Endo [Stroke] Source #

class Failable (f :: Type -> Type) where Source #

Instances of `Failable` can represent failure. This is a useful class for future work, since then we can make stroking much easier.

Methods

stupid :: t -> f t Source #

hasFailed :: f t -> Bool Source #

#### Instances

Instances details

Failable Block Source # |
Instance details Defined in Yi.Syntax.JavaScript Methods stupid :: t -> Block t Source # hasFailed :: Block t -> Bool Source #
Failable Expr Source # |
Instance details Defined in Yi.Syntax.JavaScript Methods stupid :: t -> Expr t Source # hasFailed :: Expr t -> Bool Source #
Failable ForContent Source # |
Instance details Defined in Yi.Syntax.JavaScript Methods stupid :: t -> ForContent t Source # hasFailed :: ForContent t -> Bool Source #
Failable KeyValue Source # |
Instance details Defined in Yi.Syntax.JavaScript Methods stupid :: t -> KeyValue t Source # hasFailed :: KeyValue t -> Bool Source #
Failable ParExpr Source # |
Instance details Defined in Yi.Syntax.JavaScript Methods stupid :: t -> ParExpr t Source # hasFailed :: ParExpr t -> Bool Source #
Failable Parameters Source # |
Instance details Defined in Yi.Syntax.JavaScript Methods stupid :: t -> Parameters t Source # hasFailed :: Parameters t -> Bool Source #
Failable VarDecAss Source # |
Instance details Defined in Yi.Syntax.JavaScript Methods stupid :: t -> VarDecAss t Source # hasFailed :: VarDecAss t -> Bool Source #

type BList a = [a] Source #

type Tree t = BList (Statement t) Source #

type Semicolon t = Maybe t Source #

data Statement t Source #

Constructors

FunDecl t t (Parameters t) (Block t) |
VarDecl t (BList (VarDecAss t)) (Semicolon t) |
Return t (Maybe (Expr t)) (Semicolon t) |
While t (ParExpr t) (Block t) |
DoWhile t (Block t) t (ParExpr t) (Semicolon t) |
For t t (Expr t) (ForContent t) t (Block t) |
If t (ParExpr t) (Block t) (Maybe (Statement t)) |
Else t (Block t) |
With t (ParExpr t) (Block t) |
Comm t |
Expr (Expr t) (Semicolon t) |

#### Instances

Instances details

Foldable Statement Source # |

Instance details

Defined in Yi.Syntax.JavaScript

Methods

fold :: Monoid m => Statement m -> m Source #

foldMap :: Monoid m => (a -> m) -> Statement a -> m Source #

foldMap' :: Monoid m => (a -> m) -> Statement a -> m Source #

foldr :: (a -> b -> b) -> b -> Statement a -> b Source #

foldr' :: (a -> b -> b) -> b -> Statement a -> b Source #

foldl :: (b -> a -> b) -> b -> Statement a -> b Source #

foldl' :: (b -> a -> b) -> b -> Statement a -> b Source #

foldr1 :: (a -> a -> a) -> Statement a -> a Source #

foldl1 :: (a -> a -> a) -> Statement a -> a Source #

toList :: Statement a -> [a] Source #

null :: Statement a -> Bool Source #

length :: Statement a -> Int Source #

elem :: Eq a => a -> Statement a -> Bool Source #

maximum :: Ord a => Statement a -> a Source #

minimum :: Ord a => Statement a -> a Source #

sum :: Num a => Statement a -> a Source #

product :: Num a => Statement a -> a Source #

IsTree Statement Source # |
Instance details Defined in Yi.Syntax.JavaScript Methods subtrees :: Statement t -> [Statement t] Source # uniplate :: Statement t -> ([Statement t], [Statement t] -> Statement t) Source # emptyNode :: Statement t Source #
Data t => Data (Statement t) Source # |

Instance details

Defined in Yi.Syntax.JavaScript

Methods

gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> Statement t -> c (Statement t) Source #

gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c (Statement t) Source #

toConstr :: Statement t -> Constr Source #

dataTypeOf :: Statement t -> DataType Source #

dataCast1 :: Typeable t0 => (forall d. Data d => c (t0 d)) -> Maybe (c (Statement t)) Source #

dataCast2 :: Typeable t0 => (forall d e. (Data d, Data e) => c (t0 d e)) -> Maybe (c (Statement t)) Source #

gmapT :: (forall b. Data b => b -> b) -> Statement t -> Statement t Source #

gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Statement t -> r Source #

gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Statement t -> r Source #

gmapQ :: (forall d. Data d => d -> u) -> Statement t -> [u] Source #

gmapQi :: Int -> (forall d. Data d => d -> u) -> Statement t -> u Source #

gmapM :: Monad m => (forall d. Data d => d -> m d) -> Statement t -> m (Statement t) Source #

gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> Statement t -> m (Statement t) Source #

gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> Statement t -> m (Statement t) Source #

Show t => Show (Statement t) Source # |
Instance details Defined in Yi.Syntax.JavaScript Methods showsPrec :: Int -> Statement t -> ShowS Source # show :: Statement t -> String Source # showList :: [Statement t] -> ShowS Source #
Strokable (Statement TT) Source # | 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.
Instance details Defined in Yi.Syntax.JavaScript Methods toStrokes :: Statement TT -> Endo [Stroke] Source #

data Parameters t Source #

Constructors

Parameters t (BList t) t |
ParErr t |

#### Instances

Instances details

Foldable Parameters Source # |

Instance details

Defined in Yi.Syntax.JavaScript

Methods

fold :: Monoid m => Parameters m -> m Source #

foldMap :: Monoid m => (a -> m) -> Parameters a -> m Source #

foldMap' :: Monoid m => (a -> m) -> Parameters a -> m Source #

foldr :: (a -> b -> b) -> b -> Parameters a -> b Source #

foldr' :: (a -> b -> b) -> b -> Parameters a -> b Source #

foldl :: (b -> a -> b) -> b -> Parameters a -> b Source #

foldl' :: (b -> a -> b) -> b -> Parameters a -> b Source #

foldr1 :: (a -> a -> a) -> Parameters a -> a Source #

foldl1 :: (a -> a -> a) -> Parameters a -> a Source #

toList :: Parameters a -> [a] Source #

null :: Parameters a -> Bool Source #

length :: Parameters a -> Int Source #

elem :: Eq a => a -> Parameters a -> Bool Source #

maximum :: Ord a => Parameters a -> a Source #

minimum :: Ord a => Parameters a -> a Source #

sum :: Num a => Parameters a -> a Source #

product :: Num a => Parameters a -> a Source #

Failable Parameters Source # |
Instance details Defined in Yi.Syntax.JavaScript Methods stupid :: t -> Parameters t Source # hasFailed :: Parameters t -> Bool Source #
Data t => Data (Parameters t) Source # |

Instance details

Defined in Yi.Syntax.JavaScript

Methods

gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> Parameters t -> c (Parameters t) Source #

gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c (Parameters t) Source #

toConstr :: Parameters t -> Constr Source #

dataTypeOf :: Parameters t -> DataType Source #

dataCast1 :: Typeable t0 => (forall d. Data d => c (t0 d)) -> Maybe (c (Parameters t)) Source #

dataCast2 :: Typeable t0 => (forall d e. (Data d, Data e) => c (t0 d e)) -> Maybe (c (Parameters t)) Source #

gmapT :: (forall b. Data b => b -> b) -> Parameters t -> Parameters t Source #

gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Parameters t -> r Source #

gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Parameters t -> r Source #

gmapQ :: (forall d. Data d => d -> u) -> Parameters t -> [u] Source #

gmapQi :: Int -> (forall d. Data d => d -> u) -> Parameters t -> u Source #

gmapM :: Monad m => (forall d. Data d => d -> m d) -> Parameters t -> m (Parameters t) Source #

gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> Parameters t -> m (Parameters t) Source #

gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> Parameters t -> m (Parameters t) Source #

Show t => Show (Parameters t) Source # |
Instance details Defined in Yi.Syntax.JavaScript Methods showsPrec :: Int -> Parameters t -> ShowS Source # show :: Parameters t -> String Source # showList :: [Parameters t] -> ShowS Source #
Strokable (Parameters TT) Source # |
Instance details Defined in Yi.Syntax.JavaScript Methods toStrokes :: Parameters TT -> Endo [Stroke] Source #

data ParExpr t Source #

Constructors

ParExpr t (BList (Expr t)) t |
ParExprErr t |

#### Instances

Instances details

Foldable ParExpr Source # |

Instance details

Defined in Yi.Syntax.JavaScript

Methods

fold :: Monoid m => ParExpr m -> m Source #

foldMap :: Monoid m => (a -> m) -> ParExpr a -> m Source #

foldMap' :: Monoid m => (a -> m) -> ParExpr a -> m Source #

foldr :: (a -> b -> b) -> b -> ParExpr a -> b Source #

foldr' :: (a -> b -> b) -> b -> ParExpr a -> b Source #

foldl :: (b -> a -> b) -> b -> ParExpr a -> b Source #

foldl' :: (b -> a -> b) -> b -> ParExpr a -> b Source #

foldr1 :: (a -> a -> a) -> ParExpr a -> a Source #

foldl1 :: (a -> a -> a) -> ParExpr a -> a Source #

toList :: ParExpr a -> [a] Source #

null :: ParExpr a -> Bool Source #

length :: ParExpr a -> Int Source #

elem :: Eq a => a -> ParExpr a -> Bool Source #

maximum :: Ord a => ParExpr a -> a Source #

minimum :: Ord a => ParExpr a -> a Source #

sum :: Num a => ParExpr a -> a Source #

product :: Num a => ParExpr a -> a Source #

Failable ParExpr Source # |
Instance details Defined in Yi.Syntax.JavaScript Methods stupid :: t -> ParExpr t Source # hasFailed :: ParExpr t -> Bool Source #
Data t => Data (ParExpr t) Source # |

Instance details

Defined in Yi.Syntax.JavaScript

Methods

gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> ParExpr t -> c (ParExpr t) Source #

gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c (ParExpr t) Source #

toConstr :: ParExpr t -> Constr Source #

dataTypeOf :: ParExpr t -> DataType Source #

dataCast1 :: Typeable t0 => (forall d. Data d => c (t0 d)) -> Maybe (c (ParExpr t)) Source #

dataCast2 :: Typeable t0 => (forall d e. (Data d, Data e) => c (t0 d e)) -> Maybe (c (ParExpr t)) Source #

gmapT :: (forall b. Data b => b -> b) -> ParExpr t -> ParExpr t Source #

gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> ParExpr t -> r Source #

gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> ParExpr t -> r Source #

gmapQ :: (forall d. Data d => d -> u) -> ParExpr t -> [u] Source #

gmapQi :: Int -> (forall d. Data d => d -> u) -> ParExpr t -> u Source #

gmapM :: Monad m => (forall d. Data d => d -> m d) -> ParExpr t -> m (ParExpr t) Source #

gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> ParExpr t -> m (ParExpr t) Source #

gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> ParExpr t -> m (ParExpr t) Source #

Show t => Show (ParExpr t) Source # |
Instance details Defined in Yi.Syntax.JavaScript Methods showsPrec :: Int -> ParExpr t -> ShowS Source # show :: ParExpr t -> String Source # showList :: [ParExpr t] -> ShowS Source #
Strokable (ParExpr TT) Source # |
Instance details Defined in Yi.Syntax.JavaScript Methods toStrokes :: ParExpr TT -> Endo [Stroke] Source #

data ForContent t Source #

Constructors

ForNormal t (Expr t) t (Expr t) |
ForIn t (Expr t) |
ForErr t |

#### Instances

Instances details

Foldable ForContent Source # |

Instance details

Defined in Yi.Syntax.JavaScript

Methods

fold :: Monoid m => ForContent m -> m Source #

foldMap :: Monoid m => (a -> m) -> ForContent a -> m Source #

foldMap' :: Monoid m => (a -> m) -> ForContent a -> m Source #

foldr :: (a -> b -> b) -> b -> ForContent a -> b Source #

foldr' :: (a -> b -> b) -> b -> ForContent a -> b Source #

foldl :: (b -> a -> b) -> b -> ForContent a -> b Source #

foldl' :: (b -> a -> b) -> b -> ForContent a -> b Source #

foldr1 :: (a -> a -> a) -> ForContent a -> a Source #

foldl1 :: (a -> a -> a) -> ForContent a -> a Source #

toList :: ForContent a -> [a] Source #

null :: ForContent a -> Bool Source #

length :: ForContent a -> Int Source #

elem :: Eq a => a -> ForContent a -> Bool Source #

maximum :: Ord a => ForContent a -> a Source #

minimum :: Ord a => ForContent a -> a Source #

sum :: Num a => ForContent a -> a Source #

product :: Num a => ForContent a -> a Source #

Failable ForContent Source # |
Instance details Defined in Yi.Syntax.JavaScript Methods stupid :: t -> ForContent t Source # hasFailed :: ForContent t -> Bool Source #
Data t => Data (ForContent t) Source # |

Instance details

Defined in Yi.Syntax.JavaScript

Methods

gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> ForContent t -> c (ForContent t) Source #

gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c (ForContent t) Source #

toConstr :: ForContent t -> Constr Source #

dataTypeOf :: ForContent t -> DataType Source #

dataCast1 :: Typeable t0 => (forall d. Data d => c (t0 d)) -> Maybe (c (ForContent t)) Source #

dataCast2 :: Typeable t0 => (forall d e. (Data d, Data e) => c (t0 d e)) -> Maybe (c (ForContent t)) Source #

gmapT :: (forall b. Data b => b -> b) -> ForContent t -> ForContent t Source #

gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> ForContent t -> r Source #

gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> ForContent t -> r Source #

gmapQ :: (forall d. Data d => d -> u) -> ForContent t -> [u] Source #

gmapQi :: Int -> (forall d. Data d => d -> u) -> ForContent t -> u Source #

gmapM :: Monad m => (forall d. Data d => d -> m d) -> ForContent t -> m (ForContent t) Source #

gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> ForContent t -> m (ForContent t) Source #

gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> ForContent t -> m (ForContent t) Source #

Show t => Show (ForContent t) Source # |
Instance details Defined in Yi.Syntax.JavaScript Methods showsPrec :: Int -> ForContent t -> ShowS Source # show :: ForContent t -> String Source # showList :: [ForContent t] -> ShowS Source #
Strokable (ForContent TT) Source # |
Instance details Defined in Yi.Syntax.JavaScript Methods toStrokes :: ForContent TT -> Endo [Stroke] Source #

data Block t Source #

Constructors

Block t (BList (Statement t)) t |
BlockOne (Statement t) |
BlockErr t |

#### Instances

Instances details

Foldable Block Source # |

Instance details

Defined in Yi.Syntax.JavaScript

Methods

fold :: Monoid m => Block m -> m Source #

foldMap :: Monoid m => (a -> m) -> Block a -> m Source #

foldMap' :: Monoid m => (a -> m) -> Block a -> m Source #

foldr :: (a -> b -> b) -> b -> Block a -> b Source #

foldr' :: (a -> b -> b) -> b -> Block a -> b Source #

foldl :: (b -> a -> b) -> b -> Block a -> b Source #

foldl' :: (b -> a -> b) -> b -> Block a -> b Source #

foldr1 :: (a -> a -> a) -> Block a -> a Source #

foldl1 :: (a -> a -> a) -> Block a -> a Source #

toList :: Block a -> [a] Source #

null :: Block a -> Bool Source #

length :: Block a -> Int Source #

elem :: Eq a => a -> Block a -> Bool Source #

maximum :: Ord a => Block a -> a Source #

minimum :: Ord a => Block a -> a Source #

sum :: Num a => Block a -> a Source #

product :: Num a => Block a -> a Source #

Failable Block Source # |
Instance details Defined in Yi.Syntax.JavaScript Methods stupid :: t -> Block t Source # hasFailed :: Block t -> Bool Source #
Data t => Data (Block t) Source # |

Instance details

Defined in Yi.Syntax.JavaScript

Methods

gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> Block t -> c (Block t) Source #

gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c (Block t) Source #

toConstr :: Block t -> Constr Source #

dataTypeOf :: Block t -> DataType Source #

dataCast1 :: Typeable t0 => (forall d. Data d => c (t0 d)) -> Maybe (c (Block t)) Source #

dataCast2 :: Typeable t0 => (forall d e. (Data d, Data e) => c (t0 d e)) -> Maybe (c (Block t)) Source #

gmapT :: (forall b. Data b => b -> b) -> Block t -> Block t Source #

gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Block t -> r Source #

gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Block t -> r Source #

gmapQ :: (forall d. Data d => d -> u) -> Block t -> [u] Source #

gmapQi :: Int -> (forall d. Data d => d -> u) -> Block t -> u Source #

gmapM :: Monad m => (forall d. Data d => d -> m d) -> Block t -> m (Block t) Source #

gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> Block t -> m (Block t) Source #

gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> Block t -> m (Block t) Source #

Show t => Show (Block t) Source # |
Instance details Defined in Yi.Syntax.JavaScript Methods showsPrec :: Int -> Block t -> ShowS Source # show :: Block t -> String Source # showList :: [Block t] -> ShowS Source #
Strokable (Block TT) Source # |
Instance details Defined in Yi.Syntax.JavaScript Methods toStrokes :: Block TT -> Endo [Stroke] Source #

data VarDecAss t Source #

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`.

Constructors

AssBeg t (Maybe (VarDecAss t)) |
AssRst t (Expr t) |
AssErr t |

#### Instances

Instances details

Foldable VarDecAss Source # |

Instance details

Defined in Yi.Syntax.JavaScript

Methods

fold :: Monoid m => VarDecAss m -> m Source #

foldMap :: Monoid m => (a -> m) -> VarDecAss a -> m Source #

foldMap' :: Monoid m => (a -> m) -> VarDecAss a -> m Source #

foldr :: (a -> b -> b) -> b -> VarDecAss a -> b Source #

foldr' :: (a -> b -> b) -> b -> VarDecAss a -> b Source #

foldl :: (b -> a -> b) -> b -> VarDecAss a -> b Source #

foldl' :: (b -> a -> b) -> b -> VarDecAss a -> b Source #

foldr1 :: (a -> a -> a) -> VarDecAss a -> a Source #

foldl1 :: (a -> a -> a) -> VarDecAss a -> a Source #

toList :: VarDecAss a -> [a] Source #

null :: VarDecAss a -> Bool Source #

length :: VarDecAss a -> Int Source #

elem :: Eq a => a -> VarDecAss a -> Bool Source #

maximum :: Ord a => VarDecAss a -> a Source #

minimum :: Ord a => VarDecAss a -> a Source #

sum :: Num a => VarDecAss a -> a Source #

product :: Num a => VarDecAss a -> a Source #

Failable VarDecAss Source # |
Instance details Defined in Yi.Syntax.JavaScript Methods stupid :: t -> VarDecAss t Source # hasFailed :: VarDecAss t -> Bool Source #
Data t => Data (VarDecAss t) Source # |

Instance details

Defined in Yi.Syntax.JavaScript

Methods

gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> VarDecAss t -> c (VarDecAss t) Source #

gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c (VarDecAss t) Source #

toConstr :: VarDecAss t -> Constr Source #

dataTypeOf :: VarDecAss t -> DataType Source #

dataCast1 :: Typeable t0 => (forall d. Data d => c (t0 d)) -> Maybe (c (VarDecAss t)) Source #

dataCast2 :: Typeable t0 => (forall d e. (Data d, Data e) => c (t0 d e)) -> Maybe (c (VarDecAss t)) Source #

gmapT :: (forall b. Data b => b -> b) -> VarDecAss t -> VarDecAss t Source #

gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> VarDecAss t -> r Source #

gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> VarDecAss t -> r Source #

gmapQ :: (forall d. Data d => d -> u) -> VarDecAss t -> [u] Source #

gmapQi :: Int -> (forall d. Data d => d -> u) -> VarDecAss t -> u Source #

gmapM :: Monad m => (forall d. Data d => d -> m d) -> VarDecAss t -> m (VarDecAss t) Source #

gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> VarDecAss t -> m (VarDecAss t) Source #

gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> VarDecAss t -> m (VarDecAss t) Source #

Show t => Show (VarDecAss t) Source # |
Instance details Defined in Yi.Syntax.JavaScript Methods showsPrec :: Int -> VarDecAss t -> ShowS Source # show :: VarDecAss t -> String Source # showList :: [VarDecAss t] -> ShowS Source #
Strokable (VarDecAss TT) Source # |
Instance details Defined in Yi.Syntax.JavaScript Methods toStrokes :: VarDecAss TT -> Endo [Stroke] Source #

data Expr t Source #

Constructors

ExprObj t (BList (KeyValue t)) t |
ExprPrefix t (Expr t) |
ExprNew t (Expr t) |
ExprSimple t (Maybe (Expr t)) |
ExprParen t (Expr t) t (Maybe (Expr t)) |
ExprAnonFun t (Parameters t) (Block t) |
ExprTypeOf t (Expr t) |
ExprFunCall t (ParExpr t) (Maybe (Expr t)) |
OpExpr t (Expr t) |
ExprCond t (Expr t) t (Expr t) |
ExprArr t (Maybe (Array t)) t (Maybe (Expr t)) |
PostExpr t |
ExprErr t |

#### Instances

Instances details

Foldable Expr Source # |

Instance details

Defined in Yi.Syntax.JavaScript

Methods

fold :: Monoid m => Expr m -> m Source #

foldMap :: Monoid m => (a -> m) -> Expr a -> m Source #

foldMap' :: Monoid m => (a -> m) -> Expr a -> m Source #

foldr :: (a -> b -> b) -> b -> Expr a -> b Source #

foldr' :: (a -> b -> b) -> b -> Expr a -> b Source #

foldl :: (b -> a -> b) -> b -> Expr a -> b Source #

foldl' :: (b -> a -> b) -> b -> Expr a -> b Source #

foldr1 :: (a -> a -> a) -> Expr a -> a Source #

foldl1 :: (a -> a -> a) -> Expr a -> a Source #

toList :: Expr a -> [a] Source #

null :: Expr a -> Bool Source #

length :: Expr a -> Int Source #

elem :: Eq a => a -> Expr a -> Bool Source #

maximum :: Ord a => Expr a -> a Source #

minimum :: Ord a => Expr a -> a Source #

sum :: Num a => Expr a -> a Source #

product :: Num a => Expr a -> a Source #

Failable Expr Source # |
Instance details Defined in Yi.Syntax.JavaScript Methods stupid :: t -> Expr t Source # hasFailed :: Expr t -> Bool Source #
Data t => Data (Expr t) Source # |

Instance details

Defined in Yi.Syntax.JavaScript

Methods

gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> Expr t -> c (Expr t) Source #

gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c (Expr t) Source #

toConstr :: Expr t -> Constr Source #

dataTypeOf :: Expr t -> DataType Source #

dataCast1 :: Typeable t0 => (forall d. Data d => c (t0 d)) -> Maybe (c (Expr t)) Source #

dataCast2 :: Typeable t0 => (forall d e. (Data d, Data e) => c (t0 d e)) -> Maybe (c (Expr t)) Source #

gmapT :: (forall b. Data b => b -> b) -> Expr t -> Expr t Source #

gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Expr t -> r Source #

gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Expr t -> r Source #

gmapQ :: (forall d. Data d => d -> u) -> Expr t -> [u] Source #

gmapQi :: Int -> (forall d. Data d => d -> u) -> Expr t -> u Source #

gmapM :: Monad m => (forall d. Data d => d -> m d) -> Expr t -> m (Expr t) Source #

gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> Expr t -> m (Expr t) Source #

gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> Expr t -> m (Expr t) Source #

Show t => Show (Expr t) Source # |
Instance details Defined in Yi.Syntax.JavaScript Methods showsPrec :: Int -> Expr t -> ShowS Source # show :: Expr t -> String Source # showList :: [Expr t] -> ShowS Source #
Strokable (Expr TT) Source # |
Instance details Defined in Yi.Syntax.JavaScript Methods toStrokes :: Expr TT -> Endo [Stroke] Source #

data Array t Source #

Constructors

ArrCont (Expr t) (Maybe (Array t)) |
ArrRest t (Array t) (Maybe (Array t)) |
ArrErr t |

#### Instances

Instances details

Foldable Array Source # |

Instance details

Defined in Yi.Syntax.JavaScript

Methods

fold :: Monoid m => Array m -> m Source #

foldMap :: Monoid m => (a -> m) -> Array a -> m Source #

foldMap' :: Monoid m => (a -> m) -> Array a -> m Source #

foldr :: (a -> b -> b) -> b -> Array a -> b Source #

foldr' :: (a -> b -> b) -> b -> Array a -> b Source #

foldl :: (b -> a -> b) -> b -> Array a -> b Source #

foldl' :: (b -> a -> b) -> b -> Array a -> b Source #

foldr1 :: (a -> a -> a) -> Array a -> a Source #

foldl1 :: (a -> a -> a) -> Array a -> a Source #

toList :: Array a -> [a] Source #

null :: Array a -> Bool Source #

length :: Array a -> Int Source #

elem :: Eq a => a -> Array a -> Bool Source #

maximum :: Ord a => Array a -> a Source #

minimum :: Ord a => Array a -> a Source #

sum :: Num a => Array a -> a Source #

product :: Num a => Array a -> a Source #

Data t => Data (Array t) Source # |

Instance details

Defined in Yi.Syntax.JavaScript

Methods

gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> Array t -> c (Array t) Source #

gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c (Array t) Source #

toConstr :: Array t -> Constr Source #

dataTypeOf :: Array t -> DataType Source #

dataCast1 :: Typeable t0 => (forall d. Data d => c (t0 d)) -> Maybe (c (Array t)) Source #

dataCast2 :: Typeable t0 => (forall d e. (Data d, Data e) => c (t0 d e)) -> Maybe (c (Array t)) Source #

gmapT :: (forall b. Data b => b -> b) -> Array t -> Array t Source #

gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Array t -> r Source #

gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Array t -> r Source #

gmapQ :: (forall d. Data d => d -> u) -> Array t -> [u] Source #

gmapQi :: Int -> (forall d. Data d => d -> u) -> Array t -> u Source #

gmapM :: Monad m => (forall d. Data d => d -> m d) -> Array t -> m (Array t) Source #

gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> Array t -> m (Array t) Source #

gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> Array t -> m (Array t) Source #

Show t => Show (Array t) Source # |
Instance details Defined in Yi.Syntax.JavaScript Methods showsPrec :: Int -> Array t -> ShowS Source # show :: Array t -> String Source # showList :: [Array t] -> ShowS Source #
Strokable (Array TT) Source # |
Instance details Defined in Yi.Syntax.JavaScript Methods toStrokes :: Array TT -> Endo [Stroke] Source #

data KeyValue t Source #

Constructors

KeyValue t t (Expr t) |
KeyValueErr t |

#### Instances

Instances details

Foldable KeyValue Source # |

Instance details

Defined in Yi.Syntax.JavaScript

Methods

fold :: Monoid m => KeyValue m -> m Source #

foldMap :: Monoid m => (a -> m) -> KeyValue a -> m Source #

foldMap' :: Monoid m => (a -> m) -> KeyValue a -> m Source #

foldr :: (a -> b -> b) -> b -> KeyValue a -> b Source #

foldr' :: (a -> b -> b) -> b -> KeyValue a -> b Source #

foldl :: (b -> a -> b) -> b -> KeyValue a -> b Source #

foldl' :: (b -> a -> b) -> b -> KeyValue a -> b Source #

foldr1 :: (a -> a -> a) -> KeyValue a -> a Source #

foldl1 :: (a -> a -> a) -> KeyValue a -> a Source #

toList :: KeyValue a -> [a] Source #

null :: KeyValue a -> Bool Source #

length :: KeyValue a -> Int Source #

elem :: Eq a => a -> KeyValue a -> Bool Source #

maximum :: Ord a => KeyValue a -> a Source #

minimum :: Ord a => KeyValue a -> a Source #

sum :: Num a => KeyValue a -> a Source #

product :: Num a => KeyValue a -> a Source #

Failable KeyValue Source # |
Instance details Defined in Yi.Syntax.JavaScript Methods stupid :: t -> KeyValue t Source # hasFailed :: KeyValue t -> Bool Source #
Data t => Data (KeyValue t) Source # |

Instance details

Defined in Yi.Syntax.JavaScript

Methods

gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> KeyValue t -> c (KeyValue t) Source #

gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c (KeyValue t) Source #

toConstr :: KeyValue t -> Constr Source #

dataTypeOf :: KeyValue t -> DataType Source #

dataCast1 :: Typeable t0 => (forall d. Data d => c (t0 d)) -> Maybe (c (KeyValue t)) Source #

dataCast2 :: Typeable t0 => (forall d e. (Data d, Data e) => c (t0 d e)) -> Maybe (c (KeyValue t)) Source #

gmapT :: (forall b. Data b => b -> b) -> KeyValue t -> KeyValue t Source #

gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> KeyValue t -> r Source #

gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> KeyValue t -> r Source #

gmapQ :: (forall d. Data d => d -> u) -> KeyValue t -> [u] Source #

gmapQi :: Int -> (forall d. Data d => d -> u) -> KeyValue t -> u Source #

gmapM :: Monad m => (forall d. Data d => d -> m d) -> KeyValue t -> m (KeyValue t) Source #

gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> KeyValue t -> m (KeyValue t) Source #

gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> KeyValue t -> m (KeyValue t) Source #

Show t => Show (KeyValue t) Source # |
Instance details Defined in Yi.Syntax.JavaScript Methods showsPrec :: Int -> KeyValue t -> ShowS Source # show :: KeyValue t -> String Source # showList :: [KeyValue t] -> ShowS Source #
Strokable (KeyValue TT) Source # |
Instance details Defined in Yi.Syntax.JavaScript Methods toStrokes :: KeyValue TT -> Endo [Stroke] Source #

# Helper functions.

normal :: TT -> Endo [Stroke] Source #

Normal stroker.

error :: TT -> Endo [Stroke] Source #

Error stroker.

one :: (t -> a) -> t -> Endo [a] Source #

modStroke :: StyleName -> Stroke -> Stroke Source #

Given a new style and a stroke, return a stroke with the new style appended to the old one.

# Stroking functions

nError :: [TT] -> [TT] -> Endo [Stroke] Source #

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'`.

failStroker :: [TT] -> TT -> Endo [Stroke] Source #

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.

tokenToStroke :: TT -> Stroke Source #

Given a `TT`, return a `Stroke` for it.

getStrokes :: Tree TT -> Point -> Point -> Point -> [Stroke] Source #

The main stroking function.

# The parser

parse :: P TT (Tree TT) Source #

Main parser.

statement :: P TT (Statement TT) Source #

Parser for statements such as "return", "while", "do-while", "for", etc.

block :: P TT (Block TT) Source #

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.

stmtExpr :: P TT (Expr TT) Source #

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.

opExpr :: P TT (Expr TT) Source #

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.

expression :: P TT (Expr TT) Source #

Parser for expressions.

array :: P TT (Expr TT) Source #

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]`.

# Parsing helpers

semicolon :: P TT (Maybe TT) Source #

Parses a semicolon if it's there.

parameters :: P TT (Parameters TT) Source #

Parses a comma-separated list of valid identifiers.

parExpr :: P TT (ParExpr TT) Source #

# Simple parsers

comment :: P TT TT Source #

Parses a comment.

preOp :: P TT TT Source #

Parses a prefix operator.

inOp :: P TT TT Source #

Parses a infix operator.

postOp :: P TT TT Source #

Parses a postfix operator.

opTok :: P TT TT Source #

Parses any literal.

simpleTok :: P TT TT Source #

Parses any literal.

strTok :: P TT TT Source #

Parses any string.

numTok :: P TT TT Source #

Parses any valid number.

name :: P TT TT Source #

Parses any valid identifier.

boolean :: P TT TT Source #

Parses any boolean.

res :: Reserved -> P TT TT Source #

Parses a reserved word.

spc :: Char -> P TT TT Source #

Parses a special token.

oper :: Operator -> P TT TT Source #

Parses an operator.

# Recovery parsers

plzTok :: P TT TT -> P TT TT Source #

Expects a token x, recovers with `errorToken`.

plzSpc :: Char -> P TT TT Source #

Expects a special token.

plzExpr :: P TT (Expr TT) Source #

Expects an expression.

plz :: Failable f => P TT (f TT) -> P TT (f TT) Source #

anything :: P s TT Source #

General recovery parser, inserts an error token.

hate :: Int -> P s a -> P s a Source #

Weighted recovery.

# Utility stuff

fromBlock :: Block t -> [Statement t] Source #

firstTok :: Foldable f => f t -> t Source #

errorToken :: TT Source #

isError :: TT -> Bool Source #

toTT :: t -> Tok t Source #

Better name for `tokFromT`.

fromTT :: Tok t -> t Source #

Better name for `tokT`.