Permalink
Browse files

Merge branch 'master' of github.com:qfox/ZeParser

  • Loading branch information...
2 parents ab40a34 + d509562 commit ac8fec4b6162d90274de9cf179f58027d87ab540 Peter van der Zee committed Mar 25, 2012
Showing with 15 additions and 0 deletions.
  1. +15 −0 README
View
15 README
@@ -28,11 +28,26 @@ Tokens are regular objects with several properties. Amongst them are .tokposw an
The parser has two modes for parsing: simple and extended. Simple mode is mainly for just parsing and returning the streams and a simple parse tree. There's not so much meta information here and this mode is mainly built for speed. The other mode has everything required for Zeon to do its job. This mode is toggled by the instance property .ast, which is true by default :)
+
Non-factory example:
var input = "foo";
var tree = []; // this should probably be refactored away some day
var tokenizer = new Tokenizer(input); // dito
var parser = new ZeParser(input, tokenizer, tree);
parser.parse(); // returns tree..., should never throw errors
+parser.tokenizer.fixValues(); // makes sure all tokens have a .value property
+
+
+Highlighting example:
+var parser = ZeParser.createParser(textarea.value); // textarea.value:input
+parser.tokenizer.fixValues(); // makes sure all tokens have a .value property
+var wtree = parser.tokenizer.wtree; // all the tokens ("token stream", including whitespace)
+textarea.className = '';
+var tokenstrings = wtree.map(function(t){
+ if (t.name == 14) textarea.className = 'error';
+ return '<span class="t'+t.name+'">'+(t.name==13?'\u29e6':(t.name==14?'\u292c':t.value)).replace(/&/g,'&amp;').replace(/</g,'&lt;').replace(/>/g,'&gt;')+'</span>';
+});
+// the string that would contain highlighted code
+// tokenstrings.join('');

0 comments on commit ac8fec4

Please sign in to comment.