html-template-pro 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.autotest +9 -0
- data/ARTISTIC +131 -0
- data/History.txt +4 -0
- data/LGPL +504 -0
- data/Manifest.txt +221 -0
- data/README.rdoc +52 -0
- data/Rakefile +18 -0
- data/benchmark.rb +136 -0
- data/config/website.yml +2 -0
- data/ext/html/template/internal/Pro.xs +679 -0
- data/ext/html/template/internal/builtin_findfile.inc +361 -0
- data/ext/html/template/internal/calc.h +26 -0
- data/ext/html/template/internal/calc.inc +120 -0
- data/ext/html/template/internal/callback_stubs.inc +63 -0
- data/ext/html/template/internal/expr.c +2267 -0
- data/ext/html/template/internal/expr.y +476 -0
- data/ext/html/template/internal/expr_iface.c +94 -0
- data/ext/html/template/internal/exprpstr.h +36 -0
- data/ext/html/template/internal/exprpstr.inc +144 -0
- data/ext/html/template/internal/exprtool.h +99 -0
- data/ext/html/template/internal/exprtool.inc +289 -0
- data/ext/html/template/internal/exprtype.h +62 -0
- data/ext/html/template/internal/exprval.h +30 -0
- data/ext/html/template/internal/extconf.rb +6 -0
- data/ext/html/template/internal/internal.c +449 -0
- data/ext/html/template/internal/loadfile.h +11 -0
- data/ext/html/template/internal/loadfile.inc +171 -0
- data/ext/html/template/internal/pabidecl.h +54 -0
- data/ext/html/template/internal/pabstract.h +426 -0
- data/ext/html/template/internal/parse_expr.h +15 -0
- data/ext/html/template/internal/pbuffer.c +76 -0
- data/ext/html/template/internal/pbuffer.h +31 -0
- data/ext/html/template/internal/pmiscdef.h +54 -0
- data/ext/html/template/internal/pparam.h +101 -0
- data/ext/html/template/internal/ppport.h +1098 -0
- data/ext/html/template/internal/procore.c +1189 -0
- data/ext/html/template/internal/procore.h +18 -0
- data/ext/html/template/internal/proparam.c +443 -0
- data/ext/html/template/internal/proparam.h +571 -0
- data/ext/html/template/internal/proscope.h +32 -0
- data/ext/html/template/internal/proscope.inc +107 -0
- data/ext/html/template/internal/prostate.h +49 -0
- data/ext/html/template/internal/prostate.inc +24 -0
- data/ext/html/template/internal/provalue.h +14 -0
- data/ext/html/template/internal/pstring.h +60 -0
- data/ext/html/template/internal/pstrutils.h +25 -0
- data/ext/html/template/internal/pstrutils.inc +150 -0
- data/ext/html/template/internal/tagstack.h +30 -0
- data/ext/html/template/internal/tagstack.inc +65 -0
- data/ext/html/template/internal/tmpllog.c +62 -0
- data/ext/html/template/internal/tmpllog.h +27 -0
- data/ext/html/template/internal/tmplpro.h +218 -0
- data/ext/html/template/internal/tmplpro_version.c +35 -0
- data/lib/html/template/pro.rb +225 -0
- data/script/console +10 -0
- data/script/destroy +14 -0
- data/script/generate +14 -0
- data/script/txt2html +71 -0
- data/tasks/extconf.rake +13 -0
- data/tasks/extconf/tmplpro.rake +43 -0
- data/templates-Pro/a.incl +1 -0
- data/templates-Pro/empty.incl +0 -0
- data/templates-Pro/include/1/a.incl +1 -0
- data/templates-Pro/include/2.out +3 -0
- data/templates-Pro/include/2.tmpl +1 -0
- data/templates-Pro/include/2/a.incl +1 -0
- data/templates-Pro/include/3.tmpl +1 -0
- data/templates-Pro/include/4.tmpl +1 -0
- data/templates-Pro/include/a.incl +1 -0
- data/templates-Pro/test_broken.tmpl +25 -0
- data/templates-Pro/test_broken1.out +1 -0
- data/templates-Pro/test_broken1.tmpl +1 -0
- data/templates-Pro/test_esc1.out +4 -0
- data/templates-Pro/test_esc1.tmpl +4 -0
- data/templates-Pro/test_esc2.out +5 -0
- data/templates-Pro/test_esc2.tmpl +6 -0
- data/templates-Pro/test_esc3.out +4 -0
- data/templates-Pro/test_esc3.tmpl +4 -0
- data/templates-Pro/test_esc4.out +3 -0
- data/templates-Pro/test_esc4.tmpl +4 -0
- data/templates-Pro/test_expr1.out +26 -0
- data/templates-Pro/test_expr1.tmpl +26 -0
- data/templates-Pro/test_expr2.out +34 -0
- data/templates-Pro/test_expr2.tmpl +34 -0
- data/templates-Pro/test_expr3.out +6 -0
- data/templates-Pro/test_expr3.tmpl +6 -0
- data/templates-Pro/test_expr4.out +4 -0
- data/templates-Pro/test_expr4.tmpl +4 -0
- data/templates-Pro/test_expr5.out +18 -0
- data/templates-Pro/test_expr5.tmpl +18 -0
- data/templates-Pro/test_expr6.out +18 -0
- data/templates-Pro/test_expr6.tmpl +18 -0
- data/templates-Pro/test_expr7.out +44 -0
- data/templates-Pro/test_expr7.tmpl +20 -0
- data/templates-Pro/test_expr8.out +15 -0
- data/templates-Pro/test_expr8.tmpl +15 -0
- data/templates-Pro/test_if1.out +25 -0
- data/templates-Pro/test_if1.tmpl +28 -0
- data/templates-Pro/test_if2.out +17 -0
- data/templates-Pro/test_if2.tmpl +25 -0
- data/templates-Pro/test_if3.out +12 -0
- data/templates-Pro/test_if3.tmpl +14 -0
- data/templates-Pro/test_if4.out +15 -0
- data/templates-Pro/test_if4.tmpl +31 -0
- data/templates-Pro/test_if5.out +16 -0
- data/templates-Pro/test_if5.tmpl +16 -0
- data/templates-Pro/test_if6.out +15 -0
- data/templates-Pro/test_if6.tmpl +31 -0
- data/templates-Pro/test_if7.out +14 -0
- data/templates-Pro/test_if7.tmpl +18 -0
- data/templates-Pro/test_include1.out +23 -0
- data/templates-Pro/test_include1.tmpl +7 -0
- data/templates-Pro/test_include2.out +120 -0
- data/templates-Pro/test_include2.tmpl +10 -0
- data/templates-Pro/test_include3.out +8 -0
- data/templates-Pro/test_include3.tmpl +8 -0
- data/templates-Pro/test_include4.out +7 -0
- data/templates-Pro/test_include4.tmpl +6 -0
- data/templates-Pro/test_include5.out +7 -0
- data/templates-Pro/test_include5.tmpl +6 -0
- data/templates-Pro/test_loop1.erb +17 -0
- data/templates-Pro/test_loop1.out +12 -0
- data/templates-Pro/test_loop1.tmpl +16 -0
- data/templates-Pro/test_loop2.erb +19 -0
- data/templates-Pro/test_loop2.out +40 -0
- data/templates-Pro/test_loop2.tmpl +19 -0
- data/templates-Pro/test_loop3.out +38 -0
- data/templates-Pro/test_loop3.tmpl +40 -0
- data/templates-Pro/test_loop4.out +44 -0
- data/templates-Pro/test_loop4.tmpl +20 -0
- data/templates-Pro/test_loop5.out +9 -0
- data/templates-Pro/test_loop5.tmpl +11 -0
- data/templates-Pro/test_loop6.out +33 -0
- data/templates-Pro/test_loop6.tmpl +15 -0
- data/templates-Pro/test_malloc.tmpl +1 -0
- data/templates-Pro/test_userfunc1.out +14 -0
- data/templates-Pro/test_userfunc1.tmpl +14 -0
- data/templates-Pro/test_userfunc2.out +35 -0
- data/templates-Pro/test_userfunc2.tmpl +5 -0
- data/templates-Pro/test_userfunc3.out +5 -0
- data/templates-Pro/test_userfunc3.tmpl +5 -0
- data/templates-Pro/test_userfunc4.out +10 -0
- data/templates-Pro/test_userfunc4.tmpl +10 -0
- data/templates-Pro/test_userfunc5.out +4 -0
- data/templates-Pro/test_userfunc5.tmpl +4 -0
- data/templates-Pro/test_userfunc6.out +4 -0
- data/templates-Pro/test_userfunc6.tmpl +4 -0
- data/templates-Pro/test_var1.erb +23 -0
- data/templates-Pro/test_var1.out +20 -0
- data/templates-Pro/test_var1.tmpl +23 -0
- data/templates-Pro/test_var2.erb +7 -0
- data/templates-Pro/test_var2.out +6 -0
- data/templates-Pro/test_var2.tmpl +7 -0
- data/templates-Pro/test_var3.out +14 -0
- data/templates-Pro/test_var3.tmpl +16 -0
- data/templates/case_loop.tmpl +3 -0
- data/templates/context.tmpl +3 -0
- data/templates/counter.tmpl +2 -0
- data/templates/default.tmpl +1 -0
- data/templates/default_escape.tmpl +4 -0
- data/templates/double_loop.tmpl +7 -0
- data/templates/escape.tmpl +5 -0
- data/templates/global-loops.tmpl +9 -0
- data/templates/globals.tmpl +11 -0
- data/templates/if.tmpl +7 -0
- data/templates/ifelse.tmpl +6 -0
- data/templates/include.tmpl +14 -0
- data/templates/include_path/a.tmpl +2 -0
- data/templates/include_path/b.tmpl +1 -0
- data/templates/include_path/inner.tmpl +1 -0
- data/templates/include_path/one.tmpl +2 -0
- data/templates/include_path2/inner.tmpl +1 -0
- data/templates/included.tmpl +4 -0
- data/templates/included2.tmpl +3 -0
- data/templates/js.tmpl +1 -0
- data/templates/long_loops.tmpl +307 -0
- data/templates/loop-context.tmpl +2 -0
- data/templates/loop-if.tmpl +9 -0
- data/templates/medium.tmpl +217 -0
- data/templates/multiline_tags.tmpl +7 -0
- data/templates/newline_test1.tmpl +1 -0
- data/templates/newline_test2.tmpl +1 -0
- data/templates/other-loop.tmpl +7 -0
- data/templates/outer.tmpl +3 -0
- data/templates/query-test.tmpl +21 -0
- data/templates/query-test2.tmpl +12 -0
- data/templates/recursive.tmpl +2 -0
- data/templates/searchpath/included.tmpl +4 -0
- data/templates/searchpath/three.tmpl +1 -0
- data/templates/searchpath/two.tmpl +2 -0
- data/templates/simple-loop-nonames.tmpl +13 -0
- data/templates/simple-loop.tmpl +12 -0
- data/templates/simple.tmpl +9 -0
- data/templates/unless.tmpl +5 -0
- data/templates/urlescape.tmpl +3 -0
- data/templates/vanguard1.tmpl +2 -0
- data/templates/vanguard2.tmpl +3 -0
- data/test/templates/complex.tmpl +24 -0
- data/test/templates/foo.tmpl +6 -0
- data/test/templates/func.tmpl +2 -0
- data/test/templates/loop.tmpl +14 -0
- data/test/templates/negative.tmpl +1 -0
- data/test/templates/numerics.tmpl +6 -0
- data/test/templates/register.tmpl +2 -0
- data/test/test_basic.rb +23 -0
- data/test/test_coderefs.rb +16 -0
- data/test/test_complex.rb +106 -0
- data/test/test_helper.rb +3 -0
- data/test/test_html_template.rb +583 -0
- data/test/test_html_template_internal_extn.rb +10 -0
- data/test/test_html_template_pro.rb +177 -0
- data/test/test_path_like_variable_scope.rb +59 -0
- data/test/test_random.rb +21 -0
- data/test/test_realloc.rb +16 -0
- data/test/test_register.rb +25 -0
- data/test/test_tmplpro.rb +9 -0
- data/test/tests.rb +9 -0
- data/website/index.txt +57 -0
- data/website/javascripts/rounded_corners_lite.inc.js +285 -0
- data/website/stylesheets/screen.css +159 -0
- data/website/template.html.erb +50 -0
- metadata +303 -0
|
@@ -0,0 +1,476 @@
|
|
|
1
|
+
%pure-parser
|
|
2
|
+
%lex-param {struct tmplpro_state* state}
|
|
3
|
+
%lex-param {struct expr_parser* exprobj}
|
|
4
|
+
%parse-param {struct tmplpro_state* state}
|
|
5
|
+
%parse-param {struct expr_parser* exprobj}
|
|
6
|
+
%parse-param {PSTRING* expr_retval_ptr}
|
|
7
|
+
%{
|
|
8
|
+
#include <math.h> /* For math functions, cos(), sin(), etc. */
|
|
9
|
+
#include <stdio.h> /* for printf */
|
|
10
|
+
#include <stdlib.h> /* for malloc */
|
|
11
|
+
#include <ctype.h> /* for yylex alnum */
|
|
12
|
+
#include "calc.h" /* Contains definition of `symrec'. */
|
|
13
|
+
#include "tmpllog.h"
|
|
14
|
+
#include "pabstract.h"
|
|
15
|
+
#include "prostate.h"
|
|
16
|
+
#include "provalue.h"
|
|
17
|
+
#include "pparam.h"
|
|
18
|
+
#include "pmiscdef.h"
|
|
19
|
+
/* for expr-specific only */
|
|
20
|
+
#include "exprtool.h"
|
|
21
|
+
#include "exprpstr.h"
|
|
22
|
+
#include "parse_expr.h"
|
|
23
|
+
/* Remember unsigned char assert on win32
|
|
24
|
+
Debug Assertion Failed! f:\dd\vctools\crt_bld\self_x86\crt\src \isctype.c Expression:(unsigned)(c + 1) <= 256
|
|
25
|
+
*/
|
|
26
|
+
%}
|
|
27
|
+
%union {
|
|
28
|
+
struct exprval numval; /* For returning numbers. */
|
|
29
|
+
const symrec_const *tptr; /* For returning symbol-table pointers. */
|
|
30
|
+
struct user_func_call extfunc; /* for user-defined function name */
|
|
31
|
+
}
|
|
32
|
+
%{
|
|
33
|
+
/* the second section is required as we use YYSTYPE here */
|
|
34
|
+
static void yyerror (struct tmplpro_state* state, struct expr_parser* exprobj, PSTRING* expr_retval_ptr, char const *);
|
|
35
|
+
static int yylex (YYSTYPE *lvalp, struct tmplpro_state* state, struct expr_parser* exprobj);
|
|
36
|
+
%}
|
|
37
|
+
%start line
|
|
38
|
+
%token <numval> NUM /* poly type. */
|
|
39
|
+
%token <extfunc> EXTFUNC /* user-defined function */
|
|
40
|
+
%token <tptr> VAR /* built-in Variable */
|
|
41
|
+
%token <tptr> BUILTIN_FNC_DD /* built-in D Function (D). */
|
|
42
|
+
%token <tptr> BUILTIN_FNC_DDD /* built-in D Function (D,D). */
|
|
43
|
+
%token <tptr> BUILTIN_FNC_EE /* built-in E Function (E). */
|
|
44
|
+
%type <numval> numEXP
|
|
45
|
+
%type <extfunc> arglist
|
|
46
|
+
|
|
47
|
+
/*%right '='*/
|
|
48
|
+
%left OR
|
|
49
|
+
%left AND
|
|
50
|
+
%nonassoc strGT strGE strLT strLE strEQ strNE strCMP
|
|
51
|
+
%nonassoc numGT numGE numLT numLE numEQ numNE '<' '>'
|
|
52
|
+
%nonassoc reLIKE reNOTLIKE
|
|
53
|
+
%left '-' '+'
|
|
54
|
+
%left '*' '/' '%'
|
|
55
|
+
%left '!' NOT NEG /* negation--unary minus */
|
|
56
|
+
%right '^' /* exponentiation */
|
|
57
|
+
%% /* The grammar follows. */
|
|
58
|
+
|
|
59
|
+
line: numEXP
|
|
60
|
+
{
|
|
61
|
+
expr_to_str1(state, &$1);
|
|
62
|
+
*expr_retval_ptr=$1.val.strval;
|
|
63
|
+
}
|
|
64
|
+
;
|
|
65
|
+
/* | error { yyerrok; } */
|
|
66
|
+
|
|
67
|
+
numEXP: NUM { $$ = $1; }
|
|
68
|
+
| VAR { $$.type=EXPR_TYPE_DBL; $$.val.dblval = $1->var; }
|
|
69
|
+
/*| VAR '=' numEXP { $$ = $3; $1->value.var = $3; } */
|
|
70
|
+
| arglist ')'
|
|
71
|
+
{
|
|
72
|
+
$$ = call_expr_userfunc(exprobj, state->param, $1);
|
|
73
|
+
}
|
|
74
|
+
| EXTFUNC '(' ')'
|
|
75
|
+
{
|
|
76
|
+
$1.arglist=state->param->InitExprArglistFuncPtr(state->param->ext_calluserfunc_state);
|
|
77
|
+
$$ = call_expr_userfunc(exprobj, state->param, $1);
|
|
78
|
+
}
|
|
79
|
+
| BUILTIN_FNC_EE '(' ')'
|
|
80
|
+
{
|
|
81
|
+
struct exprval e = NEW_EXPRVAL(EXPR_TYPE_PSTR);
|
|
82
|
+
e.val.strval.begin = NULL;
|
|
83
|
+
e.val.strval.endnext = NULL;
|
|
84
|
+
$$ = (*((func_t_ee)$1->fnctptr))(exprobj, e);
|
|
85
|
+
}
|
|
86
|
+
| BUILTIN_FNC_DD '(' numEXP ')'
|
|
87
|
+
{
|
|
88
|
+
$$.type=EXPR_TYPE_DBL;
|
|
89
|
+
expr_to_dbl1(exprobj, &$3);
|
|
90
|
+
$$.val.dblval = (*((func_t_dd)$1->fnctptr))($3.val.dblval);
|
|
91
|
+
}
|
|
92
|
+
| BUILTIN_FNC_DDD '(' numEXP ',' numEXP ')'
|
|
93
|
+
{
|
|
94
|
+
$$.type=EXPR_TYPE_DBL;
|
|
95
|
+
expr_to_dbl(exprobj, &$3, &$5);
|
|
96
|
+
$$.val.dblval = (*((func_t_ddd)$1->fnctptr))($3.val.dblval,$5.val.dblval);
|
|
97
|
+
}
|
|
98
|
+
| BUILTIN_FNC_EE '(' numEXP ')'
|
|
99
|
+
{
|
|
100
|
+
$$ = (*((func_t_ee)$1->fnctptr))(exprobj,$3);
|
|
101
|
+
}
|
|
102
|
+
| numEXP '+' numEXP { DO_MATHOP(exprobj, $$,+,$1,$3); }
|
|
103
|
+
| numEXP '-' numEXP { DO_MATHOP(exprobj, $$,-,$1,$3); }
|
|
104
|
+
| numEXP '*' numEXP { DO_MATHOP(exprobj, $$,*,$1,$3); }
|
|
105
|
+
| numEXP '%' numEXP
|
|
106
|
+
{
|
|
107
|
+
$$.type=EXPR_TYPE_INT;
|
|
108
|
+
expr_to_int(exprobj, &$1,&$3);
|
|
109
|
+
$$.val.intval = $1.val.intval % $3.val.intval;
|
|
110
|
+
}
|
|
111
|
+
/* old division; now always return double (due to compains 1/3==0)
|
|
112
|
+
| numEXP '/' numEXP
|
|
113
|
+
{
|
|
114
|
+
switch ($$.type=expr_to_int_or_dbl(&$1,&$3)) {
|
|
115
|
+
case EXPR_TYPE_INT:
|
|
116
|
+
if ($3.val.intval)
|
|
117
|
+
$$.val.intval = $1.val.intval / $3.val.intval;
|
|
118
|
+
else
|
|
119
|
+
{
|
|
120
|
+
$$.val.intval = 0;
|
|
121
|
+
log_expr(exprobj, TMPL_LOG_ERROR, "%s\n", "division by zero");
|
|
122
|
+
}
|
|
123
|
+
;break;
|
|
124
|
+
case EXPR_TYPE_DBL:
|
|
125
|
+
if ($3.val.dblval)
|
|
126
|
+
$$.val.dblval = $1.val.dblval / $3.val.dblval;
|
|
127
|
+
else
|
|
128
|
+
{
|
|
129
|
+
$$.val.dblval = 0;
|
|
130
|
+
log_expr(exprobj, TMPL_LOG_ERROR, "%s\n", "division by zero");
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
;break;
|
|
134
|
+
}
|
|
135
|
+
*/
|
|
136
|
+
| numEXP '/' numEXP
|
|
137
|
+
{
|
|
138
|
+
$$.type=EXPR_TYPE_DBL;
|
|
139
|
+
expr_to_dbl(exprobj, &$1,&$3);
|
|
140
|
+
if ($3.val.dblval)
|
|
141
|
+
$$.val.dblval = $1.val.dblval / $3.val.dblval;
|
|
142
|
+
else
|
|
143
|
+
{
|
|
144
|
+
$$.val.dblval = 0;
|
|
145
|
+
log_expr(exprobj, TMPL_LOG_ERROR, "%s\n", "division by zero");
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
| '-' numEXP %prec NEG
|
|
149
|
+
{
|
|
150
|
+
switch ($$.type=$2.type) {
|
|
151
|
+
case EXPR_TYPE_INT:
|
|
152
|
+
$$.val.intval = -$2.val.intval;
|
|
153
|
+
;break;
|
|
154
|
+
case EXPR_TYPE_DBL:
|
|
155
|
+
$$.val.dblval = -$2.val.dblval;
|
|
156
|
+
;break;
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
| numEXP '^' numEXP
|
|
160
|
+
{
|
|
161
|
+
$$.type=EXPR_TYPE_DBL;
|
|
162
|
+
expr_to_dbl(exprobj, &$1,&$3);
|
|
163
|
+
$$.val.dblval = pow ($1.val.dblval, $3.val.dblval);
|
|
164
|
+
}
|
|
165
|
+
| numEXP AND numEXP { DO_LOGOP(exprobj, $$,&&,$1,$3); }
|
|
166
|
+
| numEXP OR numEXP { DO_LOGOP(exprobj, $$,||,$1,$3); }
|
|
167
|
+
| numEXP numGE numEXP { DO_CMPOP(exprobj, $$,>=,$1,$3); }
|
|
168
|
+
| numEXP numLE numEXP { DO_CMPOP(exprobj, $$,<=,$1,$3); }
|
|
169
|
+
| numEXP numNE numEXP { DO_CMPOP(exprobj, $$,!=,$1,$3); }
|
|
170
|
+
| numEXP numEQ numEXP { DO_CMPOP(exprobj, $$,==,$1,$3); }
|
|
171
|
+
| numEXP '>' numEXP %prec numGT { DO_CMPOP(exprobj, $$,>,$1,$3); }
|
|
172
|
+
| numEXP '<' numEXP %prec numLT { DO_CMPOP(exprobj, $$,<,$1,$3); }
|
|
173
|
+
| '!' numEXP %prec NOT { DO_LOGOP1(exprobj, $$,!,$2); }
|
|
174
|
+
| NOT numEXP { DO_LOGOP1(exprobj, $$,!,$2); }
|
|
175
|
+
| '(' numEXP ')' { $$ = $2; }
|
|
176
|
+
| numEXP strCMP numEXP {
|
|
177
|
+
expr_to_str(state, &$1,&$3);
|
|
178
|
+
$$.type=EXPR_TYPE_INT; $$.val.intval = pstring_ge ($1.val.strval,$3.val.strval)-pstring_le ($1.val.strval,$3.val.strval);
|
|
179
|
+
}
|
|
180
|
+
| numEXP strGE numEXP { DO_TXTOP($$,pstring_ge,$1,$3,state);}
|
|
181
|
+
| numEXP strLE numEXP { DO_TXTOP($$,pstring_le,$1,$3,state);}
|
|
182
|
+
| numEXP strNE numEXP { DO_TXTOP($$,pstring_ne,$1,$3,state);}
|
|
183
|
+
| numEXP strEQ numEXP { DO_TXTOP($$,pstring_eq,$1,$3,state);}
|
|
184
|
+
| numEXP strGT numEXP { DO_TXTOP($$,pstring_gt,$1,$3,state);}
|
|
185
|
+
| numEXP strLT numEXP { DO_TXTOP($$,pstring_lt,$1,$3,state);}
|
|
186
|
+
| numEXP reLIKE numEXP { DO_TXTOP($$,re_like,$1,$3,state);}
|
|
187
|
+
| numEXP reNOTLIKE numEXP { DO_TXTOP($$,re_notlike,$1,$3,state);}
|
|
188
|
+
;
|
|
189
|
+
|
|
190
|
+
arglist: EXTFUNC '(' numEXP {
|
|
191
|
+
$1.arglist=state->param->InitExprArglistFuncPtr(state->param->expr_func_map);
|
|
192
|
+
pusharg_expr_userfunc(exprobj,state->param,$1,$3);
|
|
193
|
+
$$ = $1;
|
|
194
|
+
}
|
|
195
|
+
| arglist ',' numEXP { pusharg_expr_userfunc(exprobj,state->param,$1,$3); $$ = $1; }
|
|
196
|
+
;
|
|
197
|
+
|
|
198
|
+
/* End of grammar. */
|
|
199
|
+
%%
|
|
200
|
+
|
|
201
|
+
/* Called by yyparse on error. */
|
|
202
|
+
static void
|
|
203
|
+
yyerror (struct tmplpro_state* state, struct expr_parser* exprobj, PSTRING* expr_retval_ptr, char const *s)
|
|
204
|
+
{
|
|
205
|
+
log_expr(exprobj, TMPL_LOG_ERROR, "not a valid expression: %s\n", s);
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
#include "calc.inc"
|
|
209
|
+
|
|
210
|
+
static
|
|
211
|
+
const symrec_const
|
|
212
|
+
#ifndef __cplusplus
|
|
213
|
+
const
|
|
214
|
+
#endif
|
|
215
|
+
builtin_funcs_symrec[] =
|
|
216
|
+
{
|
|
217
|
+
/* built-in funcs */
|
|
218
|
+
{"sin", BUILTIN_FNC_DD, 0, sin},
|
|
219
|
+
{"cos", BUILTIN_FNC_DD, 0, cos},
|
|
220
|
+
{"atan", BUILTIN_FNC_DD, 0, atan},
|
|
221
|
+
{"log", BUILTIN_FNC_DD, 0, log},
|
|
222
|
+
{"exp", BUILTIN_FNC_DD, 0, exp},
|
|
223
|
+
{"sqrt", BUILTIN_FNC_DD, 0, sqrt},
|
|
224
|
+
{"atan2", BUILTIN_FNC_DDD, 0, atan2},
|
|
225
|
+
{"abs", BUILTIN_FNC_EE, 0, builtin_abs},
|
|
226
|
+
{"defined", BUILTIN_FNC_EE, 0, builtin_defined},
|
|
227
|
+
{"int", BUILTIN_FNC_EE, 0, builtin_int},
|
|
228
|
+
{"hex", BUILTIN_FNC_EE, 0, builtin_hex},
|
|
229
|
+
{"length", BUILTIN_FNC_EE, 0, builtin_length},
|
|
230
|
+
{"oct", BUILTIN_FNC_EE, 0, builtin_oct},
|
|
231
|
+
{"rand", BUILTIN_FNC_EE, 0, builtin_rand},
|
|
232
|
+
{"srand", BUILTIN_FNC_EE, 0, builtin_srand},
|
|
233
|
+
{"version", BUILTIN_FNC_EE, 0, builtin_version},
|
|
234
|
+
/* end mark */
|
|
235
|
+
{0, 0, 0}
|
|
236
|
+
};
|
|
237
|
+
|
|
238
|
+
static
|
|
239
|
+
const symrec_const
|
|
240
|
+
#ifndef __cplusplus
|
|
241
|
+
const
|
|
242
|
+
#endif
|
|
243
|
+
builtin_ops_symrec[] =
|
|
244
|
+
{
|
|
245
|
+
/* built-in ops */
|
|
246
|
+
{"eq", strEQ, 0, NULL},
|
|
247
|
+
{"ne", strNE, 0, NULL},
|
|
248
|
+
{"gt", strGT, 0, NULL},
|
|
249
|
+
{"ge", strGE, 0, NULL},
|
|
250
|
+
{"lt", strLT, 0, NULL},
|
|
251
|
+
{"le", strLE, 0, NULL},
|
|
252
|
+
{"cmp", strCMP, 0, NULL},
|
|
253
|
+
{"or", OR, 0, NULL},
|
|
254
|
+
{"and",AND, 0, NULL},
|
|
255
|
+
{"not",NOT, 0, NULL},
|
|
256
|
+
/* end mark */
|
|
257
|
+
{0, 0, 0}
|
|
258
|
+
};
|
|
259
|
+
|
|
260
|
+
TMPLPRO_LOCAL
|
|
261
|
+
PSTRING
|
|
262
|
+
parse_expr(PSTRING expression, struct tmplpro_state* state)
|
|
263
|
+
{
|
|
264
|
+
PSTRING expr_retval;
|
|
265
|
+
struct expr_parser exprobj;
|
|
266
|
+
expr_retval.begin=expression.begin;
|
|
267
|
+
expr_retval.endnext=expression.begin;
|
|
268
|
+
exprobj.expr_curpos=expression.begin;
|
|
269
|
+
exprobj.exprarea=expression;
|
|
270
|
+
exprobj.state = state;
|
|
271
|
+
exprobj.is_expect_quote_like=1;
|
|
272
|
+
yyparse (state, &exprobj, &expr_retval);
|
|
273
|
+
if (NULL!=expr_retval.begin && NULL==expr_retval.endnext) log_expr(&exprobj, TMPL_LOG_ERROR, "parse_expr internal warning: %s\n", "endnext is null pointer");
|
|
274
|
+
return expr_retval;
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
static
|
|
278
|
+
void
|
|
279
|
+
log_expr(struct expr_parser* exprobj, int loglevel, const char* fmt, ...)
|
|
280
|
+
{
|
|
281
|
+
va_list vl;
|
|
282
|
+
va_start(vl, fmt);
|
|
283
|
+
log_state(exprobj->state, loglevel, "in EXPR:at pos " MOD_TD " [" MOD_TD "]: ",
|
|
284
|
+
TO_PTRDIFF_T((exprobj->expr_curpos)-(exprobj->state->top)),
|
|
285
|
+
TO_PTRDIFF_T((exprobj->expr_curpos)-(exprobj->exprarea).begin));
|
|
286
|
+
tmpl_log(loglevel, fmt, vl);
|
|
287
|
+
va_end(vl);
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
static
|
|
291
|
+
PSTRING
|
|
292
|
+
fill_symbuf (struct expr_parser* exprobj, int is_accepted(unsigned char)) {
|
|
293
|
+
/* skip first char, already tested */
|
|
294
|
+
PSTRING retval = {exprobj->expr_curpos++};
|
|
295
|
+
while (exprobj->expr_curpos < (exprobj->exprarea).endnext && is_accepted(*exprobj->expr_curpos)) exprobj->expr_curpos++;
|
|
296
|
+
retval.endnext= exprobj->expr_curpos;
|
|
297
|
+
return retval;
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
static
|
|
301
|
+
int
|
|
302
|
+
is_alnum_lex (unsigned char c)
|
|
303
|
+
{
|
|
304
|
+
return (c == '_' || isalnum (c));
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
static
|
|
308
|
+
int
|
|
309
|
+
is_not_identifier_ext_end (unsigned char c)
|
|
310
|
+
{
|
|
311
|
+
return (c != '}');
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
#define TESTOP(c1,c2,z) if (c1 == c) { char d=*++(exprobj->expr_curpos); if (c2 != d) return c; else (exprobj->expr_curpos)++; return z; }
|
|
315
|
+
#define TESTOP3(c1,c2,c3,num2,str3) if (c1 == c) { char d=*++(exprobj->expr_curpos); if (c2 == d) {(exprobj->expr_curpos)++; return num2;} else if (c3 == d) {(exprobj->expr_curpos)++; exprobj->is_expect_quote_like=1; return str3;} else return c; }
|
|
316
|
+
|
|
317
|
+
static
|
|
318
|
+
int
|
|
319
|
+
yylex (YYSTYPE *lvalp, struct tmplpro_state* state, struct expr_parser* exprobj)
|
|
320
|
+
{
|
|
321
|
+
register unsigned char c = 0;
|
|
322
|
+
int is_identifier_ext;
|
|
323
|
+
/* TODO: newline? */
|
|
324
|
+
/* Ignore white space, get first nonwhite character. */
|
|
325
|
+
while ((exprobj->expr_curpos)<(exprobj->exprarea).endnext && ((c = *(exprobj->expr_curpos)) == ' ' || c == '\t')) (exprobj->expr_curpos)++;
|
|
326
|
+
if ((exprobj->expr_curpos)>=(exprobj->exprarea).endnext) return 0;
|
|
327
|
+
|
|
328
|
+
/* Char starts a quote => read a string */
|
|
329
|
+
if ('\''==c || '"'==c || (exprobj->is_expect_quote_like && '/'==c) ) {
|
|
330
|
+
PSTRING strvalue;
|
|
331
|
+
unsigned char terminal_quote=c;
|
|
332
|
+
int escape_flag = 0;
|
|
333
|
+
c =* ++(exprobj->expr_curpos);
|
|
334
|
+
strvalue.begin = exprobj->expr_curpos;
|
|
335
|
+
strvalue.endnext = exprobj->expr_curpos;
|
|
336
|
+
|
|
337
|
+
while ((exprobj->expr_curpos)<(exprobj->exprarea).endnext && c != terminal_quote) {
|
|
338
|
+
/* any escaped char with \ , incl. quote */
|
|
339
|
+
if ('\\' == c) {
|
|
340
|
+
escape_flag = 1;
|
|
341
|
+
exprobj->expr_curpos+=2;
|
|
342
|
+
c =*(exprobj->expr_curpos);
|
|
343
|
+
} else {
|
|
344
|
+
c = * ++(exprobj->expr_curpos);
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
strvalue.endnext = exprobj->expr_curpos;
|
|
349
|
+
if ((exprobj->expr_curpos)<(exprobj->exprarea).endnext && ((c = *(exprobj->expr_curpos)) == terminal_quote)) (exprobj->expr_curpos)++;
|
|
350
|
+
if (escape_flag) {
|
|
351
|
+
(*lvalp).numval.type=EXPR_TYPE_UPSTR;
|
|
352
|
+
} else {
|
|
353
|
+
(*lvalp).numval.type=EXPR_TYPE_PSTR;
|
|
354
|
+
}
|
|
355
|
+
(*lvalp).numval.val.strval=strvalue;
|
|
356
|
+
exprobj->is_expect_quote_like=0;
|
|
357
|
+
return NUM;
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
exprobj->is_expect_quote_like=0;
|
|
361
|
+
/* Char starts a number => parse the number. */
|
|
362
|
+
if (c == '.' || isdigit (c))
|
|
363
|
+
{
|
|
364
|
+
(*lvalp).numval=exp_read_number (exprobj, &(exprobj->expr_curpos), (exprobj->exprarea).endnext);
|
|
365
|
+
return NUM;
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
/*
|
|
369
|
+
* Emiliano Bruni extension to Expr:
|
|
370
|
+
* original HTML::Template allows almost arbitrary chars in parameter names,
|
|
371
|
+
* but original HTML::Template::Expr (as to 0.04) allows only
|
|
372
|
+
* var to be m![A-Za-z_][A-Za-z0-9_]*!.
|
|
373
|
+
* with this extension, arbitrary chars can be used
|
|
374
|
+
* if bracketed in ${}, as, for example, EXPR="${foo.bar} eq 'a'".
|
|
375
|
+
* first it was bracketing in {}, but it is changed
|
|
376
|
+
*
|
|
377
|
+
* COMPATIBILITY WARNING.
|
|
378
|
+
* Currently, this extension is not present in HTML::Template::Expr (as of 0.04).
|
|
379
|
+
*/
|
|
380
|
+
/* Let's try to see if this is an identifier between two { } - Emiliano */
|
|
381
|
+
is_identifier_ext = (int) (c == '{' || c == '$');
|
|
382
|
+
|
|
383
|
+
/* Char starts an identifier => read the name. */
|
|
384
|
+
/* variables with _leading_underscore are allowed too */
|
|
385
|
+
if (isalpha (c) || c=='_' || is_identifier_ext) {
|
|
386
|
+
const symrec_const *s;
|
|
387
|
+
PSTRING name;
|
|
388
|
+
if (is_identifier_ext) {
|
|
389
|
+
(exprobj->expr_curpos)++; /* jump over $ or { */
|
|
390
|
+
if ('$' == c && '{' == *(exprobj->expr_curpos)) {
|
|
391
|
+
(exprobj->expr_curpos)++; /* jump over { */
|
|
392
|
+
#ifndef ALLOW_OLD_BRACKETING_IN_EXPR
|
|
393
|
+
} else {
|
|
394
|
+
log_expr(exprobj, TMPL_LOG_ERROR, "{} bracketing is deprecated. Use ${} bracketing.\n");
|
|
395
|
+
#endif
|
|
396
|
+
}
|
|
397
|
+
name=fill_symbuf(exprobj, is_not_identifier_ext_end);
|
|
398
|
+
if ((exprobj->expr_curpos)<(exprobj->exprarea).endnext) (exprobj->expr_curpos)++; /* Jump the last } - Emiliano */
|
|
399
|
+
} else {
|
|
400
|
+
name=fill_symbuf(exprobj, is_alnum_lex);
|
|
401
|
+
}
|
|
402
|
+
s = getsym (builtin_ops_symrec, name);
|
|
403
|
+
if (s != 0) {
|
|
404
|
+
(*lvalp).tptr = s;
|
|
405
|
+
return s->type;
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
{
|
|
409
|
+
PSTRING varvalue;
|
|
410
|
+
const char* next_char= exprobj->expr_curpos;
|
|
411
|
+
/* optimization: funcs is always followed by ( */
|
|
412
|
+
while ((next_char<(exprobj->exprarea).endnext) && isspace(*next_char)) next_char++;
|
|
413
|
+
if ((*next_char)=='(') {
|
|
414
|
+
/* user-defined functions have precedence over buit-in */
|
|
415
|
+
if (((*lvalp).extfunc.func=(state->param->IsExprUserfncFuncPtr)(state->param->expr_func_map, name))) {
|
|
416
|
+
return EXTFUNC;
|
|
417
|
+
}
|
|
418
|
+
s = getsym (builtin_funcs_symrec, name);
|
|
419
|
+
if (s != 0) {
|
|
420
|
+
(*lvalp).tptr = s;
|
|
421
|
+
return s->type;
|
|
422
|
+
}
|
|
423
|
+
}
|
|
424
|
+
varvalue=_get_variable_value(state->param, name);
|
|
425
|
+
if (varvalue.begin==NULL) {
|
|
426
|
+
int loglevel = state->param->warn_unused ? TMPL_LOG_ERROR : TMPL_LOG_INFO;
|
|
427
|
+
log_expr(exprobj,loglevel, "non-initialized variable %.*s\n",(int)(varvalue.endnext-varvalue.begin),varvalue.begin);
|
|
428
|
+
}
|
|
429
|
+
(*lvalp).numval.type=EXPR_TYPE_PSTR;
|
|
430
|
+
(*lvalp).numval.val.strval=varvalue;
|
|
431
|
+
return NUM;
|
|
432
|
+
}
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
TESTOP3('=','=','~',numEQ,reLIKE)
|
|
436
|
+
TESTOP3('!','=','~',numNE,reNOTLIKE)
|
|
437
|
+
TESTOP('>','=',numGE)
|
|
438
|
+
TESTOP('<','=',numLE)
|
|
439
|
+
TESTOP('&','&',AND)
|
|
440
|
+
TESTOP('|','|',OR)
|
|
441
|
+
|
|
442
|
+
/* Any other character is a token by itself. */
|
|
443
|
+
(exprobj->expr_curpos)++;
|
|
444
|
+
return c;
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
static
|
|
448
|
+
struct exprval
|
|
449
|
+
call_expr_userfunc(struct expr_parser* exprobj, struct tmplpro_param* param, struct user_func_call USERFUNC) {
|
|
450
|
+
struct exprval emptyval = {EXPR_TYPE_PSTR};
|
|
451
|
+
emptyval.val.strval.begin=NULL;
|
|
452
|
+
emptyval.val.strval.endnext=NULL;
|
|
453
|
+
exprobj->userfunc_call = emptyval;
|
|
454
|
+
param->CallExprUserfncFuncPtr(param->ext_calluserfunc_state, USERFUNC.arglist, USERFUNC.func, &(exprobj->userfunc_call));
|
|
455
|
+
if (param->debug>6) _tmplpro_expnum_debug (exprobj->userfunc_call, "EXPR: function call: returned ");
|
|
456
|
+
param->FreeExprArglistFuncPtr(USERFUNC.arglist);
|
|
457
|
+
USERFUNC.arglist = NULL;
|
|
458
|
+
/* never happen; tmplpro_set_expr_as_* never set EXPR_TYPE_NULL *
|
|
459
|
+
* if (exprobj->userfunc_call.type == EXPR_TYPE_NULL) exprobj->userfunc_call.type = EXPR_TYPE_PSTR; */
|
|
460
|
+
return exprobj->userfunc_call;
|
|
461
|
+
}
|
|
462
|
+
|
|
463
|
+
static
|
|
464
|
+
void
|
|
465
|
+
pusharg_expr_userfunc(struct expr_parser* exprobj, struct tmplpro_param* param, struct user_func_call USERFUNC, struct exprval arg) {
|
|
466
|
+
if (arg.type == EXPR_TYPE_UPSTR) {
|
|
467
|
+
arg.val.strval=expr_unescape_pstring_val(&(exprobj->state->expr_left_pbuffer),arg.val.strval);
|
|
468
|
+
arg.type=EXPR_TYPE_PSTR;
|
|
469
|
+
}
|
|
470
|
+
exprobj->userfunc_call = arg;
|
|
471
|
+
param->PushExprArglistFuncPtr(USERFUNC.arglist,&(exprobj->userfunc_call));
|
|
472
|
+
if (param->debug>6) _tmplpro_expnum_debug (arg, "EXPR: arglist: pushed ");
|
|
473
|
+
}
|
|
474
|
+
|
|
475
|
+
#include "exprtool.inc"
|
|
476
|
+
#include "exprpstr.inc"
|