• R/O
  • SSH
  • HTTPS

yash: Commit


Commit MetaInfo

Revision3921 (tree)
Time2018-11-25 14:25:43
Authormagicant

Log Message

Print double-bracket command

Change Summary

Incremental Difference

--- yash/branches/double_bracket/parser.c (revision 3920)
+++ yash/branches/double_bracket/parser.c (revision 3921)
@@ -3269,6 +3269,15 @@
32693269 struct print *restrict pr, const caseitem_T *restrict caseitems,
32703270 unsigned indent)
32713271 __attribute__((nonnull(1)));
3272+#if YASH_ENABLE_DOUBLE_BRACKET
3273+static void print_double_bracket(
3274+ struct print *restrict pr, const command_T *restrict c, unsigned indent)
3275+ __attribute__((nonnull));
3276+static void print_double_bracket_expression(
3277+ struct print *restrict pr, const dbexp_T *restrict e,
3278+ dbexptype_T context, unsigned indent)
3279+ __attribute__((nonnull));
3280+#endif
32723281 static void print_function_definition(
32733282 struct print *restrict pr, const command_T *restrict command,
32743283 unsigned indent)
@@ -3416,7 +3425,7 @@
34163425 break;
34173426 #if YASH_ENABLE_DOUBLE_BRACKET
34183427 case CT_BRACKET:
3419- printf("[[ ]]"); // TODO
3428+ print_double_bracket(pr, c, indent);
34203429 break;
34213430 #endif /* YASH_ENABLE_DOUBLE_BRACKET */
34223431 case CT_FUNCDEF:
@@ -3588,6 +3597,64 @@
35883597 }
35893598 }
35903599
3600+#if YASH_ENABLE_DOUBLE_BRACKET
3601+
3602+void print_double_bracket(
3603+ struct print *restrict pr, const command_T *restrict c, unsigned indent)
3604+{
3605+ assert(c->c_type == CT_BRACKET);
3606+
3607+ wb_cat(&pr->buffer, L"[[ ");
3608+ print_double_bracket_expression(pr, c->c_dbexp, DBE_OR, indent);
3609+ wb_cat(&pr->buffer, L"]] ");
3610+}
3611+
3612+void print_double_bracket_expression(
3613+ struct print *restrict pr, const dbexp_T *restrict e,
3614+ dbexptype_T context, unsigned indent)
3615+{
3616+ assert(context == DBE_OR || context == DBE_AND || context == DBE_NOT);
3617+
3618+ switch (e->type) {
3619+ case DBE_OR:
3620+ if (context != DBE_OR)
3621+ wb_cat(&pr->buffer, L"( ");
3622+ print_double_bracket_expression(pr, e->lhs.subexp, DBE_OR, indent);
3623+ wb_cat(&pr->buffer, L"|| ");
3624+ print_double_bracket_expression(pr, e->rhs.subexp, DBE_OR, indent);
3625+ if (context != DBE_OR)
3626+ wb_cat(&pr->buffer, L") ");
3627+ break;
3628+ case DBE_AND:
3629+ if (context == DBE_NOT)
3630+ wb_cat(&pr->buffer, L"( ");
3631+ print_double_bracket_expression(pr, e->lhs.subexp, DBE_AND, indent);
3632+ wb_cat(&pr->buffer, L"&& ");
3633+ print_double_bracket_expression(pr, e->rhs.subexp, DBE_AND, indent);
3634+ if (context == DBE_NOT)
3635+ wb_cat(&pr->buffer, L") ");
3636+ break;
3637+ case DBE_NOT:
3638+ wb_cat(&pr->buffer, L"! ");
3639+ print_double_bracket_expression(pr, e->rhs.subexp, DBE_NOT, indent);
3640+ break;
3641+ case DBE_BINARY:
3642+ print_word(pr, e->lhs.word, indent);
3643+ wb_wccat(&pr->buffer, L' ');
3644+ /* falls thru! */
3645+ case DBE_UNARY:
3646+ wb_cat(&pr->buffer, e->operator);
3647+ wb_wccat(&pr->buffer, L' ');
3648+ /* falls thru! */
3649+ case DBE_STRING:
3650+ print_word(pr, e->rhs.word, indent);
3651+ wb_wccat(&pr->buffer, L' ');
3652+ break;
3653+ }
3654+}
3655+
3656+#endif
3657+
35913658 void print_function_definition(
35923659 struct print *restrict pr, const command_T *restrict c, unsigned indent)
35933660 {
Show on old repository browser