Created
December 15, 2011 14:17
-
-
Save expipiplus1/1481233 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
std::unique_ptr<TranslationUnit> TranslationUnit::Parse( Lexer::Lexer& lexer ) | |
{ | |
lexer.PushRestorePoint(); | |
if( lexer.PeekToken() == Lexer::TokenType::TECHNIQUE ) | |
{ | |
lexer.Consume(); | |
std::string name; | |
if( lexer.PeekToken() == Lexer::TokenType::IDENTIFIER ) | |
{ | |
name = lexer.PeekString(); | |
lexer.Consume(); | |
} | |
if( lexer.PeekToken() == Lexer::TokenType::OPEN_BRACE ) | |
{ | |
lexer.Consume(); | |
if( lexer.PeekToken() = Lexer::TokenType::CLOSE_BRACE ) | |
{ | |
lexer.Consume(); | |
lexer.PopRestorePoint(); | |
return std::unique_ptr<TranslationUnit>( new TranslationUnit( name ) ); | |
} | |
} | |
} | |
lexer.Restore(); | |
return nullptr; | |
} | |
std::unique_ptr<TranslationUnit> TranslationUnit::Parse( Lexer::Lexer& lexer ) | |
{ | |
lexer.PushRestorePoint(); | |
if( lexer.PeekToken() != Lexer::TokenType::TECHNIQUE ) | |
goto error; | |
lexer.Consume(); | |
std::string name; | |
if( lexer.PeekToken() == Lexer::TokenType::IDENTIFIER ) | |
{ | |
name = lexer.PeekString(); | |
lexer.Consume(); | |
} | |
if( lexer.PeekToken() != Lexer::TokenType::OPEN_BRACE ) | |
goto error; | |
lexer.Consume(); | |
if( lexer.PeekToken() != Lexer::TokenType::CLOSE_BRACE ) | |
goto error; | |
lexer.Consume(); | |
lexer.PopRestorePoint(); | |
return std::unique_ptr<TranslationUnit>( new TranslationUnit( name ) ); | |
error: | |
lexer.Restore(); | |
return nullptr; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment