yfxts_GfmlParse_fxt.java 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. /*
  2. XOWA: the XOWA Offline Wiki Application
  3. Copyright (C) 2012-2017 gnosygnu@gmail.com
  4. XOWA is licensed under the terms of the General Public License (GPL) Version 3,
  5. or alternatively under the terms of the Apache License Version 2.0.
  6. You may use XOWA according to either of these licenses as is most appropriate
  7. for your project on a case-by-case basis.
  8. The terms of each license can be found in the source code repository:
  9. GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
  10. Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
  11. */
  12. package gplx.gfml; import gplx.*;
  13. class GfmlParse_fxt {
  14. public GfmlNde_mok nde_() {return GfmlNde_mok.new_();}
  15. public GfmlTkn_mok tkn_grp_ary_(String... ary) {return GfmlTkn_mok.new_().Subs_(GfmlTkn_mok.Xto_bry(ary));}
  16. public GfmlTkn_mok tkn_grp_(GfmlTkn_mok... ary) {return GfmlTkn_mok.new_().Subs_(ary);}
  17. public GfmlTkn_mok tkn_itm_(String r) {return GfmlTkn_mok.new_().Raw_(r);}
  18. public void ini_RootLxr_Add(GfmlLxr... ary) {rootLxr.SubLxr_Add(ary);}
  19. public void tst_Doc(String raw, GfmlNde_mok... expdAry) {
  20. GfmlDoc gdoc = bldr.XtoGfmlDoc(raw);
  21. GfmlNde_mok expd = GfmlNde_mok.new_();
  22. for (GfmlNde_mok itm : expdAry)
  23. expd.Subs_(itm);
  24. TfdsTstr_fxt tstr = TfdsTstr_fxt.new_();
  25. GfmlTypeResolver_fxt.tst_Nde(tstr, expd, GfmlNde_mok.gfmlNde_(gdoc.RootNde()));
  26. tstr.tst_Equal("parse");
  27. }
  28. public void tst_Tkn(String raw, GfmlTkn_mok... expdAry) {
  29. GfmlDoc gdoc = bldr.XtoGfmlDoc(raw);
  30. GfmlTkn_mok expd = GfmlTkn_mok.new_();
  31. for (GfmlTkn_mok itm : expdAry)
  32. expd.Subs_(itm);
  33. TfdsTstr_fxt tstr = TfdsTstr_fxt.new_();
  34. GfmlTkn_mok.tst(tstr, expd, GfmlTkn_mok.gfmlNde_(gdoc.RootNde()));
  35. tstr.tst_Equal("parse");
  36. }
  37. public static GfmlParse_fxt new_() {
  38. GfmlParse_fxt rv = new GfmlParse_fxt();
  39. rv.rootLxr = GfmlDocLxrs.Root_lxr();
  40. rv.bldr = GfmlBldr_.new_();
  41. rv.bldr.Doc().RootLxr_set(rv.rootLxr);
  42. return rv;
  43. }
  44. public void tst_Err(String raw, UsrMsg_mok... expdErrs) {
  45. bldr.ThrowErrors_set(false);
  46. GfmlDoc actlDoc = bldr.XtoGfmlDoc(raw);
  47. List_adp expd = List_adp_.New(), actl = actlDoc.UsrMsgs();
  48. expd.Add_many((Object[])expdErrs);
  49. TfdsTstr_fxt tstr = TfdsTstr_fxt.new_();
  50. int max = tstr.List_Max(expd, actl);
  51. for (int i = 0; i < max; i++) {
  52. UsrMsg_mok expdUm = (UsrMsg_mok)tstr.List_FetchAtOrNull(expd, i);
  53. UsrMsg actlUm = (UsrMsg)tstr.List_FetchAtOrNull(actl, i);
  54. UsrMsg_mok actlUmm = UsrMsg_mok.new_(actlUm);
  55. tstr.Eq_str(expdUm.Main(), actlUmm.Main(), "main");
  56. for (int j = 0; j < expdUm.Args().Count(); j++) {
  57. Keyval expdKv = (Keyval)expdUm.Args().Get_at(j);
  58. Keyval actlKv = (Keyval)actlUmm.Args().Get_by(expdKv.Key());
  59. Object actlVal = actlKv == null ? String_.Null_mark : actlKv.Val();
  60. tstr.Eq_str(expdKv.Val(), actlVal, expdKv.Key());
  61. }
  62. for (int j = 0; j < expdUm.Required().Count(); j++) {
  63. String expdKv = (String)expdUm.Required().Get_at(j);
  64. Keyval actlKv = (Keyval)actlUmm.Args().Get_by(expdKv);
  65. Object actlVal = actlKv == null ? String_.Null_mark : actlKv.Val();
  66. Object actlValV = actlKv == null ? "<<REQD>>" : actlKv.Val();
  67. tstr.Eq_str(actlValV, actlVal, expdKv);
  68. }
  69. }
  70. tstr.tst_Equal("errs");
  71. }
  72. GfmlBldr bldr; GfmlLxr rootLxr;
  73. }