1
0
mirror of https://github.com/godotengine/godot.git synced 2025-11-10 13:00:37 +00:00

pattern matching: implemented parser

This commit is contained in:
Karroffel
2016-09-30 21:40:31 +02:00
committed by karroffel
parent 20c7b65b7e
commit f8a7c46273
4 changed files with 252 additions and 1 deletions

View File

@@ -257,6 +257,31 @@ public:
Vector<Node*> arguments;
OperatorNode() { type=TYPE_OPERATOR; }
};
struct PatternNode : public Node {
enum PatternType {
PT_CONSTANT,
PT_BIND,
PT_DICITIONARY,
PT_ARRAY,
PT_IGNORE_REST
};
PatternType pt_type;
ConstantNode *constant;
StringName bind;
Map<ConstantNode*, PatternNode*> dictionary;
Vector<PatternNode*> array;
};
struct PatternBranchNode : public Node {
PatternNode *pattern;
BlockNode *body;
};
struct ControlFlowNode : public Node {
enum CFType {
@@ -266,13 +291,15 @@ public:
CF_SWITCH,
CF_BREAK,
CF_CONTINUE,
CF_RETURN
CF_RETURN,
CF_MATCH
};
CFType cf_type;
Vector<Node*> arguments;
BlockNode *body;
BlockNode *body_else;
Vector<PatternBranchNode*> branches;
ControlFlowNode *_else; //used for if
ControlFlowNode() { type=TYPE_CONTROL_FLOW; cf_type=CF_IF; body=NULL; body_else=NULL;}
@@ -450,6 +477,13 @@ private:
Node* _reduce_expression(Node *p_node,bool p_to_const=false);
Node* _parse_and_reduce_expression(Node *p_parent,bool p_static,bool p_reduce_const=false,bool p_allow_assign=false);
// TODO
void _parse_pattern_block(Vector<PatternBranchNode*> &p_block, bool p_static);
PatternNode *_parse_pattern(bool p_static);
void _parse_block(BlockNode *p_block,bool p_static);
void _parse_extends(ClassNode *p_class);
void _parse_class(ClassNode *p_class);