Merge branch '2011-09-09-CxScript' of https://github.com/ChaiScript/ChaiScript into 2011-09-09-CxScript
This commit is contained in:
commit
425ca59a34
@ -22,7 +22,7 @@ namespace chaiscript
|
||||
Comparison, Addition, Subtraction, Multiplication, Division, Modulus, Array_Call, Dot_Access, Quoted_String, Single_Quoted_String,
|
||||
Lambda, Block, Def, While, If, For, Inline_Array, Inline_Map, Return, File, Prefix, Break, Map_Pair, Value_Range,
|
||||
Inline_Range, Annotation, Try, Catch, Finally, Method, Attr_Decl, Shift, Equality, Bitwise_And, Bitwise_Xor, Bitwise_Or,
|
||||
Logical_And, Logical_Or
|
||||
Logical_And, Logical_Or, Reference
|
||||
};
|
||||
};
|
||||
|
||||
@ -36,7 +36,7 @@ namespace chaiscript
|
||||
"Comparison", "Addition", "Subtraction", "Multiplication", "Division", "Modulus", "Array_Call", "Dot_Access", "Quoted_String", "Single_Quoted_String",
|
||||
"Lambda", "Block", "Def", "While", "If", "For", "Inline_Array", "Inline_Map", "Return", "File", "Prefix", "Break", "Map_Pair", "Value_Range",
|
||||
"Inline_Range", "Annotation", "Try", "Catch", "Finally", "Method", "Attr_Decl", "Shift", "Equality", "Bitwise_And", "Bitwise_Xor", "Bitwise_Or",
|
||||
"Logical_And", "Logical_Or"};
|
||||
"Logical_And", "Logical_Or", "Reference"};
|
||||
|
||||
return ast_node_types[ast_node_type];
|
||||
}
|
||||
|
@ -848,6 +848,18 @@ namespace chaiscript
|
||||
}
|
||||
};
|
||||
|
||||
struct Reference_Node : public AST_Node {
|
||||
public:
|
||||
Reference_Node(const std::string &t_ast_node_text = "", int t_id = AST_Node_Type::Prefix, const std::shared_ptr<std::string> &t_fname=std::shared_ptr<std::string>(), int t_start_line = 0, int t_start_col = 0, int t_end_line = 0, int t_end_col = 0) :
|
||||
AST_Node(t_ast_node_text, t_id, t_fname, t_start_line, t_start_col, t_end_line, t_end_col)
|
||||
{ }
|
||||
|
||||
virtual ~Reference_Node() {}
|
||||
virtual Boxed_Value eval_internal(chaiscript::detail::Dispatch_Engine &t_ss){
|
||||
return Boxed_Value();
|
||||
}
|
||||
};
|
||||
|
||||
struct Prefix_AST_Node : public AST_Node {
|
||||
public:
|
||||
Prefix_AST_Node(const std::string &t_ast_node_text = "", int t_id = AST_Node_Type::Prefix, const std::shared_ptr<std::string> &t_fname=std::shared_ptr<std::string>(), int t_start_line = 0, int t_start_col = 0, int t_end_line = 0, int t_end_col = 0) :
|
||||
|
@ -1545,7 +1545,7 @@ namespace chaiscript
|
||||
if (Keyword("auto")) {
|
||||
retval = true;
|
||||
|
||||
if (!Id(true)) {
|
||||
if (!(Reference() || Id(true))) {
|
||||
throw exception::eval_error("Incomplete variable declaration", File_Position(m_line, m_col), *m_filename);
|
||||
}
|
||||
|
||||
@ -1622,6 +1622,22 @@ namespace chaiscript
|
||||
return retval;
|
||||
}
|
||||
|
||||
bool Reference() {
|
||||
bool retval = false;
|
||||
|
||||
size_t prev_stack_top = m_match_stack.size();
|
||||
|
||||
if (Symbol("&", false)) {
|
||||
retval = true;
|
||||
|
||||
if (!Id(true)) {
|
||||
throw exception::eval_error("Incomplete '&' expression", File_Position(m_line, m_col), *m_filename);
|
||||
}
|
||||
|
||||
build_match(AST_NodePtr(new eval::Reference_Node()), prev_stack_top);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads a unary prefixed expression from input
|
||||
*/
|
||||
@ -1684,6 +1700,15 @@ namespace chaiscript
|
||||
|
||||
build_match(AST_NodePtr(new eval::Prefix_AST_Node()), prev_stack_top);
|
||||
}
|
||||
else if (Char('&', true)) {
|
||||
retval = true;
|
||||
|
||||
if (!Operator(m_operators.size()-1)) {
|
||||
throw exception::eval_error("Incomplete '~' expression", File_Position(m_line, m_col), *m_filename);
|
||||
}
|
||||
|
||||
build_match(AST_NodePtr(new eval::Prefix_AST_Node()), prev_stack_top);
|
||||
}
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
1
unittests/var_decl.chai
Normal file
1
unittests/var_decl.chai
Normal file
@ -0,0 +1 @@
|
||||
auto x
|
Loading…
x
Reference in New Issue
Block a user