comparison parser-demo.js @ 14:95b27aa47788 default tip

parse tree now displays as html.
author Atul Varma <varmaa@toolness.com>
date Sun, 31 May 2009 03:57:37 -0700
parents 1b7ea033b3f6
children
comparison
equal deleted inserted replaced
13:1b7ea033b3f6 14:95b27aa47788
26 match: '/', 26 match: '/',
27 leftBindingPower: 70}), 27 leftBindingPower: 70}),
28 28
29 new Parsing.Symbol({name: 'number', 29 new Parsing.Symbol({name: 'number',
30 match: /^[0-9]+/, 30 match: /^[0-9]+/,
31 toHtml: function() {
32 return document.createTextNode(this.value);
33 },
31 nullDenotation: function() { 34 nullDenotation: function() {
32 return this; 35 return this;
33 }, 36 },
34 toString: function() { 37 toString: function() {
35 return this.value; 38 return this.value;
43 function onInputChange() { 46 function onInputChange() {
44 var code = $('.input').val(); 47 var code = $('.input').val();
45 $('.tokenization').empty(); 48 $('.tokenization').empty();
46 $('.parse-tree').empty(); 49 $('.parse-tree').empty();
47 50
51 if (!code)
52 return;
53
48 try { 54 try {
49 var tokens = Parsing.tokenize({lexicon: MyLexicon, 55 var tokens = Parsing.tokenize({lexicon: MyLexicon,
50 text: code}); 56 text: code});
51 } catch (e) { 57 } catch (e) {
52 $('.tokenization').text(e.message); 58 $('.tokenization').text(e.message);
81 } catch (e) { 87 } catch (e) {
82 $('.parse-tree').text(e.message); 88 $('.parse-tree').text(e.message);
83 throw e; 89 throw e;
84 } 90 }
85 91
86 $('.parse-tree').text(parseTree.toString()); 92 $('.parse-tree').append(parseTree.toHtml());
87 } 93 }
88 94
89 $(window).ready( 95 $(window).ready(
90 function() { 96 function() {
91 $('.input').keyup(onInputChange); 97 $('.input').keyup(onInputChange);