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