Permalink
Browse files

move modules into external dependencies and byebye narwhal ;(

  • Loading branch information...
1 parent d071b1a commit fd891080f7975c7e29bf9d33d2b198700d4752e6 @zaach committed Jan 27, 2013
Showing with 29 additions and 7,879 deletions.
  1. +1 −0 .npmignore
  2. +3 −15 Makefile
  3. +0 −37 bin/jison
  4. +0 −3 bin/jison2json
  5. +0 −3 bin/json2jison
  6. 0 lib/{jison/cli-wrapper.js → cli.js}
  7. +9 −8 lib/jison.js
  8. +0 −44 lib/jison/bnf.js
  9. +0 −153 lib/jison/ebnf.js
  10. +0 −40 lib/jison/jison2json.js
  11. +0 −18 lib/jison/jisonlex.js
  12. +0 −172 lib/jison/json2jison.js
  13. +0 −367 lib/jison/lexer.js
  14. +0 −491 lib/jison/util/bnf-parser.js
  15. +0 −566 lib/jison/util/lex-parser.js
  16. +0 −34 lib/{jison → }/util/io.js
  17. 0 lib/{jison → }/util/set.js
  18. 0 lib/{jison → }/util/typal.js
  19. +6 −6 package.json
  20. +0 −43 script/cjs-bundler.js
  21. +0 −24 script/web-bundle.js
  22. +0 −46 src/bnf.l
  23. +0 −170 src/bnf.y
  24. +0 −82 src/jisonlex.l
  25. +0 −198 src/jisonlex.y
  26. +1 −5 tests/all-tests.js
  27. +0 −91 tests/grammar/bnf.js
  28. +0 −154 tests/grammar/bnf_parse.js
  29. +0 −72 tests/grammar/ebnf.js
  30. +0 −39 tests/grammar/ebnf_parse.js
  31. +0 −13 tests/grammar/grammar-tests.js
  32. +0 −42 tests/grammar/json2jison.js
  33. +0 −119 tests/grammar/lex.jison
  34. +0 −58 tests/grammar/lex.js
  35. +0 −115 tests/grammar/lex/ansic.jisonlex
  36. +0 −23 tests/grammar/lex/bnf.jisonlex
  37. +0 −24 tests/grammar/lex/bnf.lex.json
  38. +0 −29 tests/grammar/lex/lex_grammar.jisonlex
  39. +0 −30 tests/grammar/lex/lex_grammar.lex.json
  40. +0 −307 tests/grammar/lex_parse.js
  41. +0 −6 tests/lexer/lexer-tests.js
  42. +0 −895 tests/lexer/regexplexer.js
  43. +1 −3 tests/parser/parser-tests.js
  44. +0 −2 tests/performance.js
  45. +1 −2 tests/setup.js
  46. +7 −3,330 web/content/assets/js/jison.js
View
@@ -2,3 +2,4 @@ src/
web/
examples/
bin/
+ports/
View
@@ -1,8 +1,8 @@
-all: build test
+all: test
site:
- node script/web-bundle.js > web/content/assets/js/jison.js
+ browserify -r ./lib/jison.js -a 'file:fs' -a 'system:util' --exports require | uglifyjs > web/content/assets/js/jison.js
cd web/ && nanoc compile
cp -r examples web/output/jison/
@@ -13,20 +13,8 @@ preview:
deploy:
rm -r ../pages/jison/*
cp -r web/output/jison/* ../pages/jison/
- cd ../pages/jison && git add . && git commit -m 'Deploy site updates' && git push origin gh-pages
-
-build: build_bnf build_lex
-
-build_bnf:
- node lib/jison/cli-wrapper.js src/bnf.y src/bnf.l
- mv bnf.js lib/jison/util/bnf-parser.js
-
-build_lex:
- node lib/jison/cli-wrapper.js src/jisonlex.y src/jisonlex.l
- mv jisonlex.js lib/jison/util/lex-parser.js
+ cd ../pages/jison && git add . && git commit -m 'Deploy site updates' && git push origin gh-pages
test:
node tests/all-tests.js
-testn:
- narwhal tests/all-tests.js
View
@@ -1,37 +0,0 @@
-#!/usr/bin/env narwhal
-
-var JISON = require('../lib/jison');
- IO = require('../lib/jison/util/io');
-
-var main = function (argv) {
- var args = argv.slice(1);
-
- if (args.length) {
- var raw = IO.read(IO.join(IO.cwd(),args[0])),
- name = IO.basename(args[0]).replace(/\..*$/g,''),
- lex;
- if (args[1]) {
- lex = IO.read(IO.join(IO.cwd(),args[1]));
- }
- IO.write(name+'.js', processGrammar(raw, lex, name));
- } else {
- IO.stdin(function (raw) {
- read = true;
- IO.stdout(processGrammar(raw));
- });
- }
-}
-
-function processGrammar (rawGrammar, lex, name) {
- var grammar = require("../lib/jison/bnf").parse(rawGrammar);
- var opt = grammar.options || {};
- if (lex) grammar.lex = require("../lib/jison/jisonlex").parse(lex);
- if (!opt.moduleType) opt.moduleType = "commonjs";
- if (!opt.moduleName && name) opt.moduleName = name.replace(/-\w/g, function (match){ return match.charAt(1).toUpperCase(); });
-
- var generator = new JISON.Generator(grammar, opt);
- return generator.generate(opt);
-}
-
-main(IO.args);
-
View
@@ -1,3 +0,0 @@
-#!/usr/bin/env narwhal
-
-require('../lib/jison/jison2json').main(system.args);
View
@@ -1,3 +0,0 @@
-#!/usr/bin/env narwhal
-
-require('../lib/jison/json2jison').main(system.args);
File renamed without changes.
View
@@ -2,9 +2,12 @@
// Zachary Carter <zach@carter.name>
// MIT X Licensed
-var typal = require('./jison/util/typal').typal,
- Set = require('./jison/util/set').Set,
- RegExpLexer = require('./jison/lexer').RegExpLexer;
+var typal = require('./util/typal').typal;
+var Set = require('./util/set').Set;
+var Lexer = require('jison-lex');
+var ebnfParser = require('ebnf-parser');
+var JSONSelect = require('JSONSelect');
+var Reflect = require('reflect');
var Jison = exports.Jison = exports;
@@ -72,7 +75,7 @@ var generator = typal.beget();
generator.constructor = function Jison_Generator (grammar, opt) {
if (typeof grammar === 'string') {
- grammar = require("./jison/bnf").parse(grammar);
+ grammar = ebnfParser.parse(grammar);
}
var options = typal.mix.call({}, grammar.options, opt);
@@ -99,7 +102,7 @@ generator.constructor = function Jison_Generator (grammar, opt) {
this.processGrammar(grammar);
if (grammar.lex) {
- this.lexer = new RegExpLexer(grammar.lex, null, this.terminals_);
+ this.lexer = new Lexer(grammar.lex, null, this.terminals_);
}
};
@@ -111,7 +114,7 @@ generator.processGrammar = function processGrammarDef (grammar) {
self = this;
if (!grammar.bnf && grammar.ebnf) {
- bnf = grammar.bnf = require("./jison/ebnf").transform(grammar.ebnf);
+ bnf = grammar.bnf = ebnfParser.transform(grammar.ebnf);
}
if (tokens) {
@@ -953,8 +956,6 @@ lrGeneratorMixin.generateModule = function generateModule (opt) {
function removeErrorRecovery (fn) {
var parseFn = String(fn);
try {
- var JSONSelect = require('JSONSelect');
- var Reflect = require('reflect');
var ast = Reflect.parse(parseFn);
var labeled = JSONSelect.match(':has(:root > .label > .name:val("_handle_error"))', ast);
View
@@ -1,44 +0,0 @@
-var bnf = require("./util/bnf-parser").parser,
- jisonlex = require("./jisonlex");
-
-exports.parse = function parse () { return bnf.parse.apply(bnf, arguments); };
-
-// adds a declaration to the grammar
-bnf.yy.addDeclaration = function (grammar, decl) {
- if (decl.start) {
- grammar.start = decl.start;
- }
- else if (decl.lex) {
- grammar.lex = parseLex(decl.lex);
- }
- else if (decl.operator) {
- if (!grammar.operators) {
- grammar.operators = [];
- }
- grammar.operators.push(decl.operator);
- }
- else if (decl.include) {
- if (!grammar.moduleInclude)
- grammar.moduleInclude = '';
- grammar.moduleInclude += decl.include;
- }
-
-};
-
-// helps tokenize comments
-bnf.yy.lexComment = function (lexer) {
- var ch = lexer.input();
- if (ch === '/') {
- lexer.yytext = lexer.yytext.replace(/\*(.|\s)\/\*/, '*$1');
- return;
- } else {
- lexer.unput('/*');
- lexer.more();
- }
-};
-
-// parse an embedded lex section
-var parseLex = function (text) {
- return jisonlex.parse(text.replace(/(?:^%lex)|(?:\/lex$)/g, ''));
-};
-
View
@@ -1,153 +0,0 @@
-var EBNF = (function(){
- var grammar = {
- "lex": {
- "rules": [
- ["\\s+", "/* skip whitespace */"],
- ["[A-Za-z_]+", "return 'symbol';"],
- ["'[^']*'", "return 'symbol';"],
- ["\\\\.", "return 'symbol';"],
- ["bar", "return 'bar';"],
- ["\\(", "return '(';"],
- ["\\)", "return ')';"],
- ["\\*", "return '*';"],
- ["\\+", "return '+';"],
- ["\\?", "return '?';"],
- ["\\|", "return '|';"],
- ["$", "return 'EOF';"]
- ]
- },
- "start": "production",
- "bnf": {
- "production": [
- ["handle EOF", "return $handle;"]
- ],
- "handle_list": [
- ["handle", "$$ = [$handle];"],
- ["handle_list | handle", "$handle_list.push($handle);"]
- ],
- "handle": [
- ["", "$$ = [];"],
- ["handle expression_suffix", "$handle.push($expression_suffix);"]
- ],
- "expression_suffix": [
- ["expression suffix", "if ($suffix) $$ = [$suffix, $expression]; else $$ = $expression;"]
- ],
- "expression": [
- ["symbol", "$$ = ['symbol', $symbol];"],
- ["( handle_list )", "$$ = ['()', $handle_list];"]
- ],
- "suffix": ["", "*", "?", "+"]
- }
- };
-
- var parser = new require('../jison').Parser(grammar);
-
- var transformExpression = function(e, opts, emit) {
- var type = e[0], value = e[1], name;
-
- if (type === 'symbol') {
- if (e[1][0] === '\\') emit (e[1][1]);
- else if (e[1][0] === '\'') emit (e[1].substring(1, e[1].length-1));
- else emit (e[1]);
- } else if (type === "+") {
- name = opts.production + "_repetition_plus" + opts.repid++;
- emit(name);
-
- opts = optsForProduction(name, opts.grammar);
- var list = transformExpressionList([value], opts);
- opts.grammar[name] = [
- [list, "$$ = [$1];"],
- [
- name + " " + list,
- "$1.push($2);"
- ]
- ];
- } else if (type === "*") {
- name = opts.production + "_repetition" + opts.repid++;
- emit(name);
-
- opts = optsForProduction(name, opts.grammar);
- opts.grammar[name] = [
- ["", "$$ = [];"],
- [
- name + " " + transformExpressionList([value], opts),
- "$1.push($2);"
- ]
- ];
- } else if (type ==="?") {
- name = opts.production + "_option" + opts.optid++;
- emit(name);
-
- opts = optsForProduction(name, opts.grammar);
- opts.grammar[name] = [
- "", transformExpressionList([value], opts)
- ];
- } else if (type === "()") {
- if (value.length == 1) {
- emit(transformExpressionList(value[0], opts));
- } else {
- name = opts.production + "_group" + opts.groupid++;
- emit(name);
-
- opts = optsForProduction(name, opts.grammar);
- opts.grammar[name] = value.map(function(handle) {
- return transformExpressionList(handle, opts);
- });
- }
- }
- };
-
- var transformExpressionList = function(list, opts) {
- return list.reduce (function (tot, e) {
- transformExpression (e, opts, function (i) { tot.push(i); });
- return tot;
- }, []).
- join(" ");
- };
-
- var optsForProduction = function(id, grammar) {
- return {
- production: id,
- repid: 0,
- groupid: 0,
- optid: 0,
- grammar: grammar
- };
- };
-
- var transformProduction = function(id, production, grammar) {
- var transform_opts = optsForProduction(id, grammar);
- return production.map(function (handle) {
- var action = null, opts = null;
- if (typeof(handle) !== 'string')
- action = handle[1],
- opts = handle[2],
- handle = handle[0];
- var expressions = parser.parse(handle);
-
- handle = transformExpressionList(expressions, transform_opts);
-
- var ret = [handle];
- if (action) ret.push(action);
- if (opts) ret.push(opts);
- if (ret.length == 1) return ret[0];
- else return ret;
- });
- };
-
- var transformGrammar = function(grammar) {
- Object.keys(grammar).forEach(function(id) {
- grammar[id] = transformProduction(id, grammar[id], grammar);
- });
- };
-
- return {
- transform: function (ebnf) {
- transformGrammar(ebnf);
- return ebnf;
- }
- };
-})();
-
-exports.transform = EBNF.transform;
-
View
@@ -1,40 +0,0 @@
-#!/usr/bin/env node
-
-// Encodes Jison formatted grammars as JSON
-
-var JISON = require('../jison'),
- IO = require('./util/io');
-
-exports.main = function (argv) {
- if(argv.length == 1) return;
-
- var args = argv.slice(1);
-
- if (args.length) {
- var raw = IO.read(IO.join(IO.cwd(), args[0])),
- lex;
- if (args[1]) {
- lex = IO.read(IO.join(IO.cwd(), args[1]));
- }
-
- IO.stdout(processGrammar(raw, lex));
- } else {
- var read = false;
- IO.stdin(function (raw) {
- read = true;
- IO.stdout(processGrammar(raw));
- });
- setTimeout(function (){ if (!read) IO.exit(); }, 100);
- }
-};
-
-function processGrammar (rawGrammar, lex) {
- var grammar = require("./bnf").parse(rawGrammar);
- if (lex) grammar.lex = require("./jisonlex").parse(lex);
- grammar.bnf = grammar.bnf;
- return JSON.stringify(grammar,null, ' ');
-}
-
-if (typeof process !== 'undefined' || require.main === module)
- exports.main(IO.args);
-
View
@@ -1,18 +0,0 @@
-var jisonlex = require("./util/lex-parser").parser;
-
-var parse_ = jisonlex.parse;
-jisonlex.parse = exports.parse = function parse () {
- jisonlex.yy.ruleSection = false;
- return parse_.apply(jisonlex, arguments);
-};
-
-function encodeRE (s) { return s.replace(/([.*+?^${}()|[\]\/\\])/g, '\\$1').replace(/\\\\u([a-fA-F0-9]{4})/g,'\\u$1'); }
-
-jisonlex.yy = {
- prepareString: function (s) {
- // unescape slashes
- s = s.replace(/\\\\/g, "\\");
- s = encodeRE(s);
- return s;
- }
-};
Oops, something went wrong.

0 comments on commit fd89108

Please sign in to comment.