File:  [ELWIX - Embedded LightWeight unIX -] / embedaddon / lighttpd / src / mod_ssi_exprparser.y
Revision 1.1.1.2 (vendor branch): download - view: text, annotated - select for diffs - revision graph
Wed Nov 2 10:35:00 2016 UTC (7 years, 8 months ago) by misho
Branches: lighttpd, MAIN
CVS tags: v1_4_41p8, HEAD
lighttpd 1.4.41

    1: %token_prefix TK_
    2: %token_type {buffer *}
    3: %extra_argument {ssi_ctx_t *ctx}
    4: %name ssiexprparser
    5: 
    6: %include {
    7: #include "first.h"
    8: #include "mod_ssi_expr.h"
    9: #include "buffer.h"
   10: 
   11: #include <assert.h>
   12: #include <string.h>
   13: }
   14: 
   15: %parse_failure {
   16:   ctx->ok = 0;
   17: }
   18: 
   19: %type expr { ssi_val_t * }
   20: %type value { buffer * }
   21: %type exprline { ssi_val_t * }
   22: %type cond { int }
   23: %token_destructor { buffer_free($$); }
   24: 
   25: %left AND.
   26: %left OR.
   27: %nonassoc EQ NE GT GE LT LE.
   28: %right NOT.
   29: 
   30: input ::= exprline(B). {
   31:   ctx->val.bo = ssi_val_tobool(B);
   32:   ctx->val.type = SSI_TYPE_BOOL;
   33: 
   34:   ssi_val_free(B);
   35: }
   36: 
   37: exprline(A) ::= expr(B) cond(C) expr(D). {
   38:   int cmp;
   39: 
   40:   if (B->type == SSI_TYPE_STRING &&
   41:       D->type == SSI_TYPE_STRING) {
   42:        cmp = strcmp(B->str->ptr, D->str->ptr);
   43:   } else {
   44:     cmp = ssi_val_tobool(B) - ssi_val_tobool(D);
   45:   }
   46: 
   47:   A = B;
   48: 
   49:   switch(C) {
   50:   case SSI_COND_EQ: A->bo = (cmp == 0) ? 1 : 0; break;
   51:   case SSI_COND_NE: A->bo = (cmp != 0) ? 1 : 0; break;
   52:   case SSI_COND_GE: A->bo = (cmp >= 0) ? 1 : 0; break;
   53:   case SSI_COND_GT: A->bo = (cmp > 0) ? 1 : 0; break;
   54:   case SSI_COND_LE: A->bo = (cmp <= 0) ? 1 : 0; break;
   55:   case SSI_COND_LT: A->bo = (cmp < 0) ? 1 : 0; break;
   56:   }
   57: 
   58:   A->type = SSI_TYPE_BOOL;
   59: 
   60:   ssi_val_free(D);
   61: }
   62: exprline(A) ::= expr(B). {
   63:   A = B;
   64: }
   65: expr(A) ::= expr(B) AND expr(C). {
   66:   int e;
   67: 
   68:   e = ssi_val_tobool(B) && ssi_val_tobool(C);
   69: 
   70:   A = B;
   71:   A->bo = e;
   72:   A->type = SSI_TYPE_BOOL;
   73:   ssi_val_free(C);
   74: }
   75: 
   76: expr(A) ::= expr(B) OR expr(C). {
   77:   int e;
   78: 
   79:   e = ssi_val_tobool(B) || ssi_val_tobool(C);
   80: 
   81:   A = B;
   82:   A->bo = e;
   83:   A->type = SSI_TYPE_BOOL;
   84:   ssi_val_free(C);
   85: }
   86: 
   87: expr(A) ::= NOT expr(B). {
   88:   int e;
   89: 
   90:   e = !ssi_val_tobool(B);
   91: 
   92:   A = B;
   93:   A->bo = e;
   94:   A->type = SSI_TYPE_BOOL;
   95: }
   96: expr(A) ::= LPARAN exprline(B) RPARAN. {
   97:   A = B;
   98: }
   99: 
  100: expr(A) ::= value(B). {
  101:   A = ssi_val_init();
  102:   A->str = B;
  103:   A->type = SSI_TYPE_STRING;
  104: }
  105: 
  106: value(A) ::= VALUE(B). {
  107:   A = B;
  108: }
  109: 
  110: value(A) ::= value(B) VALUE(C). {
  111:   A = B;
  112:   buffer_append_string_buffer(A, C);
  113:   buffer_free(C);
  114: }
  115: 
  116: cond(A) ::= EQ. { A = SSI_COND_EQ; }
  117: cond(A) ::= NE. { A = SSI_COND_NE; }
  118: cond(A) ::= LE. { A = SSI_COND_LE; }
  119: cond(A) ::= GE. { A = SSI_COND_GE; }
  120: cond(A) ::= LT. { A = SSI_COND_LT; }
  121: cond(A) ::= GT. { A = SSI_COND_GT; }

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>