tree-sitter/include/tree_sitter/compiler.h

77 lines
2.6 KiB
C
Raw Normal View History

2014-03-09 22:05:17 -07:00
#ifndef TREE_SITTER_COMPILER_H_
#define TREE_SITTER_COMPILER_H_
#include <vector>
#include <string>
#include <memory>
namespace tree_sitter {
namespace rules {
class Rule;
typedef std::shared_ptr<Rule> rule_ptr;
2014-03-09 19:49:35 -07:00
std::ostream& operator<<(std::ostream& stream, const rule_ptr &rule);
2014-03-09 19:49:35 -07:00
rule_ptr blank();
rule_ptr choice(const std::vector<rule_ptr> &rules);
2014-02-21 08:23:20 -08:00
rule_ptr repeat(const rule_ptr &content);
rule_ptr seq(const std::vector<rule_ptr> &rules);
rule_ptr sym(const std::string &name);
rule_ptr pattern(const std::string &value);
rule_ptr str(const std::string &value);
rule_ptr keyword(const std::string &value);
rule_ptr keypattern(const std::string &value);
2014-02-26 19:03:43 -08:00
rule_ptr err(const rule_ptr &rule);
rule_ptr prec(int precedence, rule_ptr rule);
rule_ptr token(rule_ptr rule);
}
class Grammar {
2014-06-09 21:05:25 -07:00
protected:
const std::vector<std::pair<std::string, rules::rule_ptr>> rules_;
2014-06-09 21:47:57 -07:00
std::vector<std::string> ubiquitous_tokens_;
std::vector<char> separators_;
2014-06-09 21:05:25 -07:00
public:
Grammar(const std::vector<std::pair<std::string, rules::rule_ptr>> &rules);
bool operator==(const Grammar &other) const;
std::string start_rule_name() const;
const rules::rule_ptr rule(const std::string &name) const;
2014-06-09 21:05:25 -07:00
const std::vector<std::pair<std::string, rules::rule_ptr>> & rules() const;
const std::vector<std::string> & ubiquitous_tokens() const;
Grammar & ubiquitous_tokens(const std::vector<std::string> &ubiquitous_tokens);
const std::vector<char> & separators() const;
Grammar & separators(const std::vector<char> &separators);
};
2014-03-09 19:49:35 -07:00
struct Conflict {
Conflict(std::string description);
std::string description;
bool operator==(const Conflict &other) const;
bool operator<(const Conflict &other) const;
};
2014-05-01 23:28:40 -07:00
enum GrammarErrorType {
GrammarErrorTypeRegex,
GrammarErrorTypeUndefinedSymbol
};
class GrammarError {
public:
GrammarError(GrammarErrorType type, std::string message);
bool operator==(const GrammarError &other) const;
2014-05-01 23:28:40 -07:00
GrammarErrorType type;
std::string message;
};
std::ostream& operator<<(std::ostream &stream, const Grammar &grammar);
std::ostream& operator<<(std::ostream &stream, const Conflict &conflict);
2014-05-01 23:28:40 -07:00
std::ostream& operator<<(std::ostream &stream, const GrammarError *error);
2014-05-01 23:28:40 -07:00
std::tuple<std::string, std::vector<Conflict>, const GrammarError *>
compile(const Grammar &grammar, std::string name);
}
2014-03-09 22:05:17 -07:00
#endif // TREE_SITTER_COMPILER_H_