Used to lex the source code.
Current non-whitespace token.
Previous non-whitespace token.
Collects error messages.
Array of parser error messages.
ImportDeclarations in the source text.
Attributes are evaluated in the parsing phase. TODO: will be removed. SemanticPass1 takes care of attributes.
Moves to the first non-whitespace token.
Moves to the next token.
Starts the parser and returns the parsed Declarations.
Starts the parser and returns the parsed Expression.
Greater than 0 if Parser is in tryToParse().
Used to track nr. of errors while being in tryToParse().
This method executes the delegate parseMethod and when an error occurs the state of the lexer and parser is restored.
Causes the current call to tryToParse() to fail.
Backtracks the Parser to the given token(s).
Sets the begin and end tokens of a syntax tree node.
Sets the begin and end tokens of a syntax tree node.
Returns true if set() has been called on a node.
Returns true if the current token is of kind T!str.
Returns true if the next token is of kind T!str.
Returns the token kind of the next token.
Returns the token that comes after t.
Consumes the current token and returns it.
Consumes the current token if its kind matches T!str and returns true.
Consumes the current token if its kind matches T!str and returns it.
Asserts that the current token is of kind T!str, and then moves to the next token.
Returns true if the token after the closing parenthesis matches the searched kind.
Returns the token kind behind the closing bracket.
Skips to the token behind the closing parenthesis token. Takes nesting into account.
$(BNF ModuleDecl := module ModuleType? Identifier ("." Identifier)* ";" /ModuleType := "(" safe | system ")")
Parses DeclarationDefinitions until the end of file is hit. $(BNF DeclDefs := DeclDef*)
Parse the body of a template, class, interface, struct or union. $(BNF DeclDefsBlock := "{" DeclDefs? "}")
Parses a DeclarationDefinition.
Parses a DeclarationsBlock. $(BNF DeclsBlock := ":" DeclDefs | "{" DeclDefs? "}" | DeclDef)
$(BNF /AliasDecl := alias Attributes /AliasThisDecl := alias Identifier this ";" /AliasesDecl := alias AliasName "=" Type ("," AliasName "=" Type)* ";" /AliasName := this | Identifier)
Parses either a VariablesDecl or a FunctionDecl.
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)
Parses a NonVoidInitializer. $(BNF NonVoidInitializer := / ArrayInitializer | StructInitializer | AssignExpr)
Parses the body of a function.
$(BNF FunctionPostfix := / (const|immutable|inout|nothrow|shared|pure| "@" Identifier)*)
A tuple of all the possible postfix tokens.
$(BNF ExternLinkageType := extern "(" LinkageType ")" LinkageType := "C" | "C" "++" | "D" | "Windows" | "Pascal" | "System")
Reports an error if a linkage type has already been parsed.
Returns a StorageClass when the next token is not a "(".
Parses one or more attributes and a Declaration at the end.
$(BNF AlignAttribute := align ("(" Integer ")")?)
$(BNF AtAttribute := "@" Identifier)
$(BNF ImportDecl := static? import / ImportModule ("," ImportModule)* / (":" ImportBind ("," ImportBind)*)? / ";" /ImportModule := (AliasName "=")? ModuleName /ImportBind := (AliasName "=")? BindName /ModuleName := Identifier ("." Identifier)* /AliasName := Identifier /BindName := Identifier)
Returns true if this is an enum manifest or false if it's a normal enum declaration.
$(BNF /EnumDecl := / enum Name? (":" BasicType)? EnumBody | / enum Name ";" /EnumBody := "{" EnumMembers "}" /EnumMembers := EnumMember ("," EnumMember)* ","? /EnumMembers2 := Type? EnumMember ("," Type? EnumMember)* ","? # D2.0 /EnumMember := Name ("=" AssignExpr)?)
Wraps a declaration inside a template declaration.
$(BNF ClassDecl := / class Name TemplateParameterList? (":" BaseClasses) ClassBody | / class Name ";" /ClassBody := DeclDefsBlock)
$(BNF BaseClasses := BaseClass ("," BaseClass)* /BaseClass := Protection? BasicType /Protection := private | public | protected | package)
$(BNF InterfaceDecl := / interface Name TemplateParameterList? (":" BaseClasses) InterfaceBody | / interface Name ";" /InterfaceBody := DeclDefsBlock)
$(BNF StructDecl := / struct Name? TemplateParameterList? StructBody | / struct Name ";" /StructBody := DeclDefsBlock /UnionDecl := / union Name? TemplateParameterList? UnionBody | / union Name ";" /UnionBody := DeclDefsBlock)
$(BNF ConstructorDecl := this ParameterList FunctionBody)
$(BNF DestructorDecl := "~" this "(" ")" FunctionBody)
$(BNF StaticCtorDecl := static this "(" ")" FunctionBody)
$(BNF /StaticDtorDecl := static "~" this "(" ")" FunctionBody)
$(BNF InvariantDecl := invariant ("(" ")")? FunctionBody)
$(BNF UnittestDecl := unittest FunctionBody)
Parses an identifier or an integer. Reports an error otherwise. $(BNF IdentOrInt := Identifier | Integer)
$(BNF VersionCondition := unittest #*D2.0*# | IdentOrInt)
$(BNF DebugDecl := / debug "=" IdentOrInt ";" | / debug DebugCondition? DeclsBlock (else DeclsBlock)? /DebugCondition := "(" IdentOrInt ")")
$(BNF VersionDecl := / version "=" IdentOrInt ";" | / version VCondition DeclsBlock (else DeclsBlock)? /VCondition := "(" VersionCondition ")")
$(BNF StaticIfDecl := / static if "(" AssignExpr ")" DeclsBlock (else DeclsBlock)?)
$(BNF StaticAssertDecl := / static assert "(" AssignExpr ("," Message)? ")" ";" /Message := AssignExpr)
$(BNF TemplateDecl := / template Name TemplateParameterList Constraint? DeclDefsBlock)
$(BNF NewDecl := new ParameterList FunctionBody)
$(BNF DeleteDecl := delete ParameterList FunctionBody)
Parses a MixinDecl or MixinStmt. $(BNF /MixinDecl := (MixinExpr | MixinTemplate | MixinTemplateId) ";" /MixinExpr := mixin "(" AssignExpr ")" /MixinTemplate := mixin TemplateDecl # D2 /MixinTemplateId := mixin TemplateIdentifier / ("!" "(" TemplateArguments ")")? MixinIdentifier?)
$(BNF Statements := "{" Statement* "}")
Parses a Statement.
Parses a ScopeStmt. $(BNF ScopeStmt := NoScopeStmt)
$(BNF /NoScopeStmt := NonEmptyStmt | BlockStmt /BlockStmt := Statements)
$(BNF NoScopeOrEmptyStmt := ";" | NoScopeStmt)
$(BNF AttributeStmt := Attributes+ / (VariableOrFunctionDecl | DeclDef) /Attributes := extern | ExternLinkageType | auto | static | / final | const | immutable | enum | scope)
$(BNF IfStmt := if "(" Condition ")" ScopeStmt (else ScopeStmt)? /Condition := AutoDecl | VariableDecl | Expression)
$(BNF WhileStmt := while "(" Expression ")" ScopeStmt)
$(BNF DoWhileStmt := do ScopeStmt while "(" Expression ")")
$(BNF ForStmt := / for "(" (NoScopeStmt | ";") Expression? ";" Expression? ")" / ScopeStmt)
$(BNF ForeachStmt := / Foreach "(" ForeachVarList ";" Aggregate ")" / ScopeStmt /Foreach := foreach | foreach_reverse /ForeachVarList := ForeachVar ("," ForeachVar)* /ForeachVar := ref? (Identifier | Declarator) /RangeExpr2 := Expression ".." Expression # D2 /Aggregate := RangeExpr2 | Expression)
$(BNF SwitchStmt := final? switch "(" Expression ")" ScopeStmt)
Helper function for parsing the body of a default or case statement. $(BNF CaseOrDefaultBody := ScopeStmt*)
$(BNF CaseStmt := case ExpressionList ":" CaseOrDefaultBody | / case AssignExpr ":" ".." case AssignExpr ":" CaseOrDefaultBody)
$(BNF DefaultStmt := default ":" CaseOrDefaultBody)
$(BNF ContinueStmt := continue Identifier? ";")
$(BNF BreakStmt := break Identifier? ";")
$(BNF ReturnStmt := return Expression? ";")
$(BNF /GotoStmt := goto (case Expression? | default | Identifier) ";")
$(BNF WithStmt := with "(" Expression ")" ScopeStmt)
$(BNF SynchronizedStmt := synchronized ("(" Expression ")")? ScopeStmt)
$(BNF TryStmt := try ScopeStmt CatchStmt* LastCatchStmt? FinallyStmt? /CatchStmt := catch "(" BasicType Identifier ")" NoScopeStmt /LastCatchStmt := catch NoScopeStmt /FinallyStmt := finally NoScopeStmt)
$(BNF ThrowStmt := throw Expression ";")
$(BNF ScopeGuardStmt := scope "(" ScopeCondition ")" ScopeGuardBody /ScopeCondition := "exit" | "success" | "failure" /ScopeGuardBody := ScopeStmt | NoScopeStmt)
$(BNF VolatileStmt := volatile (ScopeStmt | NoScopeStmt))
$(BNF PragmaStmt := / pragma "(" Identifier ("," ExpressionList)? ")" NoScopeStmt)
$(BNF StaticIfStmt := / static if "(" Expression ")" NoScopeStmt (else NoScopeStmt)?)
$(BNF StaticAssertStmt := / static assert "(" AssignExpr ("," Message)? ")" ";" /Message := AssignExpr)
$(BNF DebugStmt := / debug DebugCondition? NoScopeStmt (else NoScopeStmt)?)
$(BNF VersionStmt := / version VCondition NoScopeStmt (else NoScopeStmt)?)
Parses an AsmBlockStmt. $(BNF AsmBlockStmt := asm "{" AsmStmt* "}")
$(BNF /AsmStmt := / OpcodeStmt | LabeledStmt | AsmAlignStmt | EmptyStmt /OpcodeStmt := Opcode Operands? ";" /Opcode := Identifier /Operands := AsmExpr ("," AsmExpr)* /LabeledStmt := Identifier ":" AsmStmt /AsmAlignStmt := align Integer ";" /EmptyStmt := ";")
$(BNF AsmExpr := AsmCondExpr /AsmCondExpr := AsmBinaryExpr ("?" AsmExpr ":" AsmExpr)?)
$(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 := "*" | "/" | "%" /)
$(BNF AsmPostExpr := AsmUnaryExpr ("[" AsmExpr "]")*)
$(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 /)
$(BNF AsmPrimaryExpr := / IntExpr | FloatExpr | DollarExpr | / AsmBracketExpr |AsmLocalSizeExpr | AsmRegisterExpr | / IdentifiersExpr /IntExpr := IntegerLiteral /FloatExpr := FloatLiteral /DollarExpr := "$" /AsmBracketExpr := "[" AsmExpr "]" /AsmLocalSizeExpr := "__LOCAL_SIZE" /AsmRegisterExpr := ...)
Instantiates a function that returns a new binary expression.
The function signature of newBinaryExpr.
The root method for parsing an Expression. $(BNF Expression := CommaExpr /CommaExpr := AssignExpr ("," AssignExpr)*)
$(BNF AssignExpr := CondExpr (AssignOp AssignExpr)* /AssignOp := "=" | "<<=" | ">>=" | ">>>=" | "|=" | "&=" | / "+=" | "-=" | "/=" | "*=" | "%=" | "^=" | "~=" | "^^=")
$(BNF CondExpr := BinaryExpr ("?" Expression ":" CondExpr)?)
Enumeration of binary operator precedence values.
Consumes the tokens of a binary operator.
Parses a binary operator expression.
$(BNF PostExpr := UnaryExpr / (PostIdExpr | IncOrDecExpr | CallExpr | SliceExpr | IndexExpr)* /PostIdExpr := "." (NewExpr | IdentifierExpr) /IncOrDecExpr := ("++" | "--") /CallExpr := "(" Arguments? ")" /RangeExpr := AssignExpr ".." AssignExpr /SliceExpr := "[" RangeExpr? "]") /IndexExpr := "[" ExpressionList "]")
$(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)
$(BNF IdentifiersExpr := / ModuleScopeExpr? IdentifierExpr ("." IdentifierExpr)* /ModuleScopeExpr := ".")
$(BNF IdentifierExpr := Identifier | TemplateInstance /TemplateInstance := Identifier "!" TemplateArgumentsOneOrMore)
$(BNF LambdaBody := AssignExpr)
$(BNF LambdaExpr := LambdaParams "=>" LambdaBody /LambdaParams := Identifier | ParameterList ParamsPostfix)
$(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)
$(BNF NewExpr := NewAnonClassExpr | NewObjectExpr /NewAnonClassExpr := / new NewArguments? class NewArguments? / (SuperClass InterfaceClasses)? ClassBody /NewObjectExpr := new NewArguments? Type (NewArguments | NewArray)? /NewArguments := "(" ArgumentList ")" /NewArray := "[" AssignExpr "]")
Parses a Declarator with an optional Identifier.
Parses a Declarator with an Identifier.
Parses a full Type.
Parses the basic types.
$(BNF IdentifierType := Identifier | TemplateInstance)
$(BNF TypeofType := typeof "(" Expression ")" | TypeofReturn /TypeofReturn := typeof "(" return ")")
$(BNF QualifiedType := / (this | super | TypeofType | ModuleScopeType? IdentifierType) / ("." IdentifierType)*)
$(BNF BasicType := IntegralType | QualifiedType | ModParenType /ModParenType := Modifier "(" Type ")")
$(BNF BasicType2 := / (PointerType | ArrayType | FunctionType | DelegateType)* /PointerType := "*" /FunctionType := function ParameterList /DelegateType := delegate ParameterList)
Parses the array types after the declarator (C-style.) E.g.: int a[]
$(BNF ArrayType := "[" (Type | ArrayTypeIndex) "]" /ArrayTypeIndex := AssignExpr (".." AssignExpr)?)
Parses a list of AssignExpressions. $(BNF ExpressionList := AssignExpr ("," AssignExpr)*)
Parses an optional ExpressionList and allows a trailing comma. $(BNF ExpressionList2 := (ExpressionList ","?)? )
Parses a list of Arguments. $(BNF Arguments := "(" ExpressionList2 ")")
Parses a ParameterList. $(BNF ParameterList := "(" Parameters? ")" /Parameters := Parameter ("," Parameter)* ","? /Parameter := StorageClasses? (Type Name? | Type? Name ) / ("=" AssignExpr)?)
$(BNF TemplateArgumentsOneOrMore := / TemplateArgumentList | TemplateArgumentSingle)
$(BNF TemplateArgumentList := "(" TemplateArguments? ")")
$(BNF TemplateArgumentList2 := TemplateArguments (?= "$(RP)"))
Used with method tryToParse(). $(BNF TypeArgument := Type (?= "," | "$(RP)"))
$(BNF TemplateArguments := TemplateArgument ("," TemplateArgument)* /TemplateArgument := TypeArgument | AssignExpr)
$(BNF Constraint := if "(" ConstraintExpr ")")
$(BNF TemplateParameterList := "(" TemplateParameters? ")")
$(BNF TemplateParameterList2 := "," TemplateParameters "$(RP)")
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 /)
Returns the string of a token printable to the client.
Requires a token of kind T!str.
Requires a token of kind tok. Uses the token end as the error location.
Parses an optional identifier.
Reports an error if the current token is not an identifier.
Returns the opening bracket or the current token.
Reports an error if the closing counterpart of a token is not found.
Returns true if the string str has an invalid UTF-8 sequence.
Forwards error parameters.
Creates an error report and appends it to a list.
A light-weight parser which looks only for import statements in the source text.