public
Description: A JavaScript implementation of Chris Coyne's Context Free Design Grammar.
Clone URL: git://github.com/osteele/cfdg-js.git
move core extensions into like-named file; rename render -> flash
osteele (author)
Sun Mar 23 19:52:28 -0700 2008
commit  d14dee3904b5cd60c82424954f06acdc9736c34a
tree    a1a2669e1e6ac5728395c684c9e1aee05c878e8c
parent  acbbfc4a5c0749ffb6b338c978e9ed5ca67937db
...
2
3
4
 
5
6
7
...
2
3
4
5
6
7
8
0
@@ -2,6 +2,7 @@
0
   <head>
0
     <title>CFDG</title>
0
     <link href="styles.css" type="text/css" rel="stylesheet" />
0
+ <script type="text/javascript" src="../javascripts/cfdg.core-extensions.js"></script>
0
     <script type="text/javascript" src="../javascripts/cfdg.model.js"></script>
0
     <script type="text/javascript" src="../javascripts/cfdg.parser.js"></script>
0
     <script type="text/javascript" src="../javascripts/cfdg.graphics.js"></script>
...
1
2
 
 
3
4
5
...
115
116
117
118
119
120
121
122
...
1
2
3
4
5
6
7
...
117
118
119
 
 
120
121
122
0
@@ -1,5 +1,7 @@
0
 /* Copyright 2006 Oliver Steele. All rights reserved. */
0
 
0
+var CFDG = window.CFDG || {};
0
+
0
 var canvas;
0
 var ctx;
0
 
0
@@ -115,8 +117,6 @@ Graphics.prototype.setRGBA = function (rgba) {
0
   this.ctx.globalAlpha = rgba[3];
0
 };
0
 
0
-var CFDG = window.CFDG || {};
0
-
0
 CFDG.Driver = {
0
     setup: function(options) {
0
         this.options = options;
...
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
...
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
...
3
4
5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6
7
8
...
286
287
288
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0
@@ -3,24 +3,6 @@
0
 var EOF = -1;
0
 var PUNCTUATION = "()[]{}|;";
0
 
0
-// Flash can't split on regular expressions, or we could split on /\n|\r/
0
-String.prototype.split2 = function (a, b) {
0
- var lines = this.split(a);
0
- for (var i = 0; i < lines.length; i++)
0
- lines.splice.apply(lines, [i, 1].concat(lines[i].split(b)));
0
- return lines;
0
-};
0
-
0
-String.prototype.lines = function () {return this.split2('\r', '\n');};
0
-String.prototype.words = function () {return this.split2(' ', '\t');};
0
-
0
-Array.prototype.include = function (item) {
0
- for (var i = this.length; --i >= 0; )
0
- if (this[i] == item)
0
- return true;
0
- return false;
0
-};
0
-
0
 function lex(text, parser) {
0
     parser = parser || {receive: function (type, token) {info(type, ": '" + token + "'")}};
0
   var lines = text.lines();
0
@@ -304,19 +286,3 @@ Builder.prototype = {
0
     }
0
   }
0
 };
0
-
0
-function parse(string, mode) {
0
- var m = new Model;
0
- var err = lex(string, new Parser(new Builder(m)));
0
- if (err) {
0
- print("cfdg: syntax error at \'" + err.token + "\' on line " + err.lineno + ": " + err.message);
0
- return;
0
- }
0
- if (!mode) print(m.to_s());
0
- var cxt = new Context(m);
0
- if (mode=='draw') m.draw(cxt);
0
-}
0
-
0
-function draw(string) {
0
- return parse(string, 'draw')
0
-}
...
2
3
4
 
5
6
 
7
8
9
...
15
16
17
18
 
19
20
21
...
2
3
4
5
6
7
8
9
10
11
...
17
18
19
 
20
21
22
23
0
@@ -2,8 +2,10 @@ load('parser.js');
0
 load('model.js');
0
 load('graphics.js');
0
 load("drawing.js");
0
+
0
 function info(msg) {print('Info: ' + msg)}
0
 function error(msg) {print('Error: ' + msg)}
0
+
0
 Graphics.prototype.drawPolygon = function (points) {
0
   print("polygon: " + points);
0
 };
0
@@ -15,7 +17,7 @@ function parse(string, mode) {
0
   var m = new Model;
0
   var err = lex(string, new Parser(new Builder(m)));
0
   if (err) {
0
- error("cfdg: syntax error at \'" + err.token + "\' on line " + err.lineno + ": " + err.message);
0
+ print("cfdg: syntax error at \'" + err.token + "\' on line " + err.lineno + ": " + err.message);
0
         return;
0
     }
0
   if (!mode) print(m.to_s());

Comments

    No one has commented yet.