mirror of
https://github.com/ChaiScript/ChaiScript.git
synced 2026-01-01 03:12:23 +08:00
First stab at annotation fixes. Still not perfect, but better
This commit is contained in:
parent
90aa53bdc6
commit
3d75f17d21
@ -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})
|
||||
|
||||
@ -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;
|
||||
}
|
||||
|
||||
@ -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<b) { a } else { b } } \
|
||||
# Returns true if the value is odd\n\
|
||||
def odd(x) { if (x % 2 == 1) { true } else { false } } \
|
||||
# Returns true if the value is even\n\
|
||||
def even(x) { if (x % 2 == 0) { true } else { false } } \
|
||||
# Pushes the second value onto the container first value\n\
|
||||
def push_back(container, x) { container.push_back_ref(clone(x)) } \
|
||||
# Performs the second value function over the container first value\n\
|
||||
def for_each(container, func) : call_exists(range, container) { \
|
||||
var range = range(container); \
|
||||
while (!range.empty()) { \
|
||||
@ -48,11 +59,13 @@ def map(container, func, inserter) : call_exists(range, container) { \
|
||||
range.pop_front(); \
|
||||
} \
|
||||
} \
|
||||
# Performs the second value function over the container first value. Creates a new Vector with the results\n\
|
||||
def map(container, func) { \
|
||||
var retval = Vector();\
|
||||
map(container, func, back_inserter(retval));\
|
||||
return retval;\
|
||||
}\
|
||||
# Performs the second value function over the container first value. Starts with initial and continues with each element.\n\
|
||||
def foldl(container, func, initial) : call_exists(range, container){ \
|
||||
var retval = initial; \
|
||||
var range = range(container); \
|
||||
@ -62,8 +75,11 @@ def foldl(container, func, initial) : call_exists(range, container){ \
|
||||
} \
|
||||
retval; \
|
||||
} \
|
||||
# Returns the sum of the elements of the given value\n\
|
||||
def sum(container) { foldl(container, `+`, 0.0) } \
|
||||
# Returns the product of the elements of the given value\n\
|
||||
def product(container) { foldl(container, `*`, 1.0) } \
|
||||
# Returns a new Vector with the elements of the first value concatenated with the elements of the second value\n\
|
||||
def concat(x, y) : call_exists(clone, x) { \
|
||||
var retval = x; \
|
||||
var len = y.size(); \
|
||||
@ -83,6 +99,7 @@ def take(container, num, inserter) : call_exists(range, container) { \
|
||||
--i; \
|
||||
} \
|
||||
} \
|
||||
# Returns a new Vector with the given number of elements taken from the container\n\
|
||||
def take(container, num) {\
|
||||
var retval = Vector(); \
|
||||
take(container, num, back_inserter(retval)); \
|
||||
@ -95,6 +112,7 @@ def take_while(container, f, inserter) : call_exists(range, container) { \
|
||||
r.pop_front(); \
|
||||
} \
|
||||
} \
|
||||
# Returns a new Vector with the given elements match the second value function\n\
|
||||
def take_while(container, f) {\
|
||||
var retval = Vector(); \
|
||||
take_while(container, f, back_inserter(retval)); \
|
||||
@ -112,6 +130,7 @@ def drop(container, num, inserter) : call_exists(range, container) { \
|
||||
r.pop_front(); \
|
||||
} \
|
||||
} \
|
||||
# Returns a new Vector with the given number of elements dropped from the given container \n\
|
||||
def drop(container, num) {\
|
||||
var retval = Vector(); \
|
||||
drop(container, num, back_inserter(retval)); \
|
||||
@ -127,11 +146,13 @@ def drop_while(container, f, inserter) : call_exists(range, container) { \
|
||||
r.pop_front(); \
|
||||
} \
|
||||
} \
|
||||
# Returns a new Vector with the given elements dropped that match the second value function\n\
|
||||
def drop_while(container, f) {\
|
||||
var retval = Vector(); \
|
||||
drop_while(container, f, back_inserter(retval)); \
|
||||
return retval; \
|
||||
}\
|
||||
# Applies the second value function to the container. Starts with the first two elements. Expects at least 2 elements.\n\
|
||||
def reduce(container, func) : container.size() >= 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))); \
|
||||
} \
|
||||
|
||||
@ -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(.)
|
||||
|
||||
@ -286,7 +286,13 @@ namespace dispatchkit
|
||||
void dump_function(const Dispatch_Engine::Function_Map::value_type &f, const Dispatch_Engine &e)
|
||||
{
|
||||
std::vector<Type_Info> 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)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user