aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlex Beregszaszi <alex@rtfs.hu>2017-02-08 06:12:38 +0800
committerAlex Beregszaszi <alex@rtfs.hu>2017-03-18 00:27:04 +0800
commit54230d2d5d15638fdf7c3893ee436fd8bc380e8c (patch)
tree76f6ba3de062954c65e2effcaf6b458433cf12ad
parent6d4628ace4082a4318dc61fff49e8d193eea36e9 (diff)
downloaddexon-solidity-54230d2d5d15638fdf7c3893ee436fd8bc380e8c.tar.gz
dexon-solidity-54230d2d5d15638fdf7c3893ee436fd8bc380e8c.tar.zst
dexon-solidity-54230d2d5d15638fdf7c3893ee436fd8bc380e8c.zip
Support interface (contract) keyword in the parser
-rw-r--r--libsolidity/parsing/Parser.cpp24
-rw-r--r--libsolidity/parsing/Parser.h2
-rw-r--r--libsolidity/parsing/Token.h2
3 files changed, 22 insertions, 6 deletions
diff --git a/libsolidity/parsing/Parser.cpp b/libsolidity/parsing/Parser.cpp
index acd87d55..4cf6f0a6 100644
--- a/libsolidity/parsing/Parser.cpp
+++ b/libsolidity/parsing/Parser.cpp
@@ -82,9 +82,10 @@ ASTPointer<SourceUnit> Parser::parse(shared_ptr<Scanner> const& _scanner)
case Token::Import:
nodes.push_back(parseImportDirective());
break;
+ case Token::Interface:
case Token::Contract:
case Token::Library:
- nodes.push_back(parseContractDefinition(token == Token::Library));
+ nodes.push_back(parseContractDefinition(token));
break;
default:
fatalParserError(string("Expected import directive or contract definition."));
@@ -193,13 +194,28 @@ ASTPointer<ImportDirective> Parser::parseImportDirective()
return nodeFactory.createNode<ImportDirective>(path, unitAlias, move(symbolAliases));
}
-ASTPointer<ContractDefinition> Parser::parseContractDefinition(bool _isLibrary)
+ASTPointer<ContractDefinition> Parser::parseContractDefinition(Token::Value _expectedKind)
{
ASTNodeFactory nodeFactory(*this);
ASTPointer<ASTString> docString;
if (m_scanner->currentCommentLiteral() != "")
docString = make_shared<ASTString>(m_scanner->currentCommentLiteral());
- expectToken(_isLibrary ? Token::Library : Token::Contract);
+ expectToken(_expectedKind);
+ ContractDefinition::ContractKind contractKind;
+ switch(_expectedKind)
+ {
+ case Token::Interface:
+ contractKind = ContractDefinition::ContractKind::Interface;
+ break;
+ case Token::Contract:
+ contractKind = ContractDefinition::ContractKind::Contract;
+ break;
+ case Token::Library:
+ contractKind = ContractDefinition::ContractKind::Library;
+ break;
+ default:
+ fatalParserError("Unsupported contract type.");
+ }
ASTPointer<ASTString> name = expectIdentifierToken();
vector<ASTPointer<InheritanceSpecifier>> baseContracts;
if (m_scanner->currentToken() == Token::Is)
@@ -252,7 +268,7 @@ ASTPointer<ContractDefinition> Parser::parseContractDefinition(bool _isLibrary)
docString,
baseContracts,
subNodes,
- _isLibrary ? ContractDefinition::ContractKind::Library : ContractDefinition::ContractKind::Contract
+ contractKind
);
}
diff --git a/libsolidity/parsing/Parser.h b/libsolidity/parsing/Parser.h
index 79d1d1d4..bf972c65 100644
--- a/libsolidity/parsing/Parser.h
+++ b/libsolidity/parsing/Parser.h
@@ -69,7 +69,7 @@ private:
///@name Parsing functions for the AST nodes
ASTPointer<PragmaDirective> parsePragmaDirective();
ASTPointer<ImportDirective> parseImportDirective();
- ASTPointer<ContractDefinition> parseContractDefinition(bool _isLibrary);
+ ASTPointer<ContractDefinition> parseContractDefinition(Token::Value _expectedKind);
ASTPointer<InheritanceSpecifier> parseInheritanceSpecifier();
Declaration::Visibility parseVisibilitySpecifier(Token::Value _token);
FunctionHeaderParserResult parseFunctionHeader(bool _forceEmptyName, bool _allowModifiers);
diff --git a/libsolidity/parsing/Token.h b/libsolidity/parsing/Token.h
index c6d050bb..9a557ebd 100644
--- a/libsolidity/parsing/Token.h
+++ b/libsolidity/parsing/Token.h
@@ -157,6 +157,7 @@ namespace solidity
K(Hex, "hex", 0) \
K(If, "if", 0) \
K(Indexed, "indexed", 0) \
+ K(Interface, "interface", 0) \
K(Internal, "internal", 0) \
K(Import, "import", 0) \
K(Is, "is", 0) \
@@ -225,7 +226,6 @@ namespace solidity
K(Final, "final", 0) \
K(In, "in", 0) \
K(Inline, "inline", 0) \
- K(Interface, "interface", 0) \
K(Let, "let", 0) \
K(Match, "match", 0) \
K(NullLiteral, "null", 0) \