Report a bug
If you spot a problem with this page, click here to create a Bugzilla issue.
Improve this page
Quickly fork, edit online, and submit a pull request for this page. Requires a signed-in GitHub account. This works well for small changes. If you'd like to make larger changes you may want to consider using a local clone.

ddmd.parse

Compiler implementation of the D programming language.
Authors:

Source: parse.d

PREC[TOKMAX] precedence;
Set operator precedence for each operator.
class Parser(AST): Lexer;
this(Loc loc, AST.Module _module, const(char)[] input, bool doDocComment);
Use this constructor for string mixins.

Input: loc location in source file of mixin

AST.Dsymbols* parseAutoDeclarations(StorageClass storageClass, const(char)* comment);
Parse auto declarations of the form: storageClass ident = init, ident = init, ... ; and return the array of them. Starts with token on the first ident. Ends with scanner past closing ';'
AST.Dsymbols* parseBlock(AST.Dsymbol* pLastDecl, PrefixAttributes!AST* pAttrs = null);
Parse declarations after an align, protection, or extern decl.
StorageClass appendStorageClass(StorageClass storageClass, StorageClass stc, bool deprec = false);
Give error on redundant/conflicting storage class.

TODO: remove deprecation in 2.068 and keep only error

StorageClass parseAttribute(AST.Expressions** pudas);
Parse attribute, lexer is on '@'.

Input: pudas array of UDAs to append to

Returns:
storage class if a predefined attribute; also scanner remains on identifier. 0 if not a predefined attribute *pudas set if user defined attribute, scanner is past UDA *pudas NULL if not a user defined attribute
StorageClass parsePostfix(StorageClass storageClass, AST.Expressions** pudas);
Parse const/immutable/shared/inout/nothrow/pure postfix
AST.Expression parseConstraint();
Parse constraint. Constraint is of the form: if ( ConstraintExpression )
AST.TemplateDeclaration parseTemplateDeclaration(bool ismixin = false);
Parse a TemplateDeclaration.
AST.TemplateParameters* parseTemplateParameterList(int flag = 0);
Parse template parameter list.

Input: flag 0: parsing "( list )" 1: parsing non-empty "list )"

AST.Dsymbol parseMixin();
Parse template mixin. mixin Foo; mixin Foo!(args); mixin a.b.c!(args).Foo!(args); mixin Foo!(args) identifier; mixin typeof(expr).identifier!(args);
AST.Objects* parseTemplateArguments();
Parse template arguments.

Input: current token is opening '!'

Output: current token is one after closing ')'

AST.Objects* parseTemplateArgumentList();
Parse template argument list.

Input: current token is opening '(', or ',' for _traits

Output: current token is one after closing ')'

AST.Objects* parseTemplateSingleArgument();
Parse single template argument, to support the syntax: foo!arg

Input: current token is the arg

AST.StaticAssert parseStaticAssert();
Parse a static assertion. Current token is 'static'.
AST.TypeQualified parseTypeof();
Parse typeof(expression). Current token is on the 'typeof'.
AST.Type parseVector();
Parse _vector(type). Current token is on the '_vector'.
LINK parseLinkage(AST.Identifiers** pidents, out CPPMANGLE cppmangle);

Parse: extern (linkage) extern (C++, namespaces) The parser is on the 'extern' token.

AST.Identifiers* parseQualifiedIdentifier(const(char)* entity);
Parse ident1.ident2.ident3
Parameters:
const(char)* entity what qualified identifier is expected to resolve into. Used only for better error message
Returns:
array of identifiers with actual qualified one stored last
AST.Condition parseDebugCondition();
Parse a debug conditional
AST.Condition parseVersionCondition();
Parse a version conditional
AST.Condition parseStaticIfCondition();
static if (expression) body else body Current token is 'static'.
AST.Dsymbol parseCtor(PrefixAttributes!AST* pAttrs);
Parse a constructor definition: this(parameters) { body } or postblit: this(this) { body } or constructor template: this(templateparameters)(parameters) { body } Current token is 'this'.
AST.Dsymbol parseDtor(PrefixAttributes!AST* pAttrs);
Parse a destructor definition: ~this() { body } Current token is '~'.
AST.Dsymbol parseStaticCtor(PrefixAttributes!AST* pAttrs);
Parse a static constructor definition: static this() { body } Current token is 'static'.
AST.Dsymbol parseStaticDtor(PrefixAttributes!AST* pAttrs);
Parse a static destructor definition: static ~this() { body } Current token is 'static'.
AST.Dsymbol parseSharedStaticCtor(PrefixAttributes!AST* pAttrs);
Parse a shared static constructor definition: shared static this() { body } Current token is 'shared'.
AST.Dsymbol parseSharedStaticDtor(PrefixAttributes!AST* pAttrs);
Parse a shared static destructor definition: shared static ~this() { body } Current token is 'shared'.
AST.Dsymbol parseInvariant(PrefixAttributes!AST* pAttrs);
Parse an invariant definition: invariant() { body } Current token is 'invariant'.
AST.Dsymbol parseUnitTest(PrefixAttributes!AST* pAttrs);
Parse a unittest definition: unittest { body } Current token is 'unittest'.
AST.Dsymbol parseNew(PrefixAttributes!AST* pAttrs);
Parse a new definition: new(parameters) { body } Current token is 'new'.
AST.Dsymbol parseDelete(PrefixAttributes!AST* pAttrs);
Parse a delete definition: delete(parameters) { body } Current token is 'delete'.
AST.Parameters* parseParameters(int* pvarargs, AST.TemplateParameters** tpl = null);
Parse parameter list.
AST.EnumDeclaration parseEnum();
AST.Dsymbol parseAggregate();
Parse struct, union, interface, class.
AST.BaseClasses* parseBaseClasses();
AST.Type parseBasicType2(AST.Type t);
Parse things that follow the initial type t. t * t [] t [type] t [expression] t [expression .. expression] t function t delegate
AST.Dsymbols* parseDeclarations(bool autodecl, PrefixAttributes!AST* pAttrs, const(char)* comment);
Parse Declarations. These can be: 1. declarations at global/class level 2. declarations at statement level Return array of Declaration *'s.
AST.FuncDeclaration parseContracts(AST.FuncDeclaration f);
Parse contracts following function declaration.
void checkDanglingElse(Loc elseloc);
ParseForeachRet!(isStatic, isDecl) parseForeach(bool isStatic, bool isDecl)(Loc loc, ParseForeachArgs!(isStatic, isDecl) args);
Parses foreach statements, static foreach statements and static foreach declarations. The template parameter isStatic is true, iff a static foreach should be parsed. If isStatic is true, isDecl can be true to indicate that a static foreach declaration should be parsed.
AST.Statement parseStatement(int flags, const(char)** endPtr = null, Loc* pEndloc = null);

Input: flags PSxxxx

Output: pEndloc if { ... statements ... }, store location of closing brace, otherwise loc of last token of statement

AST.Initializer parseInitializer();
Parse initializer for variable declaration.
AST.Expression parseDefaultInitExp();
Parses default argument initializer expression that is an assign expression, with special handling for __FILE__, _FILE_DIR__, __LINE__, __MODULE__, __FUNCTION__, and __PRETTY_FUNCTION__.
bool isDeclaration(Token* t, NeedDeclaratorId needId, TOK endtok, Token** pt);
Determine if the scanner is sitting on the start of a declaration.
Parameters:

Output: if *pt is not NULL, it is set to the ending token, which would be endtok

bool skipParens(Token* t, Token** pt);
Skip parens, brackets.

Input: t is on opening (

Output: *pt is set to closing token, which is ')' on success

Returns:
true successful false some parsing error
bool skipAttributes(Token* t, Token** pt);
Skip attributes.

Input: t is on a candidate attribute

Output: *pt is set to first non-attribute token on success

Returns:
true successful false some parsing error
AST.Expression parsePrimaryExp();
Expression Parser
AST.Expressions* parseArguments();
Collect argument list. Assume current token is ',', '(' or '['.
AST.Expression parseNewExp(AST.Expression thisexp);
void addComment(AST.Dsymbol s, const(char)* blockComment);