diff options
Diffstat (limited to 'libsolidity/parsing/Parser.cpp')
-rw-r--r-- | libsolidity/parsing/Parser.cpp | 33 |
1 files changed, 33 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]; |