Permalink
Browse files

first commit

  • Loading branch information...
0 parents commit 2ae4b9e59142781d473c8633139c7b056bd6fcbe @steveyen committed Apr 16, 2011
Showing with 7,021 additions and 0 deletions.
  1. +14 −0 app.rb
  2. +5 −0 config.ru
  3. +71 −0 public/index.html
  4. +4,794 −0 public/js/peg-0.6.1.js
  5. +2 −0 public/js/peg-0.6.1.min.js
  6. +215 −0 public/js/qunit/qunit.css
  7. +1,442 −0 public/js/qunit/qunit.js
  8. +71 −0 public/test/test-peg.html
  9. +335 −0 public/test/test-sample.html
  10. +17 −0 sql.pegjs
  11. +55 −0 views/index.erb
14 app.rb
@@ -0,0 +1,14 @@
+require 'rubygems'
+require 'sinatra'
+require 'erb'
+
+class App < Sinatra::Base
+ set :static, true
+ set :public, 'public'
+
+ ["/", "/index", "/index.html"].each do |path|
+ get path do
+ erb :index
+ end
+ end
+end
@@ -0,0 +1,5 @@
+require 'app'
+
+use Rack::ShowExceptions
+
+run App.new
@@ -0,0 +1,71 @@
+<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
+<html>
+<head>
+<script type="text/javascript" src="./js/peg-0.6.1.min.js"></script>
+<script type="text/javascript" src="./js/qunit/qunit.js"></script>
+<link rel="stylesheet" type="text/css" href="./js/qunit/qunit.css" media="screen">
+</head>
+<body>
+<script type="text/pegjs" id="calc_pegjs">
+start
+ = additive
+
+additive
+ = left:multiplicative "+" right:additive { return left + right; }
+ / multiplicative
+
+multiplicative
+ = left:primary "*" right:multiplicative { return left * right; }
+ / primary
+
+primary
+ = integer
+ / "(" additive:additive ")" { return additive; }
+
+integer "integer"
+ = digits:[0-9]+ { return parseInt(digits.join(""), 10); }
+</script>
+<script>
+module("PEG", {
+ setup: function() {
+ ok(PEG);
+ }
+});
+
+test("basics", 6, function() {
+ var parser = PEG.buildParser("start = ('a' / 'b')+");
+ ok(parser);
+ deepEqual(parser.parse("a"), ["a"]);
+ deepEqual(parser.parse("abba"), ["a", "b", "b", "a"]);
+ raises(function() {
+ parser.parse("abbd");
+ });
+ raises(function() {
+ parser.parse("");
+ });
+});
+
+test("calc", 7, function() {
+ calc_pegjs = document.getElementById("calc_pegjs").innerHTML;
+ ok(calc_pegjs);
+ var parser = PEG.buildParser(calc_pegjs);
+ ok(parser);
+ equal(parser.parse("2"), 2);
+ equal(parser.parse("2*(3+4)"), 14);
+ equal(parser.parse("2*((9+4))"), 26);
+ raises(function() {
+ parser.parse(" 2 ");
+ });
+});
+</script>
+
+<div>
+ <h1 id="qunit-header">Test Suite</h1>
+ <h2 id="qunit-banner"></h2>
+ <div id="qunit-testrunner-toolbar"></div>
+ <h2 id="qunit-userAgent"></h2>
+ <ol id="qunit-tests"></ol>
+ <div id="qunit-fixture">test markup</div>
+</div>
+</body>
+</html>
Oops, something went wrong.

0 comments on commit 2ae4b9e

Please sign in to comment.