Parser

The Parser produces a full parse tree by examining the list of tokens provided by the Lexer.

class Parser {}

Constructors

this
this(SourceText srcText, LexerTables tables, Diagnostics diag = null)

Constructs a Parser object.

Members

Aliases

FunctionPostfix
alias FunctionPostfix = Tuple!("const", "immutable", "inout", "nothrow", "shared", "pure", "@")

A tuple of all the possible postfix tokens.

NewBinaryExpr
alias NewBinaryExpr = Expression function(Expression, Expression, Token*)

The function signature of newBinaryExpr.

Enums

PREC
enum PREC

Enumeration of binary operator precedence values.

Functions

backtrackTo
void backtrackTo(Token* newtok, Token* newprev = null)

Backtracks the Parser to the given token(s).

checkLinkageType
void checkLinkageType(ref LinkageType prev_lt, LinkageType lt, Token* begin)

Reports an error if a linkage type has already been parsed.

consume
Token* consume()

Consumes the current token and returns it.

consumed
bool consumed()

Consumes the current token if its kind matches T!str and returns true.

consumedToken
Token* consumedToken()

Consumes the current token if its kind matches T!str and returns it.

error
void error(TypeInfo[] _arguments, va_list _argptr, Token* token, bool endLoc, MID mid)

Creates an error report and appends it to a list.

error
void error(TypeInfo[] _arguments, va_list _argptr, Token* token, bool endLoc, cstring formatMsg)

Creates an error report and appends it to a list.

error
void error(MID mid, ...)

Forwards error parameters.

error
void error(Token* token, MID mid, ...)
error2
void error2(MID mid, string arg, Token* token)
void error2(MID mid, Token* token)
error2_eL
void error2_eL(MID mid, string arg, Token* token)
error_eL
void error_eL(MID mid, ...)

Forwards error parameters.

fail_tryToParse
void fail_tryToParse()

Causes the current call to tryToParse() to fail.

getPrintable
cstring getPrintable(Token* token)

Returns the string of a token printable to the client.

getSTC
StorageClass getSTC()

Returns a StorageClass when the next token is not a "(".

hasInvalidUTF8
bool hasInvalidUTF8(cbinstr str, Token* begin)

Returns true if the string str has an invalid UTF-8 sequence.

init
void init()

Moves to the first non-whitespace token.

isEnumManifest
bool isEnumManifest()

Returns true if this is an enum manifest or false if it's a normal enum declaration.

nT
void nT()

Moves to the next token.

nextIs
bool nextIs()

Returns true if the next token is of kind T!str.

optionalIdentifier
Token* optionalIdentifier()

Parses an optional identifier.

parseAliasDecl
Declaration parseAliasDecl()

$(BNF /AliasDecl := alias Attributes /AliasThisDecl := alias Identifier this ";" /AliasesDecl := alias AliasName "=" Type ("," AliasName "=" Type)* ";" /AliasName := this | Identifier)

parseAlignAttribute
uint parseAlignAttribute(out Token* sizetok)

$(BNF AlignAttribute := align ("(" Integer ")")?)

parseArguments
Expression[] parseArguments()

Parses a list of Arguments. $(BNF Arguments := "(" ExpressionList2 ")")

parseArrayType
Type parseArrayType(Type t)

$(BNF ArrayType := "[" (Type | ArrayTypeIndex) "]" /ArrayTypeIndex := AssignExpr (".." AssignExpr)?)

parseAsmBinaryExpr
Expression parseAsmBinaryExpr(PREC prevPrec = PREC.None)

$(BNF 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 := "*" | "/" | "%" /)

parseAsmBlockStmt
Statement parseAsmBlockStmt()

Parses an AsmBlockStmt. $(BNF AsmBlockStmt := asm "{" AsmStmt* "}")

parseAsmExpr
Expression parseAsmExpr()

$(BNF AsmExpr := AsmCondExpr /AsmCondExpr := AsmBinaryExpr ("?" AsmExpr ":" AsmExpr)?)

parseAsmPostExpr
Expression parseAsmPostExpr()

$(BNF AsmPostExpr := AsmUnaryExpr ("[" AsmExpr "]")*)

parseAsmPrimaryExpr
Expression parseAsmPrimaryExpr()

$(BNF AsmPrimaryExpr := / IntExpr | FloatExpr | DollarExpr | / AsmBracketExpr |AsmLocalSizeExpr | AsmRegisterExpr | / IdentifiersExpr /IntExpr := IntegerLiteral /FloatExpr := FloatLiteral /DollarExpr := "$" /AsmBracketExpr := "[" AsmExpr "]" /AsmLocalSizeExpr := "__LOCAL_SIZE" /AsmRegisterExpr := ...)

parseAsmStmt
Statement parseAsmStmt()

$(BNF /AsmStmt := / OpcodeStmt | LabeledStmt | AsmAlignStmt | EmptyStmt /OpcodeStmt := Opcode Operands? ";" /Opcode := Identifier /Operands := AsmExpr ("," AsmExpr)* /LabeledStmt := Identifier ":" AsmStmt /AsmAlignStmt := align Integer ";" /EmptyStmt := ";")

parseAsmUnaryExpr
Expression parseAsmUnaryExpr()

$(BNF /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 /)

parseAssignExpr
Expression parseAssignExpr()

$(BNF AssignExpr := CondExpr (AssignOp AssignExpr)* /AssignOp := "=" | "<<=" | ">>=" | ">>>=" | "|=" | "&=" | / "+=" | "-=" | "/=" | "*=" | "%=" | "^=" | "~=" | "^^=")

parseAtAttribute
StorageClass parseAtAttribute()

$(BNF AtAttribute := "@" Identifier)

parseAttributeStmt
Statement parseAttributeStmt()

$(BNF AttributeStmt := Attributes+ / (VariableOrFunctionDecl | DeclDef) /Attributes := extern | ExternLinkageType | auto | static | / final | const | immutable | enum | scope)

parseAttributes
Declaration parseAttributes(Declaration* pDecl = null)

Parses one or more attributes and a Declaration at the end.

parseBaseClasses
BaseClassType[] parseBaseClasses()

$(BNF BaseClasses := BaseClass ("," BaseClass)* /BaseClass := Protection? BasicType /Protection := private | public | protected | package)

parseBasicType
Type parseBasicType()

$(BNF BasicType := IntegralType | QualifiedType | ModParenType /ModParenType := Modifier "(" Type ")")

parseBasicType2
Type parseBasicType2(Type t)

$(BNF BasicType2 := / (PointerType | ArrayType | FunctionType | DelegateType)* /PointerType := "*" /FunctionType := function ParameterList /DelegateType := delegate ParameterList)

parseBasicTypes
Type parseBasicTypes()

Parses the basic types.

parseBinaryExpr
Expression parseBinaryExpr(PREC prevPrec = PREC.None)

Parses a binary operator expression.

parseBinaryOp
PREC parseBinaryOp(out NewBinaryExpr fn, PREC prevPrec)

Consumes the tokens of a binary operator.

parseBreakStmt
Statement parseBreakStmt()

$(BNF BreakStmt := break Identifier? ";")

parseCaseOrDefaultBody
Statement parseCaseOrDefaultBody()

Helper function for parsing the body of a default or case statement. $(BNF CaseOrDefaultBody := ScopeStmt*)

parseCaseStmt
Statement parseCaseStmt()

$(BNF CaseStmt := case ExpressionList ":" CaseOrDefaultBody | / case AssignExpr ":" ".." case AssignExpr ":" CaseOrDefaultBody)

parseClassDecl
Declaration parseClassDecl()

$(BNF ClassDecl := / class Name TemplateParameterList? (":" BaseClasses) ClassBody | / class Name ";" /ClassBody := DeclDefsBlock)

parseCondExpr
Expression parseCondExpr()

$(BNF CondExpr := BinaryExpr ("?" Expression ":" CondExpr)?)

parseConstructorDecl
Declaration parseConstructorDecl()

$(BNF ConstructorDecl := this ParameterList FunctionBody)

parseContinueStmt
Statement parseContinueStmt()

$(BNF ContinueStmt := continue Identifier? ";")

parseDebugDecl
Declaration parseDebugDecl()

$(BNF DebugDecl := / debug "=" IdentOrInt ";" | / debug DebugCondition? DeclsBlock (else DeclsBlock)? /DebugCondition := "(" IdentOrInt ")")

parseDebugStmt
Statement parseDebugStmt()

$(BNF DebugStmt := / debug DebugCondition? NoScopeStmt (else NoScopeStmt)?)

parseDeclarationDefinition
Declaration parseDeclarationDefinition()

Parses a DeclarationDefinition.

parseDeclarationDefinitions
Declaration[] parseDeclarationDefinitions()

Parses DeclarationDefinitions until the end of file is hit. $(BNF DeclDefs := DeclDef*)

parseDeclarationDefinitionsBody
CompoundDecl parseDeclarationDefinitionsBody()

Parse the body of a template, class, interface, struct or union. $(BNF DeclDefsBlock := "{" DeclDefs? "}")

parseDeclarationsBlock
Declaration parseDeclarationsBlock()

Parses a DeclarationsBlock. $(BNF DeclsBlock := ":" DeclDefs | "{" DeclDefs? "}" | DeclDef)

parseDeclarator
Type parseDeclarator(ref Token* ident)

Parses a Declarator with an Identifier.

parseDeclaratorOptId
Type parseDeclaratorOptId(ref Token* ident)

Parses a Declarator with an optional Identifier.

parseDeclaratorSuffix
Type parseDeclaratorSuffix(Type lhsType)

Parses the array types after the declarator (C-style.) E.g.: int a[]

parseDefaultStmt
Statement parseDefaultStmt()

$(BNF DefaultStmt := default ":" CaseOrDefaultBody)

parseDeleteDecl
Declaration parseDeleteDecl()

$(BNF DeleteDecl := delete ParameterList FunctionBody)

parseDestructorDecl
Declaration parseDestructorDecl()

$(BNF DestructorDecl := "~" this "(" ")" FunctionBody)

parseDoWhileStmt
Statement parseDoWhileStmt()

$(BNF DoWhileStmt := do ScopeStmt while "(" Expression ")")

parseEnumDecl
Declaration parseEnumDecl()

$(BNF /EnumDecl := / enum Name? (":" BasicType)? EnumBody | / enum Name ";" /EnumBody := "{" EnumMembers "}" /EnumMembers := EnumMember ("," EnumMember)* ","? /EnumMembers2 := Type? EnumMember ("," Type? EnumMember)* ","? # D2.0 /EnumMember := Name ("=" AssignExpr)?)

parseExpression
Expression parseExpression()

The root method for parsing an Expression. $(BNF Expression := CommaExpr /CommaExpr := AssignExpr ("," AssignExpr)*)

parseExpressionList
Expression[] parseExpressionList()

Parses a list of AssignExpressions. $(BNF ExpressionList := AssignExpr ("," AssignExpr)*)

parseExpressionList2
Expression[] parseExpressionList2(TOK closing_tok)

Parses an optional ExpressionList and allows a trailing comma. $(BNF ExpressionList2 := (ExpressionList ","?)? )

parseExternLinkageType
LinkageType parseExternLinkageType()

$(BNF ExternLinkageType := extern "(" LinkageType ")" LinkageType := "C" | "C" "++" | "D" | "Windows" | "Pascal" | "System")

parseForStmt
Statement parseForStmt()

$(BNF ForStmt := / for "(" (NoScopeStmt | ";") Expression? ";" Expression? ")" / ScopeStmt)

parseForeachStmt
Statement parseForeachStmt()

$(BNF ForeachStmt := / Foreach "(" ForeachVarList ";" Aggregate ")" / ScopeStmt /Foreach := foreach | foreach_reverse /ForeachVarList := ForeachVar ("," ForeachVar)* /ForeachVar := ref? (Identifier | Declarator) /RangeExpr2 := Expression ".." Expression # D2 /Aggregate := RangeExpr2 | Expression)

parseFunctionBody
FuncBodyStmt parseFunctionBody()

Parses the body of a function.

parseFunctionPostfix
StorageClass parseFunctionPostfix()

$(BNF FunctionPostfix := / (const|immutable|inout|nothrow|shared|pure| "@" Identifier)*)

parseGotoStmt
Statement parseGotoStmt()

$(BNF /GotoStmt := goto (case Expression? | default | Identifier) ";")

parseIdentOrInt
Token* parseIdentOrInt()

Parses an identifier or an integer. Reports an error otherwise. $(BNF IdentOrInt := Identifier | Integer)

parseIdentifierExpr
Expression parseIdentifierExpr(Expression next = null)

$(BNF IdentifierExpr := Identifier | TemplateInstance /TemplateInstance := Identifier "!" TemplateArgumentsOneOrMore)

parseIdentifierType
Type parseIdentifierType(Type next = null)

$(BNF IdentifierType := Identifier | TemplateInstance)

parseIdentifiersExpr
Expression parseIdentifiersExpr()

$(BNF IdentifiersExpr := / ModuleScopeExpr? IdentifierExpr ("." IdentifierExpr)* /ModuleScopeExpr := ".")

parseIfStmt
Statement parseIfStmt()

$(BNF IfStmt := if "(" Condition ")" ScopeStmt (else ScopeStmt)? /Condition := AutoDecl | VariableDecl | Expression)

parseImportDecl
ImportDecl parseImportDecl()

$(BNF ImportDecl := static? import / ImportModule ("," ImportModule)* / (":" ImportBind ("," ImportBind)*)? / ";" /ImportModule := (AliasName "=")? ModuleName /ImportBind := (AliasName "=")? BindName /ModuleName := Identifier ("." Identifier)* /AliasName := Identifier /BindName := Identifier)

parseInitializer
Expression parseInitializer()

Parses a variable initializer. $(BNF 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)

parseInterfaceDecl
Declaration parseInterfaceDecl()

$(BNF InterfaceDecl := / interface Name TemplateParameterList? (":" BaseClasses) InterfaceBody | / interface Name ";" /InterfaceBody := DeclDefsBlock)

parseInvariantDecl
Declaration parseInvariantDecl()

$(BNF InvariantDecl := invariant ("(" ")")? FunctionBody)

parseLambdaExprBody
Expression parseLambdaExprBody()

$(BNF LambdaBody := AssignExpr)

parseMixin
RetT parseMixin()

Parses a MixinDecl or MixinStmt. $(BNF /MixinDecl := (MixinExpr | MixinTemplate | MixinTemplateId) ";" /MixinExpr := mixin "(" AssignExpr ")" /MixinTemplate := mixin TemplateDecl # D2 /MixinTemplateId := mixin TemplateIdentifier / ("!" "(" TemplateArguments ")")? MixinIdentifier?)

parseModuleDecl
Declaration parseModuleDecl()

$(BNF ModuleDecl := module ModuleType? Identifier ("." Identifier)* ";" /ModuleType := "(" safe | system ")")

parseNewDecl
Declaration parseNewDecl()

$(BNF NewDecl := new ParameterList FunctionBody)

parseNewExpr
Expression parseNewExpr(Expression frame = null)

$(BNF NewExpr := NewAnonClassExpr | NewObjectExpr /NewAnonClassExpr := / new NewArguments? class NewArguments? / (SuperClass InterfaceClasses)? ClassBody /NewObjectExpr := new NewArguments? Type (NewArguments | NewArray)? /NewArguments := "(" ArgumentList ")" /NewArray := "[" AssignExpr "]")

parseNoScopeOrEmptyStmt
Statement parseNoScopeOrEmptyStmt()

$(BNF NoScopeOrEmptyStmt := ";" | NoScopeStmt)

parseNoScopeStmt
Statement parseNoScopeStmt()

$(BNF /NoScopeStmt := NonEmptyStmt | BlockStmt /BlockStmt := Statements)

parseNonVoidInitializer
Expression parseNonVoidInitializer()

Parses a NonVoidInitializer. $(BNF NonVoidInitializer := / ArrayInitializer | StructInitializer | AssignExpr)

parseOneOrMoreTemplateArguments
TemplateArguments parseOneOrMoreTemplateArguments()

$(BNF TemplateArgumentsOneOrMore := / TemplateArgumentList | TemplateArgumentSingle)

parseOptionalConstraint
Expression parseOptionalConstraint()

$(BNF Constraint := if "(" ConstraintExpr ")")

parseParameterList
Parameters parseParameterList()

Parses a ParameterList. $(BNF ParameterList := "(" Parameters? ")" /Parameters := Parameter ("," Parameter)* ","? /Parameter := StorageClasses? (Type Name? | Type? Name ) / ("=" AssignExpr)?)

parsePostExpr
Expression parsePostExpr()

$(BNF PostExpr := UnaryExpr / (PostIdExpr | IncOrDecExpr | CallExpr | SliceExpr | IndexExpr)* /PostIdExpr := "." (NewExpr | IdentifierExpr) /IncOrDecExpr := ("++" | "--") /CallExpr := "(" Arguments? ")" /RangeExpr := AssignExpr ".." AssignExpr /SliceExpr := "[" RangeExpr? "]") /IndexExpr := "[" ExpressionList "]")

parsePragmaStmt
Statement parsePragmaStmt()

$(BNF PragmaStmt := / pragma "(" Identifier ("," ExpressionList)? ")" NoScopeStmt)

parsePrimaryExpr
Expression parsePrimaryExpr()

$(BNF 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)

parseQualifiedType
Type parseQualifiedType()

$(BNF QualifiedType := / (this | super | TypeofType | ModuleScopeType? IdentifierType) / ("." IdentifierType)*)

parseReturnStmt
Statement parseReturnStmt()

$(BNF ReturnStmt := return Expression? ";")

parseScopeGuardStmt
Statement parseScopeGuardStmt()

$(BNF ScopeGuardStmt := scope "(" ScopeCondition ")" ScopeGuardBody /ScopeCondition := "exit" | "success" | "failure" /ScopeGuardBody := ScopeStmt | NoScopeStmt)

parseScopeStmt
Statement parseScopeStmt()

Parses a ScopeStmt. $(BNF ScopeStmt := NoScopeStmt)

parseSingleParamLambdaExpr
Expression parseSingleParamLambdaExpr()

$(BNF LambdaExpr := LambdaParams "=>" LambdaBody /LambdaParams := Identifier | ParameterList ParamsPostfix)

parseStatement
Statement parseStatement()

Parses a Statement.

parseStatements
CompoundStmt parseStatements()

$(BNF Statements := "{" Statement* "}")

parseStaticAssertDecl
Declaration parseStaticAssertDecl()

$(BNF StaticAssertDecl := / static assert "(" AssignExpr ("," Message)? ")" ";" /Message := AssignExpr)

parseStaticAssertStmt
Statement parseStaticAssertStmt()

$(BNF StaticAssertStmt := / static assert "(" AssignExpr ("," Message)? ")" ";" /Message := AssignExpr)

parseStaticCtorDecl
Declaration parseStaticCtorDecl()

$(BNF StaticCtorDecl := static this "(" ")" FunctionBody)

parseStaticDtorDecl
Declaration parseStaticDtorDecl()

$(BNF /StaticDtorDecl := static "~" this "(" ")" FunctionBody)

parseStaticIfDecl
Declaration parseStaticIfDecl()

$(BNF StaticIfDecl := / static if "(" AssignExpr ")" DeclsBlock (else DeclsBlock)?)

parseStaticIfStmt
Statement parseStaticIfStmt()

$(BNF StaticIfStmt := / static if "(" Expression ")" NoScopeStmt (else NoScopeStmt)?)

parseStructOrUnionDecl
Declaration parseStructOrUnionDecl()

$(BNF StructDecl := / struct Name? TemplateParameterList? StructBody | / struct Name ";" /StructBody := DeclDefsBlock /UnionDecl := / union Name? TemplateParameterList? UnionBody | / union Name ";" /UnionBody := DeclDefsBlock)

parseSwitchStmt
Statement parseSwitchStmt()

$(BNF SwitchStmt := final? switch "(" Expression ")" ScopeStmt)

parseSynchronizedStmt
Statement parseSynchronizedStmt()

$(BNF SynchronizedStmt := synchronized ("(" Expression ")")? ScopeStmt)

parseTemplateArguments
TemplateArguments parseTemplateArguments()

$(BNF TemplateArgumentList := "(" TemplateArguments? ")")

parseTemplateArguments2
TemplateArguments parseTemplateArguments2()

$(BNF TemplateArgumentList2 := TemplateArguments (?= "$(RP)"))

parseTemplateArguments_
TemplateArguments parseTemplateArguments_()

$(BNF TemplateArguments := TemplateArgument ("," TemplateArgument)* /TemplateArgument := TypeArgument | AssignExpr)

parseTemplateDecl
TemplateDecl parseTemplateDecl()

$(BNF TemplateDecl := / template Name TemplateParameterList Constraint? DeclDefsBlock)

parseTemplateParameterList
TemplateParameters parseTemplateParameterList()

$(BNF TemplateParameterList := "(" TemplateParameters? ")")

parseTemplateParameterList2
TemplateParameters parseTemplateParameterList2()

$(BNF TemplateParameterList2 := "," TemplateParameters "$(RP)")

parseTemplateParameterList_
void parseTemplateParameterList_(TemplateParameters tparams)

Parses template parameters. $(BNF 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 /)

parseThrowStmt
Statement parseThrowStmt()

$(BNF ThrowStmt := throw Expression ";")

parseTryStmt
Statement parseTryStmt()

$(BNF TryStmt := try ScopeStmt CatchStmt* LastCatchStmt? FinallyStmt? /CatchStmt := catch "(" BasicType Identifier ")" NoScopeStmt /LastCatchStmt := catch NoScopeStmt /FinallyStmt := finally NoScopeStmt)

parseType
Type parseType()

Parses a full Type.

parseTypeArgument
Type parseTypeArgument()

Used with method tryToParse(). $(BNF TypeArgument := Type (?= "," | "$(RP)"))

parseTypeofType
Type parseTypeofType()

$(BNF TypeofType := typeof "(" Expression ")" | TypeofReturn /TypeofReturn := typeof "(" return ")")

parseUnaryExpr
Expression parseUnaryExpr()

$(BNF 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 /TypeExpr := Modifier Type)

parseUnittestDecl
Declaration parseUnittestDecl()

$(BNF UnittestDecl := unittest FunctionBody)

parseVariablesOrFunction
Declaration parseVariablesOrFunction(StorageClass stcs = StorageClass.None, Protection protection = Protection.None, LinkageType linkType = LinkageType.None, bool testAutoDeclaration = false)

Parses either a VariablesDecl or a FunctionDecl.

parseVersionCondition
Token* parseVersionCondition()

$(BNF VersionCondition := unittest #*D2.0*# | IdentOrInt)

parseVersionDecl
Declaration parseVersionDecl()

$(BNF VersionDecl := / version "=" IdentOrInt ";" | / version VCondition DeclsBlock (else DeclsBlock)? /VCondition := "(" VersionCondition ")")

parseVersionStmt
Statement parseVersionStmt()

$(BNF VersionStmt := / version VCondition NoScopeStmt (else NoScopeStmt)?)

parseVolatileStmt
Statement parseVolatileStmt()

$(BNF VolatileStmt := volatile (ScopeStmt | NoScopeStmt))

parseWhileStmt
Statement parseWhileStmt()

$(BNF WhileStmt := while "(" Expression ")" ScopeStmt)

parseWithStmt
Statement parseWithStmt()

$(BNF WithStmt := with "(" Expression ")" ScopeStmt)

peekAfter
Token* peekAfter(Token* t)

Returns the token that comes after t.

peekNext
TOK peekNext()

Returns the token kind of the next token.

putInsideTemplateDeclaration
TemplateDecl putInsideTemplateDeclaration(Token* begin, Token* name, Declaration decl, TemplateParameters tparams, Expression constraint)

Wraps a declaration inside a template declaration.

require
void require()

Requires a token of kind T!str.

require2
void require2()

Requires a token of kind tok. Uses the token end as the error location.

requireClosing
void requireClosing(Token* opening)

Reports an error if the closing counterpart of a token is not found.

requireIdentifier
Token* requireIdentifier(MID mid)

Reports an error if the current token is not an identifier.

requireOpening
Token* requireOpening()

Returns the opening bracket or the current token.

set
Class set(Class node, Token* begin, Token* end)

Sets the begin and end tokens of a syntax tree node.

set
Class set(Class node, Token* begin)

Sets the begin and end tokens of a syntax tree node.

skip
void skip()

Asserts that the current token is of kind T!str, and then moves to the next token.

skipParens
Token* skipParens(Token* peek_token, TOK closing)

Skips to the token behind the closing parenthesis token. Takes nesting into account.

start
CompoundDecl start()

Starts the parser and returns the parsed Declarations.

start2
Expression start2()

Starts the parser and returns the parsed Expression.

tokenAfterBracket
TOK tokenAfterBracket(TOK closing)

Returns the token kind behind the closing bracket.

tokenAfterParenIs
bool tokenAfterParenIs(TOK kind)

Returns true if the token after the closing parenthesis matches the searched kind.

tokenIs
bool tokenIs()

Returns true if the current token is of kind T!str.

tryToParse
RetType tryToParse(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.

Static functions

isNodeSet
bool isNodeSet(const Node node)

Returns true if set() has been called on a node.

newBinaryExpr
Expression newBinaryExpr(Expression l, Expression r, Token* op)

Instantiates a function that returns a new binary expression.

Variables

alignSize
uint alignSize;

Attributes are evaluated in the parsing phase. TODO: will be removed. SemanticPass1 takes care of attributes.

diag
Diagnostics diag;

Collects error messages.

errorCount
uint errorCount;

Used to track nr. of errors while being in tryToParse().

errors
ParserError[] errors;

Array of parser error messages.

imports
ImportDecl[] imports;

ImportDeclarations in the source text.

lexer
Lexer lexer;

Used to lex the source code.

linkageType
LinkageType linkageType;

Attributes are evaluated in the parsing phase. TODO: will be removed. SemanticPass1 takes care of attributes.

prevToken
Token* prevToken;

Previous non-whitespace token.

protection
Protection protection;
storageClass
StorageClass storageClass;

Attributes are evaluated in the parsing phase. TODO: will be removed. SemanticPass1 takes care of attributes.

token
Token* token;

Current non-whitespace token.

trying
uint trying;

Greater than 0 if Parser is in tryToParse().

Meta