# dmd.parse

Takes a token stream from the lexer, and parses it into an abstract syntax tree.

Specification: D Grammar

#### Authors

Walter Bright

#### License

Boost License 1.0

Source: parse.d

Documentation: https://dlang.org/phobos/dmd_parse.html

Coverage: https://codecov.io/gh/dlang/dmd/src/master/src/dmd/parse.d

- `Parser`

  #### Declaration

  `class `Parser`(AST, Lexer = dmd.lexer.Lexer): Lexer;`

  - `this`

    #### Declaration

    `scope this(const ref Loc `loc`, AST.Module `_module`, const(char)[] `input`, bool `doDocComment`, ErrorSink `errorSink`);`

    Use this constructor for string mixins.

    Input: `loc` location in source file of mixin

  - `parseModule`

    #### Declaration

    `AST.Dsymbols* `parseModule`();`

    Parse a module, i.e. the optional `module x.y.z` declaration and all declarations found in the current file.

    #### Return Value

    the list of declarations or an empty list in case of malformed declarations, the module declaration will be stored as `this.md` if found

  - `parseModuleDeclaration`

    #### Declaration

    `final bool `parseModuleDeclaration`();`

    Parse the optional module declaration

    #### Return Value

    `false` if a malformed module declaration was found

  - `parseModuleContent`

    #### Declaration

    `final AST.Dsymbols* `parseModuleContent`();`

    Parse the content of a module, i.e. all declarations found until the end of file.

    #### Return Value

    the list of declarations or an empty list in case of malformed declarations

  - `parseDeclDefs`

    #### Declaration

    `AST.Dsymbols* `parseDeclDefs`(int `once`, AST.Dsymbol* `pLastDecl` = null, PrefixAttributes!AST* `pAttrs` = null);`

    Parse declarations and definitions

    #### Parameters

    `int `once`` | !=0 means parse exactly one decl or def
    `AST.Dsymbol* `pLastDecl`` | set to last decl or def parsed
    `PrefixAttributes!AST* `pAttrs`` | keep track of attributes

    #### Return Value

    array of declared symbols

  - `parseTypeOrAssignExp`

    #### Declaration

    `RootObject `parseTypeOrAssignExp`(TOK `endtoken` = TOK.reserved);`

    Parse a Type or an Expression

    #### Return Value

    RootObject representing the AST

  - `parseAssignCondition`

    #### Declaration

    `AST.Parameter `parseAssignCondition`();`

    Parse an assignment condition for if or while statements.

    #### Return Value

    The variable that is declared inside the condition

  - `parseStatement`

    #### Declaration

    `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

  - `parseAsm`

    #### Declaration

    `AST.Statement `parseAsm`();`

    Parse inline assembler block.

    #### Return Value

    inline assembler block as a Statement

  - `check`

    #### Declaration

    `void `check`(Loc `loc`, TOK `value`);`

    Issue error if the current token is not ``value``, advance to next token.

    #### Parameters

    `Loc `loc`` | location for error message
    `TOK `value`` | token `value` to compare with

  - `check`

    #### Declaration

    `void `check`(TOK `value`);`

    Issue error if the current token is not ``value``, advance to next token.

    #### Parameters

    `TOK `value`` | token `value` to compare with

  - `check`

    #### Declaration

    `void `check`(TOK `value`, const(char)* `string`);`

    Issue error if the current token is not ``value``, advance to next token.

    #### Parameters

    `TOK `value`` | token `value` to compare with
    `const(char)* `string`` | for error message

  - `NeedDeclaratorId`

    #### Declaration

    `enum `NeedDeclaratorId`;`

  - `skipParens`

    #### Declaration

    `bool `skipParens`(Token* `t`, Token** `pt`);`

    Skip parentheses.

    #### Parameters

    `Token* `t`` | on opening (
    `Token** `pt`` | *`pt` is set to token past ')' on `true`

    #### Return Value

    `true` successful `false` some parsing error

  - `parsePrimaryExp`

    #### Declaration

    `AST.Expression `parsePrimaryExp`();`

    Expression Parser

  - `isBuiltinAtAttribute`

    #### Declaration

    `static StorageClass `isBuiltinAtAttribute`(Identifier `ident`);`

    Recognize builtin @ attributes

    #### Parameters

    `Identifier `ident`` | identifier

    #### Return Value

    storage class for attribute, 0 if not

- `precedence`

  #### Declaration

  `immutable PREC[EXP.max + 1] `precedence`;`

  Set operator `precedence` for each operator.

  #### Discussion

  Used by hdrgen

- `ParsedLinkage`

  #### Declaration

  `struct `ParsedLinkage`(AST);`

  The result of the `ParseLinkage` function

  - `link`

    #### Declaration

    `LINK `link`;`

    What linkage was specified

  - `cppmangle`

    #### Declaration

    `CPPMANGLE `cppmangle`;`

    If `extern(C++, class|struct)`, contains the `class|struct`

  - `idents`

    #### Declaration

    `AST.Identifiers* `idents`;`

    If `extern(C++, some.identifier)`, will be the identifiers

  - `identExps`

    #### Declaration

    `AST.Expressions* `identExps`;`

    If `extern(C++, (some_tuple_expression)|"string"), will be the expressions

)