• R/O
  • SSH
  • HTTPS

yash: Commit


Commit MetaInfo

Revision3919 (tree)
Time2018-11-25 14:25:42
Authormagicant

Log Message

Define double-bracket command syntax

Change Summary

Incremental Difference

--- yash/branches/double_bracket/exec.c (revision 3918)
+++ yash/branches/double_bracket/exec.c (revision 3919)
@@ -708,6 +708,9 @@
708708 switch (c->c_type) {
709709 case CT_SIMPLE:
710710 case CT_SUBSHELL:
711+#if YASH_ENABLE_DOUBLE_BRACKET
712+ case CT_BRACKET:
713+#endif
711714 case CT_FUNCDEF:
712715 return true;
713716 case CT_GROUP:
@@ -1189,6 +1192,11 @@
11891192 case CT_CASE:
11901193 exec_case(c, finally_exit);
11911194 break;
1195+#if YASH_ENABLE_DOUBLE_BRACKET
1196+ case CT_BRACKET:
1197+ laststatus = Exit_SUCCESS; // TODO
1198+ break;
1199+#endif /* YASH_ENABLE_DOUBLE_BRACKET */
11921200 case CT_FUNCDEF:
11931201 exec_funcdef(c, finally_exit);
11941202 break;
--- yash/branches/double_bracket/parser.c (revision 3918)
+++ yash/branches/double_bracket/parser.c (revision 3919)
@@ -49,6 +49,9 @@
4949 static void pipesfree(pipeline_T *p);
5050 static void ifcmdsfree(ifcommand_T *i);
5151 static void caseitemsfree(caseitem_T *i);
52+#if YASH_ENABLE_DOUBLE_BRACKET
53+static void dbexpfree(dbexp_T *e);
54+#endif
5255 static void wordunitfree(wordunit_T *wu)
5356 __attribute__((nonnull));
5457 static void wordfree_vp(void *w);
@@ -110,6 +113,11 @@
110113 wordfree(c->c_casword);
111114 caseitemsfree(c->c_casitems);
112115 break;
116+#if YASH_ENABLE_DOUBLE_BRACKET
117+ case CT_BRACKET:
118+ dbexpfree(c->c_dbexp);
119+ break;
120+#endif /* YASH_ENABLE_DOUBLE_BRACKET */
113121 case CT_FUNCDEF:
114122 wordfree(c->c_funcname);
115123 comsfree(c->c_funcbody);
@@ -146,6 +154,31 @@
146154 }
147155 }
148156
157+#if YASH_ENABLE_DOUBLE_BRACKET
158+void dbexpfree(dbexp_T *e)
159+{
160+ if (e == NULL)
161+ return;
162+
163+ free(e->operator);
164+ switch (e->type) {
165+ case DBE_OR:
166+ case DBE_AND:
167+ case DBE_NOT:
168+ dbexpfree(e->lhs.subexp);
169+ dbexpfree(e->rhs.subexp);
170+ break;
171+ case DBE_UNARY:
172+ case DBE_BINARY:
173+ case DBE_STRING:
174+ wordfree(e->lhs.word);
175+ wordfree(e->rhs.word);
176+ break;
177+ }
178+ free(e);
179+}
180+#endif /* YASH_ENABLE_DOUBLE_BRACKET */
181+
149182 void wordunitfree(wordunit_T *wu)
150183 {
151184 switch (wu->wu_type) {
@@ -3156,6 +3189,11 @@
31563189 case CT_CASE:
31573190 print_case(pr, c, indent);
31583191 break;
3192+#if YASH_ENABLE_DOUBLE_BRACKET
3193+ case CT_BRACKET:
3194+ printf("[[ ]]"); // TODO
3195+ break;
3196+#endif /* YASH_ENABLE_DOUBLE_BRACKET */
31593197 case CT_FUNCDEF:
31603198 print_function_definition(pr, c, indent);
31613199 assert(c->c_redirs == NULL);
--- yash/branches/double_bracket/parser.h (revision 3918)
+++ yash/branches/double_bracket/parser.h (revision 3919)
@@ -1,6 +1,6 @@
11 /* Yash: yet another shell */
22 /* parser.h: syntax parser */
3-/* (C) 2007-2015 magicant */
3+/* (C) 2007-2018 magicant */
44
55 /* This program is free software: you can redistribute it and/or modify
66 * it under the terms of the GNU General Public License as published by
@@ -62,6 +62,9 @@
6262 CT_FOR, /* for command */
6363 CT_WHILE, /* while/until command */
6464 CT_CASE, /* case command */
65+#if YASH_ENABLE_DOUBLE_BRACKET
66+ CT_BRACKET, /* double-bracket command */
67+#endif
6568 CT_FUNCDEF, /* function definition */
6669 } commandtype_T;
6770
@@ -93,6 +96,7 @@
9396 struct wordunit_T *casword; /* word compared to case patterns */
9497 struct caseitem_T *casitems; /* pairs of patterns and commands */
9598 } casecommand;
99+ struct dbexp_T *dbexp; /* double-bracket command expression */
96100 struct {
97101 struct wordunit_T *funcname; /* name of function */
98102 struct command_T *funcbody; /* body of function */
@@ -111,6 +115,7 @@
111115 #define c_whlcmds c_content.whileloop.whlcmds
112116 #define c_casword c_content.casecommand.casword
113117 #define c_casitems c_content.casecommand.casitems
118+#define c_dbexp c_content.dbexp
114119 #define c_funcname c_content.funcdef.funcname
115120 #define c_funcbody c_content.funcdef.funcbody
116121 /* `c_words' and `c_forwords' are NULL-terminated arrays of pointers to
@@ -135,6 +140,31 @@
135140 /* `ci_patterns' is a NULL-terminated array of pointers to `wordunit_T' that are
136141 * cast to `void *'. */
137142
143+/* type of dbexp_T */
144+typedef enum {
145+ DBE_OR, /* the "||" operator, two operand expressions */
146+ DBE_AND, /* the "&&" operator, two operand expressions */
147+ DBE_NOT, /* the "!" operator, one operand expression */
148+ DBE_UNARY, /* -f, -n, etc., one operand word */
149+ DBE_BINARY, /* -eq, =, etc., two operand words */
150+ DBE_STRING, /* single string primary, one operand word */
151+} dbexptype_T;
152+
153+/* operand of expression in double-bracket command */
154+typedef union dboperand_T {
155+ struct dbexp_T *subexp;
156+ struct wordunit_T *word;
157+} dboperand_T;
158+
159+/* expression in double-bracket command */
160+typedef struct dbexp_T {
161+ dbexptype_T type;
162+ wchar_t *operator;
163+ dboperand_T lhs, rhs;
164+} dbexp_T;
165+/* `operator' is NULL for non-primary expressions */
166+/* `lhs' is NULL for one-operand expressions */
167+
138168 /* embedded command */
139169 typedef struct embedcmd_T {
140170 _Bool is_preparsed;
--- yash/branches/double_bracket/variable.c (revision 3918)
+++ yash/branches/double_bracket/variable.c (revision 3919)
@@ -1295,6 +1295,9 @@
12951295 case CT_CASE:
12961296 hash_all_commands_in_case(c->c_casitems);
12971297 break;
1298+#if YASH_ENABLE_DOUBLE_BRACKET
1299+ case CT_BRACKET:
1300+#endif
12981301 case CT_FUNCDEF:
12991302 break;
13001303 }
Show on old repository browser