2014-03-09 22:05:17 -07:00
|
|
|
#ifndef COMPILER_LEX_TABLE_H_
|
|
|
|
|
#define COMPILER_LEX_TABLE_H_
|
2014-01-11 15:14:17 -08:00
|
|
|
|
2014-03-09 21:37:21 -07:00
|
|
|
#include <map>
|
2014-01-11 15:14:17 -08:00
|
|
|
#include <vector>
|
2014-02-10 18:38:01 -08:00
|
|
|
#include <set>
|
2014-03-09 21:37:21 -07:00
|
|
|
#include <string>
|
2015-10-05 18:02:59 -07:00
|
|
|
#include "compiler/precedence_range.h"
|
2014-04-28 20:43:27 -07:00
|
|
|
#include "compiler/rules/symbol.h"
|
2014-03-09 21:37:21 -07:00
|
|
|
#include "compiler/rules/character_set.h"
|
2014-01-11 15:14:17 -08:00
|
|
|
|
|
|
|
|
namespace tree_sitter {
|
2014-07-20 21:43:27 -07:00
|
|
|
|
|
|
|
|
typedef enum {
|
|
|
|
|
LexActionTypeError,
|
|
|
|
|
LexActionTypeAccept,
|
2015-12-10 21:05:54 -08:00
|
|
|
LexActionTypeAcceptFragile,
|
2014-07-20 21:43:27 -07:00
|
|
|
LexActionTypeAdvance
|
|
|
|
|
} LexActionType;
|
|
|
|
|
|
2016-01-22 22:16:47 -07:00
|
|
|
struct AdvanceAction {
|
|
|
|
|
AdvanceAction();
|
|
|
|
|
AdvanceAction(size_t, PrecedenceRange);
|
2014-07-20 21:43:27 -07:00
|
|
|
|
2016-01-22 22:16:47 -07:00
|
|
|
bool operator==(const AdvanceAction &action) const;
|
2014-07-20 21:43:27 -07:00
|
|
|
|
|
|
|
|
size_t state_index;
|
2015-10-05 18:02:59 -07:00
|
|
|
PrecedenceRange precedence_range;
|
2014-07-20 21:43:27 -07:00
|
|
|
};
|
|
|
|
|
|
2016-01-22 22:16:47 -07:00
|
|
|
struct AcceptTokenAction {
|
|
|
|
|
AcceptTokenAction();
|
|
|
|
|
AcceptTokenAction(rules::Symbol, int, bool);
|
2014-01-11 15:14:17 -08:00
|
|
|
|
2016-01-22 22:16:47 -07:00
|
|
|
bool is_present() const;
|
|
|
|
|
bool operator==(const AcceptTokenAction &action) const;
|
2014-07-20 21:43:27 -07:00
|
|
|
|
2016-01-22 22:16:47 -07:00
|
|
|
rules::Symbol symbol;
|
|
|
|
|
int precedence;
|
|
|
|
|
bool is_string;
|
|
|
|
|
bool is_fragile;
|
2014-07-20 21:43:27 -07:00
|
|
|
};
|
|
|
|
|
|
2016-01-22 22:16:47 -07:00
|
|
|
} // namespace tree_sitter
|
|
|
|
|
|
|
|
|
|
namespace std {} // namespace std
|
2014-01-11 15:14:17 -08:00
|
|
|
|
|
|
|
|
namespace tree_sitter {
|
2014-07-20 21:43:27 -07:00
|
|
|
|
|
|
|
|
class LexState {
|
|
|
|
|
public:
|
2015-02-13 22:16:27 -08:00
|
|
|
LexState();
|
2015-12-20 15:26:35 -08:00
|
|
|
std::set<rules::CharacterSet> expected_inputs() const;
|
|
|
|
|
bool operator==(const LexState &) const;
|
2016-01-22 22:16:47 -07:00
|
|
|
void each_advance_action(std::function<void(AdvanceAction *)>);
|
2015-12-20 15:26:35 -08:00
|
|
|
|
2016-01-22 22:16:47 -07:00
|
|
|
std::map<rules::CharacterSet, AdvanceAction> advance_actions;
|
|
|
|
|
AcceptTokenAction accept_action;
|
2014-09-02 07:41:29 -07:00
|
|
|
bool is_token_start;
|
2014-07-20 21:43:27 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
typedef int64_t LexStateId;
|
|
|
|
|
|
|
|
|
|
class LexTable {
|
|
|
|
|
public:
|
|
|
|
|
LexStateId add_state();
|
|
|
|
|
LexState &state(LexStateId state_id);
|
|
|
|
|
std::vector<LexState> states;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
} // namespace tree_sitter
|
2014-01-11 15:14:17 -08:00
|
|
|
|
2014-03-09 22:05:17 -07:00
|
|
|
#endif // COMPILER_LEX_TABLE_H_
|