Skip to content

Instantly share code, notes, and snippets.

@expipiplus1
Created December 15, 2011 14:17
Show Gist options
  • Save expipiplus1/1481233 to your computer and use it in GitHub Desktop.
Save expipiplus1/1481233 to your computer and use it in GitHub Desktop.
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