Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added highlighting example

  • Loading branch information...
commit d50956256813ca78583d0ca6cbcf81aed4dd349d 1 parent 5da4ae1
@qfox authored
Showing with 15 additions and 0 deletions.
  1. +15 −0 README
View
15 README
@@ -28,6 +28,7 @@ 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";
@@ -35,4 +36,18 @@ 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('');
Please sign in to comment.
Something went wrong with that request. Please try again.