Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add CommonJS support

  • Loading branch information...
commit 45a1c907cb0ddd1e11dd7aa1bd590fa0c4fadf57 1 parent ce6fe97
@felixge authored
Showing with 18 additions and 5 deletions.
  1. +7 −2 Tokenizer.js
  2. +6 −1 ZeParser.js
  3. +1 −0  index.js
  4. +4 −2 unicodecategories.js
View
9 Tokenizer.js
@@ -1,3 +1,8 @@
+if (typeof exports !== 'undefined') {
+ var window = {Unicode: require('./unicodecategories').Unicode};
+ exports.Tokenizer = Tokenizer;
+}
+
/*!
* Tokenizer for JavaScript / ECMAScript 5
* (c) Peter van der Zee, qfox.nl
@@ -6,7 +11,7 @@
/**
* @param {Object} inp
*/
-window.Tokenizer = function(inp){
+function Tokenizer(inp){
this.inp = inp||'';
// replace all other line terminators with \n (leave \r\n in tact though). we should probably remove the shadowInp when finished...
// only replace \r if it is not followed by a \n else \r\n would become \n\n causing a double newline where it is just a single
@@ -1052,4 +1057,4 @@ Tokenizer.Error = {
QuantifierRequiresNumber: {msg:'Quantifier curly requires at least one digit before the comma'},
QuantifierRequiresClosingCurly: {msg:'Quantifier curly requires to be closed'},
MissingOpeningCurly: {msg:'Encountered closing quantifier curly without seeing an opening curly'}
-};
+};
View
7 ZeParser.js
@@ -1,3 +1,8 @@
+if (typeof exports !== 'undefined') {
+ var Tokenizer = require('./tokenizer').Tokenizer;
+ exports.ZeParser = ZeParser;
+}
+
/**
* This is my js Parser: Ze. It's actually the post-dev pre-cleanup version. Clearly.
* Some optimizations have been applied :)
@@ -6,7 +11,7 @@
* @param {Tokenizer} tok
* @param {Array} stack The tokens will be put in this array. If you're looking for the AST, this would be it :)
*/
-window.ZeParser = function(inp, tok, stack, simple){
+function ZeParser(inp, tok, stack, simple){
this.input = inp;
this.tokenizer = tok;
this.stack = stack;
View
1  index.js
@@ -0,0 +1 @@
+exports.ZeParser = require('./ZeParser').ZeParser;
View
6 unicodecategories.js
@@ -1,6 +1,8 @@
// http://qfox.nl/notes/90
-
-if (!window.Unicode) window.Unicode = {};
+var Unicode = (Unicode) ? Unicode: {};
+if (typeof exports !== 'undefined') {
+ exports.Unicode = Unicode;
+}
// upper case
// http://query.yahooapis.com/v1/public/yql?q=select%20content%20from%20html%20where%20url%3D%22http%3A%2F%2Fwww.fileformat.info%2Finfo%2Funicode%2Fcategory%2FLu%2Flist.htm%22%20and%20xpath%3D'%2F%2Fa'%20and%20href%20like%20'%2Finfo%2Funicode%2Fchar%2F%25'%20and%20href%20like%20'%25%2Findex.htm'&format=json&diagnostics=false&callback=cbfunc
Please sign in to comment.
Something went wrong with that request. Please try again.