MCPcopy Create free account
hub / github.com/BehaviorTree/BehaviorTree.CPP / ScriptParser

Class ScriptParser

src/script_parser.cpp:25–419  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

23{
24
25class ScriptParser
26{
27public:
28 explicit ScriptParser(std::vector<Token> tokens) : tokens_(std::move(tokens))
29 {}
30
31 std::vector<Ast::expr_ptr> parseAll()
32 {
33 std::vector<Ast::expr_ptr> stmts;
34 while(!atEnd())
35 {
36 stmts.push_back(parseExpr(0));
37 // consume optional semicolons between statements
38 while(check(TokenType::Semicolon))
39 {
40 advance();
41 }
42 }
43 return stmts;
44 }
45
46private:
47 std::vector<Token> tokens_;
48 size_t current_ = 0;
49
50 // Binding power constants. Higher value = tighter binding.
51 static constexpr int kAssignmentBP = 2;
52 static constexpr int kTernaryBP = 4;
53 static constexpr int kComparisonBP = 10;
54 static constexpr int kMulDivBP = 18;
55 static constexpr int kPrefixBP = 20; // tighter than any infix
56
57 //--- Token access ---
58
59 const Token& peek() const
60 {
61 return tokens_[current_];
62 }
63
64 const Token& advance()
65 {
66 const Token& tok = tokens_[current_];
67 if(!atEnd())
68 current_++;
69 return tok;
70 }
71
72 bool atEnd() const
73 {
74 return peek().type == TokenType::EndOfInput;
75 }
76
77 bool check(TokenType type) const
78 {
79 return peek().type == type;
80 }
81
82 const Token& expect(TokenType type, const char* msg)

Callers

nothing calls this directly

Calls 3

RuntimeErrorClass · 0.85
StrCatFunction · 0.85
to_stringFunction · 0.50

Tested by

no test coverage detected