dil.parser.Parser

Author:

Aziz Köksal

License:

GPL3

Maturity: very high.

class Parser
The Parser produces a full parse tree by examining the list of tokens provided by the Lexer.
Lexer lexer
Used to lex the source code.
Token* token
Current non-whitespace token.
Token* prevToken
Previous non-whitespace token.
Diagnostics diag
Collects error messages.
ParserError[] errors
Array of parser error messages.
ImportDecl[] imports
ImportDeclarations in the source text.
LinkageType linkageType
Protection protection
StorageClass storageClass
uint alignSize
Attributes are evaluated in the parsing phase.

TODO:

will be removed. SemanticPass1 takes care of attributes.
this(SourceText srcText, LexerTables tables, Diagnostics diag = null)
Constructs a Parser object.

Parameters:

srcTextThe UTF-8 source code.
tablesFor the Lexer.
diagUsed for collecting error messages.
void init() [protected]
Moves to the first token.
void nT()
Moves to the next token.
CompoundDecl start()
Starts the parser and returns the parsed Declarations.
Expression start2()
Starts the parser and returns the parsed Expression.
uint trying
Greater than 0 if Parser is in tryToParse().
uint errorCount
Used to track nr. of errors while being in tryToParse().
RetType tryToParse(RetType)(RetType delegate() parseMethod, out bool success)
This method executes the delegate parseMethod and when an error occurs the state of the lexer and parser is restored.

Returns:

The return value of parseMethod().
void fail_tryToParse()
Causes the current call to tryToParse() to fail.
void backtrackTo(Token* newtok, Token* newprev = null)
Backtracks the Parser and the Lexer to the given token(s).
Class set(Class)(Class node, Token* begin)
Sets the begin and end tokens of a syntax tree node.
Class set(Class)(Class node, Token* begin, Token* end)
Sets the begin and end tokens of a syntax tree node.
bool isNodeSet(Node node) [static]
Returns true if set() has been called on a node.
bool tokenIs()(TOK kind)
Returns true if the current token is of a certain kind.
TOK peekNext()
Returns the token kind of the next token.
Token* peekAfter(Token* t)
Returns the token that comes after t.
bool consumed()(TOK k)
Consumes the current token if its kind matches k and returns true.
Token* consumedToken()(TOK k)
Consumes the current token if its kind matches k and returns it.
void skip()(TOK expectedKind)
Asserts that the current token is of kind expectedKind, and then moves to the next token.
bool tokenAfterParenIs(TOK kind)
Returns true if the token after the closing parenthesis matches the searched kind.

Parameters:

kindThe token kind to test for.
TOK tokenAfterBracket(TOK closing)
Returns the token kind behind the closing bracket.
Token* skipParens(Token* peek_token, TOK closing)
Skips to the token behind the closing parenthesis token. Takes nesting into account.

Parameters:

peek_tokenOpening token to start from.
closingMatching closing token kind.

Returns:

The token searched for, or the EOF token.
Declaration parseModuleDecl()
ModuleDecl := module Identifier ("." Identifier)* ";"
Declaration[] parseDeclarationDefinitions()
Parses DeclarationDefinitions until the end of file is hit.
DeclDefs := DeclDef*
CompoundDecl parseDeclarationDefinitionsBody()
Parse the body of a template, class, interface, struct or union.
DeclDefsBlock := "{" DeclDefs? "}"
Declaration parseDeclarationDefinition()
Parses a DeclarationDefinition.
DeclDef := Attributes | ...
Declaration parseDeclarationsBlock()
Parses a DeclarationsBlock.
DeclsBlock := ":" DeclDefs | "{" DeclDefs? "}" | DeclDef
Declaration parseVariableOrFunction(StorageClass stcs = StorageClass.None, Protection protection = Protection.None, LinkageType linkType = LinkageType.None, bool testAutoDeclaration = false)
Parses either a VariableDeclaration or a FunctionDeclaration.
VariableOrFunctionDeclaration :=
  AutoDecl | VariableDecl | FunctionDecl
AutoDecl      := AutoVariable | AutoTemplate
AutoVariable  := Name "=" Initializer MoreVariables? ";"
VariableDec   :=
  Type Name TypeSuffix? ("=" Initializer)? MoreVariables? ";"
MoreVariables := ("," Name ("=" Initializer)?)+
FunctionDec   :=
  Type Name TemplateParameterList? ParameterList FunctionBody
AutoTemplate  := Name TemplateParameterList ParameterList FunctionBody
Name          := Identifier

Parameters:

stcsPreviously parsed storage classes.
protectionPreviously parsed protection attribute.
linkTypePreviously parsed linkage type.
testAutoDeclarationWhether to check for an AutoDeclaration.
Expression parseInitializer()
Parses a variable initializer.
Initializer        := VoidInitializer | NonVoidInitializer
VoidInitializer    := void
NonVoidInitializer :=
  ArrayInitializer | StructInitializer | AssignExpr
ArrayInitializer   := "[" ArrayInitElements? "]"
ArrayInitElements  := ArrayInitElement ("," ArrayInitElement)* ","?
ArrayInitElement   := (AssignExpr ":")? NonVoidInitializer
StructInitializer  := "{" StructInitElements? "}"
StructInitElements := StructInitElement ("," StructInitElement)* ","?
StructInitElement  := (MemberName ":")? NonVoidInitializer
MemberName         := Identifier
Expression parseNonVoidInitializer()
Parses a NonVoidInitializer.
NonVoidInitializer :=
  ArrayInitializer | StructInitializer | AssignExpr
FuncBodyStmt parseFunctionBody()
Parses the body of a function.
StorageClass parseFunctionPostfix()
FunctionPostfix :=
  (const|immutable|inout|nothrow|shared|pure| "@" Identifier)*
bool isFunctionPostfix(Token* t)
Returns true if t points to a postfix attribute.
LinkageType parseExternLinkageType()
ExternLinkageType := extern "(" LinkageType ")"
LinkageType := "C" | "C" "++" | "D" | "Windows" | "Pascal" | "System"
void checkLinkageType(ref LinkageType prev_lt, LinkageType lt, Token* begin)
Reports an error if a linkage type has already been parsed.
Declaration parseAttributes(Declaration* pDecl = null)
Parses one or more attributes and a Declaration at the end.
Attributes :=
  (StorageAttribute | AlignAttribute | PragmaAttribute | ProtAttribute)*
  DeclsBlock
StorageAttribute := extern | ExternLinkageType | override | abstract |
  auto | synchronized | static | final | const | immutable | enum | scope
AlignAttribute   := align ("(" Integer ")")?
PragmaAttribute  := pragma "(" Identifier ("," ExpressionList)? ")"
ProtAttribute    := private | public | package | protected | export

Parameters:

pDeclSet to the non-attribute Declaration if non-null.
uint parseAlignAttribute(out Token* sizetok)
AlignAttribute := align ("(" Integer ")")?
StorageClass parseAtAttribute()
AtAttribute := "@" Identifier
ImportDecl parseImportDecl()
ImportDecl := static? import
              ImportModule ("," ImportModule)*
              (":" ImportBind ("," ImportBind)*)?
              ";"
ImportModule := (AliasName "=")? ModuleName
ImportBind   := (AliasName "=")? BindName
ModuleName   := Identifier ("." Identifier)*
AliasName    := Identifier
BindName     := Identifier
bool isEnumManifest()
Returns true if this is an enum manifest or false if it's a normal enum declaration.
Declaration parseEnumDecl()
EnumDecl :=
  enum Name? (":" BasicType)? EnumBody |
  enum Name ";"
EnumBody     := "{" EnumMembers "}"
EnumMembers  := EnumMember ("," EnumMember)* ","?
EnumMembers2 := Type? EnumMember ("," Type? EnumMember)* ","? # D2.0
EnumMember   := Name ("=" AssignExpr)?
TemplateDecl putInsideTemplateDeclaration(Token* begin, Token* name, Declaration decl, TemplateParameters tparams, Expression constraint)
Wraps a declaration inside a template declaration.

Parameters:

beginBegin token of decl.
nameName of decl.
declThe declaration to be wrapped.
tparamsThe template parameters.
constraintThe constraint expression.
Declaration parseClassDecl()
ClassDecl :=
  class Name TemplateParameterList? (":" BaseClasses) ClassBody |
  class Name ";"
ClassBody := DeclDefsBlock
BaseClassType[] parseBaseClasses()
BaseClasses := BaseClass ("," BaseClass)
BaseClass   := Protection? BasicType
Protection  := private | public | protected | package
Declaration parseInterfaceDecl()
InterfaceDecl :=
  interface Name TemplateParameterList? (":" BaseClasses) InterfaceBody |
  interface Name ";"
InterfaceBody := DeclDefsBlock
Declaration parseStructOrUnionDecl()
StructDecl :=
  struct Name? TemplateParameterList? StructBody |
  struct Name ";"
StructBody := DeclDefsBlock
UnionDecl  :=
  union Name? TemplateParameterList? UnionBody |
  union Name ";"
UnionBody  := DeclDefsBlock
Declaration parseConstructorDecl()
ConstructorDecl := this ParameterList FunctionBody
Declaration parseDestructorDecl()
DestructorDecl := "~" this "(" ")" FunctionBody
Declaration parseStaticCtorDecl()
StaticCtorDecl := static this "(" ")" FunctionBody
Declaration parseStaticDtorDecl()
StaticDtorDecl := static "~" this "(" ")" FunctionBody
Declaration parseInvariantDecl()
InvariantDecl := invariant ("(" ")")? FunctionBody
Declaration parseUnittestDecl()
UnittestDecl := unittest FunctionBody
Token* parseIdentOrInt()
Parses an identifier or an integer. Reports an error otherwise.
IdentOrInt := Identifier | Integer
Token* parseVersionCondition()
VersionCondition := unittest #*D2.0*# | IdentOrInt
Declaration parseDebugDecl()
DebugDecl :=
  debug "=" IdentOrInt ";" |
  debug DebugCondition? DeclsBlock (else DeclsBlock)?
DebugCondition := "(" IdentOrInt ")"
Declaration parseVersionDecl()
VersionDecl :=
  version "=" IdentOrInt ";" |
  version VCondition DeclsBlock (else DeclsBlock)?
VCondition  := "(" VersionCondition ")"
Declaration parseStaticIfDecl()
StaticIfDecl :=
  static if "(" AssignExpr ")" DeclsBlock (else DeclsBlock)?
Declaration parseStaticAssertDecl()
StaticAssertDecl :=
  static assert "(" AssignExpr ("," Message)? ")" ";"
Message          := AssignExpr
TemplateDecl parseTemplateDecl()
TemplateDecl :=
  template Name TemplateParameterList Constraint? DeclDefsBlock
Declaration parseNewDecl()
NewDecl := new ParameterList FunctionBody
Declaration parseDeleteDecl()
DeleteDecl := delete ParameterList FunctionBody
RetT parseMixin(Class, RetT = Class)()
Parses a MixinDecl or MixinStmt.
MixinDecl       := (MixinExpr | MixinTemplate | MixinTemplateId) ";"
MixinExpr       := mixin "(" AssignExpr ")"
MixinTemplate   := mixin TemplateDecl # D2
MixinTemplateId := mixin TemplateIdentifier
                   ("!" "(" TemplateArguments ")")? MixinIdentifier?
CompoundStmt parseStatements()
Statements := "{" Statement* "}"
Statement parseStatement()
Parses a Statement.
Statement parseScopeStmt()
Parses a ScopeStmt.
ScopeStmt := NoScopeStmt
Statement parseNoScopeStmt()
NoScopeStmt := NonEmptyStmt | BlockStmt
BlockStmt   := Statements
Statement parseNoScopeOrEmptyStmt()
NoScopeOrEmptyStmt := ";" | NoScopeStmt
Statement parseAttributeStmt()
AttributeStmt := Attributes+
  (VariableOrFunctionDecl | DeclDef)
Attributes := extern | ExternLinkageType | auto | static |
              final | const | immutable | enum | scope
Statement parseIfStmt()
IfStmt    := if "(" Condition ")" ScopeStmt (else ScopeStmt)?
Condition := AutoDecl | VariableDecl | Expression
Statement parseWhileStmt()
WhileStmt := while "(" Expression ")" ScopeStmt
Statement parseDoWhileStmt()
DoWhileStmt := do ScopeStmt while "(" Expression ")"
Statement parseForStmt()
ForStmt :=
  for "(" (NoScopeStmt | ";") Expression? ";" Expression? ")"
    ScopeStmt
Statement parseForeachStmt()
ForeachStmt :=
  Foreach "(" ForeachVarList ";" Aggregate ")"
    ScopeStmt
Foreach        := foreach | foreach_reverse
ForeachVarList := ForeachVar ("," ForeachVar)*
ForeachVar     := ref? (Identifier | Declarator)
Aggregate      := Expression | ForeachRange
ForeachRange   := Expression ".." Expression # D2.0
Statement parseSwitchStmt()
SwitchStmt := final? switch "(" Expression ")" ScopeStmt
Statement parseCaseOrDefaultBody()
Helper function for parsing the body of a default or case statement.
CaseOrDefaultBody := ScopeStmt*
Statement parseCaseStmt()
CaseStmt := case ExpressionList ":" CaseOrDefaultBody |
            case AssignExpr ":" ".." case AssignExpr ":" CaseOrDefaultBody
Statement parseDefaultStmt()
DefaultStmt := default ":" CaseOrDefaultBody
Statement parseContinueStmt()
ContinueStmt := continue Identifier? ";"
Statement parseBreakStmt()
BreakStmt := break Identifier? ";"
Statement parseReturnStmt()
ReturnStmt := return Expression? ";"
Statement parseGotoStmt()
GotoStmt := goto (case Expression? | default | Identifier) ";"
Statement parseWithStmt()
WithStmt := with "(" Expression ")" ScopeStmt
Statement parseSynchronizedStmt()
SynchronizedStmt := synchronized ("(" Expression ")")? ScopeStmt
Statement parseTryStmt()
TryStmt := try ScopeStmt CatchStmt* LastCatchStmt? FinallyStmt?
CatchStmt     := catch "(" BasicType Identifier ")" NoScopeStmt
LastCatchStmt := catch NoScopeStmt
FinallyStmt   := finally NoScopeStmt
Statement parseThrowStmt()
ThrowStmt := throw Expression ";"
Statement parseScopeGuardStmt()
ScopeGuardStmt := scope "(" ScopeCondition ")" ScopeGuardBody
ScopeCondition := "exit" | "success" | "failure"
ScopeGuardBody := ScopeStmt | NoScopeStmt
Statement parseVolatileStmt()
VolatileStmt := volatile (ScopeStmt | NoScopeStmt)
Statement parsePragmaStmt()
PragmaStmt :=
  pragma "(" Identifier ("," ExpressionList)? ")" NoScopeStmt
Statement parseStaticIfStmt()
StaticIfStmt :=
  static if "(" Expression ")" NoScopeStmt (else NoScopeStmt)?
Statement parseStaticAssertStmt()
StaticAssertStmt :=
  static assert "(" AssignExpr ("," Message)? ")" ";"
Message := AssignExpr
Statement parseDebugStmt()
DebugStmt :=
  debug DebugCondition? NoScopeStmt (else NoScopeStmt)?
Statement parseVersionStmt()
VersionStmt :=
  version VCondition NoScopeStmt (else NoScopeStmt)?
Statement parseAsmBlockStmt()
Parses an AsmBlockStmt.
AsmBlockStmt := asm "{" AsmStmt* "}"
Statement parseAsmStmt()
AsmStmt :=
  OpcodeStmt | LabeledStmt | AsmAlignStmt | EmptyStmt
OpcodeStmt   := Opcode Operands? ";"
Opcode       := Identifier
Operands     := AsmExpr ("," AsmExpr)*
LabeledStmt  := Identifier ":" AsmStmt
AsmAlignStmt := align Integer ";"
EmptyStmt    := ";"
Expression parseAsmExpr()
AsmExpr     := AsmCondExpr
AsmCondExpr := AsmBinaryExpr ("?" AsmExpr ":" AsmExpr)?
Expression parseAsmBinaryExpr(PREC prevPrec = PREC.None)
AsmBinaryExpr := AsmOrOrExpr
AsmOrOrExpr   := AsmAndAndExpr ("||" AsmAndAndExpr)*
AsmAndAndExpr := AsmOrExpr  ("&&" AsmOrExpr)*
AsmOrExpr     := AsmXorExpr ("|" AsmXorExpr)*
AsmXorExpr    := AsmAndExpr ("^" AsmAndExpr)*
AsmAndExpr    := AsmCmpExpr ("&" AsmCmpExpr)*
AsmCmpExpr    := AsmShiftExpr (AsmCmpOp AsmShiftExpr)*
AsmCmpOp      := "==" | "!=" | "<" | "<=" | ">" | ">="
AsmShiftExpr  := AsmAddExpr (AsmShiftOp AsmAddExpr)*
AsmShiftOp    := "<<" | ">>" | ">>>"
AsmAddExpr    := AsmMulExpr (AsmAddOp AsmMulExpr)*
AsmAddOp      := "+" | "-"
AsmMulExpr    := AsmPostExpr (AsmMulOp AsmPostExpr)*
AsmMulOp      := "*" | "/" | "%"

Parameters:

prevPrecThe precedence of the previous operator.
Expression parseAsmPostExpr()
AsmPostExpr := AsmUnaryExpr ("[" AsmExpr "]")*
Expression parseAsmUnaryExpr()
AsmUnaryExpr :=
  AsmPrimaryExpr | AsmTypeExpr | AsmOffsetExpr | AsmSegExpr |
  SignExpr | NotExpr | ComplementExpr
AsmTypeExpr := TypePrefix "ptr" AsmExpr
TypePrefix  := "byte" | "shor" | "int" | "float" | "double" | "real"
               "near" | "far" | "word" | "dword" | "qword"
AsmOffsetExpr  := "offset" AsmExpr
AsmSegExpr     := "seg" AsmExpr
SignExpr       := ("+" | "-") AsmUnaryExpr
NotExpr        := "!" AsmUnaryExpr
ComplementExpr := "~" AsmUnaryExpr
Expression parseAsmPrimaryExpr()
AsmPrimaryExpr :=
  IntExpr | FloatExpr | DollarExpr |
  AsmBracketExpr |AsmLocalSizeExpr | AsmRegisterExpr |
  IdentifiersExpr
IntExpr          := IntegerLiteral
FloatExpr        := FloatLiteral
DollarExpr       := "$"
AsmBracketExpr   := "[" AsmExpr "]"
AsmLocalSizeExpr := "__LOCAL_SIZE"
AsmRegisterExpr  := ...
Expression newBinaryExpr(E)(Expression l, Expression r, Token* op) [static]
Instantiates a function that returns a new binary expression.
alias Expression function(Expression, Expression, Token*) NewBinaryExpr
The function signature of newBinaryExpr.
Expression parseExpression()
The root method for parsing an Expression.
Expression := CommaExpr
CommaExpr := AssignExpr ("," AssignExpr)*
Expression parseAssignExpr()
AssignExpr := CondExpr (AssignOp AssignExpr)*
AssignOp   := "=" | "<<=" | ">>=" | ">>>=" | "|=" | "&=" |
              "+=" | "-=" | "/=" | "*=" | "%=" | "^=" | "~=" | "^^="
Expression parseCondExpr()
CondExpr := BinaryExpr ("?" Expression ":" CondExpr)?
enum PREC
Enumeration of binary operator precedence values.
None
No precedence.
OOr
||
AAnd
&&
Or
|
Xor
^
And
&
Cmp
in !in is !is == != < > <= >= etc.
Shift
<< >> >>>
Plus
+ - ~
Mul
* / %
Pow
^^
PREC parseBinaryOp(out NewBinaryExpr fn, PREC prevPrec)
Consumes the tokens of a binary operator.

Parameters:

fnReceives a function that creates the binary Expression.
prevPrecThe precedence value of the previous operator.

Returns:

The precedence value of the binary operator. The higher the value the stronger the operator binds.
Expression parseBinaryExpr(PREC prevPrec = PREC.None)
Parses a binary operator expression.
BinaryExpr := OrOrExpr
OrOrExpr   := AndAndExpr ("||" AndAndExpr)*
AndAndExpr := OrExpr  ("&&" OrExpr)*
OrExpr     := XorExpr ("|" XorExpr)*
XorExpr    := AndExpr ("^" AndExpr)*
AndExpr    := CmpExpr ("&" CmpExpr)*
CmpExpr    := ShiftExpr (CmpOp ShiftExpr)?
CmpOp      := "is" | "!" "is" | "in" | "==" | "!=" | "<" | "<=" | ">" |
              ">=" | "!<>=" | "!<>" | "!<=" | "!<" |
              "!>=" | "!>" | "<>=" | "<>"
ShiftExpr  := AddExpr (ShiftOp AddExpr)*
ShiftOp    := "<<" | ">>" | ">>>"
AddExpr    := MulExpr (AddOp MulExpr)*
AddOp      := "+" | "-" | "~"
MulExpr    := PostExpr (MulOp PostExpr)*
MulExpr2   := PowExpr  (MulOp PowExpr)* # D2
MulOp      := "*" | "/" | "%"
PowExpr    := PostExpr ("^^" PostExpr)* # D2

Parameters:

prevPrecThe precedence of the previous operator.

Note:

Uses the "precedence climbing" method as described here: http://www.engr.mun.ca/~theo/Misc/exp_parsing.htm#climbing
Expression parsePostExpr()
PostExpr := UnaryExpr |
  PostIdExpr | IncOrDecExpr | CallExpr | SliceExpr | IndexExpr
PostIdExpr   := UnaryExpr "." (NewExpr | IdentifierExpr)
IncOrDecExpr := UnaryExpr ("++" | "--")
CallExpr     := UnaryExpr "(" Arguments? ")"
SliceExpr    := UnaryExpr "[" (AssignExpr ".." AssignExpr)? "]"
IndexExpr    := UnaryExpr "[" ExpressionList "]"
Expression parseUnaryExpr()
UnaryExpr := PrimaryExpr |
  NewExpr | AddressExpr | PreIncrExpr |
  PreDecrExpr | DerefExpr | SignExpr |
  NotExpr | CompExpr | DeleteExpr |
  CastExpr | TypeDotIdExpr
AddressExpr   := "&" UnaryExpr
PreIncrExpr   := "++" UnaryExpr
PreDecrExpr   := "--" UnaryExpr
DerefExpr     := "*" UnaryExpr
SignExpr      := ("-" | "+") UnaryExpr
NotExpr       := "!" UnaryExpr
CompExpr      := "~" UnaryExpr
DeleteExpr    := delete UnaryExpr
CastExpr      := cast "(" Type? ")" UnaryExpr
TypeDotIdExpr := "(" Type ")" "." Identifier
Expression parseIdentifiersExpr()
IdentifiersExpr :=
  ModuleScopeExpr? IdentifierExpr ("." IdentifierExpr)*
ModuleScopeExpr := "."
Expression parseIdentifierExpr(Expression next = null)
IdentifierExpr   := Identifier | TemplateInstance
TemplateInstance := Identifier "!" TemplateArgumentsOneOrMore
Expression parseLambdaExprBody()
LambdaBody := AssignExpr
Expression parseSingleParamLambdaExpr()
LambdaExpr := LambdaParams "=>" LambdaBody
LambdaParams := Identifier | ParameterList ParamsPostfix
Expression parsePrimaryExpr()
PrimaryExpr := IdentifierExpr | ModuleScopeExpr |
  LambdaExpr | TypeofExpr | ThisExpr | SuperExpr |
  NullExpr | BoolExpr | DollarExpr | IntExpr | FloatExpr |
  CharExpr | StringExpr | ArrayLiteralExpr | AArrayLiteralExpr |
  FuncLiteralExpr | AssertExpr | MixinExpr | ImportExpr |
  TypeidExpr | IsExpr | ParenExpr | TraitsExpr | TypeDotIdExpr |
  SpecialTokenExpr
TypeofExpr    := TypeofType
ThisExpr      := this
SuperExpr     := super
NullExpr      := null
BoolExpr      := true | false
DollarExpr    := "$"
IntExpr       := IntegerLiteral
FloatExpr     := FloatLiteral
CharExpr      := CharacterLiteral
StringExpr    := StringLiteral+
StringLiteral := NormalStringLiteral | EscapeStringLiteral |
  RawStringLiteral | HexStringLiteral | DelimitedStringLiteral |
  TokenStringLiteral
ArrayLiteralExpr := "[" ExpressionList2? "]"
AArrayLiteralExpr := "[" KeyValue ("," KeyValue)* ","? "]"
KeyValue := (AssignExpr ":" AssignExpr)
FuncLiteralExpr := (function | delegate)?
  (ReturnType? ParameterList FunctionPostfix?)? "{" Statements "}"
AssertExpr := assert "(" AssignExpr ("," AssignExpr)? ")"
MixinExpr  := mixin "(" AssignExpr ")"
ImportExpr := import "(" AssignExpr ")"
TypeidExpr := typeid "(" Type ")"
IsExpr := is "(" Declarator (Specialization TemplateParameterList2)? ")"
Specialization := ((":" | "==") (SpecToken | Type))
SpecToken := typedef | struct | union | class | interface | enum |
  function | delegate | super | return |
  const | immutable | inout | shared
ParenExpr := "(" Expression ")"
TraitsExpr := __traits "(" Identifier ("," TemplateArguments)? ")"
TypeDotIdExpr := "(" Type ")" "." Identifier
SpecialTokenExpr := SpecialToken
Expression parseNewExpr(Expression frame = null)
NewExpr := NewAnonClassExpr | NewObjectExpr
NewAnonClassExpr :=
  new NewArguments? class NewArguments?
  (SuperClass InterfaceClasses)? ClassBody
NewObjectExpr := new NewArguments? Type (NewArguments | NewArray)?
NewArguments  := "(" ArgumentList ")"
NewArray      := "[" AssignExpr "]"

Parameters:

frameThe frame or 'this' pointer expression.
Type parseDeclaratorOptId(ref Token* ident)
Parses a Declarator with an optional Identifier.
DeclaratorOptId := Type (Identifier DeclaratorSuffix)?

Parameters:

identReceives the optional identifier of the declarator.
Type parseDeclarator(ref Token* ident)
Parses a Declarator with an Identifier.
Declarator := Type Identifier DeclaratorSuffix

Parameters:

identReceives the identifier of the declarator.
Type parseType()
Parses a full Type.
Type     := Modifier* BasicTypes
Modifier := inout | const | immutable | shared
Type parseBasicTypes()
Parses the basic types.
BasicTypes := BasicType BasicType2
Type parseIdentifierType(Type next = null)
IdentifierType := Identifier | TemplateInstance
Type parseTypeofType()
TypeofType   := typeof "(" Expression ")" | TypeofReturn
TypeofReturn := typeof "(" return ")"
Type parseQualifiedType()
QualifiedType :=
 (this | super | TypeofType | ModuleScopeType? IdentifierType)
 ("." IdentifierType)*
Type parseBasicType()
BasicType := IntegralType | QualifiedType |
             ConstType | ImmutableType | InoutType | SharedType # D2.0
Type parseBasicType2(Type t)
BasicType2   :=
  (PointerType | ArrayType | FunctionType | DelegateType)*
PointerType  := "*"
FunctionType := function ParameterList
DelegateType := delegate ParameterList
Type parseDeclaratorSuffix(Type lhsType)
Parses the array types after the declarator (C-style.) E.g.: int a[]
DeclaratorSuffix := ArrayType*

Returns:

lhsType or a suffix type.

Parameters:

lhsTypeThe type on the left-hand side.
Type parseArrayType(Type t)
ArrayType := "[" (Type | ArrayTypeIndex) "]"
ArrayTypeIndex := AssignExpr (".." AssignExpr)?
Expression[] parseExpressionList()
Parses a list of AssignExpressions.
ExpressionList := AssignExpr ("," AssignExpr)*
Expression[] parseExpressionList2(TOK closing_tok)
Parses a list of AssignExpressions. Allows a trailing comma.
ExpressionList2 := AssignExpr ("," AssignExpr)* ","?
Expression[] parseArguments()
Parses a list of Arguments.
Arguments := "(" ExpressionList? ")"
Parameters parseParameterList()
Parses a ParameterList.
ParameterList := "(" Parameters? ")"
Parameters := Parameter ("," Parameter)* ","?
Parameter  := StorageClasses? (Type Name? | Type? Name )
              ("=" AssignExpr)?
TemplateArguments parseOneOrMoreTemplateArguments()
TemplateArgumentsOneOrMore :=
  TemplateArgumentList | TemplateArgumentSingle
TemplateArguments parseTemplateArguments()
TemplateArgumentList := "(" TemplateArguments? ")"
TemplateArguments parseTemplateArguments2()
TemplateArgumentList2 := TemplateArguments (?= ")")
Type parseTypeArgument()
Used with method tryToParse().
TypeArgument := Type (?= "," | ")")
TemplateArguments parseTemplateArguments_()
TemplateArguments := TemplateArgument ("," TemplateArgument)*
TemplateArgument  := TypeArgument | AssignExpr
Expression parseOptionalConstraint()
Constraint := if "(" ConstraintExpr ")"
TemplateParameters parseTemplateParameterList()
TemplateParameterList := "(" TemplateParameters? ")"
TemplateParameters parseTemplateParameterList2()
TemplateParameterList2 := "," TemplateParameters ")"
void parseTemplateParameterList_(TemplateParameters tparams)
Parses template parameters.
TemplateParameters := TemplateParam ("," TemplateParam)*
TemplateParam      :=
  TemplateAliasParam | TemplateTypeParam | TemplateTupleParam |
  TemplateValueParam | TemplateThisParam
TemplateAliasParam := alias Identifier SpecOrDefaultType
TemplateTypeParam  := Identifier SpecOrDefaultType
TemplateTupleParam := Identifier "..."
TemplateValueParam := Declarator SpecOrDefaultValue
TemplateThisParam  := this Identifier SpecOrDefaultType # D2.0
SpecOrDefaultType  := (":" Type)? ("=" Type)?
SpecOrDefaultValue := (":" Value)? ("=" Value)?
Value := CondExpr
cstring getPrintable(Token* token)
Returns the string of a token printable to the client.
alias require expected
void require(TOK tok)
Requires a token of kind tok.
void require2(TOK tok)
Requires a token of kind tok. Uses the token end as the error location.
void requireNext(TOK tok)
Requires the next token to be of kind tok.
Token* optionalIdentifier()
Parses an optional identifier.

Returns:

null or the identifier.
Token* requireIdentifier(MID mid)
Reports an error if the current token is not an identifier.

Parameters:

midThe error message ID to be used.

Returns:

The identifier token or null.
void requireClosing(TOK closing, Token* opening)
Reports an error if the closing counterpart of a token is not found.
bool hasInvalidUTF8(cstring str, Token* begin)
Returns true if the string str has an invalid UTF-8 sequence.
void error(Token* token, MID mid, ...)
void error(MID mid, ...)
void error_eL(MID mid, ...)
void error2(MID mid, Token* token)
void error2(MID mid, string arg, Token* token)
void error2_eL(MID mid, string arg, Token* token)
Forwards error parameters.
void error(TypeInfo[] _arguments, va_list _argptr, Token* token, bool endLoc, cstring formatMsg)
void error(TypeInfo[] _arguments, va_list _argptr, Token* token, bool endLoc, MID mid)
Creates an error report and appends it to a list.

Parameters:

tokenUsed to get the location of the error.
endLocGet the position of the token's end or start character?
formatMsgThe parser error message.