Skip to content
Browse files

refactor pegjs

  • Loading branch information...
1 parent d73f3fa commit a34b78a5718da5103008abd35973aa3a8d073569 @maccman committed Apr 18, 2012
Showing with 44 additions and 70 deletions.
  1. +6 −0 Rakefile
  2. +22 −60 assets/javascripts/app/parsers/css.module.js
  3. +16 −10 assets/javascripts/app/parsers/css.pegjs
View
6 Rakefile
@@ -2,4 +2,10 @@ namespace :macgap do
task :build do
`macgap build --name Stylo ./public`
end
+end
+
+namespace :pegjs do
+ task :build do
+ `pegjs assets/javascripts/app/parsers/css.pegjs assets/javascripts/app/parsers/css.module.js`
+ end
end
View
82 assets/javascripts/app/parsers/css.module.js
@@ -43,11 +43,10 @@ module.exports = (function(){
"shadow": parse_shadow,
"backgroundImage": parse_backgroundImage,
"linearGradient": parse_linearGradient,
- "radialGradient": parse_radialGradient,
"url": parse_url,
- "position": parse_position,
"colorStopList": parse_colorStopList,
"colorStop": parse_colorStop,
+ "position": parse_position,
"positionKeyword": parse_positionKeyword,
"positionKeywordMultiple": parse_positionKeywordMultiple,
"positionKeywordSingle": parse_positionKeywordSingle,
@@ -485,43 +484,6 @@ module.exports = (function(){
return result0;
}
- function parse_radialGradient() {
- var result0, result1;
- var pos0;
-
- pos0 = pos;
- if (input.substr(pos, 16) === "radial-gradient(") {
- result0 = "radial-gradient(";
- pos += 16;
- } else {
- result0 = null;
- if (reportFailures === 0) {
- matchFailed("\"radial-gradient(\"");
- }
- }
- if (result0 !== null) {
- if (input.charCodeAt(pos) === 41) {
- result1 = ")";
- pos++;
- } else {
- result1 = null;
- if (reportFailures === 0) {
- matchFailed("\")\"");
- }
- }
- if (result1 !== null) {
- result0 = [result0, result1];
- } else {
- result0 = null;
- pos = pos0;
- }
- } else {
- result0 = null;
- pos = pos0;
- }
- return result0;
- }
-
function parse_url() {
var result0, result1, result2, result3;
var pos0, pos1, pos2, pos3, pos4;
@@ -672,27 +634,6 @@ module.exports = (function(){
return result0;
}
- function parse_position() {
- var result0;
- var pos0;
-
- pos0 = pos;
- result0 = parse_angle();
- if (result0 === null) {
- result0 = parse_positionKeyword();
- }
- if (result0 !== null) {
- result0 = (function(offset, angle) {
- var Position = require('app/models/properties/background').Position;
- return new Position(angle);
- })(pos0, result0);
- }
- if (result0 === null) {
- pos = pos0;
- }
- return result0;
- }
-
function parse_colorStopList() {
var result0, result1, result2, result3;
var pos0, pos1;
@@ -801,6 +742,27 @@ module.exports = (function(){
return result0;
}
+ function parse_position() {
+ var result0;
+ var pos0;
+
+ pos0 = pos;
+ result0 = parse_angle();
+ if (result0 === null) {
+ result0 = parse_positionKeyword();
+ }
+ if (result0 !== null) {
+ result0 = (function(offset, angle) {
+ var Position = require('app/models/properties/background').Position;
+ return new Position(angle);
+ })(pos0, result0);
+ }
+ if (result0 === null) {
+ pos = pos0;
+ }
+ return result0;
+ }
+
function parse_positionKeyword() {
var result0;
var pos0;
View
26 assets/javascripts/app/parsers/css.pegjs
@@ -48,16 +48,22 @@ shadow
backgroundImage
= linearGradient / url
-// linear-gradient(top left, white, #a6f2c0 30%, rgba(180, 200, 210, .9), black)
+// CSS linear gradient parser
+//
+// Format:
+// linear-gradient(top left, white, #a6f2c0 30%, rgba(180, 200, 210, .9), black)
+//
linearGradient
= "-webkit-"? "linear-gradient(" _ position:(position _)? stops:colorStopList* ")" {
var LinearGradient = require('app/models/properties/background').LinearGradient;
return new LinearGradient(position[0], stops);
}
-radialGradient
- = "radial-gradient(" ")"
-
+// CSS background image url parser
+//
+// Format:
+// url('http://example.com/image.png')
+//
url
= "url(" href:( !")" s:. { return s; })* ")" {
href = href.join('').replace(/["']{1}/gi, "");
@@ -66,12 +72,6 @@ url
return new URL(href);
}
-position
- = angle:(angle / positionKeyword) {
- var Position = require('app/models/properties/background').Position;
- return new Position(angle);
- }
-
colorStopList
= "," _ stop:colorStop _ { return stop }
@@ -83,6 +83,12 @@ colorStop
// Position
+position
+ = angle:(angle / positionKeyword) {
+ var Position = require('app/models/properties/background').Position;
+ return new Position(angle);
+ }
+
positionKeyword
= keywords:(positionKeywordMultiple / positionKeywordSingle) {
var x, y, mapping;

0 comments on commit a34b78a

Please sign in to comment.
Something went wrong with that request. Please try again.