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