mini-go-0.3.0.0: Mini Go parser and interpreter
Safe HaskellSafe-Inferred
LanguageHaskell2010

Parser.Parser

Description

Provides parser that produces AST.

Synopsis

Parser

parse :: Text -> Maybe Program Source #

Parser entry point.

Program (top-level) parsers

programP :: Parser Program Source #

Program parser.

topLevelDeclP :: Parser (Either VarDecl FunctionDef) Source #

Top-level declaration parser, it parses either var declaration or function definition.

functionDefP :: Parser FunctionDef Source #

Function definition parser.

Expressions parsers

expressionP :: Parser Expression Source #

Expression parser.

termExpressionP :: Parser Expression Source #

Terminal expression parser, it's terminal in terms of makeExprParser parser.

opsTable :: [[Operator Parser Expression]] Source #

Operators table, contains all operator parsers and their fixity.

Operators

binaryOp :: Text -> BinaryOp -> Operator Parser Expression Source #

Utility function, that takes operator symbol, binary operator constructor and gives new binary operator in return.

unaryOp :: Text -> UnaryOp -> Operator Parser Expression Source #

Utility function, that takes operator symbol, unary operator constructor and gives new unary operator in return.

funcCallOp :: Parser (Expression -> Expression) Source #

Function call operator.

arrayAccessByIndexOp :: Parser (Expression -> Expression) Source #

Array access by index operator.

Types parsers

typeP :: Parser Type Source #

Type parser.

arrayTypeP :: Parser ArrayType Source #

Array type parser.

functionTypeP :: Parser FunctionType Source #

Function type parser.

Statements parsers

statementP :: Parser Statement Source #

Statement parser.

stmtReturnP :: Parser Statement Source #

Return statement parser.

stmtForGoToP :: Parser Statement Source #

For goto statement parser.

stmtForP :: Parser Statement Source #

For statement parser.

varDeclP :: Parser VarDecl Source #

Var declaration parser.

ifElseP :: Parser IfElse Source #

If-else parser.

blockP :: Parser Block Source #

Block parser.

simpleStmtP :: Parser SimpleStmt Source #

Simple statement parser.

stmtAssignmentP :: Parser SimpleStmt Source #

Assignment statement parser.

stmtIncDecP :: Parser SimpleStmt Source #

Increment or decrement statement parser.

stmtShortVarDeclP :: Parser SimpleStmt Source #

Short var declaration statement parser.

stmtExpressionP :: Parser SimpleStmt Source #

Expression statement parser.

lvalueP :: Parser Lvalue Source #

Lvalue parser.

Values parsers

valueP :: Parser Value Source #

Value parser.

arrayValP :: Parser ArrayValue Source #

Array value parser.

functionValP :: Parser FunctionValue Source #

Function value parser.

functionP :: Parser Function Source #

Nameless function parser.

Utils

choice' :: (Foldable f, MonadParsec e s m, Functor f) => f (m a) -> m a Source #

Choice between elements parser with built-in backtracking support.

eitherP' :: MonadParsec e s m => m a -> m b -> m (Either a b) Source #

Combine two alternatives with built-in backtracking support.

optional' :: MonadParsec e s m => m a -> m (Maybe a) Source #

Optional element parser with built-in backtracking support.

maybeVoid :: MonadParsec e s m => m a -> m (MaybeVoid a) Source #