1 //===- ScriptParser.h -------------------------------------------*- C++ -*-===// 2 // 3 // The LLVM Linker 4 // 5 // This file is distributed under the University of Illinois Open Source 6 // License. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 10 #ifndef LLD_ELF_SCRIPT_PARSER_H 11 #define LLD_ELF_SCRIPT_PARSER_H 12 13 #include "lld/Core/LLVM.h" 14 #include "llvm/ADT/StringRef.h" 15 #include <utility> 16 #include <vector> 17 18 namespace lld { 19 namespace elf { 20 21 class ScriptParserBase { 22 public: 23 explicit ScriptParserBase(StringRef S) : Input(S), Tokens(tokenize(S)) {} 24 explicit ScriptParserBase(std::vector<StringRef> Tokens) 25 : Input(""), Tokens(std::move(Tokens)) {} 26 27 protected: 28 void setError(const Twine &Msg); 29 static std::vector<StringRef> tokenize(StringRef S); 30 static StringRef skipSpace(StringRef S); 31 bool atEOF(); 32 StringRef next(); 33 StringRef peek(); 34 bool skip(StringRef Tok); 35 void expect(StringRef Expect); 36 37 size_t getPos(); 38 void printErrorPos(); 39 40 std::vector<uint8_t> parseHex(StringRef S); 41 42 StringRef Input; 43 std::vector<StringRef> Tokens; 44 size_t Pos = 0; 45 bool Error = false; 46 }; 47 48 } // namespace elf 49 } // namespace lld 50 51 #endif 52