GfmlDoc_.java 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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. public class GfmlDoc_ {
  14. public static GfmlDoc parse_any_eol_(String raw) {return parse(String_.Replace(raw, String_.CrLf, String_.Lf));}
  15. public static GfmlDoc parse(String raw) {
  16. GfmlBldr bldr = GfmlBldr_.default_();
  17. return bldr.XtoGfmlDoc(raw);
  18. }
  19. }
  20. class GfmlUsrMsgs {
  21. public static UsrMsg fail_HndTkn_alreadyExists() {return UsrMsg.new_("hndTkn already exists");}
  22. public static UsrMsg fail_KeyTkn_alreadyExists() {return UsrMsg.new_("keyTkn already exists");}
  23. public static UsrMsg fail_DatTkn_notFound() {return UsrMsg.new_("datTkn not found");}
  24. public static UsrMsg fail_Frame_danglingBgn() {return UsrMsg.new_("dangling frame");}
  25. public static void MakeErr(GfmlBldr bldr, UsrMsg um, String raw) {
  26. bldr.Doc().UsrMsgs().Add(um);
  27. GfmlStringHighlighter sh = GfmlStringHighlighter.new_();
  28. sh.Raw_(raw).Mark_(bldr.StreamPos(), '*', "failed");
  29. um.Add("errorPos", bldr.StreamPos());
  30. um.Add("errorHighlight", String_.CrLf + String_.Concat_lines_crlf(sh.Gen()));
  31. }
  32. public static Err gfmlParseError(GfmlBldr bldr) {
  33. Err rv = Err_.new_wo_type("gfml parse error");
  34. for (int i = 0; i < bldr.Doc().UsrMsgs().Count(); i++) {
  35. UsrMsg um = (UsrMsg)bldr.Doc().UsrMsgs().Get_at(i);
  36. rv.Args_add("err" + Int_.To_str(i), um.To_str());
  37. }
  38. return rv;
  39. }
  40. }