| 1 |
This file groups information on how to do some hacking on CTPL. |
| 2 |
It is not complete for now, but still useful though. |
| 3 |
|
| 4 |
|
| 5 |
# Adding a binary operator |
| 6 |
|
| 7 |
You first need to add a new constant CTPL_OPERATOR_<NAME> on the |
| 8 |
CtplOperator enum. Then, add the new operator constant and its |
| 9 |
representation in the template on the `operators_array` array in |
| 10 |
src/ctpl-lexer-expr.c. |
| 11 |
Also update the CTPL_OPERATOR_CHARS if needed: it should list all |
| 12 |
characters that may be part of an operator, then if your operator |
| 13 |
introduces new operator characters, you must add them here. |
| 14 |
Then, you're finished for the lexing part. Lets parse this brand new |
| 15 |
operator. |
| 16 |
|
| 17 |
The parsing part is not really more complicated. Go to eval.c, and: |
| 18 |
1) Write a function that evaluates your operator (look at other operator |
| 19 |
evaluation functions like ctpl_eval_operator_minus() or |
| 20 |
ctpl_eval_operator_and_or() for example); |
| 21 |
2) Update ctpl_eval_operator_internal() to handle your new operator and |
| 22 |
call your evaluation function. |
| 23 |
|
| 24 |
Last but not least, remember to add it in the documentation (on top of |
| 25 |
ctpl-lexer-expr.c). |
| 26 |
That's it, your new operator is ready! |