idris-0.9.17: Functional Programming Language with Dependent Types

Safe HaskellNone
LanguageHaskell98

Idris.Parser

Contents

Synopsis

Main grammar

moduleHeader :: IdrisParser (Maybe (Docstring ()), [String]) Source

Parses module definition

      ModuleHeader ::= DocComment_t? 'module' Identifier_t ';'?;

import_ :: IdrisParser (Bool, String, Maybe String, FC) Source

Parses an import statement

  Import ::= 'import' Identifier_t ';'?;

prog :: SyntaxInfo -> IdrisParser [PDecl] Source

Parses program source

     Prog ::= Decl* EOF;

decl :: SyntaxInfo -> IdrisParser [PDecl] Source

Parses a top-level declaration

Decl ::=
    Decl'
  | Using
  | Params
  | Mutual
  | Namespace
  | Class
  | Instance
  | DSL
  | Directive
  | Provider
  | Transform
  | Import!
  ;

decl' :: SyntaxInfo -> IdrisParser PDecl Source

Parses a top-level declaration with possible syntax sugar

Decl' ::=
    Fixity
  | FunDecl'
  | Data
  | Record
  | SyntaxDecl
  ;

syntaxDecl :: SyntaxInfo -> IdrisParser PDecl Source

Parses a syntax extension declaration (and adds the rule to parser state)

  SyntaxDecl ::= SyntaxRule;

addSyntax :: IState -> Syntax -> IState Source

Extend an IState with a new syntax extension. See also addReplSyntax.

addReplSyntax :: IState -> Syntax -> IState Source

Like addSyntax, but no effect on the IBC.

syntaxRule :: SyntaxInfo -> IdrisParser Syntax Source

Parses a syntax extension declaration

SyntaxRuleOpts ::= term | pattern;
SyntaxRule ::=
  SyntaxRuleOpts? syntax SyntaxSym+ '=' TypeExpr Terminator;
SyntaxSym ::=   '[' Name_t ']'
             |  '{' Name_t '}'
             |  Name_t
             |  StringLiteral_t
             ;

syntaxSym :: IdrisParser SSymbol Source

Parses a syntax symbol (either binding variable, keyword or expression)

SyntaxSym ::=   '[' Name_t ']'
             |  '{' Name_t '}'
             |  Name_t
             |  StringLiteral_t
             ;

fnDecl :: SyntaxInfo -> IdrisParser [PDecl] Source

Parses a function declaration with possible syntax sugar

  FunDecl ::= FunDecl';

fnDecl' :: SyntaxInfo -> IdrisParser PDecl Source

Parses a function declaration

 FunDecl' ::=
  DocComment_t? FnOpts* Accessibility? FnOpts* FnName TypeSig Terminator
  | Postulate
  | Pattern
  | CAF
  ;

fnOpts :: [FnOpt] -> IdrisParser [FnOpt] Source

Parses function options given initial options

FnOpts ::= total
  | partial
  | implicit
  | % no_implicit
  | % assert_total
  | % error_handler
  | % reflection
  | % specialise '[' NameTimesList? ']'
  ;
NameTimes ::= FnName Natural?;
NameTimesList ::=
  NameTimes
  | NameTimes ',' NameTimesList
  ;

postulate :: SyntaxInfo -> IdrisParser PDecl Source

Parses a postulate

Postulate ::=
  DocComment_t? postulate FnOpts* Accesibility? FnOpts* FnName TypeSig Terminator
  ;

using_ :: SyntaxInfo -> IdrisParser [PDecl] Source

Parses a using declaration

Using ::=
  using '(' UsingDeclList ')' OpenBlock Decl* CloseBlock
  ;

params :: SyntaxInfo -> IdrisParser [PDecl] Source

Parses a parameters declaration

Params ::=
  parameters '(' TypeDeclList ')' OpenBlock Decl* CloseBlock
  ;

mutual :: SyntaxInfo -> IdrisParser [PDecl] Source

Parses a mutual declaration (for mutually recursive functions)

Mutual ::=
  mutual OpenBlock Decl* CloseBlock
  ;

namespace :: SyntaxInfo -> IdrisParser [PDecl] Source

Parses a namespace declaration

Namespace ::=
  namespace identifier OpenBlock Decl+ CloseBlock
  ;

instanceBlock :: SyntaxInfo -> IdrisParser [PDecl] Source

Parses a methods block (for instances)

  InstanceBlock ::= 'where' OpenBlock FnDecl* CloseBlock

classBlock :: SyntaxInfo -> IdrisParser [PDecl] Source

Parses a methods and instances block (for type classes)

MethodOrInstance ::=
   FnDecl
   | Instance
   ;
ClassBlock ::=
  'where' OpenBlock MethodOrInstance* CloseBlock
  ;

class_ :: SyntaxInfo -> IdrisParser [PDecl] Source

Parses a type class declaration

ClassArgument ::=
   Name
   | '(' Name : Expr ')'
   ;
Class ::=
  DocComment_t? Accessibility? 'class' ConstraintList? Name ClassArgument* ClassBlock?
  ;

instance_ :: SyntaxInfo -> IdrisParser [PDecl] Source

Parses a type class instance declaration

  Instance ::=
    DocComment_t? 'instance' InstanceName? ConstraintList? Name SimpleExpr* InstanceBlock?
    ;
InstanceName ::= '[' Name ']';

usingDeclList :: SyntaxInfo -> IdrisParser [Using] Source

Parses a using declaration list

UsingDeclList ::=
  UsingDeclList'
  | NameList TypeSig
  ;
UsingDeclList' ::=
  UsingDecl
  | UsingDecl ',' UsingDeclList'
  ;
NameList ::=
  Name
  | Name ',' NameList
  ;

usingDecl :: SyntaxInfo -> IdrisParser Using Source

Parses a using declaration

UsingDecl ::=
  FnName TypeSig
  | FnName FnName+
  ;

pattern :: SyntaxInfo -> IdrisParser PDecl Source

Parse a clause with patterns

Pattern ::= Clause;

caf :: SyntaxInfo -> IdrisParser PDecl Source

Parse a constant applicative form declaration

CAF ::= 'let' FnName '=' Expr Terminator;

argExpr :: SyntaxInfo -> IdrisParser PTerm Source

Parse an argument expression

ArgExpr ::= HSimpleExpr | ;

rhs :: SyntaxInfo -> Name -> IdrisParser PTerm Source

Parse a right hand side of a function

RHS ::= '='            Expr
     |  ?=  RHSName? Expr
     |  impossible
     ;
RHSName ::= '{' FnName '}';

clause :: SyntaxInfo -> IdrisParser PClause Source

Parses a function clause

RHSOrWithBlock ::= RHS WhereOrTerminator
               | with SimpleExpr OpenBlock FnDecl+ CloseBlock
               ;
Clause ::=                                                               WExpr+ RHSOrWithBlock
       |   SimpleExpr <==  FnName                                             RHS WhereOrTerminator
       |   ArgExpr Operator ArgExpr                                      WExpr* RHSOrWithBlock 
       |                     FnName ConstraintArg* ImplicitOrArgExpr*    WExpr* RHSOrWithBlock
       ;
ImplicitOrArgExpr ::= ImplicitArg | ArgExpr;
WhereOrTerminator ::= WhereBlock | Terminator;

wExpr :: SyntaxInfo -> IdrisParser PTerm Source

Parses with pattern

WExpr ::= '|' Expr';

whereBlock :: Name -> SyntaxInfo -> IdrisParser ([PDecl], [(Name, Name)]) Source

Parses a where block

WhereBlock ::= 'where' OpenBlock Decl+ CloseBlock;

codegen_ :: IdrisParser Codegen Source

Parses a code generation target language name

Codegen ::= C
        |   Java
        |   JavaScript
        |   Node
        |   LLVM
        |   Bytecode
        ;

directive :: SyntaxInfo -> IdrisParser [PDecl] Source

Parses a compiler directive StringList ::= String | String ',' StringList ;

Directive ::= % Directive';
Directive' ::= lib            CodeGen String_t
           |   link           CodeGen String_t
           |   flag           CodeGen String_t
           |   include        CodeGen String_t
           |   hide           Name
           |   freeze         Name
           |   access         Accessibility
           |   'default'        Totality
           |   logging        Natural
           |   dynamic        StringList
           |   name           Name NameList
           |   error_handlers Name NameList
           |   language       TypeProviders
           |   language       ErrorReflection
           ;

totality :: IdrisParser Bool Source

Parses a totality

Totality ::= partial | total

provider :: SyntaxInfo -> IdrisParser [PDecl] Source

Parses a type provider

Provider ::= DocComment_t? % provide Provider_What? '(' FnName TypeSig ')' with Expr;
ProviderWhat ::= proof | term | 'type' | postulate

transform :: SyntaxInfo -> IdrisParser [PDecl] Source

Parses a transform

Transform ::= % transform Expr ==> Expr

Loading and parsing

parseExpr :: IState -> String -> Result PTerm Source

Parses an expression from input

parseConst :: IState -> String -> Result Const Source

Parses a constant form input

parseTactic :: IState -> String -> Result PTactic Source

Parses a tactic from input

parseImports :: FilePath -> String -> Idris (Maybe (Docstring ()), [String], [(Bool, String, Maybe String, FC)], Maybe Delta) Source

Parse module header and imports

findFC :: Doc -> (FC, String) Source

There should be a better way of doing this...

fixColour :: Bool -> Doc -> Doc Source

Check if the coloring matches the options and corrects if necessary

parseProg :: SyntaxInfo -> FilePath -> String -> Maybe Delta -> Idris [PDecl] Source

A program is a list of declarations, possibly with associated documentation strings.

loadModule :: FilePath -> Idris (Maybe String) Source

Load idris module and show error if something wrong happens

loadModule' :: FilePath -> Idris (Maybe String) Source

Load idris module

loadFromIFile :: Bool -> IFileType -> Maybe Int -> Idris () Source

Load idris code from file

loadSource' :: Bool -> FilePath -> Maybe Int -> Idris () Source

Load idris source code and show error if something wrong happens

loadSource :: Bool -> FilePath -> Maybe Int -> Idris () Source

Load Idris source code

addHides :: [(Name, Maybe Accessibility)] -> Idris () Source

Adds names to hide list