1.3.5 Identifiers

identifier Unicode identifier

The syntax tree node for an identifier contains the identifier as a UTF-32-encoded string.

// ast.ixx:

export module minilang.ast;

// ...

class IdentifierNode : public Node
{
public:
    IdentifierNode(const std::u32string& str_);
    const std::u32string& Str() const { return str; }
    // ...
private:
    std::u32string str;
};

// ...

Because used lexer is instantiated with the UTF-32 character type, char32_t , the token.ToString() function returns the match for the token as a UTF-32 string.

// identifier_parser.parser:

export module minilang.parser.identifier;

[implementation]import minilang.ast;
[implementation]import minilang.lexer;
[implementation]import minilang.token;

parser IdentifierParser
{
    lexer minilang::lexer::MinilangLexer<char32_t>;

    Identifier : minilang::ast::IdentifierNode*
        ::= ID{ auto token = lexer.GetToken(pos); return new minilang::ast::IdentifierNode(token.ToString()); }
        ;
}