Add langkit namespace
This commit is contained in:
parent
ce52cae45c
commit
416242286a
@ -10,8 +10,8 @@
|
||||
|
||||
template <typename Eval_Engine>
|
||||
class ChaiScript_System {
|
||||
Lexer lexer;
|
||||
Rule parser;
|
||||
langkit::Lexer lexer;
|
||||
langkit::Rule parser;
|
||||
Eval_Engine engine;
|
||||
|
||||
public:
|
||||
@ -30,10 +30,10 @@ public:
|
||||
val = Cast_Helper<std::string &>()(vals[0]);
|
||||
}
|
||||
catch (std::exception &e) {
|
||||
throw EvalError("Can not evaluate string: " + val, TokenPtr());
|
||||
throw EvalError("Can not evaluate string: " + val, langkit::TokenPtr());
|
||||
}
|
||||
catch (EvalError &ee) {
|
||||
throw EvalError("Can not evaluate string: " + val + " reason: " + ee.reason, TokenPtr());
|
||||
throw EvalError("Can not evaluate string: " + val + " reason: " + ee.reason, langkit::TokenPtr());
|
||||
}
|
||||
return evaluate_string(val);
|
||||
}
|
||||
@ -57,7 +57,8 @@ public:
|
||||
return ret_val;
|
||||
}
|
||||
|
||||
void debug_print(TokenPtr token, std::string prepend) {
|
||||
void debug_print(langkit::TokenPtr token, std::string prepend) {
|
||||
using namespace langkit;
|
||||
std::cout << prepend << "Token: " << token->text << "(" << tokentype_to_string(token->identifier) << ") @ " << token->filename
|
||||
<< ": (" << token->start.line << ", " << token->start.column << ") to ("
|
||||
<< token->end.line << ", " << token->end.column << ") " << std::endl;
|
||||
@ -67,13 +68,15 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
void debug_print(std::vector<TokenPtr> &tokens) {
|
||||
void debug_print(std::vector<langkit::TokenPtr> &tokens) {
|
||||
using namespace langkit;
|
||||
for (unsigned int i = 0; i < tokens.size(); ++i) {
|
||||
debug_print(tokens[i], "");
|
||||
}
|
||||
}
|
||||
|
||||
Lexer build_lexer() {
|
||||
langkit::Lexer build_lexer() {
|
||||
using namespace langkit;
|
||||
Lexer lexer;
|
||||
lexer.set_skip(Pattern("[ \\t]+", TokenType::Whitespace));
|
||||
lexer.set_line_sep(Pattern("\\n|\\r\\n", TokenType::Carriage_Return));
|
||||
@ -98,7 +101,8 @@ public:
|
||||
return lexer;
|
||||
}
|
||||
|
||||
Rule build_parser_rules() {
|
||||
langkit::Rule build_parser_rules() {
|
||||
using namespace langkit;
|
||||
Rule params;
|
||||
Rule block(TokenType::Scoped_Block);
|
||||
Rule fundef(TokenType::Function_Def);
|
||||
@ -184,7 +188,8 @@ public:
|
||||
}
|
||||
|
||||
|
||||
Eval_Engine build_eval_system(Lexer &lexer, Rule &parser) {
|
||||
Eval_Engine build_eval_system(langkit::Lexer &lexer, langkit::Rule &parser) {
|
||||
using namespace langkit;
|
||||
Eval_Engine ss;
|
||||
Bootstrap::bootstrap(ss);
|
||||
bootstrap_vector<std::vector<Boxed_Value> >(ss, "Vector");
|
||||
@ -197,7 +202,8 @@ public:
|
||||
return ss;
|
||||
}
|
||||
|
||||
TokenPtr parse(Rule &rule, std::vector<TokenPtr> &tokens, const char *filename) {
|
||||
langkit::TokenPtr parse(langkit::Rule &rule, std::vector<langkit::TokenPtr> &tokens, const char *filename) {
|
||||
using namespace langkit;
|
||||
|
||||
Token_Iterator iter = tokens.begin(), end = tokens.end();
|
||||
TokenPtr parent(new Token("Root", TokenType::File, filename));
|
||||
@ -215,6 +221,7 @@ public:
|
||||
}
|
||||
|
||||
Boxed_Value evaluate_string(const std::string &input, const char *filename = "__EVAL__") {
|
||||
using namespace langkit;
|
||||
std::vector<TokenPtr> tokens = lexer.lex(input, filename);
|
||||
Boxed_Value value;
|
||||
|
||||
|
@ -8,33 +8,33 @@
|
||||
|
||||
struct ParserError {
|
||||
std::string reason;
|
||||
TokenPtr location;
|
||||
langkit::TokenPtr location;
|
||||
|
||||
ParserError(const std::string &why, const TokenPtr where) : reason(why), location(where){ }
|
||||
ParserError(const std::string &why, const langkit::TokenPtr where) : reason(why), location(where){ }
|
||||
};
|
||||
|
||||
struct EvalError {
|
||||
std::string reason;
|
||||
TokenPtr location;
|
||||
langkit::TokenPtr location;
|
||||
|
||||
EvalError(const std::string &why, const TokenPtr where) : reason(why), location(where) { }
|
||||
EvalError(const std::string &why, const langkit::TokenPtr where) : reason(why), location(where) { }
|
||||
};
|
||||
|
||||
struct ReturnValue {
|
||||
Boxed_Value retval;
|
||||
TokenPtr location;
|
||||
langkit::TokenPtr location;
|
||||
|
||||
ReturnValue(const Boxed_Value &return_value, const TokenPtr where) : retval(return_value), location(where) { }
|
||||
ReturnValue(const Boxed_Value &return_value, const langkit::TokenPtr where) : retval(return_value), location(where) { }
|
||||
};
|
||||
|
||||
struct BreakLoop {
|
||||
TokenPtr location;
|
||||
langkit::TokenPtr location;
|
||||
|
||||
BreakLoop(const TokenPtr where) : location(where) { }
|
||||
BreakLoop(const langkit::TokenPtr where) : location(where) { }
|
||||
};
|
||||
|
||||
template <typename Eval_System>
|
||||
const Boxed_Value eval_function (Eval_System &ss, TokenPtr node, const std::vector<std::string> ¶m_names, const std::vector<Boxed_Value> &vals) {
|
||||
const Boxed_Value eval_function (Eval_System &ss, langkit::TokenPtr node, const std::vector<std::string> ¶m_names, const std::vector<Boxed_Value> &vals) {
|
||||
ss.new_scope();
|
||||
|
||||
for (unsigned int i = 0; i < param_names.size(); ++i) {
|
||||
@ -47,7 +47,7 @@ const Boxed_Value eval_function (Eval_System &ss, TokenPtr node, const std::vect
|
||||
}
|
||||
|
||||
template <typename Eval_System>
|
||||
Boxed_Value eval_token(Eval_System &ss, TokenPtr node) {
|
||||
Boxed_Value eval_token(Eval_System &ss, langkit::TokenPtr node) {
|
||||
Boxed_Value retval;
|
||||
unsigned int i, j;
|
||||
|
||||
|
@ -8,6 +8,8 @@
|
||||
#include <tr1/memory>
|
||||
#include <string>
|
||||
|
||||
namespace langkit
|
||||
{
|
||||
struct File_Position {
|
||||
int line;
|
||||
int column;
|
||||
@ -200,5 +202,5 @@ struct Lexer {
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
#endif /* LANGKIT_LEXER_HPP_ */
|
||||
|
@ -8,6 +8,8 @@
|
||||
|
||||
#include "langkit_lexer.hpp"
|
||||
|
||||
namespace langkit
|
||||
{
|
||||
struct RuleImpl;
|
||||
|
||||
typedef std::vector<TokenPtr>::iterator Token_Iterator;
|
||||
@ -442,5 +444,6 @@ typedef Rule_Builder<Token_Iterator, Rule, &Wrap_Rule<Token_Iterator, Rule> > Wr
|
||||
typedef Rule_Builder<Token_Iterator, Rule, &Ignore_Rule<Token_Iterator, Rule> > Ign;
|
||||
typedef Rule_Builder<Token_Iterator, int, &Id_Rule<Token_Iterator> > Id;
|
||||
typedef Rule_Builder<Token_Iterator, const std::string&, &String_Rule<Token_Iterator> > Str;
|
||||
}
|
||||
|
||||
#endif /* LANGKIT_PARSER_HPP_ */
|
||||
|
@ -24,7 +24,7 @@ const char *tokentype_to_string(int tokentype) {
|
||||
return token_types[tokentype];
|
||||
}
|
||||
|
||||
void debug_print(TokenPtr token, std::string prepend) {
|
||||
void debug_print(langkit::TokenPtr token, std::string prepend) {
|
||||
std::cout << prepend << "Token: " << token->text << "(" << tokentype_to_string(token->identifier) << ") @ " << token->filename
|
||||
<< ": (" << token->start.line << ", " << token->start.column << ") to ("
|
||||
<< token->end.line << ", " << token->end.column << ") " << std::endl;
|
||||
@ -34,7 +34,7 @@ void debug_print(TokenPtr token, std::string prepend) {
|
||||
}
|
||||
}
|
||||
|
||||
void debug_print(std::vector<TokenPtr> &tokens) {
|
||||
void debug_print(std::vector<langkit::TokenPtr> &tokens) {
|
||||
for (unsigned int i = 0; i < tokens.size(); ++i) {
|
||||
debug_print(tokens[i], "");
|
||||
}
|
||||
@ -59,7 +59,8 @@ std::string load_file(const char *filename) {
|
||||
return ret_val;
|
||||
}
|
||||
|
||||
void parse(std::vector<TokenPtr> &tokens, const char *filename) {
|
||||
void parse(std::vector<langkit::TokenPtr> &tokens, const char *filename) {
|
||||
using namespace langkit;
|
||||
|
||||
/*
|
||||
Rule lhs;
|
||||
@ -161,6 +162,7 @@ void parse(std::vector<TokenPtr> &tokens, const char *filename) {
|
||||
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
using namespace langkit;
|
||||
std::string input;
|
||||
|
||||
Lexer lexer;
|
||||
|
Loading…
x
Reference in New Issue
Block a user