/
structural.html
70 lines (58 loc) · 1.89 KB
/
structural.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
<html>
<head>
<script src="jquery.min.js"></script>
<script src="../StructuralFramework.js"></script>
<script src="../StructuralEditor.js"></script>
<script src="../StructuralGrammar.js"></script>
<script src="../Tokenizers.js"></script>
<style>
.eatom { color: red }
.selected { border: 1px solid blue; }
.box { background: lightgreen }
.unparsed { opacity: 0.5 }
.cursor_selected { border-left: 1px solid blue }
.cursor_selected_right { border-right: 1px solid blue }
.modeline { font-weight: bold }
.indented { margin-left: 4em }
</style>
<script>
// main : jQuery * StructuralFramework * (top_node -> StructuralEditor) -> Module
var main = function($, SF, SG, SE) {
var space = SG.token(/\s*/, ' ');
var top_class = SG.grammar('stmts', {
'stmts': SG.choice(
SG.empty,
SG.seq(SG.sym('stmt'), SG.literal(';', ';\n'), SG.sym('stmts'))),
'stmt': SG.choice(
SG.sym('var_decl'),
SG.sym('if_expr'),
SG.sym('funcall')),
'var_decl': SG.seq(SG.literal('var'), space, SG.sym('identifier')),
'if_expr': SG.seq(SG.literal('if'), space, SG.literal('('), SG.sym('expr'), SG.literal(')'), space,
SG.literal('{', '{\n'), SG.indent(SG.sym('stmts')), SG.literal('}')),
'funcall': SG.seq(SG.sym('identifier'), SG.literal('('), SG.sym('expr'), SG.literal(')')),
'identifier': SG.token(/[a-zA-Z_$][\w$]*/),
'expr': SG.sym('identifier')
});
var top_node = top_class.open();
var editor = SE(top_node, $(document));
$(document.body).append(editor);
};
jQuery(function() {
var SF = StructuralFramework(jQuery);
var Tok = Tokenizers();
var SG = StructuralGrammar(SF, Tok);
main(
jQuery,
SF,
SG,
function(top_node, event_node) {
return StructuralEditor(jQuery, SF, top_node, event_node)
}
);
});
</script>
</head>
<body>
</body>
</html>