rain 4 лет назад
Родитель
Сommit
9e280bf475
3 измененных файлов с 86 добавлено и 8 удалено
  1. 76 8
      arch/arch_templ.c
  2. 6 0
      include/tripl/tripl.h
  3. 4 0
      sample.trp

+ 76 - 8
arch/arch_templ.c

@@ -38,6 +38,7 @@ char 	*psave;
 __arch_templ static int new_var(char *p, struct arch *);
 __arch_templ static int new_var(char *p, struct arch *);
 __arch_templ static int set_name(char *p, struct arch *);
 __arch_templ static int set_name(char *p, struct arch *);
 __arch_templ static int math_set_name(char *p, struct arch *);
 __arch_templ static int math_set_name(char *p, struct arch *);
+__arch_templ static int check_condition(char *p, struct arch *);
 
 
 
 
 
 
@@ -67,9 +68,8 @@ __arch_templ int arch_do_keyword(char *p, struct arch *arch_fn) {
 		break;
 		break;
 
 
 	default:
 	default:
-		if (set_name(p, arch_fn)) 
-			if (math_set_name(p, arch_fn)) 
-				exit(generic_error("unknow keyword", psave, lno));
+		if (set_name(p, arch_fn) + math_set_name(p, arch_fn) + check_condition(p, arch_fn) == 0) 
+			exit(generic_error("unknow keyword", psave, lno));
 
 
 		break;
 		break;
 	}
 	}
@@ -144,7 +144,7 @@ static int set_name(char *p, struct arch *arch_fn) {
 	getword(p, &type, &out);
 	getword(p, &type, &out);
 
 
 	if (type != WORDTYPE_NAME) 
 	if (type != WORDTYPE_NAME) 
-		return 1;
+		return 0;
 
 
 	name = strndup(p, out);
 	name = strndup(p, out);
 
 
@@ -154,7 +154,7 @@ static int set_name(char *p, struct arch *arch_fn) {
 	getword(p, &type, &out);
 	getword(p, &type, &out);
 
 
 	if (type != WORDTYPE_KWORD || out != '=') 
 	if (type != WORDTYPE_KWORD || out != '=') 
-		return 1;
+		return 0;
 
 
 	p++;
 	p++;
 	_skip_spaces(p);
 	_skip_spaces(p);
@@ -169,7 +169,7 @@ static int set_name(char *p, struct arch *arch_fn) {
 
 
 	free(name);
 	free(name);
 
 
-	return 0;
+	return 1;
 }
 }
 
 
 
 
@@ -184,7 +184,7 @@ static int math_set_name(char *p, struct arch *arch_fn) {
 	getword(p, &type, &out);
 	getword(p, &type, &out);
 
 
 	if (type != WORDTYPE_NR) 
 	if (type != WORDTYPE_NR) 
-		return 1;
+		return 0;
 
 
 	nr = out;
 	nr = out;
 
 
@@ -215,9 +215,77 @@ static int math_set_name(char *p, struct arch *arch_fn) {
 
 
 	free(name);
 	free(name);
 
 
-	return 0;
+	return 1;
 }
 }
 
 
 
 
+/* # a - 10
+ * a : 10 {
+ * 	# = 1
+ * 	1:	xxx;
+ * 	# = 2
+ * 	2: 	yyy;
+ * 	# = 4
+ * 	4: 	zzz;
+ * } */
+
+static int check_condition(char *p, struct arch *arch_fn) {
+	struct condition cond;
+	int type, out;
+
+	getword(p, &type, &out);
+
+	if (type == WORDTYPE_NR) {
+		cond.nra = out;
+
+		_skip_word(p);
+	}
+
+	else if (type == WORDTYPE_NAME) {
+		cond.namea = strndup(p, out);
+		
+		p += out;
+	}
+
+	else 
+		return 0;
+
+	_skip_spaces(p);
+
+	getword(p, &type, &out);
+	
+	getword(p, &type, &out);
+
+	if (type != WORDTYPE_KWORD || out != ':') 
+		return 0;
+
+
+	p++;
+	_skip_spaces(p);
+
+	getword(p, &type, &out);
+
+	if (type == WORDTYPE_NR) {
+		cond.nrb = out;
+
+		_skip_word(p);
+	}
+	
+	else if (type == WORDTYPE_NAME) {
+		cond.nameb = strndup(p, out);
+
+		p += out;
+	}
+
+	else 
+		return 0;
+
+
+	printf("condition: %d %d %s %s\n", 
+			cond.nra, cond.nrb, 
+			cond.namea, cond.nameb);
+
+	return 1;
+}
 
 
 
 

+ 6 - 0
include/tripl/tripl.h

@@ -137,12 +137,18 @@ struct arg_entry {
 	struct arg_entry 	*next, *prev;
 	struct arg_entry 	*next, *prev;
 };
 };
 
 
+struct condition {
+	char 			*namea, *nameb;
+	int 			nra, nrb;
+};
+
 
 
 struct attr_table {
 struct attr_table {
 	char 			*attrname;
 	char 			*attrname;
 	int 			attrmask;
 	int 			attrmask;
 };
 };
 
 
+
 extern const struct attr_table vardef_attrtab[];
 extern const struct attr_table vardef_attrtab[];
 extern const struct attr_table import_attrtab[];
 extern const struct attr_table import_attrtab[];
 
 

+ 4 - 0
sample.trp

@@ -4,3 +4,7 @@ $ aasdf = 12341234;
 aasdf = 1234;
 aasdf = 1234;
 12345 -> aasdf;
 12345 -> aasdf;
 
 
+aasdf : 0 {
+	asdf;
+};
+