Remove 'annotation' feature

This commit is contained in:
Jason Turner 2016-04-16 07:52:39 -06:00
parent 498339c202
commit 32bd936a18
11 changed files with 23 additions and 101 deletions

View File

@ -695,11 +695,10 @@
/// Begins a function or method definition
///
/// ~~~~~~~~
/// Function Definition ::= [annotation + CR/LF] "def" identifier "(" [[type] arg ("," [type] arg)*] ")" [":" guard] block
/// Method Definition ::= [annotation + CR/LF] "def" class_name "::" method_name "(" [[type] arg ("," [type] arg)*] ")" [":" guard] block
/// Function Definition ::= "def" identifier "(" [[type] arg ("," [type] arg)*] ")" [":" guard] block
/// Method Definition ::= "def" class_name "::" method_name "(" [[type] arg ("," [type] arg)*] ")" [":" guard] block
/// ~~~~~~~~
///
/// annotation: meta-annotation on function, currently used as documentation. Optional.
/// identifier: name of function. Required.
/// args: comma-delimited list of parameter names with optional type specifiers. Optional.
/// guards: guarding statement that act as a prerequisite for the function. Optional.

View File

@ -376,7 +376,6 @@ namespace chaiscript
m.add(user_type<std::exception>(), "exception");
m.add(fun(&dispatch::Proxy_Function_Base::get_arity), "get_arity");
m.add(fun(&dispatch::Proxy_Function_Base::annotation), "get_annotation");
m.add(fun(&dispatch::Proxy_Function_Base::operator==), "==");

View File

@ -310,11 +310,6 @@ namespace chaiscript
[&vals, &t_conversions](const Proxy_Function &f){ return f->call_match(vals, t_conversions); });
}
std::string annotation() const override
{
return "Multiple method dispatch function wrapper.";
}
protected:
Boxed_Value do_call(const std::vector<Boxed_Value> &params, const Type_Conversions_State &t_conversions) const override
{
@ -1046,11 +1041,7 @@ namespace chaiscript
void dump_function(const std::pair<const std::string, Proxy_Function > &f) const
{
std::vector<Type_Info> params = f.second->get_param_types();
std::string annotation = f.second->annotation();
if (annotation.size() > 0) {
std::cout << annotation;
}
dump_type(params.front());
std::cout << " " << f.first << "(";
@ -1524,3 +1515,4 @@ namespace chaiscript
#endif

View File

@ -98,12 +98,6 @@ namespace chaiscript
return {m_func};
}
std::string annotation() const override
{
return m_func->annotation();
}
protected:
virtual Boxed_Value do_call(const std::vector<Boxed_Value> &params, const Type_Conversions_State &t_conversions) const override
{
@ -219,11 +213,6 @@ namespace chaiscript
return m_func->call_match(new_vals, t_conversions);
}
std::string annotation() const override
{
return m_func->annotation();
}
protected:
Boxed_Value do_call(const std::vector<Boxed_Value> &params, const Type_Conversions_State &t_conversions) const override
{

View File

@ -204,8 +204,6 @@ namespace chaiscript
return m_arity;
}
virtual std::string annotation() const = 0;
static bool compare_type_to_param(const Type_Info &ti, const Boxed_Value &bv, const Type_Conversions_State &t_conversions)
{
if (ti.is_undef()
@ -306,11 +304,10 @@ namespace chaiscript
int t_arity=-1,
AST_NodePtr t_parsenode = AST_NodePtr(),
Param_Types t_param_types = Param_Types(),
std::string t_description = "",
Proxy_Function t_guard = Proxy_Function())
: Proxy_Function_Base(build_param_type_list(t_param_types), t_arity),
m_param_types(std::move(t_param_types)),
m_guard(std::move(t_guard)), m_parsenode(std::move(t_parsenode)), m_description(std::move(t_description))
m_guard(std::move(t_guard)), m_parsenode(std::move(t_parsenode))
{
}
@ -343,11 +340,6 @@ namespace chaiscript
return m_parsenode;
}
virtual std::string annotation() const override
{
return m_description;
}
protected:
bool test_guard(const std::vector<Boxed_Value> &params, const Type_Conversions_State &t_conversions) const
@ -387,7 +379,6 @@ namespace chaiscript
Param_Types m_param_types;
Proxy_Function m_guard;
AST_NodePtr m_parsenode;
std::string m_description;
};
@ -401,13 +392,11 @@ namespace chaiscript
int t_arity=-1,
AST_NodePtr t_parsenode = AST_NodePtr(),
Param_Types t_param_types = Param_Types(),
std::string t_description = "",
Proxy_Function t_guard = Proxy_Function())
: Dynamic_Proxy_Function(
t_arity,
std::move(t_parsenode),
std::move(t_param_types),
std::move(t_description),
std::move(t_guard)
),
m_f(std::move(t_f))
@ -506,10 +495,6 @@ namespace chaiscript
return args;
}
virtual std::string annotation() const override
{
return "Bound: " + m_f->annotation();
}
protected:
static std::vector<Type_Info> build_param_type_info(const Const_Proxy_Function &t_f,
@ -554,11 +539,6 @@ namespace chaiscript
{
}
std::string annotation() const override
{
return "";
}
bool call_match(const std::vector<Boxed_Value> &vals, const Type_Conversions_State &t_conversions) const override
{
return static_cast<int>(vals.size()) == get_arity()
@ -692,11 +672,6 @@ namespace chaiscript
return vals[0].get_type_info().bare_equal(user_type<Class>());
}
std::string annotation() const override
{
return "";
}
protected:
Boxed_Value do_call(const std::vector<Boxed_Value> &params, const Type_Conversions_State &t_conversions) const override
{

View File

@ -35,7 +35,7 @@ namespace chaiscript
enum class AST_Node_Type { Error, Id, Eol, Fun_Call, Arg_List, Variable, Equation, Var_Decl,
Comparison, Addition, Subtraction, Multiplication, Division, Modulus, Array_Call, Dot_Access,
Lambda, Block, Def, While, If, For, Inline_Array, Inline_Map, Return, File, Prefix, Break, Continue, Map_Pair, Value_Range,
Inline_Range, Annotation, Try, Catch, Finally, Method, Attr_Decl, Shift, Equality, Bitwise_And, Bitwise_Xor, Bitwise_Or,
Inline_Range, Try, Catch, Finally, Method, Attr_Decl, Shift, Equality, Bitwise_And, Bitwise_Xor, Bitwise_Or,
Logical_And, Logical_Or, Reference, Switch, Case, Default, Ternary_Cond, Noop, Class, Binary, Arg, Global_Decl, Constant
};
@ -47,7 +47,7 @@ namespace chaiscript
static const char * const ast_node_types[] = { "Internal Parser Error", "Id", "Eol", "Fun_Call", "Arg_List", "Variable", "Equation", "Var_Decl",
"Comparison", "Addition", "Subtraction", "Multiplication", "Division", "Modulus", "Array_Call", "Dot_Access",
"Lambda", "Block", "Def", "While", "If", "For", "Inline_Array", "Inline_Map", "Return", "File", "Prefix", "Break", "Continue", "Map_Pair", "Value_Range",
"Inline_Range", "Annotation", "Try", "Catch", "Finally", "Method", "Attr_Decl", "Shift", "Equality", "Bitwise_And", "Bitwise_Xor", "Bitwise_Or",
"Inline_Range", "Try", "Catch", "Finally", "Method", "Attr_Decl", "Shift", "Equality", "Bitwise_And", "Bitwise_Xor", "Bitwise_Or",
"Logical_And", "Logical_Or", "Reference", "Switch", "Case", "Default", "Ternary Condition", "Noop", "Class", "Binary", "Arg", "Constant"};
return ast_node_types[static_cast<int>(ast_node_type)];
@ -447,7 +447,6 @@ namespace chaiscript
const std::string text;
Parse_Location location;
std::vector<AST_NodePtr> children;
AST_NodePtr annotation;
const std::string &filename() const {
return *location.filename;

View File

@ -578,7 +578,6 @@ namespace chaiscript
try {
const std::string & l_function_name = this->children[0]->text;
const std::string & l_annotation = this->annotation?this->annotation->text:"";
const auto & func_node = this->children.back();
t_ss->add(
dispatch::make_dynamic_proxy_function(
@ -587,7 +586,7 @@ namespace chaiscript
return detail::eval_function(engine, func_node, t_param_names, t_params);
},
static_cast<int>(numparams), this->children.back(),
param_types, l_annotation, guard), l_function_name);
param_types, guard), l_function_name);
}
catch (const exception::reserved_word_error &e) {
throw exception::eval_error("Reserved word used as function name '" + e.word() + "'");
@ -991,11 +990,6 @@ namespace chaiscript
mutable std::atomic_uint_fast32_t m_loc;
};
struct Annotation_AST_Node final : AST_Node {
Annotation_AST_Node(std::string t_ast_node_text, Parse_Location t_loc) :
AST_Node(std::move(t_ast_node_text), AST_Node_Type::Annotation, std::move(t_loc)) { }
};
struct Try_AST_Node final : AST_Node {
Try_AST_Node(std::string t_ast_node_text, Parse_Location t_loc, std::vector<AST_NodePtr> t_children) :
AST_Node(std::move(t_ast_node_text), AST_Node_Type::Try, std::move(t_loc), std::move(t_children)) { }
@ -1162,7 +1156,6 @@ namespace chaiscript
}
try {
const std::string & l_annotation = annotation?annotation->text:"";
const std::string & function_name = children[static_cast<size_t>(1 + class_offset)]->text;
auto node = children.back();
@ -1175,7 +1168,7 @@ namespace chaiscript
[engine, t_param_names, node](const std::vector<Boxed_Value> &t_params) {
return chaiscript::eval::detail::eval_function(engine, node, t_param_names, t_params);
},
static_cast<int>(numparams), node, param_types, l_annotation, guard
static_cast<int>(numparams), node, param_types, guard
)
),
function_name);
@ -1191,7 +1184,7 @@ namespace chaiscript
[engine, t_param_names, node](const std::vector<Boxed_Value> &t_params) {
return chaiscript::eval::detail::eval_function(engine, node, t_param_names, t_params);
},
static_cast<int>(numparams), node, param_types, l_annotation, guard), type),
static_cast<int>(numparams), node, param_types, guard), type),
function_name);
}
}

View File

@ -166,6 +166,7 @@ namespace chaiscript
static constexpr const char * const m_multiline_comment_begin = "/*";
static constexpr const char * const m_multiline_comment_end = "*/";
static constexpr const char * const m_singleline_comment = "//";
static constexpr const char * const m_annotation = "#";
const std::array<std::array<bool, detail::lengthof_alphabet>, detail::max_alphabet> &m_alphabet = create_alphabet();
const std::vector<std::vector<std::string>> &m_operator_matches = create_operator_matches();
@ -398,6 +399,19 @@ namespace chaiscript
}
}
return true;
} else if (Symbol_(m_annotation)) {
while (m_position.has_more()) {
if (Symbol_("\r\n")) {
m_position -= 2;
break;
} else if (Char_('\n')) {
--m_position;
break;
} else {
++m_position;
}
}
return true;
}
return false;
}
@ -822,31 +836,6 @@ namespace chaiscript
/// Checks for a node annotation of the form "#<annotation>"
bool Annotation() {
SkipWS();
const auto start = m_position;
if (Symbol_("#")) {
do {
while (m_position.has_more()) {
if (Eol_()) {
break;
}
else {
++m_position;
}
}
} while (Symbol("#"));
auto match = Position::str(start, m_position);
m_match_stack.push_back(make_node<eval::Annotation_AST_Node>(std::move(match), start.line, start.col));
return true;
}
else {
return false;
}
}
/// Reads a quoted string from input, without skipping initial whitespace
bool Quoted_String_() {
if (m_position.has_more() && (*m_position == '\"')) {
@ -1468,13 +1457,6 @@ namespace chaiscript
/// Reads a function definition from input
bool Def(const bool t_class_context = false) {
bool retval = false;
AST_NodePtr annotation;
if (Annotation()) {
while (Eol_()) {}
annotation = m_match_stack.back();
m_match_stack.pop_back();
}
const auto prev_stack_top = m_match_stack.size();
@ -1522,9 +1504,6 @@ namespace chaiscript
build_match<eval::Def_AST_Node>(prev_stack_top);
}
if (annotation) {
m_match_stack.back()->annotation = std::move(annotation);
}
}
return retval;

View File

@ -1,7 +1,6 @@
assert_equal(`==`, `==`);
assert_not_equal(`==`, `<`);
assert_equal(`<`.get_arity(), 2);
assert_equal(`+`.get_annotation(), "Multiple method dispatch function wrapper.");
assert_equal(get_arity.get_contained_functions().size(), 0);
assert_equal(get_arity.get_arity(), 1);
assert_equal(get_arity.get_param_types().size(), 2);

View File

@ -10,7 +10,6 @@ def test_function(a)
// test_function tests
assert_equal(test_function.get_arity(), 1);
assert_equal(trim(test_function.get_annotation()), "#Test Function Description");
assert_equal(test_function.get_contained_functions().size(), 0);
assert_equal(test_function.get_param_types().size(), 2);

View File

@ -10,7 +10,6 @@ def test_function(a)
// test_function tests
assert_equal(test_function.get_arity(), 1);
assert_equal(trim(test_function.get_annotation()), "#Test Function Description");
assert_equal(test_function.get_contained_functions().size(), 0);
assert_equal(test_function.get_param_types().size(), 2);