Copyright © (C) 2014, Sergey
Authors: Sergey (me@seriyps.ru).
Compiled = gettexter_plural:compile("nplurals=3; plural=...;"),
% ...store Compiled
somwhere and reuse...
3 = gettexter_plural:nplurals(Compiled),
PluralFormNum = gettexter_plural:compile(N, Compiled),
The most hard part here, is that in C true==1 and false==0.
So, runtime dependency used for type casting (see runtime_mod option).
You may use default value, which is absolutely ok, if runtime dependency
from 'gettexter' is ok for you. But if you want to embed generated code
in your own generated code, take a look at to_erlang_ast/2
and runtime_mod
option.
bin_expr() = {atom(), math_expr(), math_expr()}
if_expr() = {'if', math_expr(), math_expr(), math_expr()}
math_expr() = if_expr() | bin_expr() | un_expr() | operand()
operand() = non_neg_integer() | n
opts() = [{runtime_mod, atom()}]
module used for runtime calls 'to_boolean/1' and 'to_integer/1'
plural_rule() = {plural_rule, integer(), math_expr()}
result, returned by parser
un_expr() = {atom(), math_expr()}
compile/2 |
Compile plural expression like
nplurals=3; plural=...;
to internal representation, used for fast expression evaluation. |
nplurals/1 | Return number of plural forms for language. |
plural/2 | Calculate plural form number, using (compiled) plural form expression. |
to_boolean/1 | |
to_erlang_abstract/2 |
Converts output of gettexter_plural_parser to erl_parse abstract form. |
to_erlang_ast/2 |
Converts output of gettexter_plural_parser to erl_syntax AST. |
to_erlang_code/2 | For debugging - return human-readable generated Erlang code. |
to_integer/1 |
compile(StringExpr::string(), Opts::opts()) -> #plural_rule_compiled{nplurals = non_neg_integer(), abstract_form = erl_parse:abstract_expr()}
Compile plural expression like
nplurals=3; plural=...;
to internal representation, used for fast expression evaluation.
nplurals(Plural_rule_compiled) -> any()
Return number of plural forms for language. Value of 'nplurals' from plural rule.
plural(N, Plural_rule_compiled) -> any()
Calculate plural form number, using (compiled) plural form expression. Usage:
CompiledExpr = compile("nplurals=3; plural=...;", []),
% Compiled expr may be stored somewhere and reused
PluralFormNum = plural(N, CompiledExpr).
to_boolean(N) -> any()
to_erlang_abstract(Rule::plural_rule(), Opts::opts()) -> erl_parse:abstract_expr()
Converts output of gettexter_plural_parser
to erl_parse
abstract form.
You, most probably, shouldn't call this from your programs.
Return value may be interpreted by erl_eval:expr/2
(see plural/2
).
May be printed as erlang code snippet by erl_prettypr
(see to_erlang_code/2
).
to_erlang_ast(X1::plural_rule(), Opts::opts()) -> erl_syntax:syntaxTree()
Converts output of gettexter_plural_parser
to erl_syntax
AST.
May be used for embedding to generated code.
May be wrapped to module AST and compiled to .beam file.
Note: generated code uses one free variable: 'N', and calls runtime dependencies:
runtime_mod:to_boolean/1
and runtime_mod:to_integer/1
.
runtime_mod
is ?MODULE
by default.
to_erlang_code(Rule, Opts) -> any()
For debugging - return human-readable generated Erlang code.
to_integer(N) -> any()
Generated by EDoc