From e4c22c254957638d5a8f9ff376475f4a994c208d Mon Sep 17 00:00:00 2001 From: Roman Hotsiy Date: Tue, 20 Dec 2016 20:27:58 +0200 Subject: [PATCH] Allow for quoted empty strings with double-quotes (fixes #16) --- parser.jison | 1 + parser.js | 18 ++++++++++-------- test/test.js | 3 +++ 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/parser.jison b/parser.jison index 761c4c8..51173c3 100644 --- a/parser.jison +++ b/parser.jison @@ -201,6 +201,7 @@ hsla\(\s*[0-9]+\s*\,\s*[0-9]+\%\s*\,\s*[0-9]+\%\s*\,\s*([0-1]|0?\.[0-9]+)\s*\) [0-9]+("."[0-9]+)?\b return 'NUMBER'; [a-zA-Z0-9-_.]+\b return 'STRING'; \'(\\[^\']|[^\'\\])*\' yytext = yytext.slice(1,-1); return 'STRING'; +\"(\\[^\"]|[^\"\\])*\" yytext = yytext.slice(1,-1); return 'STRING'; "(" return 'LPAREN'; ")" return 'RPAREN'; "==" return 'RELOP'; diff --git a/parser.js b/parser.js index a566df7..2b6bbb7 100644 --- a/parser.js +++ b/parser.js @@ -1,4 +1,4 @@ -/* parser generated by jison 0.4.16 */ +/* parser generated by jison 0.4.17 */ /* Returns a Parser object of the following structure: @@ -179,7 +179,7 @@ parseError: function parseError(str, hash) { this.message = msg; this.hash = hash; } - _parseError.prototype = new Error(); + _parseError.prototype = Error; throw new _parseError(str, hash); } @@ -1045,11 +1045,11 @@ case 196:return 41; break; case 197:yy_.yytext = yy_.yytext.slice(1,-1); return 41; break; -case 198:return 7; +case 198:yy_.yytext = yy_.yytext.slice(1,-1); return 41; break; -case 199:return 8; +case 199:return 7; break; -case 200:return 14; +case 200:return 8; break; case 201:return 14; break; @@ -1061,12 +1061,14 @@ case 204:return 14; break; case 205:return 14; break; -case 206:return 5; +case 206:return 14; +break; +case 207:return 5; break; } }, -rules: [/^(?:\s+)/,/^(?:true\b)/,/^(?:TRUE\b)/,/^(?:false\b)/,/^(?:FALSE\b)/,/^(?:AND\b)/,/^(?:and\b)/,/^(?:OR\b)/,/^(?:or\b)/,/^(?:NOT\b)/,/^(?:not\b)/,/^(?:\*)/,/^(?:\/)/,/^(?:\+)/,/^(?:-)/,/^(?:rgb\(\s*[0-9]+%?\s*,\s*[0-9]+%?\s*,\s*[0-9]+%?\s*\))/,/^(?:hsl\(\s*[0-9]+\s*,\s*[0-9]+%\s*,\s*[0-9]+%\s*\))/,/^(?:rgba\(\s*[0-9]+%?\s*,\s*[0-9]+%?\s*,\s*[0-9]+%?\s*,\s*([0-1]|0?\.[0-9]+)\s*\))/,/^(?:hsla\(\s*[0-9]+\s*,\s*[0-9]+%\s*,\s*[0-9]+%\s*,\s*([0-1]|0?\.[0-9]+)\s*\))/,/^(?:#[0-9a-fA-F]{6}([0-9a-fA-F]{2})?\b)/,/^(?:#[0-9a-fA-F]{3}([0-9a-fA-F])?\b)/,/^(?:aliceblue\b)/,/^(?:antiquewhite\b)/,/^(?:aqua\b)/,/^(?:aquamarine\b)/,/^(?:azure\b)/,/^(?:beige\b)/,/^(?:bisque\b)/,/^(?:black\b)/,/^(?:blanchedalmond\b)/,/^(?:blue\b)/,/^(?:blueviolet\b)/,/^(?:brown\b)/,/^(?:burlywood\b)/,/^(?:cadetblue\b)/,/^(?:chartreuse\b)/,/^(?:chocolate\b)/,/^(?:coral\b)/,/^(?:cornflowerblue\b)/,/^(?:cornsilk\b)/,/^(?:crimson\b)/,/^(?:cyan\b)/,/^(?:darkblue\b)/,/^(?:darkcyan\b)/,/^(?:darkgoldenrod\b)/,/^(?:darkgray\b)/,/^(?:darkgreen\b)/,/^(?:darkgrey\b)/,/^(?:darkkhaki\b)/,/^(?:darkmagenta\b)/,/^(?:darkolivegreen\b)/,/^(?:darkorange\b)/,/^(?:darkorchid\b)/,/^(?:darkred\b)/,/^(?:darksalmon\b)/,/^(?:darkseagreen\b)/,/^(?:darkslateblue\b)/,/^(?:darkslategray\b)/,/^(?:darkslategrey\b)/,/^(?:darkturquoise\b)/,/^(?:darkviolet\b)/,/^(?:deeppink\b)/,/^(?:deepskyblue\b)/,/^(?:dimgray\b)/,/^(?:dimgrey\b)/,/^(?:dodgerblue\b)/,/^(?:firebrick\b)/,/^(?:floralwhite\b)/,/^(?:forestgreen\b)/,/^(?:fuchsia\b)/,/^(?:gainsboro\b)/,/^(?:ghostwhite\b)/,/^(?:gold\b)/,/^(?:goldenrod\b)/,/^(?:gray\b)/,/^(?:green\b)/,/^(?:greenyellow\b)/,/^(?:grey\b)/,/^(?:honeydew\b)/,/^(?:hotpink\b)/,/^(?:indianred\b)/,/^(?:indigo\b)/,/^(?:ivory\b)/,/^(?:khaki\b)/,/^(?:lavender\b)/,/^(?:lavenderblush\b)/,/^(?:lawngreen\b)/,/^(?:lemonchiffon\b)/,/^(?:lightblue\b)/,/^(?:lightcoral\b)/,/^(?:lightcyan\b)/,/^(?:lightgoldenrodyellow\b)/,/^(?:lightgray\b)/,/^(?:lightgreen\b)/,/^(?:lightgrey\b)/,/^(?:lightpink\b)/,/^(?:lightsalmon\b)/,/^(?:lightseagreen\b)/,/^(?:lightskyblue\b)/,/^(?:lightslategray\b)/,/^(?:lightslategrey\b)/,/^(?:lightsteelblue\b)/,/^(?:lightyellow\b)/,/^(?:lime\b)/,/^(?:limegreen\b)/,/^(?:linen\b)/,/^(?:magenta\b)/,/^(?:maroon\b)/,/^(?:mediumaquamarine\b)/,/^(?:mediumblue\b)/,/^(?:mediumorchid\b)/,/^(?:mediumpurple\b)/,/^(?:mediumseagreen\b)/,/^(?:mediumslateblue\b)/,/^(?:mediumspringgreen\b)/,/^(?:mediumturquoise\b)/,/^(?:mediumvioletred\b)/,/^(?:midnightblue\b)/,/^(?:mintcream\b)/,/^(?:mistyrose\b)/,/^(?:moccasin\b)/,/^(?:navajowhite\b)/,/^(?:navy\b)/,/^(?:oldlace\b)/,/^(?:olive\b)/,/^(?:olivedrab\b)/,/^(?:orange\b)/,/^(?:orangered\b)/,/^(?:orchid\b)/,/^(?:palegoldenrod\b)/,/^(?:palegreen\b)/,/^(?:paleturquoise\b)/,/^(?:palevioletred\b)/,/^(?:papayawhip\b)/,/^(?:peachpuff\b)/,/^(?:peru\b)/,/^(?:pink\b)/,/^(?:plum\b)/,/^(?:powderblue\b)/,/^(?:purple\b)/,/^(?:rebeccapurple\b)/,/^(?:red\b)/,/^(?:rosybrown\b)/,/^(?:royalblue\b)/,/^(?:saddlebrown\b)/,/^(?:salmon\b)/,/^(?:sandybrown\b)/,/^(?:seagreen\b)/,/^(?:seashell\b)/,/^(?:sienna\b)/,/^(?:silver\b)/,/^(?:skyblue\b)/,/^(?:slateblue\b)/,/^(?:slategray\b)/,/^(?:slategrey\b)/,/^(?:snow\b)/,/^(?:springgreen\b)/,/^(?:steelblue\b)/,/^(?:tan\b)/,/^(?:teal\b)/,/^(?:thistle\b)/,/^(?:tomato\b)/,/^(?:turquoise\b)/,/^(?:violet\b)/,/^(?:wheat\b)/,/^(?:white\b)/,/^(?:whitesmoke\b)/,/^(?:yellow\b)/,/^(?:yellowgreen\b)/,/^(?:[0-9]+(\.[0-9]+)?px\b)/,/^(?:[0-9]+(\.[0-9]+)?cm\b)/,/^(?:[0-9]+(\.[0-9]+)?mm\b)/,/^(?:[0-9]+(\.[0-9]+)?in\b)/,/^(?:[0-9]+(\.[0-9]+)?pt\b)/,/^(?:[0-9]+(\.[0-9]+)?pc\b)/,/^(?:[0-9]+(\.[0-9]+)?deg\b)/,/^(?:[0-9]+(\.[0-9]+)?grad\b)/,/^(?:[0-9]+(\.[0-9]+)?rad\b)/,/^(?:[0-9]+(\.[0-9]+)?turn\b)/,/^(?:[0-9]+(\.[0-9]+)?s\b)/,/^(?:[0-9]+(\.[0-9]+)?ms\b)/,/^(?:[0-9]+(\.[0-9]+)?Hz\b)/,/^(?:[0-9]+(\.[0-9]+)?kHz\b)/,/^(?:[0-9]+(\.[0-9]+)?dpi\b)/,/^(?:[0-9]+(\.[0-9]+)?dpcm\b)/,/^(?:[0-9]+(\.[0-9]+)?dppx\b)/,/^(?:[0-9]+(\.[0-9]+)?em\b)/,/^(?:[0-9]+(\.[0-9]+)?ex\b)/,/^(?:[0-9]+(\.[0-9]+)?ch\b)/,/^(?:[0-9]+(\.[0-9]+)?rem\b)/,/^(?:[0-9]+(\.[0-9]+)?vw\b)/,/^(?:[0-9]+(\.[0-9]+)?vh\b)/,/^(?:[0-9]+(\.[0-9]+)?vmin\b)/,/^(?:[0-9]+(\.[0-9]+)?vmax\b)/,/^(?:[0-9]+(\.[0-9]+)?%)/,/^(?:[0-9]+(\.[0-9]+)?\b)/,/^(?:[a-zA-Z0-9-_.]+\b)/,/^(?:'(\\[^\']|[^\'\\])*')/,/^(?:\()/,/^(?:\))/,/^(?:==)/,/^(?:!=)/,/^(?:>=)/,/^(?:>)/,/^(?:<=)/,/^(?:<)/,/^(?:$)/], -conditions: {"INITIAL":{"rules":[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,123,124,125,126,127,128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143,144,145,146,147,148,149,150,151,152,153,154,155,156,157,158,159,160,161,162,163,164,165,166,167,168,169,170,171,172,173,174,175,176,177,178,179,180,181,182,183,184,185,186,187,188,189,190,191,192,193,194,195,196,197,198,199,200,201,202,203,204,205,206],"inclusive":true}} +rules: [/^(?:\s+)/,/^(?:true\b)/,/^(?:TRUE\b)/,/^(?:false\b)/,/^(?:FALSE\b)/,/^(?:AND\b)/,/^(?:and\b)/,/^(?:OR\b)/,/^(?:or\b)/,/^(?:NOT\b)/,/^(?:not\b)/,/^(?:\*)/,/^(?:\/)/,/^(?:\+)/,/^(?:-)/,/^(?:rgb\(\s*[0-9]+%?\s*,\s*[0-9]+%?\s*,\s*[0-9]+%?\s*\))/,/^(?:hsl\(\s*[0-9]+\s*,\s*[0-9]+%\s*,\s*[0-9]+%\s*\))/,/^(?:rgba\(\s*[0-9]+%?\s*,\s*[0-9]+%?\s*,\s*[0-9]+%?\s*,\s*([0-1]|0?\.[0-9]+)\s*\))/,/^(?:hsla\(\s*[0-9]+\s*,\s*[0-9]+%\s*,\s*[0-9]+%\s*,\s*([0-1]|0?\.[0-9]+)\s*\))/,/^(?:#[0-9a-fA-F]{6}([0-9a-fA-F]{2})?\b)/,/^(?:#[0-9a-fA-F]{3}([0-9a-fA-F])?\b)/,/^(?:aliceblue\b)/,/^(?:antiquewhite\b)/,/^(?:aqua\b)/,/^(?:aquamarine\b)/,/^(?:azure\b)/,/^(?:beige\b)/,/^(?:bisque\b)/,/^(?:black\b)/,/^(?:blanchedalmond\b)/,/^(?:blue\b)/,/^(?:blueviolet\b)/,/^(?:brown\b)/,/^(?:burlywood\b)/,/^(?:cadetblue\b)/,/^(?:chartreuse\b)/,/^(?:chocolate\b)/,/^(?:coral\b)/,/^(?:cornflowerblue\b)/,/^(?:cornsilk\b)/,/^(?:crimson\b)/,/^(?:cyan\b)/,/^(?:darkblue\b)/,/^(?:darkcyan\b)/,/^(?:darkgoldenrod\b)/,/^(?:darkgray\b)/,/^(?:darkgreen\b)/,/^(?:darkgrey\b)/,/^(?:darkkhaki\b)/,/^(?:darkmagenta\b)/,/^(?:darkolivegreen\b)/,/^(?:darkorange\b)/,/^(?:darkorchid\b)/,/^(?:darkred\b)/,/^(?:darksalmon\b)/,/^(?:darkseagreen\b)/,/^(?:darkslateblue\b)/,/^(?:darkslategray\b)/,/^(?:darkslategrey\b)/,/^(?:darkturquoise\b)/,/^(?:darkviolet\b)/,/^(?:deeppink\b)/,/^(?:deepskyblue\b)/,/^(?:dimgray\b)/,/^(?:dimgrey\b)/,/^(?:dodgerblue\b)/,/^(?:firebrick\b)/,/^(?:floralwhite\b)/,/^(?:forestgreen\b)/,/^(?:fuchsia\b)/,/^(?:gainsboro\b)/,/^(?:ghostwhite\b)/,/^(?:gold\b)/,/^(?:goldenrod\b)/,/^(?:gray\b)/,/^(?:green\b)/,/^(?:greenyellow\b)/,/^(?:grey\b)/,/^(?:honeydew\b)/,/^(?:hotpink\b)/,/^(?:indianred\b)/,/^(?:indigo\b)/,/^(?:ivory\b)/,/^(?:khaki\b)/,/^(?:lavender\b)/,/^(?:lavenderblush\b)/,/^(?:lawngreen\b)/,/^(?:lemonchiffon\b)/,/^(?:lightblue\b)/,/^(?:lightcoral\b)/,/^(?:lightcyan\b)/,/^(?:lightgoldenrodyellow\b)/,/^(?:lightgray\b)/,/^(?:lightgreen\b)/,/^(?:lightgrey\b)/,/^(?:lightpink\b)/,/^(?:lightsalmon\b)/,/^(?:lightseagreen\b)/,/^(?:lightskyblue\b)/,/^(?:lightslategray\b)/,/^(?:lightslategrey\b)/,/^(?:lightsteelblue\b)/,/^(?:lightyellow\b)/,/^(?:lime\b)/,/^(?:limegreen\b)/,/^(?:linen\b)/,/^(?:magenta\b)/,/^(?:maroon\b)/,/^(?:mediumaquamarine\b)/,/^(?:mediumblue\b)/,/^(?:mediumorchid\b)/,/^(?:mediumpurple\b)/,/^(?:mediumseagreen\b)/,/^(?:mediumslateblue\b)/,/^(?:mediumspringgreen\b)/,/^(?:mediumturquoise\b)/,/^(?:mediumvioletred\b)/,/^(?:midnightblue\b)/,/^(?:mintcream\b)/,/^(?:mistyrose\b)/,/^(?:moccasin\b)/,/^(?:navajowhite\b)/,/^(?:navy\b)/,/^(?:oldlace\b)/,/^(?:olive\b)/,/^(?:olivedrab\b)/,/^(?:orange\b)/,/^(?:orangered\b)/,/^(?:orchid\b)/,/^(?:palegoldenrod\b)/,/^(?:palegreen\b)/,/^(?:paleturquoise\b)/,/^(?:palevioletred\b)/,/^(?:papayawhip\b)/,/^(?:peachpuff\b)/,/^(?:peru\b)/,/^(?:pink\b)/,/^(?:plum\b)/,/^(?:powderblue\b)/,/^(?:purple\b)/,/^(?:rebeccapurple\b)/,/^(?:red\b)/,/^(?:rosybrown\b)/,/^(?:royalblue\b)/,/^(?:saddlebrown\b)/,/^(?:salmon\b)/,/^(?:sandybrown\b)/,/^(?:seagreen\b)/,/^(?:seashell\b)/,/^(?:sienna\b)/,/^(?:silver\b)/,/^(?:skyblue\b)/,/^(?:slateblue\b)/,/^(?:slategray\b)/,/^(?:slategrey\b)/,/^(?:snow\b)/,/^(?:springgreen\b)/,/^(?:steelblue\b)/,/^(?:tan\b)/,/^(?:teal\b)/,/^(?:thistle\b)/,/^(?:tomato\b)/,/^(?:turquoise\b)/,/^(?:violet\b)/,/^(?:wheat\b)/,/^(?:white\b)/,/^(?:whitesmoke\b)/,/^(?:yellow\b)/,/^(?:yellowgreen\b)/,/^(?:[0-9]+(\.[0-9]+)?px\b)/,/^(?:[0-9]+(\.[0-9]+)?cm\b)/,/^(?:[0-9]+(\.[0-9]+)?mm\b)/,/^(?:[0-9]+(\.[0-9]+)?in\b)/,/^(?:[0-9]+(\.[0-9]+)?pt\b)/,/^(?:[0-9]+(\.[0-9]+)?pc\b)/,/^(?:[0-9]+(\.[0-9]+)?deg\b)/,/^(?:[0-9]+(\.[0-9]+)?grad\b)/,/^(?:[0-9]+(\.[0-9]+)?rad\b)/,/^(?:[0-9]+(\.[0-9]+)?turn\b)/,/^(?:[0-9]+(\.[0-9]+)?s\b)/,/^(?:[0-9]+(\.[0-9]+)?ms\b)/,/^(?:[0-9]+(\.[0-9]+)?Hz\b)/,/^(?:[0-9]+(\.[0-9]+)?kHz\b)/,/^(?:[0-9]+(\.[0-9]+)?dpi\b)/,/^(?:[0-9]+(\.[0-9]+)?dpcm\b)/,/^(?:[0-9]+(\.[0-9]+)?dppx\b)/,/^(?:[0-9]+(\.[0-9]+)?em\b)/,/^(?:[0-9]+(\.[0-9]+)?ex\b)/,/^(?:[0-9]+(\.[0-9]+)?ch\b)/,/^(?:[0-9]+(\.[0-9]+)?rem\b)/,/^(?:[0-9]+(\.[0-9]+)?vw\b)/,/^(?:[0-9]+(\.[0-9]+)?vh\b)/,/^(?:[0-9]+(\.[0-9]+)?vmin\b)/,/^(?:[0-9]+(\.[0-9]+)?vmax\b)/,/^(?:[0-9]+(\.[0-9]+)?%)/,/^(?:[0-9]+(\.[0-9]+)?\b)/,/^(?:[a-zA-Z0-9-_.]+\b)/,/^(?:'(\\[^\']|[^\'\\])*')/,/^(?:"(\\[^\"]|[^\"\\])*")/,/^(?:\()/,/^(?:\))/,/^(?:==)/,/^(?:!=)/,/^(?:>=)/,/^(?:>)/,/^(?:<=)/,/^(?:<)/,/^(?:$)/], +conditions: {"INITIAL":{"rules":[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,123,124,125,126,127,128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143,144,145,146,147,148,149,150,151,152,153,154,155,156,157,158,159,160,161,162,163,164,165,166,167,168,169,170,171,172,173,174,175,176,177,178,179,180,181,182,183,184,185,186,187,188,189,190,191,192,193,194,195,196,197,198,199,200,201,202,203,204,205,206,207],"inclusive":true}} }); return lexer; })(); diff --git a/test/test.js b/test/test.js index 8fbae76..0035086 100644 --- a/test/test.js +++ b/test/test.js @@ -85,6 +85,9 @@ test('@if true { foo: bar } @else if false { bar: baz } @else { bat: quux }', 'f test('@if false { foo: bar } @else if true { bar: baz } @else { bat: quux }', 'bar: baz'); test('@if false { foo: bar } @else if false { bar: baz } @else { bat: quux }', 'bat: quux'); test('@if \'\' == \'\' { foo: bar }', 'foo: bar'); +test('@if "" == "" { foo: bar }', 'foo: bar'); +test('@if \'\' == "" { foo: bar }', 'foo: bar'); +test('@if "" == \'\' { foo: bar }', 'foo: bar'); test('@if \'foo\\bar\' == \'foo\\bar\' { foo: bar }', 'foo: bar'); test('@if .foo == .foo { foo: bar }', 'foo: bar'); test('@if .foo == .bar { foo: bar }', '');