Previous Up Next

Appendix A  Collected Moby syntax

A.1  Identifiers

A.1.1  Identifier classes

Moby has a number of distinct classes of identifiers. In most cases, these are distinguished by context, but in some cases a capitalization convention is used to distinguish between classes.
Class Case Description
ModuleId Upper Module IDs
SigId Upper Signature IDs
TypeId Upper Type and type constructor IDs
TypeVar Lower Type variables
ClassId Upper Class IDs
Label Lower Object and record labels
MakerId Lower Maker IDs
DataCon Upper Data-constructor IDs
ValueId Lower Value IDs

A.1.2  Reserved symbols and keywords

A.2  Collected syntax

CompilationUnit
::= SignatureDecl
| ModuleDecl
| ParamModuleDecl
SignatureDecl
::= signature SigId { Specification* }
| signature SigId = SigId (with { TypeReveal+ })opt
Specification
::= include SigId
| ModuleSpec
| TypeSpec
| ClassSpec
| ConstSpec
| ValueSpec
ModuleSpec
::= module ModuleId : Signature
Signature
::= { Specification* }
| SigId (with { TypeReveal+ })opt
TypeSpec
::= type TypeId TypeParamsopt
| TypeReveal
| DataTypeDecl
| EnumTypeDecl
| TagTypeDecl
| ObjectTypeDecl
TypeReveal
::= type TypeId TypeParamsopt = Type
| type TypeId TypeParamsopt <: Type
TypeParams
::= ( TypeVar (, TypeVar)* )
ClassSpec
::= class ClassId TypeParamsopt : ClassInterface
ClassInterface
::= { InheritsSpecopt ImplementsSpecopt MemberSpec* }
InheritsSpec
::= inherits NamedClass
ImplementsSpec
::= implements NamedType (, NamedType)*
MemberSpec
::= publicopt field Label : ExtendedType
| publicopt MethodSpec
| publicopt maker MakerId of Types
MethodSpec
::= abstract method Label : TypeScheme
| method Label : TypeScheme
| final method Label : TypeScheme
ConstSpec
::= const DataCon : TypeParamsopt Type (of Types)opt
| deconst DataCon : TypeParamsopt Type (of Types)opt
ValueSpec
::= val ValueId : TypeScheme
| val DataCon : TypeScheme
ModuleDecl
::= module ModuleId (: Signature)opt ModuleBody
| module ModuleId (: Signature)opt = ModuleDef
ModuleBody
::= { Declaration* }
ModuleDef
::= Pathopt ModuleId
| ModuleId ( (ModuleExp (, ModuleExp)*)opt )
ModuleExp
::= ModuleBody
| ModuleDef
ParamModuleDecl
::= module ModuleId ( ModuleParamsopt ) (: Signature)opt ModuleBody
| module ModuleId ( ModuleParamsopt ) (: Signature)opt = ModuleDef
ModuleParams
::= ModuleId : Signature (, ModuleId : Signature)*
Declaration
::= localopt ModuleDecl
| localopt TypeDecl
| localopt ClassDecl
| localopt ConstDecl
| localopt FunDecl
| localopt ValueDecl
TypeDecl
::= TypeNameDecl
| DataTypeDecl
| EnumTypeDecl
| TagTypeDecl
| ObjectTypeDecl
TypeNameDecl
::= type TypeId TypeParamsopt = Type
DataTypeDecl
::= datatype TypeId TypeParamsopt DataTypeDef
| datatype TypeId TypeParamsopt = NamedType
DataTypeDef
::= { DataConDef (, DataConDef)* }
DataConDef
::= DataCon (of Types)opt
EnumTypeDecl
::= enumtype TypeId EnumTypeDef
| enumtype TypeId = Pathopt TypeId
EnumTypeDef
::= { DataCon (, DataCon)* }
TagTypeDecl
::= tagtype TypeId TypeParamsopt (of Types)opt (extends NamedType)opt
| tagtype TypeId TypeParamsopt = NamedType
ObjectTypeDecl
::= objtype TypeId TypeParamsopt ObjectMembers
| objtype TypeId TypeParamsopt = NamedType
ObjectMembers
::= { ObjectMember* }
ObjectMember
::= extends NamedType
| field Label : ExtendedType
| method Label : TypeScheme
TypeScheme
::= BoundTypeVarsopt Type
BoundTypeVars
::= [ BoundTypeVar (, BoundTypeVar)* ]
BoundTypeVar
::= TypeVar (<: Type)opt
Types
::= TypeTuple
| Type
TypeTuple
::= ( (Type (, Type)+)opt )
Type
::= FunType
| AtomicType
FunType
::= AtomicTypes -> FunType
| AtomicTypes -> AtomicTypes
AtomicTypes
::= TypeTuple
| AtomicType
AtomicType
::= TypeVar
| NamedType
| $ TypeTuple
NamedType
::= Pathopt TypeId TypeArgsopt
| typeof ( NamedClass )
| # NamedClass
TypeArgs
::= ( Type (, Type)* )
ExtendedType
::= TypeScheme
| var Type
ClassDecl
::= class ClassId (: ClassInterface)opt ClassDef
| class ClassId (: ClassInterface)opt = NamedClass
ClassDef
::= { (inherits NamedClass)opt MemberDecl* InitiallyClauseopt }
NamedClass
::= Pathopt ClassId TypeArgsopt
MemberDecl
::= publicopt FieldDecl
| publicopt MethodDecl
| publicopt MakerDecl
FieldDecl
::= field Label : ExtendedType
MethodDecl
::= abstract method Label : TypeScheme
| finalopt overrideopt method Label FunDef
MakerDecl
::= maker MakerId Params MakerBlock
MakerBlock
::= { MakerStmt (; MakerStmt)* }
| { }
MakerStmt
::= super MakerId Expression
| field Label = Expression
| Statement
InitiallyClause
::= initially Expression
ConstDecl
::= const DataCon : TypeScheme = Pattern
| const DataCon : TypeParamsopt Type of Params = Pattern
FunDecl
::= fun ValueId FunDef
FunDef
::= BoundTypeVarsopt Params+ -> Type Block
| : TypeScheme MatchCase
Params
::= ( (Param (, Param)*)opt )
Param
::= ValueId : Type
ValueDecl
::= val BoundTypeVarsopt Params = Expression
| val BoundTypeVarsopt Param = Expression
Block
::= { (Statement ;)* Expression }
| { }
Statement
::= Expression
| Binding
Binding
::= let Patterns = Expression
| fun ValueId FunDef (and ValueId FunDef)*
Expression
::= if Expression then Expression else Expression
| TryExpression
| raise Expression
| spawn Expression
| sync Expression
| event Expression
| AssignmentExpr
TryExpression
::= try Expression except MatchCase
| try Expression finally Expression
AssignmentExpr
::= ConditionalOrExpr := ConditionalOrExpr
| ConditionalOrExpr
ConditionalOrExpr
::= ConditionalOrExpr || ConditionalAndExpr
| ConditionalAndExpr
ConditionalAndExpr
::= ConditionalAndExpr && EqualityExpr
| EqualityExpr
EqualityExpr
::= EqualityExpr EqualityOp RelationalExpr
| RelationalExpr
EqualityOp
::= == | !=
RelationalExpr
::= RelationalExpr RelationalOp ListExpr
| ListExpr
RelationalOp
::= < | <= | >= | >
ListExpr
::= ShiftExpr ListOp ListExpr
| ShiftExpr
ListOp
::= @ | ::
ShiftExpr
::= ShiftExpr ShiftOp BitwiseOrExpr
| BitwiseOrExpr
ShiftOp
::= << | >> | >>>
BitwiseOrExpr
::= BitwiseOrExpr | BitwiseAndExpr
| BitwiseOrExpr \/ BitwiseAndExpr
| BitwiseAndExpr
BitwiseAndExpr
::= BitwiseAndExpr & AdditiveExpr
| BitwiseAndExpr /\ AdditiveExpr
| AdditiveExpr
AdditiveExpr
::= AdditiveExpr AdditiveOp MultiplicativeExpr
| MultiplicativeExpr
AdditiveOp
::= + | -
MultiplicativeExpr
::= MultiplicativeExpr MultiplicativeOp Expr
| ExponentialExpr
MultiplicativeOp
::= * | / | %
ExponentialExpr
::= ExponentialExpr ** CompositionExpr
| CompositionExpr
CompositionExpr
::= PrefixExpr ^ CompositionExpr
| PrefixExpr
PrefixExpr
::= PrefixOp PrefixExpr
| ApplicationExpr
PrefixOp
::= * | & | ! | ~ | -
ApplicationExpr
::= ApplicationExpr PostfixExpr
| PostfixExpr
PostfixExpr
::= PostfixExpr . Label
| PostfixExpr [ Expression ]
| AtomicExpr
AtomicExpr
::= fn FunDef
| case Expression of MatchCase
| ( (Expression (, Expression)*)opt )
| ( Expression : Type )
| ( Expression is Pattern )
| ( Expression isnot Pattern )
| ChoiceEvent
| Block
| new Pathopt MakerId
| self
| super . Label
| nack_event
| rdy_event
| ( Operator )
| Pathopt ValueId
| DataConstructor
| # DataConstructor
| ? DataConstructor
| Literal
DataConstructor
::= Pathopt DataCon
| $
ChoiceEvent
::= {| WrappedEvent (, WrappedEvent)* |}
WrappedEvent
::= Expression
| Expression \ Pattern => Expression
| Expression \ MatchCase
MatchCase
::= { MatchRule (, MatchRule)* }
MatchRule
::= Patterns (when Expression)opt => Expression
Patterns
::= PatternTuple
| Pattern
PatternTuple
::= ( Pattern (, Pattern)+ )
Pattern
::= IsPattern : Type
| IsPattern
IsPattern
::= ValueId is OrPattern
| ValueId isnot OrPattern
| _ isnot OrPattern
| OrPattern
OrPattern
::= OrPattern (| ConsPattern)+
| ConsPattern
ConsPattern
::= ApplyPattern :: ConsPattern
| ApplyPattern
ApplyPattern
::= Pathopt DataCon PatternTuple
| Pathopt DataCon AtomicPattern
| AtomicPattern
AtomicPattern
::= ( Pattern )
| _
| ValueId
| DataConstructor
| Literal
| - NumericLiteral
Literal
::= True
| False
| CharLit
| StringLit
| NumericLiteral
NumericLiteral
::= IntegerLiteral
| FloatLiteral
Path
::= (ModuleId .)+
Operator
::= ==   |   !=   |   <   |   <=   |   =>   |   >   |   @   |   ::   |   <<   |   >>   |   >>>   |   |   |   \/   |   &   |   /\   |   +   |   -   |   *   |   /   |   %   |   **   |   ^   |   !   |   ~

Previous Up Next