File: HACKING

package info (click to toggle)
ctpl 0.3.3.dfsg-4
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 2,872 kB
  • ctags: 931
  • sloc: sh: 11,047; ansic: 5,773; python: 156; makefile: 128
file content (26 lines) | stat: -rw-r--r-- 1,117 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
This file groups information on how to do some hacking on CTPL.
It is not complete for now, but still useful though.


# Adding a binary operator

You first need to add a new constant CTPL_OPERATOR_<NAME> on the
CtplOperator enum. Then, add the new operator constant and its
representation in the template on the `operators_array` array in
src/ctpl-lexer-expr.c.
Also update the CTPL_OPERATOR_CHARS if needed: it should list all
characters that may be part of an operator, then if your operator
introduces new operator characters, you must add them here.
Then, you're finished for the lexing part. Lets parse this brand new
operator.

The parsing part is not really more complicated. Go to eval.c, and:
1) Write a function that evaluates your operator (look at other operator
   evaluation functions like ctpl_eval_operator_minus() or
   ctpl_eval_operator_and_or() for example);
2) Update ctpl_eval_operator_internal() to handle your new operator and
   call your evaluation function.

Last but not least, remember to add it in the documentation (on top of
ctpl-lexer-expr.c).
That's it, your new operator is ready!