gmltest.html 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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. <!--
  8. #
  9. # /*
  10. # * This program is free software: you can redistribute it and/or modify
  11. # * it under the terms of the GNU General Public License as published by
  12. # * the Free Software Foundation, either version 3 of the License, or
  13. # * (at your option) any later version.
  14. # *
  15. # * This program is distributed in the hope that it will be useful,
  16. # * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. # * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. # * GNU General Public License for more details.
  19. # *
  20. # * You should have received a copy of the GNU General Public License
  21. # * along with this program. If not, see <http://www.gnu.org/licenses/>.
  22. # *
  23. # * SPDX-License-Identifier: GPL-3.0+
  24. # * License-Filename: LICENSE
  25. # *
  26. # */
  27. #
  28. -->
  29. <script src="gmlpeg-parser.js"></script>
  30. <script>
  31. function checkgml() {
  32. var text = document.getElementById("textin").value;
  33. try {
  34. var g=gmlpeg.parse(text);
  35. strOut2 = "<b>Syntax oke</b>";
  36. } catch (err) {
  37. /* console.log(err.message); */
  38. /* console.log(err.location.start.line); */
  39. strOut2 = '<b>Syntax error at line ' + err.location.start.line + ' ' + err.message + '</b>';
  40. }
  41. var resultselement2 = document.getElementById("results2");
  42. resultselement2.innerHTML = strOut2;
  43. }
  44. </script><br>
  45. <b> check gml graph for syntax errors</b><br>
  46. <br>
  47. <form>
  48. <p> <textarea rows="20" cols="80" id="textin" wrap="off"># this is a comment line
  49. # colors in nodes/edges using 'fill'
  50. # background color of a node is set using `fill'
  51. # border color of a node is set using `outline'
  52. # edge line color is set using `fill'
  53. graph [
  54. directed 1
  55. node [ id 0 label "n0" graphics [ fill "#f00000" ] ]
  56. node [ id 1 label "n1" graphics [ outline "#ff0000" fill "#00ff00" ] ]
  57. node [ id 2 label "n2" graphics [ outline "#00ff00" fill "#f0ff00" ] ]
  58. node [ id 3 label "n3" graphics [ outline "#0000ff" fill "#f08000" ] ]
  59. node [ id 4 label "n4" graphics [ fill "#f0000f" ] ]
  60. node [ id 5 label "n5" graphics [ outline "#f0000f" fill "#ffffff" ] ]
  61. edge [ source 4 target 0 graphics [ fill "#f000ff" ] ]
  62. edge [ source 0 target 1 label "foo" graphics [ fill "#0f0ff0" ] ]
  63. edge [ source 1 target 2 graphics [ fill "#abf000" ] ]
  64. edge [ source 2 target 3 graphics [ fill "#f0f000" ] ]
  65. edge [ source 3 target 0 graphics [ fill "#f000f0" ] ]
  66. edge [ source 3 target 0 graphics [ fill "#ff000b" ] ]
  67. edge [ source 5 target 0 graphics [ fill "#ff000b" ] ]
  68. ]
  69. </textarea><br>
  70. <table>
  71. <tbody>
  72. <tr>
  73. <td><button onclick="checkgml()" type="button">Check GML
  74. Graph syntax</button></td>
  75. </tr>
  76. </tbody>
  77. </table>
  78. </p>
  79. <p> </p>
  80. <br>
  81. <div id="results2"> </div>
  82. <br>
  83. The syntax parser is a javascript parser made with pegjs at <a
  84. href="https://pegjs.org/">https://pegjs.org/</a><br>
  85. <br>
  86. This is the gml.pegjs gml grammar<br>
  87. <br>
  88. <br>
  89. file = _ head _ id _ list _<br>
  90. <br>
  91. head = (pair)*<br>
  92. <br>
  93. list = "[" _ some_items* _ "]" _<br>
  94. <br>
  95. some_items = id list2 / pair<br>
  96. <br>
  97. list2 = _ "[" _ some_items* _ "]" _<br>
  98. <br>
  99. pair = (id string) / (id id) / (id fpnum) / (id digit)<br>
  100. <br>
  101. digit = (("-"[0-9]+ _ ) / ("+"[0-9]+ _ ) / ([0-9]+ _ ))<br>
  102. <br>
  103. fpnum = (("-"[0-9]*["."][0-9]* _ ) / ("+"[0-9]*["."][0-9]* _ ) /
  104. ([0-9]*["."][0-9]* _ ))<br>
  105. <br>
  106. id&nbsp;&nbsp;&nbsp; =&nbsp; [a-zA-Z_]+[a-zA-Z_0-9]*&nbsp; _<br>
  107. <br>
  108. string&nbsp;&nbsp;&nbsp; = '"'&nbsp; char*&nbsp; '"'&nbsp; _<br>
  109. <br>
  110. char&nbsp;&nbsp;&nbsp; =<br>
  111. &nbsp;&nbsp;&nbsp; "\\" "\""<br>
  112. &nbsp;&nbsp;&nbsp; / "\\" "\\"<br>
  113. &nbsp;&nbsp;&nbsp; / "\\" "b"<br>
  114. &nbsp;&nbsp;&nbsp; / "\\" "f"<br>
  115. &nbsp;&nbsp;&nbsp; / "\\" "n"<br>
  116. &nbsp;&nbsp;&nbsp; / "\\" "r"<br>
  117. &nbsp;&nbsp;&nbsp; / "\\" "t"<br>
  118. &nbsp;&nbsp;&nbsp; / (!"\"" .)<br>
  119. <br>
  120. _&nbsp;&nbsp;&nbsp; =&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; (space
  121. / comment / endofline)*<br>
  122. <br>
  123. space&nbsp;&nbsp;&nbsp; =&nbsp;&nbsp;&nbsp; (" " / "\t" /
  124. endofline)<br>
  125. <br>
  126. comment&nbsp;&nbsp;&nbsp; =&nbsp;&nbsp;&nbsp; "#" (!endofline .)*<br>
  127. <br>
  128. endofline&nbsp;&nbsp;&nbsp; =&nbsp;&nbsp;&nbsp; ( "\r\n" / "\n" /
  129. "\r" / "\n\r" )<br>
  130. <br>
  131. <br>
  132. </form>
  133. </body>
  134. </html>