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 <vector> 16 17 namespace lld { 18 namespace elf { 19 20 class ScriptParserBase { 21 public: 22 explicit ScriptParserBase(StringRef S) : Input(S), Tokens(tokenize(S)) {} 23 explicit ScriptParserBase(std::vector<StringRef> Tokens) 24 : Input(""), Tokens(Tokens) {} 25 26 protected: 27 void setError(const Twine &Msg); 28 static std::vector<StringRef> tokenize(StringRef S); 29 static StringRef skipSpace(StringRef S); 30 bool atEOF(); 31 StringRef next(); 32 StringRef peek(); 33 bool skip(StringRef Tok); 34 void expect(StringRef Expect); 35 36 size_t getPos(); 37 void printErrorPos(); 38 39 std::vector<uint8_t> parseHex(StringRef S); 40 41 StringRef Input; 42 std::vector<StringRef> Tokens; 43 size_t Pos = 0; 44 bool Error = false; 45 }; 46 47 } // namespace elf 48 } // namespace lld 49 50 #endif 51