diff options
author | chriseth <c@ethdev.com> | 2016-08-20 01:57:21 +0800 |
---|---|---|
committer | chriseth <c@ethdev.com> | 2016-09-01 06:02:51 +0800 |
commit | 3c412ed2f63a58b27eeb00fe584b9378311b099f (patch) | |
tree | cba706f91c05658a8b1f8794ad21745ea5619e39 /libsolidity/parsing | |
parent | 52d9f897126394dcc7388277d4fbd3ef7b4df38a (diff) | |
download | dexon-solidity-3c412ed2f63a58b27eeb00fe584b9378311b099f.tar.gz dexon-solidity-3c412ed2f63a58b27eeb00fe584b9378311b099f.tar.zst dexon-solidity-3c412ed2f63a58b27eeb00fe584b9378311b099f.zip |
Version pragma.
Diffstat (limited to 'libsolidity/parsing')
-rw-r--r-- | libsolidity/parsing/Parser.cpp | 33 | ||||
-rw-r--r-- | libsolidity/parsing/Parser.h | 1 | ||||
-rw-r--r-- | libsolidity/parsing/Token.h | 1 |
3 files changed, 35 insertions, 0 deletions
diff --git a/libsolidity/parsing/Parser.cpp b/libsolidity/parsing/Parser.cpp index b8f72238..b2f4a156 100644 --- a/libsolidity/parsing/Parser.cpp +++ b/libsolidity/parsing/Parser.cpp @@ -76,6 +76,9 @@ ASTPointer<SourceUnit> Parser::parse(shared_ptr<Scanner> const& _scanner) { switch (auto token = m_scanner->currentToken()) { + case Token::Pragma: + nodes.push_back(parsePragmaDirective()); + break; case Token::Import: nodes.push_back(parseImportDirective()); break; @@ -97,6 +100,36 @@ ASTPointer<SourceUnit> Parser::parse(shared_ptr<Scanner> const& _scanner) } } +ASTPointer<PragmaDirective> Parser::parsePragmaDirective() +{ + // pragma anything* ; + // Currently supported: + // pragma solidity ^0.4.0 || ^0.3.0; + ASTNodeFactory nodeFactory(*this); + expectToken(Token::Pragma); + vector<string> literals; + vector<Token::Value> tokens; + do + { + Token::Value token = m_scanner->currentToken(); + if (token == Token::Illegal) + parserError("Token incompatible with Solidity parser as part of pragma directive."); + else + { + string literal = m_scanner->currentLiteral(); + if (literal.empty() && Token::toString(token)) + literal = Token::toString(token); + literals.push_back(literal); + tokens.push_back(token); + } + m_scanner->next(); + } + while (m_scanner->currentToken() != Token::Semicolon && m_scanner->currentToken() != Token::EOS); + nodeFactory.markEndPosition(); + expectToken(Token::Semicolon); + return nodeFactory.createNode<PragmaDirective>(tokens, literals); +} + ASTPointer<ImportDirective> Parser::parseImportDirective() { // import "abc" [as x]; diff --git a/libsolidity/parsing/Parser.h b/libsolidity/parsing/Parser.h index d776c3fd..9c30cf60 100644 --- a/libsolidity/parsing/Parser.h +++ b/libsolidity/parsing/Parser.h @@ -55,6 +55,7 @@ private: ///@{ ///@name Parsing functions for the AST nodes + ASTPointer<PragmaDirective> parsePragmaDirective(); ASTPointer<ImportDirective> parseImportDirective(); ASTPointer<ContractDefinition> parseContractDefinition(bool _isLibrary); ASTPointer<InheritanceSpecifier> parseInheritanceSpecifier(); diff --git a/libsolidity/parsing/Token.h b/libsolidity/parsing/Token.h index 007baef4..15d4860f 100644 --- a/libsolidity/parsing/Token.h +++ b/libsolidity/parsing/Token.h @@ -167,6 +167,7 @@ namespace solidity K(Modifier, "modifier", 0) \ K(New, "new", 0) \ K(Public, "public", 0) \ + K(Pragma, "pragma", 0) \ K(Private, "private", 0) \ K(Return, "return", 0) \ K(Returns, "returns", 0) \ |