diff --git a/chaiscript/CMakeLists.txt b/chaiscript/CMakeLists.txt index 8f27a34..ac24a34 100644 --- a/chaiscript/CMakeLists.txt +++ b/chaiscript/CMakeLists.txt @@ -7,13 +7,13 @@ SET (CMAKE_BUILD_TYPE gdb) SET (CMAKE_C_FLAGS_GDB " -Wall -ggdb") SET (CMAKE_CXX_FLAGS_GDB " -Wall -ggdb") -find_package(Boost 1.36.0 COMPONENTS regex unit_test_framework) +find_package(Boost 1.36.0 COMPONENTS) if(Boost_FOUND) include_directories(${Boost_INCLUDE_DIRS}) include_directories(../dispatchkit) - add_executable(chaiscript_test main.cpp) - target_link_libraries(chaiscript_test ${Boost_LIBRARIES}) + add_executable(chaiscript_eval main.cpp) + target_link_libraries(chaiscript_eval ${Boost_LIBRARIES}) #add_executable(chaiscript_callbacktest callbacktest.cpp) #target_link_libraries(chaiscript_callbacktest ${Boost_LIBRARIES}) diff --git a/chaiscript/chaiscript_parser.hpp b/chaiscript/chaiscript_parser.hpp index 85aff5e..5a79839 100644 --- a/chaiscript/chaiscript_parser.hpp +++ b/chaiscript/chaiscript_parser.hpp @@ -218,6 +218,7 @@ namespace chaiscript } bool Annotation() { + SkipWS(); std::string::iterator start = input_pos; int prev_col = col; int prev_line = line; @@ -232,7 +233,7 @@ namespace chaiscript ++input_pos; } } - } while (Symbol_("#")); + } while (Symbol("#")); std::string match(start, input_pos); TokenPtr t(new Token(match, Token_Type::Annotation, filename, prev_line, prev_col, line, col)); @@ -1369,7 +1370,7 @@ namespace chaiscript line = 1; col = 1; filename = fname; - if ((input.size() > 0) && (input[0] == '#')) { + if ((input.size() > 1) && (input[0] == '#') && (input[1] == '!')) { while ((input_pos != input_end) && (!Eol())) { ++input_pos; } diff --git a/chaiscript/chaiscript_prelude.hpp b/chaiscript/chaiscript_prelude.hpp index d2cfeb4..3bccda7 100644 --- a/chaiscript/chaiscript_prelude.hpp +++ b/chaiscript/chaiscript_prelude.hpp @@ -9,27 +9,38 @@ //by C++, so CODE_STRING, takes two expressions and adds in the missing comma #define CODE_STRING(x, y) #x ", " #y -#define chaiscript_prelude CODE_STRING( \n\n \ +#define chaiscript_prelude CODE_STRING(\ +# to_string for Pair()\n\ def to_string(x) : call_exists(first, x) && call_exists(second, x) { \ "<" + x.first.to_string() + ", " + x.second.to_string() + ">"; \ -} \n \n \ +}\ +# to_string for containers\n\ def to_string(x) : call_exists(range, x) && !x.is_type("string"){ \ "[" + x.join(", ") + "]"; \ -} \ +}\ +# Basic to_string function\n\ def to_string(x) { \ return internal_to_string(x); \ -} \ +}\ +# Prints to console with no carriage return\n\ def puts(x) { \ print_string(x.to_string()); \ } \ +# Prints to console with carriage return\n\ def print(x) { \ println_string(x.to_string()); \ } \ +# Returns the maximum value of two numbers\n\ def max(a, b) { if (a>b) { a } else { b } } \ +# Returns the minimum value of two numbers\n\ def min(a, b) { if (a= 2 && call_exists(range, container) { \ var r = range(container); \ var retval = r.front(); \ @@ -144,6 +165,7 @@ def reduce(container, func) : container.size() >= 2 && call_exists(range, contai } \ retval; \ } \ +# Returns a string of the elements in container delimited by the second value string\n\ def join(container, delim) { \ var retval = ""; \ var range = range(container); \ @@ -167,6 +189,7 @@ def filter(container, f, inserter) : call_exists(range, container) { \ r.pop_front(); \ } \ } \ +# Returns a new Vector which match the second value function\n\ def filter(container, f) { \ var retval = Vector(); \ filter(container, f, back_inserter(retval));\ @@ -179,11 +202,13 @@ def generate_range(x, y, inserter) { \ ++i; \ } \ } \ +# Returns a new Vector which represents the range from the first value to the second value\n\ def generate_range(x, y) { \ var retval = Vector(); \ generate_range(x,y,back_inserter(retval)); \ return retval; \ }\ +# Returns a new Vector with the first value to the second value as its elements\n\ def collate(x, y) { \ [x, y]; \ } \ @@ -196,29 +221,37 @@ def zip_with(f, x, y, inserter) : call_exists(range, x) && call_exists(range, y) r_y.pop_front(); \ } \ } \ +# Returns a new Vector which joins matching elements of the second and third value with the first value function\n\ def zip_with(f, x, y) { \ var retval = Vector(); \ zip_with(f,x,y,back_inserter(retval)); \ return retval;\ }\ +# Returns a new Vector which joins matching elements of the first and second\n\ def zip(x, y) { \ zip_with(collate, x, y); \ }\ +# Returns the position of the second value string in the first value string\n\ def find(str, substr) { \ return int(find(str, substr, size_t(0))); \ } \ +# Returns the position of last match of the second value string in the first value string\n\ def rfind(str, substr) { \ return int(rfind(str, substr, size_t(-1))); \ } \ +# Returns the position of the first match of elements in the second value string in the first value string\n\ def find_first_of(str, list) { \ return int(find_first_of(str, list, size_t(0))); \ } \ +# Returns the position of the last match of elements in the second value string in the first value string\n\ def find_last_of(str, list) { \ return int(find_last_of(str, list, size_t(-1))); \ } \ +# Returns the position of the first non-matching element in the second value string in the first value string\n\ def find_first_not_of(str, list) { \ return int(find_first_not_of(str, list, size_t(0))); \ } \ +# Returns the position of the last non-matching element in the second value string in the first value string\n\ def find_last_not_of(str, list) { \ return int(find_last_not_of(str, list, size_t(-1))); \ } \ diff --git a/dispatchkit/CMakeLists.txt b/dispatchkit/CMakeLists.txt index b2cf357..6c9b64d 100644 --- a/dispatchkit/CMakeLists.txt +++ b/dispatchkit/CMakeLists.txt @@ -7,7 +7,7 @@ SET (CMAKE_BUILD_TYPE gdb) SET (CMAKE_C_FLAGS_GDB " -Wall -ggdb") SET (CMAKE_CXX_FLAGS_GDB " -Wall -ggdb") -find_package( Boost 1.36.0 COMPONENTS regex unit_test_framework) +find_package( Boost 1.36.0 COMPONENTS unit_test_framework) if(Boost_FOUND) include_directories(${Boost_INCLUDE_DIRS}) include_directories(.) diff --git a/dispatchkit/dispatchkit.hpp b/dispatchkit/dispatchkit.hpp index 2b6fbbb..41c5b8c 100644 --- a/dispatchkit/dispatchkit.hpp +++ b/dispatchkit/dispatchkit.hpp @@ -286,7 +286,13 @@ namespace dispatchkit void dump_function(const Dispatch_Engine::Function_Map::value_type &f, const Dispatch_Engine &e) { std::vector params = f.second->get_param_types(); + std::string annotation = f.second->annotation(); + if (annotation.size() > 0) { + std::cout << "##############" << std::endl; + std::cout << annotation; + std::cout << "##############" << std::endl; + } dump_type(params.front(), e); std::cout << " " << f.first << "("; @@ -304,7 +310,7 @@ namespace dispatchkit } - std::cout << ") " << f.second->annotation() << std::endl; + std::cout << ") " << std::endl; } void dump_system(const Dispatch_Engine &s)