aboutsummaryrefslogtreecommitdiffstats
path: root/Parser.cpp
diff options
context:
space:
mode:
authorLefteris Karapetsas <lefteris@refu.co>2015-02-10 01:08:56 +0800
committerLefteris Karapetsas <lefteris@refu.co>2015-02-14 06:16:14 +0800
commita295417f3476428c286f96433a42a96bfe29fee3 (patch)
treee5f9b374407dfcdc4f11943d91df69e4ec559b0a /Parser.cpp
parent54ed8877aa673fd6765c1238bcef598331ae41ae (diff)
downloaddexon-solidity-a295417f3476428c286f96433a42a96bfe29fee3.tar
dexon-solidity-a295417f3476428c286f96433a42a96bfe29fee3.tar.gz
dexon-solidity-a295417f3476428c286f96433a42a96bfe29fee3.tar.bz2
dexon-solidity-a295417f3476428c286f96433a42a96bfe29fee3.tar.lz
dexon-solidity-a295417f3476428c286f96433a42a96bfe29fee3.tar.xz
dexon-solidity-a295417f3476428c286f96433a42a96bfe29fee3.tar.zst
dexon-solidity-a295417f3476428c286f96433a42a96bfe29fee3.zip
Parsing enums for Solidity - WIP
Diffstat (limited to 'Parser.cpp')
-rw-r--r--Parser.cpp41
1 files changed, 40 insertions, 1 deletions
diff --git a/Parser.cpp b/Parser.cpp
index f076df87..2f0796d6 100644
--- a/Parser.cpp
+++ b/Parser.cpp
@@ -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());