//--------------------------------------------------------------------*- C++ -*- // CLING - the C++ LLVM-based InterpreterG :) // author: Vassil Vassilev // // This file is dual-licensed: you can choose to license it under the University // of Illinois Open Source License or the GNU Lesser General Public License. See // LICENSE.TXT for details. //------------------------------------------------------------------------------ #ifndef CLING_META_PARSER_H #define CLING_META_PARSER_H #include "MetaLexer.h" // for cling::Token #include "MetaSema.h" // for ActionResult #include "llvm/ADT/OwningPtr.h" #include "llvm/ADT/SmallVector.h" namespace llvm { class StringRef; } namespace cling { class MetaLexer; class MetaSema; class Value; // Command syntax: MetaCommand := // CommandSymbol := '.' | '//.' // Command := LCommand | XCommand | qCommand | UCommand | // ICommand | OCommand | RawInputCommand | // PrintDebugCommand | DynamicExtensionsCommand | // HelpCommand | FileExCommand | FilesCommand | // ClassCommand | GCommand | StoreStateCommand | // CompareStateCommand | StatsCommand | undoCommand // LCommand := 'L' FilePath // >Command := '>' FilePath // qCommand := 'q' // XCommand := 'x' FilePath[ArgList] | 'X' FilePath[ArgList] // UCommand := 'U' FilePath // ICommand := 'I' [FilePath] // OCommand := 'O'[' ']Constant // RawInputCommand := 'rawInput' [Constant] // PrintDebugCommand := 'printDebug' [Constant] // StoreStateCommand := 'storeState' "Ident" // CompareStateCommand := 'compareState' "Ident" // StatsCommand := 'stats' ['ast'] // undoCommand := 'undo' [Constant] // DynamicExtensionsCommand := 'dynamicExtensions' [Constant] // HelpCommand := 'help' // FileExCommand := 'fileEx' // FilesCommand := 'files' // ClassCommand := 'class' AnyString | 'Class' // GCommand := 'g' [Ident] // FilePath := AnyString // ArgList := (ExtraArgList) ' ' [ArgList] // ExtraArgList := AnyString [, ExtraArgList] // AnyString := *^(' ' | '\t') // Constant := {0-9} // Ident := a-zA-Z{a-zA-Z0-9} // class MetaParser { private: llvm::OwningPtr m_Lexer; llvm::OwningPtr m_Actions; llvm::SmallVector m_TokenCache; llvm::SmallVector m_MetaSymbolCache; private: ///\brief Returns the current token without consuming it. /// inline const Token& getCurTok() { return lookAhead(0); } ///\brief Consume the current 'peek' token. /// void consumeToken(); void consumeAnyStringToken(tok::TokenKind stopAt = tok::space); const Token& lookAhead(unsigned Num); void skipWhitespace(); bool isCommandSymbol(); bool isCommand(MetaSema::ActionResult& actionResult, Value* resultValue); bool isLCommand(MetaSema::ActionResult& actionResult); bool isRedirectCommand(MetaSema::ActionResult& actionResult); bool isExtraArgList(); bool isXCommand(MetaSema::ActionResult& actionResult, Value* resultValue); bool isqCommand(); bool isUCommand(MetaSema::ActionResult& actionResult); bool isICommand(); bool isOCommand(); bool israwInputCommand(); bool isprintDebugCommand(); bool isstoreStateCommand(); bool iscompareStateCommand(); bool isstatsCommand(); bool isundoCommand(); bool isdynamicExtensionsCommand(); bool ishelpCommand(); bool isfileExCommand(); bool isfilesCommand(); bool isClassCommand(); bool isNamespaceCommand(); bool isgCommand(); bool isTypedefCommand(); bool isShellCommand(MetaSema::ActionResult& actionResult, Value* resultValue); public: MetaParser(MetaSema* Actions); void enterNewInputLine(llvm::StringRef Line); ///\brief Drives the recursive decendent parsing. /// ///\returns true if it was meta command. /// bool isMetaCommand(MetaSema::ActionResult& actionResult, Value* resultValue); ///\brief Returns whether quit was requested via .q command /// bool isQuitRequested() const; MetaSema& getActions() const { return *m_Actions.get(); } }; } // end namespace cling #endif // CLING_META_PARSER_H