Merge branch 'ui-integration'
[Bookkeeping.git] / cc / bkeeping.cc
bloba87ba402840527504af112931e79662930a0053e
2 Package com.interrupt.bookkeeping.cc;
5 Helpers
7 all = [0 .. 127];
9 lowercase = ['a' .. 'z'];
10 uppercase = ['A' .. 'Z'];
11 digit = ['0' .. '9'];
12 hex_digit = [ digit+ [['a' .. 'f'] + ['A' .. 'F']] ];
14 tab = 9;
15 cr = 13;
16 lf = 10;
17 eol = cr lf | cr | lf; // This takes care of different platforms
18 dash = '-';
19 dot = '.';
20 forwardslash = '/';
21 backslash = '\';
22 asterix = 42;
23 equals_helper = '=';
24 colon_helper = ':';
25 ats = '@';
26 underscore = '_';
28 single_quote = ''';
29 double_quote = '"';
31 lsquare_bracket = '[';
32 rsquare_bracket = ']';
34 left_bracket = '(';
35 right_bracket = ')';
38 ws = (' ' | tab | eol);
42 States
43 bkeeping, freetext; // we need a way to ignore commands in freetext
46 Tokens
49 //** VARIABLE
50 {bkeeping} var = 'var';
53 //** COMMANDS
54 {bkeeping} create = 'create';
55 {bkeeping} add = 'add';
56 {bkeeping} update = 'update';
57 {bkeeping} remove = 'remove';
58 {bkeeping} reverse = 'reverse';
59 {bkeeping} find = 'find';
60 {bkeeping} list = 'list';
62 {bkeeping} print = 'print';
63 {bkeeping} commit = 'commit';
65 {bkeeping} load = 'load';
66 {bkeeping} login = 'login';
67 {bkeeping} logout = 'logout';
68 {bkeeping} exit = 'exit';
70 {bkeeping} semicolon = ( 59 )?;
72 whitespace = (' ' | tab | eol);
73 comment_line = forwardslash forwardslash all* eol;
74 comment_block = forwardslash asterix all* asterix forwardslash;
77 //** COMMAND OPTIONS
78 entry_opt = '-entry' ws+ ( lowercase | uppercase | dash | colon_helper | ats | underscore | digit | dot )*;
79 entryid_opt = '-entryid' ws+ ( lowercase | uppercase | dash | colon_helper | ats | underscore | digit | dot )*;
80 account_opt = '-account' ws+ ( lowercase | uppercase | dash | colon_helper | ats | underscore | digit | dot )*;
81 accountid_opt = '-accountid' ws+ ( lowercase | uppercase | dash | colon_helper | ats | underscore | digit | dot )*;
82 journal_opt = '-journal' ws+ ( lowercase | uppercase | dash | colon_helper | ats | underscore | digit | dot )*;
83 name_opt = '-name' ws+ ( lowercase | uppercase | dash | colon_helper | ats | underscore | digit | dot )*;
84 type_opt = '-type' ws+ ( lowercase | uppercase | dash | colon_helper | ats | underscore | digit | dot )*;
85 counterweight_opt = '-counterWeight' ws+ lowercase+;
86 amount_opt = '-amount' ws+ digit+'.'digit+;
87 id_opt = '-id' ws+ ( lowercase | uppercase | dash | colon_helper | ats | underscore | digit | dot )*;
88 entrynum_opt = '-entrynum' ws+ digit*;
89 date_opt = '-date' ws+ digit+'/'digit+'/'digit+;
90 file_opt = '-F' ws+ ( lowercase | uppercase | dash | colon_helper | ats | underscore | digit | dot )*;
92 group_opt = '-group' ws+ ( lowercase | uppercase | dash | colon_helper | ats | underscore | digit | dot )*;
93 uname_opt = '-username' ws+ ( lowercase | uppercase | dash | colon_helper | ats | underscore | digit | dot )*;
94 passwd_opt = '-password' ws+ ( lowercase | uppercase | dash | colon_helper | ats | underscore | digit | dot )*;
95 groupid_opt = '-groupid' ws+ ( lowercase | uppercase | dash | colon_helper | ats | underscore | digit | dot )*;
96 userid_opt = '-userid' ws+ ( lowercase | uppercase | dash | colon_helper | ats | underscore | digit | dot )*;
97 currency_opt = '-currency' ws+ ( lowercase | uppercase | dash | colon_helper | ats | underscore | digit | dot )*;
101 //** COMMAND TOKENS
102 system_tok = 'system';
103 debit_tok = 'debit';
104 credit_tok = 'credit';
105 entry_tok = 'entry';
106 entries_tok = 'entries';
107 journal_tok = 'journal';
108 journals_tok = 'journals';
109 transaction_tok = 'transaction';
110 account_tok = 'account';
111 accounts_tok = 'accounts';
113 user_tok = 'user';
114 users_tok = 'users';
115 group_tok = 'group';
116 groups_tok = 'groups';
118 allowedactions_tok = 'allowedActions';
119 command_tok = 'command';
120 profiledetails_tok = 'profileDetails';
121 profiledetail_tok = 'profileDetail';
122 usersession_tok = 'userSession';
125 lparen = '<';
126 rparen = '>';
129 listdelimiter = ',';
130 exclamation = 33;
131 question = 63;
132 doubledash = dash dash;
135 lbracket = left_bracket;
136 rbracket = right_bracket;
137 //lsbracket = lsquare_bracket;
138 //rsbracket = rsquare_bracket;
140 equals = equals_helper;
141 fslash = forwardslash;
142 atsign = ats;
143 colon = colon_helper;
145 {bkeeping -> freetext, freetext -> bkeeping} quote = ( double_quote | single_quote );
146 {bkeeping -> freetext, freetext -> bkeeping} backquote = '`';
148 word = ( lowercase | uppercase | dash | underscore | digit | dot )+;
150 //xpath_chars = ( ats | forwardslash | colon_helper | left_bracket | right_bracket | lsquare_bracket | rsquare_bracket | equals_helper | double_quote | single_quote );
151 xpath_chars = ( colon_helper | left_bracket | right_bracket | lsquare_bracket | rsquare_bracket );
154 xmlns = 'xmlns';
155 decl_xml = 'xml';
156 decl_dtd = 'DOCTYPE';
157 eoll = (cr | lf | cr lf)?;
160 Ignored Tokens
162 whitespace,
163 comment_line,
164 comment_block;
167 Productions
170 expr = {cmd} command semicolon |
171 {thexpr} twohandexpr semicolon;
173 /***************************
174 * VARIABLES
176 * @memory
177 * @previous
180 twohandexpr = var word equals command; // assigning results to variables
181 varname = atsign word?; // put an '@' sign in front of variable name to reference it
184 /***************************
185 * COMMANDS
187 * add ((token.literal) token.literal, ...)
188 * update ((token.literal) token.literal, ...)
189 * remove ((token.literal) token.literal, ...)
191 * reverse ((token.literal) (token.literal) token.literal)
194 * find ((token.literal) token -opts)
195 * list ((token.literal) token -opts)
197 * create (token -opts)
199 * load (token -opts) <-- DB
200 * commit (token.literal) <-- DB
202 * print (token.literal)
204 * login (token -opts) <-- DB
205 * logout <-- DB
206 * exit
209 command = {c1} command1 |
210 {c5} command5 |
211 {c2} command2 |
212 {c3} command3 |
213 {c4} command4 |
214 {c6} command6 |
215 {c7} command7;
218 command1 = {add} add [lbdepth1]:lbracket [lbdepth2]:lbracket command_input [rbdepth2]:rbracket ilist* [rbdepth1]:rbracket |
219 {update} update [lbdepth1]:lbracket [lbdepth2]:lbracket [c1]:command_input [rbdepth2]:rbracket [c2]:command_input [rbdepth1]:rbracket |
220 {remove} remove [lbdepth1]:lbracket [lbdepth2]:lbracket command_input [rbdepth2]:rbracket ilist* [rbdepth1]:rbracket;
222 command5 = {reverse} reverse [lbdepth1]:lbracket [lbdepth2]:lbracket [ci1]:command_input [rbdepth2]:rbracket [lbdepth3]:lbracket [ci2]:command_input [rbdepth3]:rbracket [ci3]:command_input [rbdepth1]:rbracket;
224 //** input list & delimiter
225 ilist = command_input ilistpart*;
226 ilistpart = listdelimiter command_input;
229 command2 = {find} find [lbdepth1]:lbracket [lbdepth2]:lbracket [c1]:command_input [rbdepth2]:rbracket [c2]:command_input [rbdepth1]:rbracket|
230 {list} list [lbdepth1]:lbracket [lbdepth2]:lbracket [c1]:command_input [rbdepth2]:rbracket [c2]:command_input [rbdepth1]:rbracket;
232 command3 = {load} load lbracket command_input rbracket |
233 {create} create lbracket command_input rbracket |
234 {login} login lbracket command_input rbracket;
236 command4 = {logout} logout|
237 {exit} exit;
239 command6 = {print} print lbracket command_input rbracket;
241 command7 = {commit} commit [lbdepth1]:lbracket [lbdepth2]:lbracket [input1]:command_input [rbdepth2]:rbracket [input2]:command_input [rbdepth1]:rbracket;
245 /**************************
246 * COMMAND INPUT
248 command_input = {var} varname |
249 {xml} xmlblock |
250 {opts} input_option |
251 {cmd} command |
252 {xpath} xpath;
255 // token -opts
256 input_option = commandtoken commandoption*;
259 xpath = [left]:backquote xpath_part* [right]:backquote;
260 xpath_part = {wd} wordetal |
261 {xpc} xpath_chars |
262 {fslash} fslash |
263 {quote} quote |
264 {ats} atsign |
265 {equals} equals;
269 /***************************
270 * COMMAND OPTIONS
272 commandoption = {entry} entry_opt |
273 {entryid} entryid_opt |
274 {account} account_opt |
275 {accountid} accountid_opt |
276 {journal} journal_opt |
277 {name} name_opt |
278 {type} type_opt |
279 {cweight} counterweight_opt |
280 {amount} amount_opt |
281 {id} id_opt |
282 {entrynum} entrynum_opt |
283 {date} date_opt |
284 {file} file_opt |
285 {group} group_opt |
286 {uname} uname_opt |
287 {passwd} passwd_opt |
288 {groupid} groupid_opt |
289 {userid} userid_opt |
290 {currency} currency_opt;
294 /***************************
295 * XML BLOCKS
297 xmlblock = xml_decl? fulltag;
299 fulltag = {fulltag} opentag fulltag* wordetal* closetag |
300 {emptytag} emptytag |
301 {comment} xmlcomment;
303 opentag = lparen nsprefix? wordetal attribute* rparen;
304 emptytag = lparen nsprefix? wordetal attribute* fslash rparen;
305 closetag = lparen fslash nsprefix? wordetal rparen;
309 xml_decl = {xml_schem} xml_decl_schem |
310 {xml_dtd} xml_decl_dtd;
312 // <?xml version="1.0" encoding="iso8859-1" ?>
313 xml_decl_schem = lparen [left]:question wordetal attribute+ [right]:question rparen;
315 // <!DOCTYPE greeting SYSTEM "hello.dtd" >
316 xml_decl_dtd = lparen exclamation word_dtd+ rparen;
317 word_dtd = {attrhs} attributerhs |
318 {word} word;
321 attribute = nsprefix? attributelhs equals attributerhs;
322 attributelhs = wordetal;
323 attributerhs = [left]:quote zzz* [right]:quote;
325 nsprefix = wordetal colon;
327 xmlcomment = xml_opencomment wordetal* xml_closecomment;
329 xml_opencomment = lparen exclamation doubledash;
330 xml_closecomment = doubledash rparen;
333 zzz = {one} wordetal |
334 {two} fslash;
336 wordetal = {word} word |
337 {ctoken} commandtoken;
341 /***************************
342 * COMMAND TOKENS
344 commandtoken = {system} system_tok |
345 {debit} debit_tok |
346 {credit} credit_tok |
347 {entry} entry_tok |
348 {entries} entries_tok |
349 {journal} journal_tok |
350 {journals} journals_tok |
351 {transaction} transaction_tok |
352 {accounts} accounts_tok |
353 {account} account_tok |
354 {user} user_tok |
355 {users} users_tok |
356 {group} group_tok |
357 {groups} groups_tok |
358 {allowedactions} allowedactions_tok |
359 {command} command_tok |
360 {profiledetails} profiledetails_tok |
361 {profiledetail} profiledetail_tok |
362 {usersession} usersession_tok;
366 // >>>>>>>>>> TODO
368 // 7. include CDATA blocks
369 // <a> <![CDATA[ do something ]]> </a>
373 /**
375 * TEST XMLs
377 // <xml>
378 // <xml/>
379 // <xml> ccc </xml>
380 // <xml> lorem ipsum some text </xml>
381 // <xml attr1="" attr2="wert" />
382 // <xml attr1="" attr2="wert" > </xml>
384 // <xml:xml />
385 // <xml:xml></xml:xml>
387 // <xml:xml attr1="" attr2="wert" />
388 // <xml:xml attr1="" attr2="wert" ></xml:xml>
390 // <xml:xml attr1="" attr2="wert" > <a> <b/> </a> lorem ipsum some text </xml:xml>
391 // <xml:xml attr1="" attr2="wert" > <a> <!-- this is comments --> <b/> </a> lorem ipsum some text </xml:xml>
392 // <xml:xml pre:attr1="" pref:attr2="wert" > <a> <!-- this is comments --> <b/> </a> lorem ipsum some text </xml:xml>
394 // <?xml version="1.0" encoding="iso8859-1" ?> <xml:xml attr1="" attr2="wert" > <a> <!-- this is comments --> <b/> </a> lorem ipsum some text </xml:xml>
395 // <!DOCTYPE greeting SYSTEM "hello.dtd" > <xml:xml attr1="" attr2="wert" > <a> <!-- this is comments --> <b/> </a> lorem ipsum some text </xml:xml>
397 // <debit xmlns='com/interrupt/bookkeeping/account' id='def' amount='1.50' entryid='e1' accountid='2' />
398 // <?xml version="1.0" encoding="iso8859-1" ?><credit xmlns='com/interrupt/bookkeeping/account' id='def' amount='1.50' entryid='e1' accountid='2' />
400 // <account xmlns='com/interrupt/bookkeeping/account' id='1' name='office equipment' type='asset' counterWeight='debit' ><debit xmlns='com/interrupt/bookkeeping/account' id='' amount='10.00' entryid='' accountid='1' /></account>
403 /**
405 * SCRATCH XML
407 // <lebit xmlns='com/interrupt/bookkeeping/account' id='def' amount='1.50' entryid='e1' accountid='2' />
408 // <lebit xmlns='comaccount' id='def' amount='1.50' entryid='e1' accountid='2' />
409 // <debit xmlns='comaccount' id='def' amount='1.50' entryid='e1' accountid='2' />
410 // <xml:xml attr1="com/interrupt/bookkeeping/account" attr2="wert" > <a> <b/> </a> lorem ipsum some text </xml:xml>
411 // <xml attr1="com/interrupt/bookkeeping/account" attr2="wert" > <a> <b/> </a> lorem ipsum some text </xml>
412 // <xml attr1="com/interrupt/bookkeeping/account" attr2="wert" > <a> <b/> </a> </xml>
414 // <xml attr1="comaccount" attr2="wert" > <a> <b/> </a> </xml>
415 // <xml attr1="comaccount" attr2="wert" > <a> <b/> </a> lorem ipsum </xml>
416 // <xml attr1="com/interrupt/bookkeeping/account" attr2="wert" > <a> <b/> </a> lorem ipsum </xml>
418 // <debit attr1="com/interrupt/bookkeeping/account" attr2="wert" > <a> <b/> </a> </debit>
419 // <debit attr1="com/interrupt/bookkeeping/account" attr2="wert" > </debit>
423 /**
425 * TEST OPTIONS
427 // -entry journal
428 // -type type -name some
429 // -type type -name some -id qerfb1435c -date 06/24/2003
431 //[X] -account "account name"
432 //[X] -journal journal name -entry journal
434 // -counterWeight debit
435 // -amount 123.33
436 // -id qerfb1435c
437 // -entrynum 765
438 // -date 06/24/2003
439 // -F filename
442 // login ( user -username root -password password );
443 // load ( users -id aauth.users );
446 //** create ( debit -id erfg -amount 123.33 );
447 // create ( <debit xmlns='com/interrupt/bookkeeping/account' id='def' amount='1.50' /> );
450 // load ( users -id aauth.users );
451 // load ( debit -amount 10.00 );
452 // load ( debit -id abc -amount 10.00 );
453 // load ( <debit xmlns='com/interrupt/bookkeeping/account' id='def' amount='1.50' /> );
456 //** add ((create ( entry -id ez ) ) create ( debit -id dbzz -amount 10.00 ) );
457 // add ((create ( entry -id ez ) ) load ( debit -id abc -amount 10.00 ) );
459 // add ((create ( entry -id ez -currency CDN ) ) create ( <debit xmlns='com/interrupt/bookkeeping/account' id='def' amount='1.50' currency='CDN' /> ) );
462 // remove ( (load ( entry -id e1 )) );
463 // remove ( (load ( entry -id e1 )) load ( debit -id abc -amount 10.00 ) );
466 /* reverse ( (
467 <entries xmlns='com/interrupt/bookkeeping/journal' id='' >
468 <entry xmlns='com/interrupt/bookkeeping/journal' id='e1' entrynum='' state='closed' journalid='' date='' >
469 <debit xmlns='com/interrupt/bookkeeping/account' id='abc' amount='10.00' entryid='e1' accountid='1' />
470 <debit xmlns='com/interrupt/bookkeeping/account' id='def' amount='1.50' entryid='e1' accountid='2' />
471 <credit xmlns='com/interrupt/bookkeeping/account' id='ghi' amount='11.50' entryid='e1' accountid='3' />
472 </entry>
473 </entries>
476 <entry xmlns='com/interrupt/bookkeeping/journal' id='e1' entrynum='' state='closed' journalid='' date='' >
477 <debit xmlns='com/interrupt/bookkeeping/account' id='abc' amount='10.00' entryid='e1' accountid='1' />
478 <debit xmlns='com/interrupt/bookkeeping/account' id='def' amount='1.50' entryid='e1' accountid='2' />
479 <credit xmlns='com/interrupt/bookkeeping/account' id='ghi' amount='11.50' entryid='e1' accountid='3' />
480 </entry>
482 <entry xmlns='com/interrupt/bookkeeping/journal' id='ereverse' entrynum='' state='closed' journalid='' date='' >
483 <debit xmlns='com/interrupt/bookkeeping/account' id='reverseabc' amount='11.50' entryid='ereverse' accountid='1' />
484 <credit xmlns='com/interrupt/bookkeeping/account' id='reverseghi' amount='11.50' entryid='ereverse' accountid='3' />
485 </entry>
488 // reverse ( (entries -id es1) (entry -id e1) <entry xmlns='com/interrupt/bookkeeping/journal' id='newid' state='closed' > </entry> );
491 // find ( (load ( account -id 2 )) load ( debit -amount 1.50 ) );
494 // list ( (load ( entry -id e1 )) load ( debit -entryid e1) );
495 //** list ( (load ( entry -id e1 )) <debit xmlns='com/interrupt/bookkeeping/account' / > );
496 // list ( (load ( entry -id e1 )) <debit xmlns='com/interrupt/bookkeeping/account' entryid='e1' / > );
500 //** VARIABLES
501 // var timmy = list ( (load ( entry -id e1 )) <debit xmlns='com/interrupt/bookkeeping/account' / > );
502 // find ( (load ( entry -id e1 )) @timmy );
504 // print ( @timmy );
507 //** COMMITING
509 add ( (load ( entries -id es1 ))
510 add (
511 (create ( entry -id e2 ))
512 create (debit -id nsfada -entryid e2 -amount 52.30 -accountid 1 ),
513 create (credit -id efiafd -entryid e2 -amount 52.30 -accountid 3 )
518 // add ( ( create (entries) ) create ( entry ) );
519 // add ( ( create (entries) ) create ( entry ), create ( entry ) );
523 var tim = add (
524 (create ( entry -id e2 ))
525 create (debit -id nsfada -entryid e2 -amount 52.30 -accountid 1 ),
526 create (credit -id efiafd -entryid e2 -amount 52.30 -accountid 3 )
529 // var result = add ( (load ( entries -id es1 )) @tim );
530 // commit ( @result );
535 // >>>>>>>>>> DONE
536 // * Tokens cannot use other tokens
538 // [OK] multiple attributes
539 // [OK] include 2 tokens in a production rule
541 // [OK] include xml comments
542 // <!-- -->
544 // [OK] include namespace declarations; namespace usage in tags and attributes
545 // xmlns='' xmlns:ans='' <ans:tagname att='' />
547 // [OK] text in open/close tags
548 // <a att='' >
549 // <b/>
550 // some text
551 // </a>
554 // [OK] include document declaration ( DTD & schema )
555 // <?xml version="1.0" encoding="iso8859-1" **allow any and all characters between** ?>
556 // <!DOCTYPE greeting SYSTEM "hello.dtd" **allow any and all characters between** >
558 // [OK] implement token & options (this will also be the short form of inputs )
560 // [OK] comments