forked from ermine/sulci
-
Notifications
You must be signed in to change notification settings - Fork 0
/
plugin_calc.ml
67 lines (62 loc) · 2.03 KB
/
plugin_calc.ml
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
(*
* (c) 2004-2010 Anastasia Gornostaeva
*)
open Common
open Hooks
open Plugin_command
open Math
open Icalc
let pcalc xmpp env kind jid_from text =
if text <> "" then
let reply =
try
let lexbuf = Lexing.from_string text in
Pcalc.line Pcalc_lexer.token lexbuf
with
| MathNumberTooBig ->
Lang.get_msg env.env_lang "plugin_calc_number_too_big" []
| MathCannotFloatFact ->
Lang.get_msg env.env_lang "plugin_calc_cannot_float_fact" []
| MathNegNumber ->
Lang.get_msg env.env_lang "plugin_calc_negative_number" []
| _ ->
Lang.get_msg env.env_lang "plugin_calc_not_parsed" []
in
env.env_message xmpp kind jid_from reply
else
env.env_message xmpp kind jid_from
(Lang.get_msg env.env_lang "plugin_calc_empty_command" [])
let icalc xmpp env kind jid_from text =
if text <> "" then
let reply =
try
let lexbuf = Ulexing.from_utf8_string text in
Icalc.line (fun _ -> Icalc_ulex.token lexbuf)
(Lexing.from_string "dummy")
(*
let lexbuf = Lexing.from_string text in
Icalc.line Icalc_lexer.token lexbuf
*)
with
| MathNumberTooBig ->
Lang.get_msg env.env_lang "plugin_calc_number_too_big" []
| MathCannotFloatFact ->
Lang.get_msg env.env_lang "plugin_calc_cannot_float_fact" []
| MathNegNumber ->
Lang.get_msg env.env_lang "plugin_calc_negative_number" []
| Failure _err ->
Lang.get_msg env.env_lang "plugin_calc_divide_by_zero" []
| _exn ->
Lang.get_msg env.env_lang "plugin_calc_not_parsed" []
in
env.env_message xmpp kind jid_from reply
else
env.env_message xmpp kind jid_from
(Lang.get_msg env.env_lang "plugin_calc_empty_command" [])
let plugin opts =
add_for_token
(fun _opts xmpp ->
add_commands xmpp [("calc", icalc); ("rpn", pcalc)] opts
)
let _ =
Plugin.add_plugin "calc" plugin