diff options
Diffstat (limited to 'Parser.cpp')
-rw-r--r-- | Parser.cpp | 41 |
1 files changed, 40 insertions, 1 deletions
@@ -119,6 +119,7 @@ ASTPointer<ContractDefinition> Parser::parseContractDefinition() ASTPointer<ASTString> name = expectIdentifierToken(); vector<ASTPointer<InheritanceSpecifier>> baseContracts; vector<ASTPointer<StructDefinition>> structs; + vector<ASTPointer<EnumDefinition>> enums; vector<ASTPointer<VariableDeclaration>> stateVariables; vector<ASTPointer<FunctionDefinition>> functions; vector<ASTPointer<ModifierDefinition>> modifiers; @@ -140,6 +141,8 @@ ASTPointer<ContractDefinition> Parser::parseContractDefinition() functions.push_back(parseFunctionDefinition(name.get())); else if (currentToken == Token::Struct) structs.push_back(parseStructDefinition()); + else if (currentToken == Token::Enum) + enums.push_back(parseEnumDefinition()); else if (currentToken == Token::Identifier || currentToken == Token::Mapping || Token::isElementaryTypeName(currentToken)) { @@ -157,7 +160,7 @@ ASTPointer<ContractDefinition> Parser::parseContractDefinition() } nodeFactory.markEndPosition(); expectToken(Token::RBrace); - return nodeFactory.createNode<ContractDefinition>(name, docString, baseContracts, structs, + return nodeFactory.createNode<ContractDefinition>(name, docString, baseContracts, structs, enums, stateVariables, functions, modifiers, events); } @@ -263,6 +266,35 @@ ASTPointer<StructDefinition> Parser::parseStructDefinition() return nodeFactory.createNode<StructDefinition>(name, members); } +ASTPointer<EnumDeclaration> Parser::parseEnumDeclaration() +{ + ASTNodeFactory nodeFactory(*this); + ASTPointer<ASTString> name = expectIdentifierToken(); + nodeFactory.markEndPosition(); + return nodeFactory.createNode<EnumDeclaration>(name); +} + +ASTPointer<EnumDefinition> Parser::parseEnumDefinition() +{ + ASTNodeFactory nodeFactory(*this); + expectToken(Token::Enum); + ASTPointer<ASTString> name = expectIdentifierToken(); + vector<ASTPointer<Declaration>> members; + expectToken(Token::LBrace); + + while (m_scanner->getCurrentToken() == Token::Identifier) + { + members.push_back(parseEnumDeclaration()); + if (m_scanner->getCurrentToken() == Token::RBrace) + break; + expectToken(Token::Comma); + } + + nodeFactory.markEndPosition(); + expectToken(Token::RBrace); + return nodeFactory.createNode<EnumDefinition>(name, members); +} + ASTPointer<VariableDeclaration> Parser::parseVariableDeclaration(VarDeclParserOptions const& _options) { ASTNodeFactory nodeFactory(*this); @@ -823,6 +855,13 @@ ASTPointer<ASTString> Parser::expectIdentifierToken() return getLiteralAndAdvance(); } +ASTPointer<ASTString> Parser::peekIdentifierToken() +{ + if (m_scanner->getCurrentToken() != Token::Identifier) + return nullptr; + return getLiteralAndAdvance(); +} + ASTPointer<ASTString> Parser::getLiteralAndAdvance() { ASTPointer<ASTString> identifier = make_shared<ASTString>(m_scanner->getCurrentLiteral()); |