-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Lua parser and pretty-printer -- -- Lua 5.2 lexer, parser and pretty-printer. -- -- Changelog: -- -- 0.5.0: -- -- -- -- 0.4.6: -- -- -- -- 0.4.5: -- -- -- -- 0.4.4: -- -- -- -- 0.4.3: -- -- -- -- 0.4.2: -- -- -- -- 0.4.1: -- -- -- -- 0.4.0: -- -- -- -- 0.3.1: -- -- -- -- 0.3.0: -- -- -- -- 0.2.3: -- -- -- -- 0.2.2: -- -- -- -- 0.2.0: -- -- @package language-lua @version 0.5.0 -- | Lua 5.2 syntax tree, as specified in -- http://www.lua.org/manual/5.2/manual.html#9. Annotation -- implementation is inspired by haskell-src-exts. module Language.Lua.Annotated.Syntax data Name a Name :: a -> String -> Name a data Stat a -- | var1, var2 .. = exp1, exp2 .. Assign :: a -> [Var a] -> [Exp a] -> Stat a -- | function call FunCall :: a -> (FunCall a) -> Stat a -- | label for goto Label :: a -> (Name a) -> Stat a -- | break Break :: a -> Stat a -- | goto label Goto :: a -> (Name a) -> Stat a -- | do .. end Do :: a -> (Block a) -> Stat a -- | while .. do .. end While :: a -> (Exp a) -> (Block a) -> Stat a -- | repeat .. until .. Repeat :: a -> (Block a) -> (Exp a) -> Stat a -- | if .. then .. [elseif ..] [else ..] end If :: a -> [(Exp a, Block a)] -> (Maybe (Block a)) -> Stat a -- | for x=start, end [, step] do .. end ForRange :: a -> (Name a) -> (Exp a) -> (Exp a) -> (Maybe (Exp a)) -> (Block a) -> Stat a -- | for x in .. do .. end ForIn :: a -> [Name a] -> [Exp a] -> (Block a) -> Stat a -- | function <var> (..) .. end FunAssign :: a -> (FunName a) -> (FunBody a) -> Stat a -- | local function <var> (..) .. end LocalFunAssign :: a -> (Name a) -> (FunBody a) -> Stat a -- | local var1, var2 .. = exp1, exp2 .. LocalAssign :: a -> [Name a] -> (Maybe [Exp a]) -> Stat a -- | ; EmptyStat :: a -> Stat a data Exp a Nil :: a -> Exp a Bool :: a -> Bool -> Exp a Number :: a -> String -> Exp a String :: a -> String -> Exp a -- | ... Vararg :: a -> Exp a -- | function (..) .. end EFunDef :: a -> (FunDef a) -> Exp a PrefixExp :: a -> (PrefixExp a) -> Exp a -- | table constructor TableConst :: a -> (Table a) -> Exp a -- | binary operators, + - * ^ % .. <= >= == ~= and or Binop :: a -> (Binop a) -> (Exp a) -> (Exp a) -> Exp a -- | unary operators, - not # Unop :: a -> (Unop a) -> (Exp a) -> Exp a data Var a -- | variable VarName :: a -> (Name a) -> Var a -- | table[exp] Select :: a -> (PrefixExp a) -> (Exp a) -> Var a -- | table.variable SelectName :: a -> (PrefixExp a) -> (Name a) -> Var a data Binop a Add :: a -> Binop a Sub :: a -> Binop a Mul :: a -> Binop a Div :: a -> Binop a Exp :: a -> Binop a Mod :: a -> Binop a Concat :: a -> Binop a LT :: a -> Binop a LTE :: a -> Binop a GT :: a -> Binop a GTE :: a -> Binop a EQ :: a -> Binop a NEQ :: a -> Binop a And :: a -> Binop a Or :: a -> Binop a data Unop a Neg :: a -> Unop a Not :: a -> Unop a Len :: a -> Unop a data PrefixExp a PEVar :: a -> (Var a) -> PrefixExp a PEFunCall :: a -> (FunCall a) -> PrefixExp a Paren :: a -> (Exp a) -> PrefixExp a data Table a -- | list of table fields Table :: a -> [TableField a] -> Table a data TableField a -- | [exp] = exp ExpField :: a -> (Exp a) -> (Exp a) -> TableField a -- | name = exp NamedField :: a -> (Name a) -> (Exp a) -> TableField a Field :: a -> (Exp a) -> TableField a -- | A block is list of statements with optional return statement. data Block a Block :: a -> [Stat a] -> (Maybe [Exp a]) -> Block a data FunName a FunName :: a -> (Name a) -> [Name a] -> (Maybe (Name a)) -> FunName a data FunDef a FunDef :: a -> (FunBody a) -> FunDef a data FunBody a -- | (args, vararg, block) FunBody :: a -> [Name a] -> (Maybe a) -> (Block a) -> FunBody a data FunCall a -- | prefixexp ( funarg ) NormalFunCall :: a -> (PrefixExp a) -> (FunArg a) -> FunCall a -- | prefixexp : name ( funarg ) MethodCall :: a -> (PrefixExp a) -> (Name a) -> (FunArg a) -> FunCall a data FunArg a -- | list of args Args :: a -> [Exp a] -> FunArg a -- | table constructor TableArg :: a -> (Table a) -> FunArg a -- | string StringArg :: a -> String -> FunArg a class Functor ast => Annotated ast ann :: Annotated ast => ast l -> l amap :: Annotated ast => (l -> l) -> ast l -> ast l instance Typeable Name instance Typeable Binop instance Typeable Unop instance Typeable FunName instance Typeable FunArg instance Typeable Table instance Typeable TableField instance Typeable Exp instance Typeable FunDef instance Typeable FunBody instance Typeable Block instance Typeable Stat instance Typeable FunCall instance Typeable PrefixExp instance Typeable Var instance Show a => Show (Name a) instance Eq a => Eq (Name a) instance Functor Name instance Data a => Data (Name a) instance Show a => Show (Binop a) instance Eq a => Eq (Binop a) instance Functor Binop instance Data a => Data (Binop a) instance Show a => Show (Unop a) instance Eq a => Eq (Unop a) instance Functor Unop instance Data a => Data (Unop a) instance Show a => Show (FunName a) instance Eq a => Eq (FunName a) instance Functor FunName instance Data a => Data (FunName a) instance Show a => Show (FunArg a) instance Eq a => Eq (FunArg a) instance Functor FunArg instance Data a => Data (FunArg a) instance Show a => Show (Table a) instance Eq a => Eq (Table a) instance Functor Table instance Data a => Data (Table a) instance Show a => Show (TableField a) instance Eq a => Eq (TableField a) instance Functor TableField instance Data a => Data (TableField a) instance Show a => Show (Exp a) instance Eq a => Eq (Exp a) instance Functor Exp instance Data a => Data (Exp a) instance Show a => Show (FunDef a) instance Eq a => Eq (FunDef a) instance Functor FunDef instance Data a => Data (FunDef a) instance Show a => Show (FunBody a) instance Eq a => Eq (FunBody a) instance Functor FunBody instance Data a => Data (FunBody a) instance Show a => Show (Block a) instance Eq a => Eq (Block a) instance Functor Block instance Data a => Data (Block a) instance Show a => Show (Stat a) instance Eq a => Eq (Stat a) instance Functor Stat instance Data a => Data (Stat a) instance Show a => Show (FunCall a) instance Eq a => Eq (FunCall a) instance Functor FunCall instance Data a => Data (FunCall a) instance Show a => Show (PrefixExp a) instance Eq a => Eq (PrefixExp a) instance Functor PrefixExp instance Data a => Data (PrefixExp a) instance Show a => Show (Var a) instance Eq a => Eq (Var a) instance Functor Var instance Data a => Data (Var a) instance Annotated FunArg instance Annotated FunCall instance Annotated FunBody instance Annotated FunDef instance Annotated FunName instance Annotated Block instance Annotated TableField instance Annotated Table instance Annotated PrefixExp instance Annotated Unop instance Annotated Binop instance Annotated Var instance Annotated Exp instance Annotated Stat module Language.Lua.Token -- | Lua tokens data LToken -- | + LTokPlus :: LToken -- | - LTokMinus :: LToken -- | * LTokStar :: LToken -- | / LTokSlash :: LToken -- | % LTokPercent :: LToken -- | ^ LTokExp :: LToken -- | # LTokSh :: LToken -- | == LTokEqual :: LToken -- | ~= LTokNotequal :: LToken -- | <= LTokLEq :: LToken -- | >= LTokGEq :: LToken -- | < LTokLT :: LToken -- | > LTokGT :: LToken -- | = LTokAssign :: LToken -- | ( LTokLParen :: LToken -- | ) LTokRParen :: LToken -- | { LTokLBrace :: LToken -- | } LTokRBrace :: LToken -- | [ LTokLBracket :: LToken -- | ] LTokRBracket :: LToken -- | :: LTokDColon :: LToken -- | ; LTokSemic :: LToken -- | : LTokColon :: LToken -- | , LTokComma :: LToken -- | . LTokDot :: LToken -- | .. LTokDDot :: LToken -- | ... LTokEllipsis :: LToken -- | and LTokAnd :: LToken -- | break LTokBreak :: LToken -- | do LTokDo :: LToken -- | else LTokElse :: LToken -- | elseif LTokElseIf :: LToken -- | end LTokEnd :: LToken -- | false LTokFalse :: LToken -- | for LTokFor :: LToken -- | function LTokFunction :: LToken -- | goto LTokGoto :: LToken -- | if LTokIf :: LToken -- | in LTokIn :: LToken -- | local LTokLocal :: LToken -- | nil LTokNil :: LToken -- | not LTokNot :: LToken -- | or LTokOr :: LToken -- | repeat LTokRepeat :: LToken -- | return LTokReturn :: LToken -- | then LTokThen :: LToken -- | true LTokTrue :: LToken -- | until LTokUntil :: LToken -- | while LTokWhile :: LToken -- | number constant LTokNum :: String -> LToken -- | string constant LTokSLit :: String -> LToken -- | identifier LTokIdent :: String -> LToken -- | end of file LTokEof :: LToken instance Eq LToken instance Show LToken module Language.Lua.Annotated.Lexer -- | Lua lexer. llex :: String -> [LTok] -- | Run Lua lexer on a file. llexFile :: FilePath -> IO [LTok] -- | Lua token with position information. type LTok = (LToken, AlexPosn) data AlexPosn AlexPn :: !Int -> !Int -> !Int -> AlexPosn instance Eq AlexPosn instance Show AlexPosn instance Show EOF instance Functor AlexLastAcc instance Monad Alex -- | Lexer/Parsec interface module Text.Parsec.LTok -- | Parses given LToken. tok :: Stream [LTok] m LTok => LToken -> ParsecT [LTok] u m LToken -- | Parses a LTokIdent. anyIdent :: Monad m => ParsecT [LTok] u m String -- | Parses a LTokNum. number :: Monad m => ParsecT [LTok] u m String -- | Parses a LTokSLit. stringlit :: Monad m => ParsecT [LTok] u m String type Parser = Parsec [LTok] () module Language.Lua.Annotated.Parser -- | Runs Lua lexer before parsing. Use parseText stat to parse -- statements, and parseText exp to parse expressions. parseText :: Parser a -> String -> Either ParseError a -- | Parse a Lua file. You can use parseText chunk to parse a file -- from a string. parseFile :: FilePath -> IO (Either ParseError (Block SourcePos)) -- | Statement parser. stat :: Parser (Stat SourcePos) -- | Expression parser. exp :: Parser (Exp SourcePos) -- | Lua file parser. chunk :: Parser (Block SourcePos) instance Show a => Show (PrimaryExp a) instance Eq a => Eq (PrimaryExp a) instance Show a => Show (SuffixExp a) instance Eq a => Eq (SuffixExp a) instance Show a => Show (SuffixedExp a) instance Eq a => Eq (SuffixedExp a) module Language.Lua.Annotated -- | Runs Lua lexer before parsing. Use parseText stat to parse -- statements, and parseText exp to parse expressions. parseText :: Parser a -> String -> Either ParseError a -- | Parse a Lua file. You can use parseText chunk to parse a file -- from a string. parseFile :: FilePath -> IO (Either ParseError (Block SourcePos)) -- | Statement parser. stat :: Parser (Stat SourcePos) -- | Expression parser. exp :: Parser (Exp SourcePos) -- | Lua file parser. chunk :: Parser (Block SourcePos) -- | Lua 5.2 syntax tree, as specified in -- http://www.lua.org/manual/5.2/manual.html#9. module Language.Lua.Syntax type Name = String data Stat -- | var1, var2 .. = exp1, exp2 .. Assign :: [Var] -> [Exp] -> Stat -- | function call FunCall :: FunCall -> Stat -- | label for goto Label :: Name -> Stat -- | break Break :: Stat -- | goto label Goto :: Name -> Stat -- | do .. end Do :: Block -> Stat -- | while .. do .. end While :: Exp -> Block -> Stat -- | repeat .. until .. Repeat :: Block -> Exp -> Stat -- | if .. then .. [elseif ..] [else ..] end If :: [(Exp, Block)] -> (Maybe Block) -> Stat -- | for x=start, end [, step] do .. end ForRange :: Name -> Exp -> Exp -> (Maybe Exp) -> Block -> Stat -- | for x in .. do .. end ForIn :: [Name] -> [Exp] -> Block -> Stat -- | function <var> (..) .. end FunAssign :: FunName -> FunBody -> Stat -- | local function <var> (..) .. end LocalFunAssign :: Name -> FunBody -> Stat -- | local var1, var2 .. = exp1, exp2 .. LocalAssign :: [Name] -> (Maybe [Exp]) -> Stat -- | ; EmptyStat :: Stat data Exp Nil :: Exp Bool :: Bool -> Exp Number :: String -> Exp String :: String -> Exp -- | ... Vararg :: Exp -- | function (..) .. end EFunDef :: FunBody -> Exp PrefixExp :: PrefixExp -> Exp -- | table constructor TableConst :: [TableField] -> Exp -- | binary operators, + - * ^ % .. <= >= == ~= and or Binop :: Binop -> Exp -> Exp -> Exp -- | unary operators, - not # Unop :: Unop -> Exp -> Exp data Var -- | variable VarName :: Name -> Var -- | table[exp] Select :: PrefixExp -> Exp -> Var -- | table.variable SelectName :: PrefixExp -> Name -> Var data Binop Add :: Binop Sub :: Binop Mul :: Binop Div :: Binop Exp :: Binop Mod :: Binop Concat :: Binop LT :: Binop LTE :: Binop GT :: Binop GTE :: Binop EQ :: Binop NEQ :: Binop And :: Binop Or :: Binop data Unop Neg :: Unop Not :: Unop Len :: Unop data PrefixExp PEVar :: Var -> PrefixExp PEFunCall :: FunCall -> PrefixExp Paren :: Exp -> PrefixExp data TableField -- | [exp] = exp ExpField :: Exp -> Exp -> TableField -- | name = exp NamedField :: Name -> Exp -> TableField Field :: Exp -> TableField -- | A block is list of statements with optional return statement. data Block Block :: [Stat] -> (Maybe [Exp]) -> Block data FunName FunName :: Name -> [Name] -> (Maybe Name) -> FunName data FunBody -- | (args, vararg, block) FunBody :: [Name] -> Bool -> Block -> FunBody data FunCall -- | prefixexp ( funarg ) NormalFunCall :: PrefixExp -> FunArg -> FunCall -- | prefixexp : name ( funarg ) MethodCall :: PrefixExp -> Name -> FunArg -> FunCall data FunArg -- | list of args Args :: [Exp] -> FunArg -- | table constructor TableArg :: [TableField] -> FunArg -- | string StringArg :: String -> FunArg instance Typeable Binop instance Typeable Unop instance Typeable FunName instance Typeable FunArg instance Typeable TableField instance Typeable Exp instance Typeable FunBody instance Typeable Block instance Typeable Stat instance Typeable FunCall instance Typeable PrefixExp instance Typeable Var instance Show Binop instance Eq Binop instance Data Binop instance Show Unop instance Eq Unop instance Data Unop instance Show FunName instance Eq FunName instance Data FunName instance Show FunArg instance Eq FunArg instance Data FunArg instance Show TableField instance Eq TableField instance Data TableField instance Show Exp instance Eq Exp instance Data Exp instance Show FunBody instance Eq FunBody instance Data FunBody instance Show Block instance Eq Block instance Data Block instance Show Stat instance Eq Stat instance Data Stat instance Show FunCall instance Eq FunCall instance Data FunCall instance Show PrefixExp instance Eq PrefixExp instance Data PrefixExp instance Show Var instance Eq Var instance Data Var -- | Lua pretty-printer. module Language.Lua.PrettyPrinter -- | This is the default pretty printer which is used by show, -- putDoc and hPutDoc. (renderPretty ribbonfrac width -- x) renders document x with a page width of -- width and a ribbon width of (ribbonfrac * width) -- characters. The ribbon width is the maximal amount of non-indentation -- characters on a line. The parameter ribbonfrac should be -- between 0.0 and 1.0. If it is lower or higher, the -- ribbon width will be 0 or width respectively. renderPretty :: Float -> Int -> Doc -> SimpleDoc -- | (displayS simpleDoc) takes the output simpleDoc from -- a rendering function and transforms it to a ShowS type (for use -- in the Show class). -- --
--   showWidth :: Int -> Doc -> String
--   showWidth w x   = displayS (renderPretty 0.4 w x) ""
--   
displayS :: SimpleDoc -> ShowS -- | (displayIO handle simpleDoc) writes simpleDoc to the -- file handle handle. This function is used for example by -- hPutDoc: -- --
--   hPutDoc handle doc  = displayIO handle (renderPretty 0.4 100 doc)
--   
displayIO :: Handle -> SimpleDoc -> IO () class LPretty a where pprint = pprint' 0 pprint' _ = pprint pprint :: LPretty a => a -> Doc instance LPretty Stat instance LPretty FunArg instance LPretty FunCall instance LPretty FunBody instance LPretty FunName instance LPretty Block instance LPretty TableField instance LPretty [TableField] instance LPretty PrefixExp instance LPretty Unop instance LPretty Binop instance LPretty Var instance LPretty Exp instance LPretty Bool instance LPretty [Char] -- | Remove annotations. module Language.Lua.Annotated.Simplify sName :: Name a -> Name sStat :: Stat a -> Stat sExp :: Exp a -> Exp sBlock :: Block a -> Block sVar :: Var a -> Var sFunCall :: FunCall a -> FunCall sFunName :: FunName a -> FunName sFunBody :: FunBody a -> FunBody sFunDef :: FunDef a -> FunBody sPrefixExp :: PrefixExp a -> PrefixExp sTable :: Table a -> [TableField] sBinop :: Binop a -> Binop sUnop :: Unop a -> Unop sFunArg :: FunArg a -> FunArg sTableField :: TableField a -> TableField module Language.Lua.Parser parseText :: Parser a -> String -> Either ParseError a parseFile :: FilePath -> IO (Either ParseError Block) stat :: Parser Stat exp :: Parser Exp chunk :: Parser Block module Language.Lua parseText :: Parser a -> String -> Either ParseError a parseFile :: FilePath -> IO (Either ParseError Block) stat :: Parser Stat exp :: Parser Exp chunk :: Parser Block pprint :: LPretty a => a -> Doc