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: ddmd.lexer.Lexer;
this(Loc loc, Module _module, const(char)[] input, bool doDocComment);
Use this constructor for string mixins.

Input: loc location in source file of mixin

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 ';'
Dsymbols* parseBlock(Dsymbol* pLastDecl, PrefixAttributes* 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(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, Expressions** pudas);
Parse const/immutable/shared/inout/nothrow/pure postfix
Expression parseConstraint();
Parse constraint. Constraint is of the form: if ( ConstraintExpression )
TemplateDeclaration parseTemplateDeclaration(bool ismixin = false);
Parse a TemplateDeclaration.
TemplateParameters* parseTemplateParameterList(int flag = 0);
Parse template parameter list.

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

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);
Objects* parseTemplateArguments();
Parse template arguments.

Input: current token is opening '!'

Output: current token is one after closing ')'

Objects* parseTemplateArgumentList();
Parse template argument list.

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

Output: current token is one after closing ')'

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

Input: current token is the arg

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

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

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
Condition parseDebugCondition();
Parse a debug conditional
Condition parseVersionCondition();
Parse a version conditional
Condition parseStaticIfCondition();
static if (expression) body else body Current token is 'static'.
Dsymbol parseCtor(PrefixAttributes* pAttrs);
Parse a constructor definition: this(parameters) { body } or postblit: this(this) { body } or constructor template: this(templateparameters)(parameters) { body } Current token is 'this'.
Dsymbol parseDtor(PrefixAttributes* pAttrs);
Parse a destructor definition: ~this() { body } Current token is '~'.
Dsymbol parseStaticCtor(PrefixAttributes* pAttrs);
Parse a static constructor definition: static this() { body } Current token is 'static'.
Dsymbol parseStaticDtor(PrefixAttributes* pAttrs);
Parse a static destructor definition: static ~this() { body } Current token is 'static'.
Dsymbol parseSharedStaticCtor(PrefixAttributes* pAttrs);
Parse a shared static constructor definition: shared static this() { body } Current token is 'shared'.
Dsymbol parseSharedStaticDtor(PrefixAttributes* pAttrs);
Parse a shared static destructor definition: shared static ~this() { body } Current token is 'shared'.
Dsymbol parseInvariant(PrefixAttributes* pAttrs);
Parse an invariant definition: invariant() { body } Current token is 'invariant'.
Dsymbol parseUnitTest(PrefixAttributes* pAttrs);
Parse a unittest definition: unittest { body } Current token is 'unittest'.
Dsymbol parseNew(PrefixAttributes* pAttrs);
Parse a new definition: new(parameters) { body } Current token is 'new'.
Dsymbol parseDelete(PrefixAttributes* pAttrs);
Parse a delete definition: delete(parameters) { body } Current token is 'delete'.
Parameters* parseParameters(int* pvarargs, TemplateParameters** tpl = null);
Parse parameter list.
EnumDeclaration parseEnum();
Dsymbol parseAggregate();
Parse struct, union, interface, class.
BaseClasses* parseBaseClasses();
Type parseBasicType2(Type t);
Parse things that follow the initial type t. t * t [] t [type] t [expression] t [expression .. expression] t function t delegate
Dsymbols* parseDeclarations(bool autodecl, PrefixAttributes* 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.
FuncDeclaration parseContracts(FuncDeclaration f);
Parse contracts following function declaration.
void checkDanglingElse(Loc elseloc);
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 first token of next statement

Initializer parseInitializer();
Parse initializer for variable declaration.
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
Expression parsePrimaryExp();
Expression Parser
Expressions* parseArguments();
Collect argument list. Assume current token is ',', '(' or '['.
Expression parseNewExp(Expression thisexp);
void addComment(Dsymbol s, const(char)* blockComment);