gmltest.html 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
  2. <html>
  3. <head>
  4. <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  5. </head>
  6. <body>
  7. <script src="gmlpeg-parser.js"></script>
  8. <script>
  9. function checkgml() {
  10. var text = document.getElementById("textin").value;
  11. try {
  12. var g=gmlpeg.parse(text);
  13. strOut2 = "<b>Syntax oke</b>";
  14. } catch (err) {
  15. /* console.log(err.message); */
  16. /* console.log(err.location.start.line); */
  17. strOut2 = '<b>Syntax error at line ' + err.location.start.line + ' ' + err.message + '</b>';
  18. }
  19. var resultselement2 = document.getElementById("results2");
  20. resultselement2.innerHTML = strOut2;
  21. }
  22. </script><br>
  23. <b> check gml graph for syntax errors</b><br>
  24. <br>
  25. <form>
  26. <p> <textarea rows="20" cols="80" id="textin" wrap="off"># this is a comment line
  27. # colors in nodes/edges using 'fill'
  28. # background color of a node is set using `fill'
  29. # border color of a node is set using `outline'
  30. # edge line color is set using `fill'
  31. graph [
  32. directed 1
  33. node [ id 0 label "n0" graphics [ fill "#f00000" ] ]
  34. node [ id 1 label "n1" graphics [ outline "#ff0000" fill "#00ff00" ] ]
  35. node [ id 2 label "n2" graphics [ outline "#00ff00" fill "#f0ff00" ] ]
  36. node [ id 3 label "n3" graphics [ outline "#0000ff" fill "#f08000" ] ]
  37. node [ id 4 label "n4" graphics [ fill "#f0000f" ] ]
  38. node [ id 5 label "n5" graphics [ outline "#f0000f" fill "#ffffff" ] ]
  39. edge [ source 4 target 0 graphics [ fill "#f000ff" ] ]
  40. edge [ source 0 target 1 label "foo" graphics [ fill "#0f0ff0" ] ]
  41. edge [ source 1 target 2 graphics [ fill "#abf000" ] ]
  42. edge [ source 2 target 3 graphics [ fill "#f0f000" ] ]
  43. edge [ source 3 target 0 graphics [ fill "#f000f0" ] ]
  44. edge [ source 3 target 0 graphics [ fill "#ff000b" ] ]
  45. edge [ source 5 target 0 graphics [ fill "#ff000b" ] ]
  46. ]
  47. </textarea><br>
  48. <table>
  49. <tbody>
  50. <tr>
  51. <td><button onclick="checkgml()" type="button">Check GML
  52. Graph syntax</button></td>
  53. </tr>
  54. </tbody>
  55. </table>
  56. </p>
  57. <p> </p>
  58. <br>
  59. <div id="results2"> </div>
  60. <br>
  61. The syntax parser is a javascript parser made with pegjs at <a
  62. href="https://pegjs.org/">https://pegjs.org/</a><br>
  63. <br>
  64. This is the gml.pegjs gml grammar<br>
  65. <br>
  66. <br>
  67. file = _ head _ id _ list _<br>
  68. <br>
  69. head = (pair)*<br>
  70. <br>
  71. list = "[" _ some_items* _ "]" _<br>
  72. <br>
  73. some_items = id list2 / pair<br>
  74. <br>
  75. list2 = _ "[" _ some_items* _ "]" _<br>
  76. <br>
  77. pair = (id string) / (id id) / (id fpnum) / (id digit)<br>
  78. <br>
  79. digit = (("-"[0-9]+ _ ) / ("+"[0-9]+ _ ) / ([0-9]+ _ ))<br>
  80. <br>
  81. fpnum = (("-"[0-9]*["."][0-9]* _ ) / ("+"[0-9]*["."][0-9]* _ ) /
  82. ([0-9]*["."][0-9]* _ ))<br>
  83. <br>
  84. id&nbsp;&nbsp;&nbsp; =&nbsp; [a-zA-Z_]+[a-zA-Z_0-9]*&nbsp; _<br>
  85. <br>
  86. string&nbsp;&nbsp;&nbsp; = '"'&nbsp; char*&nbsp; '"'&nbsp; _<br>
  87. <br>
  88. char&nbsp;&nbsp;&nbsp; =<br>
  89. &nbsp;&nbsp;&nbsp; "\\" "\""<br>
  90. &nbsp;&nbsp;&nbsp; / "\\" "\\"<br>
  91. &nbsp;&nbsp;&nbsp; / "\\" "b"<br>
  92. &nbsp;&nbsp;&nbsp; / "\\" "f"<br>
  93. &nbsp;&nbsp;&nbsp; / "\\" "n"<br>
  94. &nbsp;&nbsp;&nbsp; / "\\" "r"<br>
  95. &nbsp;&nbsp;&nbsp; / "\\" "t"<br>
  96. &nbsp;&nbsp;&nbsp; / (!"\"" .)<br>
  97. <br>
  98. _&nbsp;&nbsp;&nbsp; =&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; (space
  99. / comment / endofline)*<br>
  100. <br>
  101. space&nbsp;&nbsp;&nbsp; =&nbsp;&nbsp;&nbsp; (" " / "\t" /
  102. endofline)<br>
  103. <br>
  104. comment&nbsp;&nbsp;&nbsp; =&nbsp;&nbsp;&nbsp; "#" (!endofline .)*<br>
  105. <br>
  106. endofline&nbsp;&nbsp;&nbsp; =&nbsp;&nbsp;&nbsp; ( "\r\n" / "\n" /
  107. "\r" / "\n\r" )<br>
  108. <br>
  109. <br>
  110. </form>
  111. </body>
  112. </html>