From e0c66ccf9bdccb4f3a5f28d90ddcbc68a605bb19 Mon Sep 17 00:00:00 2001
From: Matt
Date: Tue, 7 Jun 2016 12:31:18 -0400
Subject: [PATCH 1/2] Added latest version of scssphp.
---
lib/scssphp/.gitignore | 6 -
lib/scssphp/.travis.yml | 10 -
lib/scssphp/LICENSE.md | 642 +--
lib/scssphp/Makefile | 2 -
lib/scssphp/README.md | 33 +-
lib/scssphp/bin/pscss | 200 +-
lib/scssphp/classmap.php | 62 -
lib/scssphp/composer.json | 25 +-
lib/scssphp/package.sh | 24 -
lib/scssphp/phpunit.xml.dist | 29 -
lib/scssphp/scss.inc.php | 39 +-
lib/scssphp/site/.gitignore | 2 -
lib/scssphp/site/composer.html | 6 -
lib/scssphp/site/docs/index.md | 325 --
lib/scssphp/site/index.md | 233 -
lib/scssphp/site/site.moon | 15 -
lib/scssphp/site/style.scss | 303 --
lib/scssphp/site/templates/index.html | 81 -
lib/scssphp/site/www/.gitignore | 2 -
lib/scssphp/site/www/img/tile.png | Bin 244 -> 0 bytes
lib/scssphp/site/www/style/normalize.css | 500 --
lib/scssphp/src/Base/Range.php | 47 +
lib/scssphp/src/Block.php | 60 +
lib/scssphp/src/Colors.php | 16 +-
lib/scssphp/src/Compiler.php | 4221 ++++++++++++-----
lib/scssphp/src/Compiler/Environment.php | 40 +
.../src/Exception/CompilerException.php | 21 +
lib/scssphp/src/Exception/ParserException.php | 21 +
lib/scssphp/src/Exception/ServerException.php | 21 +
lib/scssphp/src/Formatter.php | 169 +-
lib/scssphp/src/Formatter/Compact.php | 45 +
lib/scssphp/src/Formatter/Compressed.php | 26 +-
lib/scssphp/src/Formatter/Crunched.php | 26 +-
lib/scssphp/src/Formatter/Debug.php | 119 +
lib/scssphp/src/Formatter/Expanded.php | 42 +-
lib/scssphp/src/Formatter/Nested.php | 185 +-
lib/scssphp/src/Formatter/OutputBlock.php | 50 +
lib/scssphp/src/Node.php | 40 +
lib/scssphp/src/Node/Number.php | 329 ++
lib/scssphp/src/Parser.php | 1741 ++++---
lib/scssphp/src/Server.php | 210 +-
lib/scssphp/src/Type.php | 69 +
lib/scssphp/src/Util.php | 55 +
lib/scssphp/src/Version.php | 22 +
lib/scssphp/tests/ApiTest.php | 82 -
lib/scssphp/tests/ExceptionTest.php | 93 -
lib/scssphp/tests/InputTest.php | 98 -
lib/scssphp/tests/compare-scss.sh | 25 -
lib/scssphp/tests/inputs/builtins.scss | 171 -
lib/scssphp/tests/inputs/comments.scss | 44 -
lib/scssphp/tests/inputs/compass_extract.scss | 248 -
lib/scssphp/tests/inputs/content.scss | 61 -
.../tests/inputs/content_with_function.scss | 17 -
lib/scssphp/tests/inputs/default_args.scss | 15 -
lib/scssphp/tests/inputs/directives.scss | 108 -
lib/scssphp/tests/inputs/extends.scss | 184 -
lib/scssphp/tests/inputs/filter_effects.scss | 48 -
lib/scssphp/tests/inputs/functions.scss | 89 -
lib/scssphp/tests/inputs/ie7.scss | 12 -
lib/scssphp/tests/inputs/if.scss | 76 -
lib/scssphp/tests/inputs/if_on_null.scss | 8 -
lib/scssphp/tests/inputs/import.scss | 23 -
.../tests/inputs/imports/_partial.scss | 10 -
lib/scssphp/tests/inputs/imports/simple.scss | 4 -
lib/scssphp/tests/inputs/interpolation.scss | 86 -
lib/scssphp/tests/inputs/keyword_args.scss | 24 -
lib/scssphp/tests/inputs/list.scss | 15 -
lib/scssphp/tests/inputs/looping.scss | 51 -
lib/scssphp/tests/inputs/media.scss | 208 -
lib/scssphp/tests/inputs/mixins.scss | 183 -
lib/scssphp/tests/inputs/nesting.scss | 45 -
lib/scssphp/tests/inputs/null.scss | 41 -
lib/scssphp/tests/inputs/operators.scss | 143 -
.../tests/inputs/parsing_comments.scss | 59 -
.../tests/inputs/placeholder_selector.scss | 18 -
lib/scssphp/tests/inputs/scss_css.scss | 986 ----
lib/scssphp/tests/inputs/selectors.scss | 195 -
lib/scssphp/tests/inputs/values.scss | 43 -
lib/scssphp/tests/inputs/variables.scss | 56 -
lib/scssphp/tests/outputs/builtins.css | 126 -
lib/scssphp/tests/outputs/comments.css | 31 -
lib/scssphp/tests/outputs/compass_extract.css | 28 -
lib/scssphp/tests/outputs/content.css | 29 -
.../tests/outputs/content_with_function.css | 2 -
lib/scssphp/tests/outputs/default_args.css | 3 -
lib/scssphp/tests/outputs/directives.css | 77 -
lib/scssphp/tests/outputs/extends.css | 87 -
lib/scssphp/tests/outputs/filter_effects.css | 20 -
lib/scssphp/tests/outputs/functions.css | 25 -
lib/scssphp/tests/outputs/ie7.css | 8 -
lib/scssphp/tests/outputs/if.css | 21 -
lib/scssphp/tests/outputs/if_on_null.css | 2 -
lib/scssphp/tests/outputs/import.css | 27 -
lib/scssphp/tests/outputs/interpolation.css | 54 -
lib/scssphp/tests/outputs/keyword_args.css | 6 -
lib/scssphp/tests/outputs/list.css | 7 -
lib/scssphp/tests/outputs/looping.css | 45 -
lib/scssphp/tests/outputs/media.css | 103 -
lib/scssphp/tests/outputs/mixins.css | 93 -
lib/scssphp/tests/outputs/nesting.css | 22 -
lib/scssphp/tests/outputs/null.css | 21 -
lib/scssphp/tests/outputs/operators.css | 105 -
.../tests/outputs/parsing_comments.css | 50 -
.../tests/outputs/placeholder_selector.css | 7 -
lib/scssphp/tests/outputs/scss_css.css | 771 ---
lib/scssphp/tests/outputs/selectors.css | 341 --
lib/scssphp/tests/outputs/values.css | 34 -
lib/scssphp/tests/outputs/variables.css | 24 -
lib/scssphp/todo | 47 -
109 files changed, 6048 insertions(+), 9851 deletions(-)
delete mode 100755 lib/scssphp/.gitignore
delete mode 100755 lib/scssphp/.travis.yml
delete mode 100755 lib/scssphp/Makefile
delete mode 100755 lib/scssphp/classmap.php
delete mode 100755 lib/scssphp/package.sh
delete mode 100755 lib/scssphp/phpunit.xml.dist
delete mode 100755 lib/scssphp/site/.gitignore
delete mode 100755 lib/scssphp/site/composer.html
delete mode 100755 lib/scssphp/site/docs/index.md
delete mode 100755 lib/scssphp/site/index.md
delete mode 100755 lib/scssphp/site/site.moon
delete mode 100755 lib/scssphp/site/style.scss
delete mode 100755 lib/scssphp/site/templates/index.html
delete mode 100755 lib/scssphp/site/www/.gitignore
delete mode 100755 lib/scssphp/site/www/img/tile.png
delete mode 100755 lib/scssphp/site/www/style/normalize.css
create mode 100755 lib/scssphp/src/Base/Range.php
create mode 100755 lib/scssphp/src/Block.php
create mode 100755 lib/scssphp/src/Compiler/Environment.php
create mode 100755 lib/scssphp/src/Exception/CompilerException.php
create mode 100755 lib/scssphp/src/Exception/ParserException.php
create mode 100755 lib/scssphp/src/Exception/ServerException.php
create mode 100755 lib/scssphp/src/Formatter/Compact.php
create mode 100755 lib/scssphp/src/Formatter/Debug.php
create mode 100755 lib/scssphp/src/Formatter/OutputBlock.php
create mode 100755 lib/scssphp/src/Node.php
create mode 100755 lib/scssphp/src/Node/Number.php
create mode 100755 lib/scssphp/src/Type.php
create mode 100755 lib/scssphp/src/Util.php
create mode 100755 lib/scssphp/src/Version.php
delete mode 100755 lib/scssphp/tests/ApiTest.php
delete mode 100755 lib/scssphp/tests/ExceptionTest.php
delete mode 100755 lib/scssphp/tests/InputTest.php
delete mode 100755 lib/scssphp/tests/compare-scss.sh
delete mode 100755 lib/scssphp/tests/inputs/builtins.scss
delete mode 100755 lib/scssphp/tests/inputs/comments.scss
delete mode 100755 lib/scssphp/tests/inputs/compass_extract.scss
delete mode 100755 lib/scssphp/tests/inputs/content.scss
delete mode 100755 lib/scssphp/tests/inputs/content_with_function.scss
delete mode 100755 lib/scssphp/tests/inputs/default_args.scss
delete mode 100755 lib/scssphp/tests/inputs/directives.scss
delete mode 100755 lib/scssphp/tests/inputs/extends.scss
delete mode 100755 lib/scssphp/tests/inputs/filter_effects.scss
delete mode 100755 lib/scssphp/tests/inputs/functions.scss
delete mode 100755 lib/scssphp/tests/inputs/ie7.scss
delete mode 100755 lib/scssphp/tests/inputs/if.scss
delete mode 100755 lib/scssphp/tests/inputs/if_on_null.scss
delete mode 100755 lib/scssphp/tests/inputs/import.scss
delete mode 100755 lib/scssphp/tests/inputs/imports/_partial.scss
delete mode 100755 lib/scssphp/tests/inputs/imports/simple.scss
delete mode 100755 lib/scssphp/tests/inputs/interpolation.scss
delete mode 100755 lib/scssphp/tests/inputs/keyword_args.scss
delete mode 100755 lib/scssphp/tests/inputs/list.scss
delete mode 100755 lib/scssphp/tests/inputs/looping.scss
delete mode 100755 lib/scssphp/tests/inputs/media.scss
delete mode 100755 lib/scssphp/tests/inputs/mixins.scss
delete mode 100755 lib/scssphp/tests/inputs/nesting.scss
delete mode 100755 lib/scssphp/tests/inputs/null.scss
delete mode 100755 lib/scssphp/tests/inputs/operators.scss
delete mode 100755 lib/scssphp/tests/inputs/parsing_comments.scss
delete mode 100755 lib/scssphp/tests/inputs/placeholder_selector.scss
delete mode 100755 lib/scssphp/tests/inputs/scss_css.scss
delete mode 100755 lib/scssphp/tests/inputs/selectors.scss
delete mode 100755 lib/scssphp/tests/inputs/values.scss
delete mode 100755 lib/scssphp/tests/inputs/variables.scss
delete mode 100755 lib/scssphp/tests/outputs/builtins.css
delete mode 100755 lib/scssphp/tests/outputs/comments.css
delete mode 100755 lib/scssphp/tests/outputs/compass_extract.css
delete mode 100755 lib/scssphp/tests/outputs/content.css
delete mode 100755 lib/scssphp/tests/outputs/content_with_function.css
delete mode 100755 lib/scssphp/tests/outputs/default_args.css
delete mode 100755 lib/scssphp/tests/outputs/directives.css
delete mode 100755 lib/scssphp/tests/outputs/extends.css
delete mode 100755 lib/scssphp/tests/outputs/filter_effects.css
delete mode 100755 lib/scssphp/tests/outputs/functions.css
delete mode 100755 lib/scssphp/tests/outputs/ie7.css
delete mode 100755 lib/scssphp/tests/outputs/if.css
delete mode 100755 lib/scssphp/tests/outputs/if_on_null.css
delete mode 100755 lib/scssphp/tests/outputs/import.css
delete mode 100755 lib/scssphp/tests/outputs/interpolation.css
delete mode 100755 lib/scssphp/tests/outputs/keyword_args.css
delete mode 100755 lib/scssphp/tests/outputs/list.css
delete mode 100755 lib/scssphp/tests/outputs/looping.css
delete mode 100755 lib/scssphp/tests/outputs/media.css
delete mode 100755 lib/scssphp/tests/outputs/mixins.css
delete mode 100755 lib/scssphp/tests/outputs/nesting.css
delete mode 100755 lib/scssphp/tests/outputs/null.css
delete mode 100755 lib/scssphp/tests/outputs/operators.css
delete mode 100755 lib/scssphp/tests/outputs/parsing_comments.css
delete mode 100755 lib/scssphp/tests/outputs/placeholder_selector.css
delete mode 100755 lib/scssphp/tests/outputs/scss_css.css
delete mode 100755 lib/scssphp/tests/outputs/selectors.css
delete mode 100755 lib/scssphp/tests/outputs/values.css
delete mode 100755 lib/scssphp/tests/outputs/variables.css
delete mode 100755 lib/scssphp/todo
diff --git a/lib/scssphp/.gitignore b/lib/scssphp/.gitignore
deleted file mode 100755
index 6eec948..0000000
--- a/lib/scssphp/.gitignore
+++ /dev/null
@@ -1,6 +0,0 @@
-/*.scss
-/*.css
-.sass-cache
-/sass/
-/compass/
-/vendor/
diff --git a/lib/scssphp/.travis.yml b/lib/scssphp/.travis.yml
deleted file mode 100755
index 4d069b5..0000000
--- a/lib/scssphp/.travis.yml
+++ /dev/null
@@ -1,10 +0,0 @@
-language: php
-
-php:
- - 5.3
- - 5.4
- - 5.5
-# - hhvm
-
-script:
- - phpunit tests
diff --git a/lib/scssphp/LICENSE.md b/lib/scssphp/LICENSE.md
index c0600e1..2f5412f 100755
--- a/lib/scssphp/LICENSE.md
+++ b/lib/scssphp/LICENSE.md
@@ -1,15 +1,4 @@
-For ease of distribution, scssphp is available under a dual license.
-You are free to pick which one suits your needs.
-
-* * *
-
-
-MIT LICENSE
-
-
-
-
-Copyright (c) 2012 Leaf Corcoran, http://leafo.net/scssphp
+Copyright (c) 2015 Leaf Corcoran, http://leafo.github.io/scssphp
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
@@ -29,632 +18,3 @@ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-
-* * *
-
-
-GPL VERSION 3
-
-
-
-
- GNU GENERAL PUBLIC LICENSE
- Version 3, 29 June 2007
-
- Copyright (C) 2007 Free Software Foundation, Inc.
- Everyone is permitted to copy and distribute verbatim copies
- of this license document, but changing it is not allowed.
-
- Preamble
-
- The GNU General Public License is a free, copyleft license for
-software and other kinds of works.
-
- The licenses for most software and other practical works are designed
-to take away your freedom to share and change the works. By contrast,
-the GNU General Public License is intended to guarantee your freedom to
-share and change all versions of a program--to make sure it remains free
-software for all its users. We, the Free Software Foundation, use the
-GNU General Public License for most of our software; it applies also to
-any other work released this way by its authors. You can apply it to
-your programs, too.
-
- When we speak of free software, we are referring to freedom, not
-price. Our General Public Licenses are designed to make sure that you
-have the freedom to distribute copies of free software (and charge for
-them if you wish), that you receive source code or can get it if you
-want it, that you can change the software or use pieces of it in new
-free programs, and that you know you can do these things.
-
- To protect your rights, we need to prevent others from denying you
-these rights or asking you to surrender the rights. Therefore, you have
-certain responsibilities if you distribute copies of the software, or if
-you modify it: responsibilities to respect the freedom of others.
-
- For example, if you distribute copies of such a program, whether
-gratis or for a fee, you must pass on to the recipients the same
-freedoms that you received. You must make sure that they, too, receive
-or can get the source code. And you must show them these terms so they
-know their rights.
-
- Developers that use the GNU GPL protect your rights with two steps:
-(1) assert copyright on the software, and (2) offer you this License
-giving you legal permission to copy, distribute and/or modify it.
-
- For the developers' and authors' protection, the GPL clearly explains
-that there is no warranty for this free software. For both users' and
-authors' sake, the GPL requires that modified versions be marked as
-changed, so that their problems will not be attributed erroneously to
-authors of previous versions.
-
- Some devices are designed to deny users access to install or run
-modified versions of the software inside them, although the manufacturer
-can do so. This is fundamentally incompatible with the aim of
-protecting users' freedom to change the software. The systematic
-pattern of such abuse occurs in the area of products for individuals to
-use, which is precisely where it is most unacceptable. Therefore, we
-have designed this version of the GPL to prohibit the practice for those
-products. If such problems arise substantially in other domains, we
-stand ready to extend this provision to those domains in future versions
-of the GPL, as needed to protect the freedom of users.
-
- Finally, every program is threatened constantly by software patents.
-States should not allow patents to restrict development and use of
-software on general-purpose computers, but in those that do, we wish to
-avoid the special danger that patents applied to a free program could
-make it effectively proprietary. To prevent this, the GPL assures that
-patents cannot be used to render the program non-free.
-
- The precise terms and conditions for copying, distribution and
-modification follow.
-
- TERMS AND CONDITIONS
-
- 0. Definitions.
-
- "This License" refers to version 3 of the GNU General Public License.
-
- "Copyright" also means copyright-like laws that apply to other kinds of
-works, such as semiconductor masks.
-
- "The Program" refers to any copyrightable work licensed under this
-License. Each licensee is addressed as "you". "Licensees" and
-"recipients" may be individuals or organizations.
-
- To "modify" a work means to copy from or adapt all or part of the work
-in a fashion requiring copyright permission, other than the making of an
-exact copy. The resulting work is called a "modified version" of the
-earlier work or a work "based on" the earlier work.
-
- A "covered work" means either the unmodified Program or a work based
-on the Program.
-
- To "propagate" a work means to do anything with it that, without
-permission, would make you directly or secondarily liable for
-infringement under applicable copyright law, except executing it on a
-computer or modifying a private copy. Propagation includes copying,
-distribution (with or without modification), making available to the
-public, and in some countries other activities as well.
-
- To "convey" a work means any kind of propagation that enables other
-parties to make or receive copies. Mere interaction with a user through
-a computer network, with no transfer of a copy, is not conveying.
-
- An interactive user interface displays "Appropriate Legal Notices"
-to the extent that it includes a convenient and prominently visible
-feature that (1) displays an appropriate copyright notice, and (2)
-tells the user that there is no warranty for the work (except to the
-extent that warranties are provided), that licensees may convey the
-work under this License, and how to view a copy of this License. If
-the interface presents a list of user commands or options, such as a
-menu, a prominent item in the list meets this criterion.
-
- 1. Source Code.
-
- The "source code" for a work means the preferred form of the work
-for making modifications to it. "Object code" means any non-source
-form of a work.
-
- A "Standard Interface" means an interface that either is an official
-standard defined by a recognized standards body, or, in the case of
-interfaces specified for a particular programming language, one that
-is widely used among developers working in that language.
-
- The "System Libraries" of an executable work include anything, other
-than the work as a whole, that (a) is included in the normal form of
-packaging a Major Component, but which is not part of that Major
-Component, and (b) serves only to enable use of the work with that
-Major Component, or to implement a Standard Interface for which an
-implementation is available to the public in source code form. A
-"Major Component", in this context, means a major essential component
-(kernel, window system, and so on) of the specific operating system
-(if any) on which the executable work runs, or a compiler used to
-produce the work, or an object code interpreter used to run it.
-
- The "Corresponding Source" for a work in object code form means all
-the source code needed to generate, install, and (for an executable
-work) run the object code and to modify the work, including scripts to
-control those activities. However, it does not include the work's
-System Libraries, or general-purpose tools or generally available free
-programs which are used unmodified in performing those activities but
-which are not part of the work. For example, Corresponding Source
-includes interface definition files associated with source files for
-the work, and the source code for shared libraries and dynamically
-linked subprograms that the work is specifically designed to require,
-such as by intimate data communication or control flow between those
-subprograms and other parts of the work.
-
- The Corresponding Source need not include anything that users
-can regenerate automatically from other parts of the Corresponding
-Source.
-
- The Corresponding Source for a work in source code form is that
-same work.
-
- 2. Basic Permissions.
-
- All rights granted under this License are granted for the term of
-copyright on the Program, and are irrevocable provided the stated
-conditions are met. This License explicitly affirms your unlimited
-permission to run the unmodified Program. The output from running a
-covered work is covered by this License only if the output, given its
-content, constitutes a covered work. This License acknowledges your
-rights of fair use or other equivalent, as provided by copyright law.
-
- You may make, run and propagate covered works that you do not
-convey, without conditions so long as your license otherwise remains
-in force. You may convey covered works to others for the sole purpose
-of having them make modifications exclusively for you, or provide you
-with facilities for running those works, provided that you comply with
-the terms of this License in conveying all material for which you do
-not control copyright. Those thus making or running the covered works
-for you must do so exclusively on your behalf, under your direction
-and control, on terms that prohibit them from making any copies of
-your copyrighted material outside their relationship with you.
-
- Conveying under any other circumstances is permitted solely under
-the conditions stated below. Sublicensing is not allowed; section 10
-makes it unnecessary.
-
- 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
-
- No covered work shall be deemed part of an effective technological
-measure under any applicable law fulfilling obligations under article
-11 of the WIPO copyright treaty adopted on 20 December 1996, or
-similar laws prohibiting or restricting circumvention of such
-measures.
-
- When you convey a covered work, you waive any legal power to forbid
-circumvention of technological measures to the extent such circumvention
-is effected by exercising rights under this License with respect to
-the covered work, and you disclaim any intention to limit operation or
-modification of the work as a means of enforcing, against the work's
-users, your or third parties' legal rights to forbid circumvention of
-technological measures.
-
- 4. Conveying Verbatim Copies.
-
- You may convey verbatim copies of the Program's source code as you
-receive it, in any medium, provided that you conspicuously and
-appropriately publish on each copy an appropriate copyright notice;
-keep intact all notices stating that this License and any
-non-permissive terms added in accord with section 7 apply to the code;
-keep intact all notices of the absence of any warranty; and give all
-recipients a copy of this License along with the Program.
-
- You may charge any price or no price for each copy that you convey,
-and you may offer support or warranty protection for a fee.
-
- 5. Conveying Modified Source Versions.
-
- You may convey a work based on the Program, or the modifications to
-produce it from the Program, in the form of source code under the
-terms of section 4, provided that you also meet all of these conditions:
-
- a) The work must carry prominent notices stating that you modified
- it, and giving a relevant date.
-
- b) The work must carry prominent notices stating that it is
- released under this License and any conditions added under section
- 7. This requirement modifies the requirement in section 4 to
- "keep intact all notices".
-
- c) You must license the entire work, as a whole, under this
- License to anyone who comes into possession of a copy. This
- License will therefore apply, along with any applicable section 7
- additional terms, to the whole of the work, and all its parts,
- regardless of how they are packaged. This License gives no
- permission to license the work in any other way, but it does not
- invalidate such permission if you have separately received it.
-
- d) If the work has interactive user interfaces, each must display
- Appropriate Legal Notices; however, if the Program has interactive
- interfaces that do not display Appropriate Legal Notices, your
- work need not make them do so.
-
- A compilation of a covered work with other separate and independent
-works, which are not by their nature extensions of the covered work,
-and which are not combined with it such as to form a larger program,
-in or on a volume of a storage or distribution medium, is called an
-"aggregate" if the compilation and its resulting copyright are not
-used to limit the access or legal rights of the compilation's users
-beyond what the individual works permit. Inclusion of a covered work
-in an aggregate does not cause this License to apply to the other
-parts of the aggregate.
-
- 6. Conveying Non-Source Forms.
-
- You may convey a covered work in object code form under the terms
-of sections 4 and 5, provided that you also convey the
-machine-readable Corresponding Source under the terms of this License,
-in one of these ways:
-
- a) Convey the object code in, or embodied in, a physical product
- (including a physical distribution medium), accompanied by the
- Corresponding Source fixed on a durable physical medium
- customarily used for software interchange.
-
- b) Convey the object code in, or embodied in, a physical product
- (including a physical distribution medium), accompanied by a
- written offer, valid for at least three years and valid for as
- long as you offer spare parts or customer support for that product
- model, to give anyone who possesses the object code either (1) a
- copy of the Corresponding Source for all the software in the
- product that is covered by this License, on a durable physical
- medium customarily used for software interchange, for a price no
- more than your reasonable cost of physically performing this
- conveying of source, or (2) access to copy the
- Corresponding Source from a network server at no charge.
-
- c) Convey individual copies of the object code with a copy of the
- written offer to provide the Corresponding Source. This
- alternative is allowed only occasionally and noncommercially, and
- only if you received the object code with such an offer, in accord
- with subsection 6b.
-
- d) Convey the object code by offering access from a designated
- place (gratis or for a charge), and offer equivalent access to the
- Corresponding Source in the same way through the same place at no
- further charge. You need not require recipients to copy the
- Corresponding Source along with the object code. If the place to
- copy the object code is a network server, the Corresponding Source
- may be on a different server (operated by you or a third party)
- that supports equivalent copying facilities, provided you maintain
- clear directions next to the object code saying where to find the
- Corresponding Source. Regardless of what server hosts the
- Corresponding Source, you remain obligated to ensure that it is
- available for as long as needed to satisfy these requirements.
-
- e) Convey the object code using peer-to-peer transmission, provided
- you inform other peers where the object code and Corresponding
- Source of the work are being offered to the general public at no
- charge under subsection 6d.
-
- A separable portion of the object code, whose source code is excluded
-from the Corresponding Source as a System Library, need not be
-included in conveying the object code work.
-
- A "User Product" is either (1) a "consumer product", which means any
-tangible personal property which is normally used for personal, family,
-or household purposes, or (2) anything designed or sold for incorporation
-into a dwelling. In determining whether a product is a consumer product,
-doubtful cases shall be resolved in favor of coverage. For a particular
-product received by a particular user, "normally used" refers to a
-typical or common use of that class of product, regardless of the status
-of the particular user or of the way in which the particular user
-actually uses, or expects or is expected to use, the product. A product
-is a consumer product regardless of whether the product has substantial
-commercial, industrial or non-consumer uses, unless such uses represent
-the only significant mode of use of the product.
-
- "Installation Information" for a User Product means any methods,
-procedures, authorization keys, or other information required to install
-and execute modified versions of a covered work in that User Product from
-a modified version of its Corresponding Source. The information must
-suffice to ensure that the continued functioning of the modified object
-code is in no case prevented or interfered with solely because
-modification has been made.
-
- If you convey an object code work under this section in, or with, or
-specifically for use in, a User Product, and the conveying occurs as
-part of a transaction in which the right of possession and use of the
-User Product is transferred to the recipient in perpetuity or for a
-fixed term (regardless of how the transaction is characterized), the
-Corresponding Source conveyed under this section must be accompanied
-by the Installation Information. But this requirement does not apply
-if neither you nor any third party retains the ability to install
-modified object code on the User Product (for example, the work has
-been installed in ROM).
-
- The requirement to provide Installation Information does not include a
-requirement to continue to provide support service, warranty, or updates
-for a work that has been modified or installed by the recipient, or for
-the User Product in which it has been modified or installed. Access to a
-network may be denied when the modification itself materially and
-adversely affects the operation of the network or violates the rules and
-protocols for communication across the network.
-
- Corresponding Source conveyed, and Installation Information provided,
-in accord with this section must be in a format that is publicly
-documented (and with an implementation available to the public in
-source code form), and must require no special password or key for
-unpacking, reading or copying.
-
- 7. Additional Terms.
-
- "Additional permissions" are terms that supplement the terms of this
-License by making exceptions from one or more of its conditions.
-Additional permissions that are applicable to the entire Program shall
-be treated as though they were included in this License, to the extent
-that they are valid under applicable law. If additional permissions
-apply only to part of the Program, that part may be used separately
-under those permissions, but the entire Program remains governed by
-this License without regard to the additional permissions.
-
- When you convey a copy of a covered work, you may at your option
-remove any additional permissions from that copy, or from any part of
-it. (Additional permissions may be written to require their own
-removal in certain cases when you modify the work.) You may place
-additional permissions on material, added by you to a covered work,
-for which you have or can give appropriate copyright permission.
-
- Notwithstanding any other provision of this License, for material you
-add to a covered work, you may (if authorized by the copyright holders of
-that material) supplement the terms of this License with terms:
-
- a) Disclaiming warranty or limiting liability differently from the
- terms of sections 15 and 16 of this License; or
-
- b) Requiring preservation of specified reasonable legal notices or
- author attributions in that material or in the Appropriate Legal
- Notices displayed by works containing it; or
-
- c) Prohibiting misrepresentation of the origin of that material, or
- requiring that modified versions of such material be marked in
- reasonable ways as different from the original version; or
-
- d) Limiting the use for publicity purposes of names of licensors or
- authors of the material; or
-
- e) Declining to grant rights under trademark law for use of some
- trade names, trademarks, or service marks; or
-
- f) Requiring indemnification of licensors and authors of that
- material by anyone who conveys the material (or modified versions of
- it) with contractual assumptions of liability to the recipient, for
- any liability that these contractual assumptions directly impose on
- those licensors and authors.
-
- All other non-permissive additional terms are considered "further
-restrictions" within the meaning of section 10. If the Program as you
-received it, or any part of it, contains a notice stating that it is
-governed by this License along with a term that is a further
-restriction, you may remove that term. If a license document contains
-a further restriction but permits relicensing or conveying under this
-License, you may add to a covered work material governed by the terms
-of that license document, provided that the further restriction does
-not survive such relicensing or conveying.
-
- If you add terms to a covered work in accord with this section, you
-must place, in the relevant source files, a statement of the
-additional terms that apply to those files, or a notice indicating
-where to find the applicable terms.
-
- Additional terms, permissive or non-permissive, may be stated in the
-form of a separately written license, or stated as exceptions;
-the above requirements apply either way.
-
- 8. Termination.
-
- You may not propagate or modify a covered work except as expressly
-provided under this License. Any attempt otherwise to propagate or
-modify it is void, and will automatically terminate your rights under
-this License (including any patent licenses granted under the third
-paragraph of section 11).
-
- However, if you cease all violation of this License, then your
-license from a particular copyright holder is reinstated (a)
-provisionally, unless and until the copyright holder explicitly and
-finally terminates your license, and (b) permanently, if the copyright
-holder fails to notify you of the violation by some reasonable means
-prior to 60 days after the cessation.
-
- Moreover, your license from a particular copyright holder is
-reinstated permanently if the copyright holder notifies you of the
-violation by some reasonable means, this is the first time you have
-received notice of violation of this License (for any work) from that
-copyright holder, and you cure the violation prior to 30 days after
-your receipt of the notice.
-
- Termination of your rights under this section does not terminate the
-licenses of parties who have received copies or rights from you under
-this License. If your rights have been terminated and not permanently
-reinstated, you do not qualify to receive new licenses for the same
-material under section 10.
-
- 9. Acceptance Not Required for Having Copies.
-
- You are not required to accept this License in order to receive or
-run a copy of the Program. Ancillary propagation of a covered work
-occurring solely as a consequence of using peer-to-peer transmission
-to receive a copy likewise does not require acceptance. However,
-nothing other than this License grants you permission to propagate or
-modify any covered work. These actions infringe copyright if you do
-not accept this License. Therefore, by modifying or propagating a
-covered work, you indicate your acceptance of this License to do so.
-
- 10. Automatic Licensing of Downstream Recipients.
-
- Each time you convey a covered work, the recipient automatically
-receives a license from the original licensors, to run, modify and
-propagate that work, subject to this License. You are not responsible
-for enforcing compliance by third parties with this License.
-
- An "entity transaction" is a transaction transferring control of an
-organization, or substantially all assets of one, or subdividing an
-organization, or merging organizations. If propagation of a covered
-work results from an entity transaction, each party to that
-transaction who receives a copy of the work also receives whatever
-licenses to the work the party's predecessor in interest had or could
-give under the previous paragraph, plus a right to possession of the
-Corresponding Source of the work from the predecessor in interest, if
-the predecessor has it or can get it with reasonable efforts.
-
- You may not impose any further restrictions on the exercise of the
-rights granted or affirmed under this License. For example, you may
-not impose a license fee, royalty, or other charge for exercise of
-rights granted under this License, and you may not initiate litigation
-(including a cross-claim or counterclaim in a lawsuit) alleging that
-any patent claim is infringed by making, using, selling, offering for
-sale, or importing the Program or any portion of it.
-
- 11. Patents.
-
- A "contributor" is a copyright holder who authorizes use under this
-License of the Program or a work on which the Program is based. The
-work thus licensed is called the contributor's "contributor version".
-
- A contributor's "essential patent claims" are all patent claims
-owned or controlled by the contributor, whether already acquired or
-hereafter acquired, that would be infringed by some manner, permitted
-by this License, of making, using, or selling its contributor version,
-but do not include claims that would be infringed only as a
-consequence of further modification of the contributor version. For
-purposes of this definition, "control" includes the right to grant
-patent sublicenses in a manner consistent with the requirements of
-this License.
-
- Each contributor grants you a non-exclusive, worldwide, royalty-free
-patent license under the contributor's essential patent claims, to
-make, use, sell, offer for sale, import and otherwise run, modify and
-propagate the contents of its contributor version.
-
- In the following three paragraphs, a "patent license" is any express
-agreement or commitment, however denominated, not to enforce a patent
-(such as an express permission to practice a patent or covenant not to
-sue for patent infringement). To "grant" such a patent license to a
-party means to make such an agreement or commitment not to enforce a
-patent against the party.
-
- If you convey a covered work, knowingly relying on a patent license,
-and the Corresponding Source of the work is not available for anyone
-to copy, free of charge and under the terms of this License, through a
-publicly available network server or other readily accessible means,
-then you must either (1) cause the Corresponding Source to be so
-available, or (2) arrange to deprive yourself of the benefit of the
-patent license for this particular work, or (3) arrange, in a manner
-consistent with the requirements of this License, to extend the patent
-license to downstream recipients. "Knowingly relying" means you have
-actual knowledge that, but for the patent license, your conveying the
-covered work in a country, or your recipient's use of the covered work
-in a country, would infringe one or more identifiable patents in that
-country that you have reason to believe are valid.
-
- If, pursuant to or in connection with a single transaction or
-arrangement, you convey, or propagate by procuring conveyance of, a
-covered work, and grant a patent license to some of the parties
-receiving the covered work authorizing them to use, propagate, modify
-or convey a specific copy of the covered work, then the patent license
-you grant is automatically extended to all recipients of the covered
-work and works based on it.
-
- A patent license is "discriminatory" if it does not include within
-the scope of its coverage, prohibits the exercise of, or is
-conditioned on the non-exercise of one or more of the rights that are
-specifically granted under this License. You may not convey a covered
-work if you are a party to an arrangement with a third party that is
-in the business of distributing software, under which you make payment
-to the third party based on the extent of your activity of conveying
-the work, and under which the third party grants, to any of the
-parties who would receive the covered work from you, a discriminatory
-patent license (a) in connection with copies of the covered work
-conveyed by you (or copies made from those copies), or (b) primarily
-for and in connection with specific products or compilations that
-contain the covered work, unless you entered into that arrangement,
-or that patent license was granted, prior to 28 March 2007.
-
- Nothing in this License shall be construed as excluding or limiting
-any implied license or other defenses to infringement that may
-otherwise be available to you under applicable patent law.
-
- 12. No Surrender of Others' Freedom.
-
- If conditions are imposed on you (whether by court order, agreement or
-otherwise) that contradict the conditions of this License, they do not
-excuse you from the conditions of this License. If you cannot convey a
-covered work so as to satisfy simultaneously your obligations under this
-License and any other pertinent obligations, then as a consequence you may
-not convey it at all. For example, if you agree to terms that obligate you
-to collect a royalty for further conveying from those to whom you convey
-the Program, the only way you could satisfy both those terms and this
-License would be to refrain entirely from conveying the Program.
-
- 13. Use with the GNU Affero General Public License.
-
- Notwithstanding any other provision of this License, you have
-permission to link or combine any covered work with a work licensed
-under version 3 of the GNU Affero General Public License into a single
-combined work, and to convey the resulting work. The terms of this
-License will continue to apply to the part which is the covered work,
-but the special requirements of the GNU Affero General Public License,
-section 13, concerning interaction through a network will apply to the
-combination as such.
-
- 14. Revised Versions of this License.
-
- The Free Software Foundation may publish revised and/or new versions of
-the GNU General Public License from time to time. Such new versions will
-be similar in spirit to the present version, but may differ in detail to
-address new problems or concerns.
-
- Each version is given a distinguishing version number. If the
-Program specifies that a certain numbered version of the GNU General
-Public License "or any later version" applies to it, you have the
-option of following the terms and conditions either of that numbered
-version or of any later version published by the Free Software
-Foundation. If the Program does not specify a version number of the
-GNU General Public License, you may choose any version ever published
-by the Free Software Foundation.
-
- If the Program specifies that a proxy can decide which future
-versions of the GNU General Public License can be used, that proxy's
-public statement of acceptance of a version permanently authorizes you
-to choose that version for the Program.
-
- Later license versions may give you additional or different
-permissions. However, no additional obligations are imposed on any
-author or copyright holder as a result of your choosing to follow a
-later version.
-
- 15. Disclaimer of Warranty.
-
- THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
-APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
-HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
-OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
-THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
-PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
-IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
-ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
-
- 16. Limitation of Liability.
-
- IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
-WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
-THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
-GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
-USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
-DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
-PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
-EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
-SUCH DAMAGES.
-
- 17. Interpretation of Sections 15 and 16.
-
- If the disclaimer of warranty and limitation of liability provided
-above cannot be given local legal effect according to their terms,
-reviewing courts shall apply local law that most closely approximates
-an absolute waiver of all civil liability in connection with the
-Program, unless a warranty or assumption of liability accompanies a
-copy of the Program in return for a fee.
-
diff --git a/lib/scssphp/Makefile b/lib/scssphp/Makefile
deleted file mode 100755
index 03d0bf0..0000000
--- a/lib/scssphp/Makefile
+++ /dev/null
@@ -1,2 +0,0 @@
-test:
- vendor/bin/phpunit --colors tests
diff --git a/lib/scssphp/README.md b/lib/scssphp/README.md
index 0d09fde..53a4c7a 100755
--- a/lib/scssphp/README.md
+++ b/lib/scssphp/README.md
@@ -1,14 +1,12 @@
-# scssphp v0.1.1
-###
+# scssphp
+###
-[](http://travis-ci.org/leafo/scssphp)
+[](http://travis-ci.org/leafo/scssphp)
+[](https://packagist.org/packages/leafo/scssphp)
`scssphp` is a compiler for SCSS written in PHP.
-It implements SCSS 3.2.12. It does not implement the SASS syntax, only the SCSS
-syntax.
-
-Checkout the homepage, , for directions on how to use.
+Checkout the homepage, , for directions on how to use.
## Running Tests
@@ -16,19 +14,34 @@ Checkout the homepage, , for directions on how to use.
Run the following command from the root directory to run every test:
- phpunit tests
+ vendor/bin/phpunit tests
-There are two kinds of tests in the `tests/` directory:
+There are several tests in the `tests/` directory:
* `ApiTest.php` contains various unit tests that test the PHP interface.
* `ExceptionTest.php` contains unit tests that test for exceptions thrown by the parser and compiler.
+* `FailingTest.php` contains tests reported in Github issues that demonstrate compatibility bugs.
* `InputTest.php` compiles every `.scss` file in the `tests/inputs` directory
then compares to the respective `.css` file in the `tests/outputs` directory.
+* `ScssTest.php` extracts (ruby) `scss` tests from the `tests/scss_test.rb` file.
+* `ServerTest.php` contains functional tests for the `Server` class.
When changing any of the tests in `tests/inputs`, the tests will most likely
fail because the output has changed. Once you verify that the output is correct
you can run the following command to rebuild all the tests:
- BUILD=true phpunit tests
+ BUILD=1 vendor/bin/phpunit tests
This will compile all the tests, and save results into `tests/outputs`.
+
+To enable the `scss` compatibility tests:
+
+ TEST_SCSS_COMPAT=1 vendor/bin/phpunit tests
+
+## Coding Standard
+
+`scssphp` source conforms to [PSR2](http://www.php-fig.org/psr/psr-2/).
+
+Run the following command from the root directory to check the code for "sniffs".
+
+ vendor/bin/phpcs --standard=PSR2 bin src tests
diff --git a/lib/scssphp/bin/pscss b/lib/scssphp/bin/pscss
index 451f0fb..3175ea0 100755
--- a/lib/scssphp/bin/pscss
+++ b/lib/scssphp/bin/pscss
@@ -1,66 +1,204 @@
#!/usr/bin/env php
parse($data));
+ print_r(json_decode(json_encode($parser->parse($data)), true));
exit();
}
$scss = new Compiler();
-if (has("f")) {
- $scss->setFormatter('Leafo\\ScssPhp\\' . ucfirst($opts["f"]));
+if ($debugInfo && $inputFile) {
+ $scss->setLineNumberStyle(Compiler::DEBUG_INFO);
+}
+
+if ($lineNumbers && $inputFile) {
+ $scss->setLineNumberStyle(Compiler::LINE_COMMENTS);
}
-echo $scss->compile($data, "STDIN");
+if ($ignoreErrors) {
+ $scss->setIgnoreErrors($ignoreErrors);
+}
+
+if ($loadPaths) {
+ $scss->setImportPaths(explode(PATH_SEPARATOR, $loadPaths));
+}
+
+if ($precision) {
+ $scss->setNumberPrecision($precision);
+}
+
+if ($style) {
+ $scss->setFormatter('Leafo\\ScssPhp\\Formatter\\' . ucfirst($style));
+}
+
+if ($encoding) {
+ $scss->setEncoding($encoding);
+}
+
+echo $scss->compile($data, $inputFile);
+
+if ($changeDir) {
+ chdir($oldWorkingDir);
+}
diff --git a/lib/scssphp/classmap.php b/lib/scssphp/classmap.php
deleted file mode 100755
index 543efb9..0000000
--- a/lib/scssphp/classmap.php
+++ /dev/null
@@ -1,62 +0,0 @@
-=5.3.0"
+ "php": ">=5.4.0"
},
"require-dev": {
- "phpunit/phpunit": "3.7.*"
+ "squizlabs/php_codesniffer": "~2.5",
+ "phpunit/phpunit": "~3.7",
+ "kherge/box": "~2.5"
},
- "bin": ["bin/pscss"]
+ "bin": ["bin/pscss"],
+ "archive": {
+ "exclude": [
+ "/Makefile",
+ "/.gitattributes",
+ "/.gitignore",
+ "/.travis.yml",
+ "/box.json.dist",
+ "/phpunit.xml.dist",
+ "/tests"
+ ]
+ }
}
diff --git a/lib/scssphp/package.sh b/lib/scssphp/package.sh
deleted file mode 100755
index 02a528d..0000000
--- a/lib/scssphp/package.sh
+++ /dev/null
@@ -1,24 +0,0 @@
-#!/bin/sh
-
-# creates tar.gz for current version
-
-TARGET_DIR="site/www/src"
-
-VERSION=`./pscss -v | sed -n 's/^v\(.*\)$/\1/p'`
-OUT_DIR="tmp/scssphp"
-TMP=`dirname $OUT_DIR`
-
-mkdir -p $OUT_DIR
-tar -c `git ls-files` | tar -C $OUT_DIR -x
-
-rm $OUT_DIR/.gitignore
-rm $OUT_DIR/package.sh
-rm $OUT_DIR/todo
-rm -r $OUT_DIR/site
-
-OUT_PATH="$TARGET_DIR/scssphp-$VERSION.tar.gz"
-tar -czf "$OUT_PATH" -C $TMP scssphp/
-echo "Wrote $OUT_PATH"
-
-rm -r $TMP
-
diff --git a/lib/scssphp/phpunit.xml.dist b/lib/scssphp/phpunit.xml.dist
deleted file mode 100755
index 57219d2..0000000
--- a/lib/scssphp/phpunit.xml.dist
+++ /dev/null
@@ -1,29 +0,0 @@
-
-
-
-
-
-
-
- tests
-
-
-
-
-
- src
-
-
-
-
diff --git a/lib/scssphp/scss.inc.php b/lib/scssphp/scss.inc.php
index 39d2310..b6892fe 100755
--- a/lib/scssphp/scss.inc.php
+++ b/lib/scssphp/scss.inc.php
@@ -1,11 +1,30 @@
{
- "require" : {
- "leafo/scssphp" : "$current_version"
- }
-}
-
diff --git a/lib/scssphp/site/docs/index.md b/lib/scssphp/site/docs/index.md
deleted file mode 100755
index 2df0831..0000000
--- a/lib/scssphp/site/docs/index.md
+++ /dev/null
@@ -1,325 +0,0 @@
- title: Documentation
---
-
-scssphp $current_version Documentation
-
-$index
-
-## PHP Interface
-
-### Including
-
-The project can be loaded through a `composer` generated auto-loader.
-
-Alternatively, the entire project can be loaded through a utility file.
-Just include it somewhere to start using it:
-
- ```php
- compile('
- $color: #abc;
- div { color: lighten($color, 20%); }
- ');
- ```
-
-* `compile($scssCode)` will attempt to compile a string of SCSS code. If it
- succeeds then the CSS will be returned as a string. If there is any error, an
- exception is thrown with an appropriate error message.
-
-
-### Import Paths
-
-When you import a file using the `@import` directive, the current path of your
-PHP script is used as the search path by default. This is often not what
-you want, so there are two methods for manipulating the import path:
-`addImportPath`, and `setImportPaths`.
-
-* `addImportPath($path)` will append `$path` to the list of the import
- paths that are searched.
-
-* `setImportPaths($pathArray)` will replace the entire import path with
- `$pathArray`. The value of `$pathArray` will be converted to an array if it
- isn't one already.
-
-If the import path is set to `array()` then importing is effectively disabled.
-The default import path is `array("")`, which means the current directory.
-
- ```php
- setImportPaths("assets/stylesheets/");
-
- // will search for `assets/stylesheets/mixins.scss'
- echo $scss->compile('@import "mixins.scss"');
- ```
-
-Besides adding static import paths, it's also possible to add custom import
-functions. This allows you to load paths from a database, or HTTP, or using
-files that SCSS would otherwise not process (such as vanilla CSS imports).
-
- ```php
- addImportPath(function($path) {
- if (!file_exists('stylesheets/'.$path)) return null;
- return 'stylesheets/'.$path;
- });
-
- // will import `stylesheets/vanilla.css'
- echo $scss->compile('@import "vanilla.css"');
- ```
-
-### Output Formatting
-
-It's possible to customize the formatting of the output CSS by changing the
-default formatter.
-
-Three formatters are included:
-
-* `Leafo\ScssPhp\Formatter\Expanded`
-* `Leafo\ScssPhp\Formatter\Nested` *(default)*
-* `Leafo\ScssPhp\Formatter\Compressed`
-
-We can change the formatting using the `setFormatter` method.
-
-* `setFormatter($formatterName)` sets the current formatter to `$formatterName`,
- the name of a class as a string that implements the formatting interface. See
- the source for `Leafo\ScssPhp\Formatter\Expanded` for an example.
-
-
-Given the following SCSS:
-
- ```scss
- .navigation {
- ul {
- line-height: 20px;
- color: blue;
- a {
- color: red;
- }
- }
- }
-
- .footer {
- .copyright {
- color: silver;
- }
- }
- ```
-
-The formatters will output,
-
-`Leafo\ScssPhp\Formatter\Expanded`:
-
- ```css
- .navigation ul {
- line-height: 20px;
- color: blue;
- }
- .navigation ul a {
- color: red;
- }
- .footer .copyright {
- color: silver;
- }
- ```
-
-`Leafo\ScssPhp\Formatter\Nested`:
-
- ```css
- .navigation ul {
- line-height: 20px;
- color: blue; }
- .navigation ul a {
- color: red; }
-
- .footer .copyright {
- color: silver; }
- ```
-
-`Leafo\ScssPhp\Formatter\Compressed`:
-
- ```css
- .navigation ul{line-height:20px;color:blue;}.navigation ul a{color:red;}.footer .copyright{color:silver;}
- ```
-
-### Custom Functions
-
-It's possible to register custom functions written in PHP that can be called
-from SCSS. Some possible applications include appending your assets directory
-to a URL with an `asset-url` function, or converting image URLs to an embedded
-data URI to reduce the number of requests on a page with a `data-uri` function.
-
-We can add and remove functions using the methods `registerFunction` and
-`unregisterFunction`.
-
-* `registerFunction($functionName, $callable)` assigns the callable value to
- the name `$functionName`. The name is normalized using the rules of SCSS.
- Meaning underscores and dashes are interchangeable. If a function with the
- same name already exists then it is replaced.
-
-* `unregisterFunction($functionName)` removes `$functionName` from the list of
- available functions.
-
-
-The `$callable` can be anything that PHP knows how to call using
-`call_user_func`. The function receives two arguments when invoked. The first
-is an array of SCSS typed arguments that the function was sent. The second is a
-reference to the current `scss` instance.
-
-The *SCSS typed arguments* are actually just arrays that represent SCSS values.
-SCSS has different types than PHP, and this is how **scssphp** represents them
-internally.
-
-For example, the value `10px` in PHP would be `array("number", 1, "px")`. There
-is a large variety of types. Experiment with a debugging function like `print_r`
-to examine the possible inputs.
-
-The return value of the custom function can either be a SCSS type or a basic
-PHP type. (such as a string or a number) If it's a PHP type, it will be converted
-automatically to the corresponding SCSS type.
-
-As an example, a function called `add-two` is registered, which adds two numbers
-together. PHP's anonymous function syntax is used to define the function.
-
- ```php
- registerFunction("add-two", function($args) {
- list($a, $b) = $args;
- return $a[1] + $b[1];
- });
-
- $scss->compile('.ex1 { result: add-two(10, 10); }');
- ```
-
-It's worth noting that in this example we lose the units of the number, and we
-also don't do any type checking. This will have undefined results if we give it
-anything other than two numbers.
-
-
-## SCSS Server
-
-The SCSS server is a small class that helps with automatically compiling SCSS.
-
-It's an endpoint for your web application that searches for SCSS files in a
-directory then compiles and serves them as CSS. It will only compile
-files if they've been modified (or one of the imports has been modified).
-
-### Using `serveFrom`
-
-`Server::serveFrom` is a simple to use function that should handle most cases.
-
-For example, create a file `style.php`:
-
- ```php
- `Server::serveFrom($directory)` will serve SCSS files out of
- `$directory`. It will attempt to get the path to the file out of
- `$_SERVER["PATH_INFO"]`. (It also looks at the GET parameter `p`)
-
-
-If it can not find the file it will return an HTTP 404 page:
-
- ```text
- /* INPUT NOT FOUND scss v0.0.1 */
- ```
-
-If the file can't be compiled due to an error, then an HTTP 500 page is
-returned. Similar to the following:
-
- ```text
- Parse error: parse error: failed at `height: ;` stylesheets/test.scss on line 8
- ```
-
-By default , the SCSS server must have write access to the style sheet
-directory. It writes its cache in a special directory called `scss_cache`.
-
-Also, because SCSS server writes headers, make sure no output is written before
-it runs.
-
-### Using `Leafo\ScssPhp\Server`
-
-Creating an instance of `Server` is just another way of accomplishing what
-`serveFrom` does. It lets us customize the cache directory and the instance
-of the `Compiler` that is used to compile
-
-
-* `new Server($sourceDir, $cacheDir, $scss)` creates a new server that
- serves files from `$sourceDir`. The cache dir is where the cached compiled
- files are placed. When `null`, `$sourceDir . "/scss_cache"` is used. `$scss`
- is the instance of `scss` that is used to compile.
-
-
-Just call the `serve` method to let it render its output.
-
-Here's an example of creating a SCSS server that outputs compressed CSS:
-
- ```php
- setFormatter("scss_formatter_compressed");
-
- $server = new Server("stylesheets", null, $scss);
- $server->serve();
- ```
-
-
-## Command Line Tool
-
-A really basic command line tool is included for integration with scripts. It
-is called `pscss`. It reads a SCSS file from standard out and returns the CSS.
-
-If passed the flag `-v`, input is ignored and the current version if returned.
-
-The flag `-f` can be used to set the [formatter](#Output_formatting):
-
- ```bash
- $ bin/pscss -f scss_formatter_compressed < styles.scss
- ```
-
diff --git a/lib/scssphp/site/index.md b/lib/scssphp/site/index.md
deleted file mode 100755
index 894051e..0000000
--- a/lib/scssphp/site/index.md
+++ /dev/null
@@ -1,233 +0,0 @@
-**scssphp** is a compiler for [SCSS][0] written in PHP.
-
-SCSS is a CSS preprocessor that adds many features like variables, mixins,
-imports, color manipulation, functions, and tons of other powerful features.
-
-The entire compiler comes in a single class file ready for including in any
-kind of project in addition to a command line tool for running the compiler
-from the terminal.
-
-**scssphp** implements SCSS (3.2.12). It does not implement the SASS syntax,
-only the SCSS syntax.
-
-Follow the author on twitter: [@moonscript](http://twitter.com/moonscript).
-
-
-
-
-
-
-
-## Installing
-
-You can always download the latest version here:
-scssphp-$current_version.tar.gz
-
-You can also find the latest source online:
-
-
-If you use [Packagist][2] for installing packages, then you can update your `composer.json` like so:
-
-$render{[[composer]]}
-
-
-## Language Reference
-
-For a complete guide to the syntax of SCSS, consult the [official documentation][1].
-
-## PHP Reference
-
-Complete documentation for **scssphp** is located at http://leafo.net/scssphp/docs/ .
-
-### Quickstart
-
-If you just want to start serving compiled `scss` files as quick as possible
-then start here.
-
-**scssphp** comes with a easy to use class that automatically compiles modified
-`scss` files and serves them from a directory you specify.
-
-Create a file, like `style.php`:
-
- ```php
- compile('
- $color: #abc;
- div { color: lighten($color, 20%); }
- ');
-
- ```
-
-The `compile` method takes `SCSS` as a string, and returns the `CSS`. If there
-is an error when compiling then an exception is thrown with an appropriate
-message.
-
-
-For a more detailed guide consult http://leafo.net/scssphp/docs/ .
-
-
-## Issues
-
-Find any issues? I'd love to fix them for you, post about them on [the issues tracker][3].
-
-
-## Changelog
-
-* **0.1.1** -- Aug 12, 2014
- * add stub classes -- a backward compatibility layer (vladimmi)
-* **0.1.0** -- Aug 9, 2014
- * raise PHP requirement (5.3+)
- * reformat/reorganize source files to be PSR-2 compliant
-* **0.0.15** -- Aug 6, 2014
- * fix regression with default values in functions (torkiljohnsen)
-* **0.0.14** -- Aug 5, 2014
- * @keyframes $name - didn't work inside mixin (sergeylukin)
- * Bourbon transform(translateX()) didn't work (dovy and greynor)
-* **0.0.13** -- Aug 4, 2014
- * handle If-None-Match in client request, and send ETag in response (NSmithUK)
- * normalize quotation marks (NoxNebula)
- * improve handling of escape sequence in selectors (matt3224)
- * add "scss_formatter_crunched" which strips comments
- * internal: generate more accurate parse tree
-* **0.0.12** -- July 6, 2014
- * revert erroneous import-partials-fix (smuuf)
- * handle If-Modified-Since in client request, and send Last-Modified in response (braver)
- * add hhvm to travis-ci testing
-* **0.0.11** -- July 5, 2014
- * support multi-line continuation character (backslash)per CSS2.1 and CSS3 spec (caiosm1005)
- * imported partials should not be compiled (squarestar)
- * add setVariables() and unsetVariable() to interface (leafo/lessphp)
- * micro-optimizing is_null() (Yahasana)
-* **0.0.10** -- April 14, 2014
- * fix media query merging (timonbaetz)
- * inline if should treat null as false (wonderslug)
- * optimizing toHSL() (jfsullivan)
-* **0.0.9** -- December 23, 2013
- * fix @for/@while inside @content block (sergeylukin)
- * fix functions in mixin_content (timonbaetz)
- * fix infinite loop when target extends itself (oscherler)
- * fix function arguments are lost inside of @content block
- * allow setting number precision (kasperisager)
- * add public function helpers (toBool, get, findImport, assertList, assertColor, assertNumber, throwError) (Burgov, atdt)
- * add optional cache buster prefix to serve() method (iMoses)
-* **0.0.8** -- September 16, 2013
- * Avoid IE7 content: counter bug
- * Support transparent as color name
- * Recursively create cache dir (turksheadsw)
- * Fix for INPUT NOT FOUND (morgen32)
-* **0.0.7** -- May 24, 2013
- * Port various fixes from leafo/lessphp.
- * Improve filter precision.
- * Parsing large image data-urls does not work.
- * Add == and != ops for colors.
- * @if and @while directives should treat null like false.
- * Add pscss as bin in composer.json (Christian Lück).
- * Fix !default bug (James Shannon, Alberto Aldegheri).
- * Fix mixin content includes (James Shannon, Christian Brandt).
- * Fix passing of varargs to another mixin.
- * Fix interpolation bug in expToString() (Matti Jarvinen).
-* **0.0.5** -- March 11, 2013
- * Better compile time errors
- * Fix top level properties inside of a nested `@media` (Anthon Pang)
- * Fix some issues with `@extends` (Anthon Pang)
- * Enhanced handling of `null` (Anthon Pang)
- * Helper functions shouldn't mix with css builtins (Anthon Pang)
- * Enhance selector parsing (Guilherme Blanco, Anthon Pang)
- * Add Placeholder selector support (Martin Hasoň)
- * Add variable argument support (Martin Hasoň)
- * Add zip, index, comparable functions (Martin Hasoň)
- * A bunch of parser and bug fixes
-* **0.0.4** -- Nov 3nd, 2012
- * [Import path can be a function](docs/#import_paths) (Christian Lück).
- * Correctly parse media queries with more than one item (Christian Lück).
- * Add `ie_hex_str`, `abs`, `min`, `max` functions (Martin Hasoň)
- * Ignore expressions inside of `calc()` (Martin Hasoň)
- * Improve operator evaluation (Martin Hasoň)
- * Add [`@content`](http://sass-lang.com/docs/yardoc/file.SASS_REFERENCE.html#mixin-content) support.
- * Misc bug fixes.
-* **0.0.3** -- August 2nd, 2012
- * Add missing and/or/not operators.
- * Expression evaluation happens correctly.
- * Import file caching and _partial filename support.
- * Misc bug fixes.
-* **0.0.2** -- July 30th, 2012
- * SCSS server is aware of imports
- * added custom function interface
- * compressed formatter
- * wrote documentation
-* Initial Release v0.0.1 -- July 29th, 2012
-
-
-
-
-
-## Comments
-
-
-
-
-
- [0]: http://sass-lang.com/
- [1]: http://sass-lang.com/docs/yardoc/file.SASS_REFERENCE.html#css_extensions
- [2]: http://packagist.org/
- [3]: https://github.com/leafo/scssphp/issues
- [4]: https://github.com/leafo/scssphp/
diff --git a/lib/scssphp/site/site.moon b/lib/scssphp/site/site.moon
deleted file mode 100755
index 95afb92..0000000
--- a/lib/scssphp/site/site.moon
+++ /dev/null
@@ -1,15 +0,0 @@
-require "sitegen"
-
-tools = require "sitegen.tools"
-
-sitegen.create_site =>
- @current_version = "0.1.1"
- @title = "SCSS Compiler in PHP"
-
- scssphp = tools.system_command "bin/pscss < %s > %s", "css"
- build scssphp, "style.scss", "style/style.css"
-
- deploy_to "leaf@leafo.net", "www/scssphp/"
-
- add "docs/index.md"
-
diff --git a/lib/scssphp/site/style.scss b/lib/scssphp/site/style.scss
deleted file mode 100755
index 18ecc09..0000000
--- a/lib/scssphp/site/style.scss
+++ /dev/null
@@ -1,303 +0,0 @@
-
-$site_width: 640px;
-
-$light_teal: #7FC7AF;
-$teal: desaturate(#3FB8AF, 10%);
-$brown: #DAD8A7;
-$pink: darken(#FF9E9D, 10%);
-$btn_color: desaturate(#FF3D7F, 10%);
-
-::selection {
- background: red;
- color: white;
-}
-
-@mixin unselectable {
- -moz-user-select: none;
- -webkit-user-select: none;
- user-select: none;
-}
-
-@mixin grad($top, $bottom) {
- background-color: mix($top, $bottom);
- background-image: linear-gradient(bottom, $bottom 0%, $top 100%);
- background-image: -webkit-linear-gradient(bottom, $bottom 0%, $top 100%);
- background-image: -moz-linear-gradient(bottom, $bottom 0%, $top 100%);
- background-image: -o-linear-gradient(bottom, $bottom 0%, $top 100%);
- background-image: -ms-linear-gradient(bottom, $bottom 0%, $top 100%);
-}
-
-@mixin autograd($color, $amount: 10%) {
- @include grad($color, darken($color, $amount));
-}
-
-body {
- background: $pink;
- font-family: Lato, sans-serif;
-}
-
-.header, .footer, .body {
- .inner {
- width: $site_width;
- margin: 0 auto;
- }
-}
-
-.header {
- text-shadow: 0px -1px 0px darken($teal, 15%);
-
- .color {
- background: $teal url(../img/tile.png);
- border-top: 4px solid $light_teal;
- box-shadow: inset 0px 1px 0px rgba(255,255,255, 0.5), inset 0px 8px 8px -8px #37505A, inset 0px -1px 0px rgba(255,255,255, 0.3);
- }
-
- h1 {
- font-family: 'Quicksand', sans-serif;
- font-size: 40px;
- line-height: 100px;
- font-weight: normal;
- margin: 0;
-
- a {
- text-decoration: none;
- color: #EDFFF9;
-
- &:active {
- position: relative;
- top: 1px;
- }
- }
- }
-
- .nav {
- padding: 8px 0;
- font-size: 17px;
- text-shadow: none;
- background: darken($teal, 30%);
- color: $teal;
- box-shadow: inset 0px 4px 8px -4px rgba(0,0,0,0.9), inset 0px -1px 0px rgba(255,255,255, 0.8);
-
- a {
- color: lighten($teal, 40%);
- text-decoration: none;
-
- &:hover {
- text-decoration: underline;
- }
- }
-
- .social {
- float: right;
- margin-top: -2px;
- }
- }
-
- .download-area {
- float: right;
- margin-top: 25px;
- background: rgba(255,255,255, 0.3);
- border-radius: 8px;
- padding: 5px;
-
- a {
- text-decoration: none;
- }
-
- .download-button {
- $height: 8px;
- $depress: 4px;
-
- @include unselectable;
-
- color: white;
- text-align: center;
-
- @include autograd($btn_color);
-
- position: relative;
- top: -1 * $height;
-
- padding: 8px 20px;
- border-radius: 8px;
- text-shadow: none;
-
- box-shadow: 0px $height 0px darken($btn_color, 30%), inset 0px -1px 0px rgba(255,255,255, 0.2), inset 0px 1px 0px rgba(0,0,0, 0.2);
- text-shadow: 0px 1px 2px darken($btn_color, 40%);
-
- cursor: pointer;
-
- -webkit-transition: all 0.05s ease-in-out;
- -moz-transition: all 0.05s ease-in-out;
- transition: all 0.05s ease-in-out;
-
- &:hover {
- @include autograd(lighten($btn_color, 3%));
- }
-
- &:active {
- box-shadow: 0px $height - $depress 0px darken($btn_color, 30%), inset 0px -1px 0px rgba(255,255,255, 0.2), inset 0px 1px 0px rgba(0,0,0, 0.2);
- top: -1 * ($height - $depress);
- }
-
- .top {
- font-weight: bold;
- font-size: 16px;
- }
-
- .sub {
- font-size: 14px;
- }
- }
- }
-
-}
-
-.body {
- $bg_color: #FEFFED;
- $text_color: darken($brown, 60%);
- box-shadow: inset 0px 4px 8px -4px rgba(0,0,0,0.7), inset 0px -4px 8px -4px rgba(0,0,0,0.4);
- background: $bg_color;
- overflow: hidden;
- color: $text_color;
- font-size: 18px;
- padding-bottom: 20px;
-
- .inner {
- background: white;
- margin-top: 20px;
- padding: 30px 50px;
- border: 1px solid lightGrey;
- box-shadow: 0px 4px 20px rgba(0, 0, 0, 0.19);
-
- h1, h2, h3 {
- margin: 0 0 20px 0;
- }
- }
-
- h1, h2, h3 {
- text-shadow: 1px 1px 0px $bg_color, 2px 2px 0px rgba($text_color, 0.3);
- letter-spacing: -1px;
- }
-
- h3 {
- color: #4D4C3D;
- }
-
- p {
- margin: 0 0 15px 0;
- }
-
- a {
- color: #DB1C4A;
- &:hover {
- color: lighten(#DB1C4A, 10%);
- }
- }
-
- pre {
- margin: 20px 0;
- }
-}
-
-.footer {
- font-size: 16px;
- color: lighten($pink, 20%);
- text-shadow: 0px 1px 0px darken($pink, 20%);
-
- border-top: 1px dashed darken($pink, 50%);
- box-shadow: inset 0px 1px 0px rgba(255,255,255, 0.5);
- padding: 8px 0 20px 0;
-
- line-height: 150%;
-
- a {
- color: white;
- font-weight: bold;
- text-decoration: none;
- padding: 0 4px;
- border-radius: 4px;
- border: 1px solid lighten($pink, 4%);
-
- &:hover {
- background: darken($pink, 3%);
- border: 1px solid lighten($pink, 4%);
- }
- }
-}
-
-
-p {
- line-height: 150%;
- code {
- background: rgba(0,0,0, 0.1);
- border-radius: 4px;
- padding: 1px 4px;
- }
-}
-
-.comments {
- font-size: 12px;
-}
-
-.index {
- line-height: 150%;
- margin-bottom: 20px;
-
- ul {
- margin: 0;
- }
-}
-
-.highlight {
- background: #333;
- color: white;
- font-size: 14px;
- padding: 10px;
- box-shadow: 0px 1px 3px rgba(0,0,0, 0.7), inset 0px 0px 0px 1px rgba(255,255,255,0.3);
- border-radius: 2px;
- border: 1px solid #222;
-
-
- // builtins
- .nb {
- color: #FFA67C;
- }
-
- // strings
- .s, .s1, .s2, .se, .nt {
- color: #ffe898;
- }
-
- // proper names
- .nc, .vc, .bp {
- color: #98d9ff;
- }
-
- // true, false, nil
- .kc {
- color: #acfff0;
- }
-
- // function lit, braces, parens
- .nf, .kt {
- color: #9fff98;
- }
-
- .nv {
- color: #ff9898;
- }
-
- // keywords
- .k, .kd, .na {
- color: #cb98ff;
- }
-
- .c1, .c2 {
- color: #929292;
- }
-
- .m, .mi, .mf, .mh, .o {
- color: #9495ff;
- }
-}
diff --git a/lib/scssphp/site/templates/index.html b/lib/scssphp/site/templates/index.html
deleted file mode 100755
index 587b691..0000000
--- a/lib/scssphp/site/templates/index.html
+++ /dev/null
@@ -1,81 +0,0 @@
-
-
-
-
- $if{"title"}[[$title - ]]scssphp
-
-
-
- $analytics{"UA-136625-1"}
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/lib/scssphp/site/www/.gitignore b/lib/scssphp/site/www/.gitignore
deleted file mode 100755
index e821797..0000000
--- a/lib/scssphp/site/www/.gitignore
+++ /dev/null
@@ -1,2 +0,0 @@
-docs/index.html
-index.html
\ No newline at end of file
diff --git a/lib/scssphp/site/www/img/tile.png b/lib/scssphp/site/www/img/tile.png
deleted file mode 100755
index ecb7149dc6e07dae7f0d8914934990ef05724d73..0000000000000000000000000000000000000000
GIT binary patch
literal 0
HcmV?d00001
literal 244
zcmeAS@N?(olHy`uVBq!ia0vp^93afW1|*O0@9PFqY)RhkE)4%caKYZ?lYt_f1s;*b
z3=G`DAk4@xYmNj^kiEpy*OmPayNrmS^x=@jAa$~tArU3c`MJ5Nc_lzD1A}u>YGO%h
zib8p2Nrr;Er*A-tUMf3KJi^n(F+}2W@3}y(Lke5Raw8wpPSUJuBp7`l{tC*%AJj89QNf(9B9+NRVe%W`3bYE
djp3nx7K_KUN$MMF6@mQ4;OXk;vd$@?2>=OJP@w<-
diff --git a/lib/scssphp/site/www/style/normalize.css b/lib/scssphp/site/www/style/normalize.css
deleted file mode 100755
index 8fa27e0..0000000
--- a/lib/scssphp/site/www/style/normalize.css
+++ /dev/null
@@ -1,500 +0,0 @@
-/*! normalize.css 2012-07-07T09:50 UTC - http://github.com/necolas/normalize.css */
-
-/* ==========================================================================
- HTML5 display definitions
- ========================================================================== */
-
-/*
- * Corrects `block` display not defined in IE6/7/8/9 & FF3.
- */
-
-article,
-aside,
-details,
-figcaption,
-figure,
-footer,
-header,
-hgroup,
-nav,
-section,
-summary {
- display: block;
-}
-
-/*
- * Corrects `inline-block` display not defined in IE6/7/8/9 & FF3.
- */
-
-audio,
-canvas,
-video {
- display: inline-block;
- *display: inline;
- *zoom: 1;
-}
-
-/*
- * Prevents modern browsers from displaying `audio` without controls.
- * Remove excess height in iOS5 devices.
- */
-
-audio:not([controls]) {
- display: none;
- height: 0;
-}
-
-/*
- * Addresses styling for `hidden` attribute not present in IE7/8/9, FF3, S4.
- * Known issue: no IE6 support.
- */
-
-[hidden] {
- display: none;
-}
-
-/* ==========================================================================
- Base
- ========================================================================== */
-
-/*
- * 1. Corrects text resizing oddly in IE6/7 when body `font-size` is set using
- * `em` units.
- * 2. Prevents iOS text size adjust after orientation change, without disabling
- * user zoom.
- */
-
-html {
- font-size: 100%; /* 1 */
- -webkit-text-size-adjust: 100%; /* 2 */
- -ms-text-size-adjust: 100%; /* 2 */
-}
-
-/*
- * Addresses `font-family` inconsistency between `textarea` and other form
- * elements.
- */
-
-html,
-button,
-input,
-select,
-textarea {
- font-family: sans-serif;
-}
-
-/*
- * Addresses margins handled incorrectly in IE6/7.
- */
-
-body {
- margin: 0;
-}
-
-/* ==========================================================================
- Links
- ========================================================================== */
-
-/*
- * Addresses `outline` inconsistency between Chrome and other browsers.
- */
-
-a:focus {
- outline: thin dotted;
-}
-
-/*
- * Improves readability when focused and also mouse hovered in all browsers.
- * people.opera.com/patrickl/experiments/keyboard/test
- */
-
-a:active,
-a:hover {
- outline: 0;
-}
-
-/* ==========================================================================
- Typography
- ========================================================================== */
-
-/*
- * Addresses font sizes and margins set differently in IE6/7.
- * Addresses font sizes within `section` and `article` in FF4+, Chrome, S5.
- */
-
-h1 {
- font-size: 2em;
- margin: 0.67em 0;
-}
-
-h2 {
- font-size: 1.5em;
- margin: 0.83em 0;
-}
-
-h3 {
- font-size: 1.17em;
- margin: 1em 0;
-}
-
-h4 {
- font-size: 1em;
- margin: 1.33em 0;
-}
-
-h5 {
- font-size: 0.83em;
- margin: 1.67em 0;
-}
-
-h6 {
- font-size: 0.75em;
- margin: 2.33em 0;
-}
-
-/*
- * Addresses styling not present in IE7/8/9, S5, Chrome.
- */
-
-abbr[title] {
- border-bottom: 1px dotted;
-}
-
-/*
- * Addresses style set to `bolder` in FF3+, S4/5, Chrome.
- */
-
-b,
-strong {
- font-weight: bold;
-}
-
-blockquote {
- margin: 1em 40px;
-}
-
-/*
- * Addresses styling not present in S5, Chrome.
- */
-
-dfn {
- font-style: italic;
-}
-
-/*
- * Addresses styling not present in IE6/7/8/9.
- */
-
-mark {
- background: #ff0;
- color: #000;
-}
-
-/*
- * Addresses margins set differently in IE6/7.
- */
-
-p,
-pre {
- margin: 1em 0;
-}
-
-/*
- * Corrects font family set oddly in IE6, S4/5, Chrome.
- * en.wikipedia.org/wiki/User:Davidgothberg/Test59
- */
-
-code,
-kbd,
-pre,
-samp {
- font-family: monospace, serif;
- _font-family: 'courier new', monospace;
- font-size: 1em;
-}
-
-/*
- * Improves readability of pre-formatted text in all browsers.
- */
-
-pre {
- white-space: pre;
- white-space: pre-wrap;
- word-wrap: break-word;
-}
-
-/*
- * Addresses CSS quotes not supported in IE6/7.
- */
-
-q {
- quotes: none;
-}
-
-/*
- * Addresses `quotes` property not supported in S4.
- */
-
-q:before,
-q:after {
- content: '';
- content: none;
-}
-
-small {
- font-size: 75%;
-}
-
-/*
- * Prevents `sub` and `sup` affecting `line-height` in all browsers.
- * gist.github.com/413930
- */
-
-sub,
-sup {
- font-size: 75%;
- line-height: 0;
- position: relative;
- vertical-align: baseline;
-}
-
-sup {
- top: -0.5em;
-}
-
-sub {
- bottom: -0.25em;
-}
-
-/* ==========================================================================
- Lists
- ========================================================================== */
-
-/*
- * Addresses margins set differently in IE6/7.
- */
-
-dl,
-menu,
-ol,
-ul {
- margin: 1em 0;
-}
-
-dd {
- margin: 0 0 0 40px;
-}
-
-/*
- * Addresses paddings set differently in IE6/7.
- */
-
-menu,
-ol,
-ul {
- padding: 0 0 0 40px;
-}
-
-/*
- * Corrects list images handled incorrectly in IE7.
- */
-
-nav ul,
-nav ol {
- list-style: none;
- list-style-image: none;
-}
-
-/* ==========================================================================
- Embedded content
- ========================================================================== */
-
-/*
- * 1. Removes border when inside `a` element in IE6/7/8/9, FF3.
- * 2. Improves image quality when scaled in IE7.
- * code.flickr.com/blog/2008/11/12/on-ui-quality-the-little-things-client-side-image-resizing/
- */
-
-img {
- border: 0; /* 1 */
- -ms-interpolation-mode: bicubic; /* 2 */
-}
-
-/*
- * Corrects overflow displayed oddly in IE9.
- */
-
-svg:not(:root) {
- overflow: hidden;
-}
-
-/* ==========================================================================
- Figures
- ========================================================================== */
-
-/*
- * Addresses margin not present in IE6/7/8/9, S5, O11.
- */
-
-figure {
- margin: 0;
-}
-
-/* ==========================================================================
- Forms
- ========================================================================== */
-
-/*
- * Corrects margin displayed oddly in IE6/7.
- */
-
-form {
- margin: 0;
-}
-
-/*
- * Define consistent border, margin, and padding.
- */
-
-fieldset {
- border: 1px solid #c0c0c0;
- margin: 0 2px;
- padding: 0.35em 0.625em 0.75em;
-}
-
-/*
- * 1. Corrects color not being inherited in IE6/7/8/9.
- * 2. Corrects text not wrapping in FF3.
- * 3. Corrects alignment displayed oddly in IE6/7.
- */
-
-legend {
- border: 0; /* 1 */
- padding: 0;
- white-space: normal; /* 2 */
- *margin-left: -7px; /* 3 */
-}
-
-/*
- * 1. Corrects font size not being inherited in all browsers.
- * 2. Addresses margins set differently in IE6/7, FF3+, S5, Chrome.
- * 3. Improves appearance and consistency in all browsers.
- */
-
-button,
-input,
-select,
-textarea {
- font-size: 100%; /* 1 */
- margin: 0; /* 2 */
- vertical-align: baseline; /* 3 */
- *vertical-align: middle; /* 3 */
-}
-
-/*
- * Addresses FF3/4 setting `line-height` on `input` using `!important` in the
- * UA stylesheet.
- */
-
-button,
-input {
- line-height: normal;
-}
-
-/*
- * 1. Avoid the WebKit bug in Android 4.0.* where (2) destroys native `audio`
- * and `video` controls.
- * 2. Corrects inability to style clickable `input` types in iOS.
- * 3. Improves usability and consistency of cursor style between image-type
- * `input` and others.
- * 4. Removes inner spacing in IE7 without affecting normal text inputs.
- * Known issue: inner spacing remains in IE6.
- */
-
-button,
-html input[type="button"], /* 1 */
-input[type="reset"],
-input[type="submit"] {
- -webkit-appearance: button; /* 2 */
- cursor: pointer; /* 3 */
- *overflow: visible; /* 4 */
-}
-
-/*
- * Re-set default cursor for disabled elements.
- */
-
-button[disabled],
-input[disabled] {
- cursor: default;
-}
-
-/*
- * 1. Addresses box sizing set to content-box in IE8/9.
- * 2. Removes excess padding in IE8/9.
- * 3. Removes excess padding in IE7.
- * Known issue: excess padding remains in IE6.
- */
-
-input[type="checkbox"],
-input[type="radio"] {
- box-sizing: border-box; /* 1 */
- padding: 0; /* 2 */
- *height: 13px; /* 3 */
- *width: 13px; /* 3 */
-}
-
-/*
- * 1. Addresses `appearance` set to `searchfield` in S5, Chrome.
- * 2. Addresses `box-sizing` set to `border-box` in S5, Chrome (include `-moz`
- * to future-proof).
- */
-
-input[type="search"] {
- -webkit-appearance: textfield; /* 1 */
- -moz-box-sizing: content-box;
- -webkit-box-sizing: content-box; /* 2 */
- box-sizing: content-box;
-}
-
-/*
- * Removes inner padding and search cancel button in S5, Chrome on OS X.
- */
-
-input[type="search"]::-webkit-search-cancel-button,
-input[type="search"]::-webkit-search-decoration {
- -webkit-appearance: none;
-}
-
-/*
- * Removes inner padding and border in FF3+.
- */
-
-button::-moz-focus-inner,
-input::-moz-focus-inner {
- border: 0;
- padding: 0;
-}
-
-/*
- * 1. Removes default vertical scrollbar in IE6/7/8/9.
- * 2. Improves readability and alignment in all browsers.
- */
-
-textarea {
- overflow: auto; /* 1 */
- vertical-align: top; /* 2 */
-}
-
-/* ==========================================================================
- Tables
- ========================================================================== */
-
-/*
- * Remove most spacing between table cells.
- */
-
-table {
- border-collapse: collapse;
- border-spacing: 0;
-}
diff --git a/lib/scssphp/src/Base/Range.php b/lib/scssphp/src/Base/Range.php
new file mode 100755
index 0000000..a591d7b
--- /dev/null
+++ b/lib/scssphp/src/Base/Range.php
@@ -0,0 +1,47 @@
+
+ */
+class Range
+{
+ public $first;
+ public $last;
+
+ /**
+ * Initialize range
+ *
+ * @param integer|float $first
+ * @param integer|float $last
+ */
+ public function __construct($first, $last)
+ {
+ $this->first = $first;
+ $this->last = $last;
+ }
+
+ /**
+ * Test for inclusion in range
+ *
+ * @param integer|float $value
+ *
+ * @return boolean
+ */
+ public function includes($value)
+ {
+ return $value >= $this->first && $value <= $this->last;
+ }
+}
diff --git a/lib/scssphp/src/Block.php b/lib/scssphp/src/Block.php
new file mode 100755
index 0000000..6b972a1
--- /dev/null
+++ b/lib/scssphp/src/Block.php
@@ -0,0 +1,60 @@
+
+ */
+class Block
+{
+ /**
+ * @var string
+ */
+ public $type;
+
+ /**
+ * @var \Leafo\ScssPhp\Block
+ */
+ public $parent;
+
+ /**
+ * @var integer
+ */
+ public $sourceIndex;
+
+ /**
+ * @var integer
+ */
+ public $sourceLine;
+
+ /**
+ * @var integer
+ */
+ public $sourceColumn;
+
+ /**
+ * @var array
+ */
+ public $selectors;
+
+ /**
+ * @var array
+ */
+ public $comments;
+
+ /**
+ * @var array
+ */
+ public $children;
+}
diff --git a/lib/scssphp/src/Colors.php b/lib/scssphp/src/Colors.php
index 7b7bf8a..ff48c19 100755
--- a/lib/scssphp/src/Colors.php
+++ b/lib/scssphp/src/Colors.php
@@ -2,18 +2,15 @@
/**
* SCSSPHP
*
- * @copyright 2012-2014 Leaf Corcoran
+ * @copyright 2012-2015 Leaf Corcoran
*
- * @license http://opensource.org/licenses/gpl-license GPL-3.0
* @license http://opensource.org/licenses/MIT MIT
*
- * @link http://leafo.net/scssphp
+ * @link http://leafo.github.io/scssphp
*/
namespace Leafo\ScssPhp;
-use Leafo\ScssPhp\Parser;
-
/**
* CSS Colors
*
@@ -25,8 +22,10 @@ class Colors
* CSS Colors
*
* @see http://www.w3.org/TR/css3-color
+ *
+ * @var array
*/
- public static $cssColors = array(
+ public static $cssColors = [
'aliceblue' => '240,248,255',
'antiquewhite' => '250,235,215',
'aqua' => '0,255,255',
@@ -146,6 +145,7 @@ class Colors
'plum' => '221,160,221',
'powderblue' => '176,224,230',
'purple' => '128,0,128',
+ 'rebeccapurple' => '102,51,153',
'red' => '255,0,0',
'rosybrown' => '188,143,143',
'royalblue' => '65,105,225',
@@ -174,6 +174,6 @@ class Colors
'white' => '255,255,255',
'whitesmoke' => '245,245,245',
'yellow' => '255,255,0',
- 'yellowgreen' => '154,205,50'
- );
+ 'yellowgreen' => '154,205,50',
+ ];
}
diff --git a/lib/scssphp/src/Compiler.php b/lib/scssphp/src/Compiler.php
index 5d36efb..19623e6 100755
--- a/lib/scssphp/src/Compiler.php
+++ b/lib/scssphp/src/Compiler.php
@@ -2,18 +2,25 @@
/**
* SCSSPHP
*
- * @copyright 2012-2014 Leaf Corcoran
+ * @copyright 2012-2015 Leaf Corcoran
*
- * @license http://opensource.org/licenses/gpl-license GPL-3.0
* @license http://opensource.org/licenses/MIT MIT
*
- * @link http://leafo.net/scssphp
+ * @link http://leafo.github.io/scssphp
*/
namespace Leafo\ScssPhp;
+use Leafo\ScssPhp\Base\Range;
+use Leafo\ScssPhp\Block;
use Leafo\ScssPhp\Colors;
+use Leafo\ScssPhp\Compiler\Environment;
+use Leafo\ScssPhp\Exception\CompilerException;
+use Leafo\ScssPhp\Formatter\OutputBlock;
+use Leafo\ScssPhp\Node;
+use Leafo\ScssPhp\Type;
use Leafo\ScssPhp\Parser;
+use Leafo\ScssPhp\Util;
/**
* The scss compiler and parser.
@@ -27,7 +34,7 @@
* types are brought to the lowest form before being dump as strings. This
* handles math equations, variable dereferences, and the like.
*
- * The `parse` function of `Compiler` is the entry point.
+ * The `compile` function of `Compiler` is the entry point.
*
* In summary:
*
@@ -49,86 +56,140 @@
*/
class Compiler
{
- static public $VERSION = 'v0.1.1';
-
- static protected $operatorNames = array(
- '+' => 'add',
- '-' => 'sub',
- '*' => 'mul',
- '/' => 'div',
- '%' => 'mod',
-
- '==' => 'eq',
- '!=' => 'neq',
- '<' => 'lt',
- '>' => 'gt',
-
- '<=' => 'lte',
- '>=' => 'gte',
- );
-
- static protected $namespaces = array(
- 'special' => '%',
- 'mixin' => '@',
- 'function' => '^',
- );
-
- static protected $unitTable = array(
- 'in' => array(
- 'in' => 1,
- 'pt' => 72,
- 'pc' => 6,
- 'cm' => 2.54,
- 'mm' => 25.4,
- 'px' => 96,
- )
- );
+ const LINE_COMMENTS = 1;
+ const DEBUG_INFO = 2;
- static public $true = array('keyword', 'true');
- static public $false = array('keyword', 'false');
- static public $null = array('null');
+ const WITH_RULE = 1;
+ const WITH_MEDIA = 2;
+ const WITH_SUPPORTS = 4;
+ const WITH_ALL = 7;
- static public $defaultValue = array('keyword', '');
- static public $selfSelector = array('self');
+ /**
+ * @var array
+ */
+ static protected $operatorNames = [
+ '+' => 'add',
+ '-' => 'sub',
+ '*' => 'mul',
+ '/' => 'div',
+ '%' => 'mod',
+
+ '==' => 'eq',
+ '!=' => 'neq',
+ '<' => 'lt',
+ '>' => 'gt',
+
+ '<=' => 'lte',
+ '>=' => 'gte',
+ '<=>' => 'cmp',
+ ];
- protected $importPaths = array('');
- protected $importCache = array();
+ /**
+ * @var array
+ */
+ static protected $namespaces = [
+ 'special' => '%',
+ 'mixin' => '@',
+ 'function' => '^',
+ ];
+
+ static public $true = [Type::T_KEYWORD, 'true'];
+ static public $false = [Type::T_KEYWORD, 'false'];
+ static public $null = [Type::T_NULL];
+ static public $nullString = [Type::T_STRING, '', []];
+ static public $defaultValue = [Type::T_KEYWORD, ''];
+ static public $selfSelector = [Type::T_SELF];
+ static public $emptyList = [Type::T_LIST, '', []];
+ static public $emptyMap = [Type::T_MAP, [], []];
+ static public $emptyString = [Type::T_STRING, '"', []];
+ static public $with = [Type::T_KEYWORD, 'with'];
+ static public $without = [Type::T_KEYWORD, 'without'];
+
+ protected $importPaths = [''];
+ protected $importCache = [];
+ protected $importedFiles = [];
+ protected $userFunctions = [];
+ protected $registeredVars = [];
+ protected $registeredFeatures = [
+ 'extend-selector-pseudoclass' => false,
+ 'at-error' => true,
+ 'units-level-3' => false,
+ 'global-variable-shadowing' => false,
+ ];
+
+ protected $encoding = null;
+ protected $lineNumberStyle = null;
- protected $userFunctions = array();
- protected $registeredVars = array();
+ protected $formatter = 'Leafo\ScssPhp\Formatter\Nested';
- protected $numberPrecision = 5;
+ protected $rootEnv;
+ protected $rootBlock;
+
+ protected $env;
+ protected $scope;
+ protected $storeEnv;
+ protected $charsetSeen;
+ protected $sourceNames;
+
+ private $indentLevel;
+ private $commentsSeen;
+ private $extends;
+ private $extendsMap;
+ private $parsedFiles;
+ private $parser;
+ private $sourceIndex;
+ private $sourceLine;
+ private $sourceColumn;
+ private $stderr;
+ private $shouldEvaluate;
+ private $ignoreErrors;
- protected $formatter = 'Leafo\ScssPhp\Formatter\Nested';
+ /**
+ * Constructor
+ */
+ public function __construct()
+ {
+ $this->parsedFiles = [];
+ $this->sourceNames = [];
+ }
/**
* Compile scss
*
+ * @api
+ *
* @param string $code
- * @param string $name
+ * @param string $path
*
* @return string
*/
- public function compile($code, $name = null)
+ public function compile($code, $path = null)
{
- $this->indentLevel = -1;
- $this->commentsSeen = array();
- $this->extends = array();
- $this->extendsMap = array();
- $this->parsedFiles = array();
- $this->env = null;
- $this->scope = null;
-
$locale = setlocale(LC_NUMERIC, 0);
setlocale(LC_NUMERIC, 'C');
- $this->parser = new Parser($name);
-
+ $this->indentLevel = -1;
+ $this->commentsSeen = [];
+ $this->extends = [];
+ $this->extendsMap = [];
+ $this->sourceIndex = null;
+ $this->sourceLine = null;
+ $this->sourceColumn = null;
+ $this->env = null;
+ $this->scope = null;
+ $this->storeEnv = null;
+ $this->charsetSeen = null;
+ $this->shouldEvaluate = null;
+ $this->stderr = fopen('php://stderr', 'w');
+
+ $this->parser = $this->parserFactory($path);
$tree = $this->parser->parse($code);
+ $this->parser = null;
$this->formatter = new $this->formatter();
+ $this->rootBlock = null;
+ $this->rootEnv = $this->pushEnv($tree);
- $this->pushEnv($tree);
$this->injectVariables($this->registeredVars);
$this->compileRoot($tree);
$this->popEnv();
@@ -140,6 +201,31 @@ public function compile($code, $name = null)
return $out;
}
+ /**
+ * Instantiate parser
+ *
+ * @param string $path
+ *
+ * @return \Leafo\ScssPhp\Parser
+ */
+ protected function parserFactory($path)
+ {
+ $parser = new Parser($path, count($this->sourceNames), $this->encoding);
+
+ $this->sourceNames[] = $path;
+ $this->addParsedFile($path);
+
+ return $parser;
+ }
+
+ /**
+ * Is self extend?
+ *
+ * @param array $target
+ * @param array $origin
+ *
+ * @return boolean
+ */
protected function isSelfExtend($target, $origin)
{
foreach ($origin as $sel) {
@@ -151,112 +237,158 @@ protected function isSelfExtend($target, $origin)
return false;
}
- protected function pushExtends($target, $origin)
+ /**
+ * Push extends
+ *
+ * @param array $target
+ * @param array $origin
+ * @param \stdClass $block
+ */
+ protected function pushExtends($target, $origin, $block)
{
if ($this->isSelfExtend($target, $origin)) {
return;
}
$i = count($this->extends);
- $this->extends[] = array($target, $origin);
+ $this->extends[] = [$target, $origin, $block];
foreach ($target as $part) {
if (isset($this->extendsMap[$part])) {
$this->extendsMap[$part][] = $i;
} else {
- $this->extendsMap[$part] = array($i);
+ $this->extendsMap[$part] = [$i];
}
}
}
+ /**
+ * Make output block
+ *
+ * @param string $type
+ * @param array $selectors
+ *
+ * @return \Leafo\ScssPhp\Formatter\OutputBlock
+ */
protected function makeOutputBlock($type, $selectors = null)
{
- $out = new \stdClass;
- $out->type = $type;
- $out->lines = array();
- $out->children = array();
- $out->parent = $this->scope;
+ $out = new OutputBlock;
+ $out->type = $type;
+ $out->lines = [];
+ $out->children = [];
+ $out->parent = $this->scope;
$out->selectors = $selectors;
- $out->depth = $this->env->depth;
+ $out->depth = $this->env->depth;
return $out;
}
- protected function matchExtendsSingle($single, &$outOrigin)
+ /**
+ * Compile root
+ *
+ * @param \Leafo\ScssPhp\Block $rootBlock
+ */
+ protected function compileRoot(Block $rootBlock)
{
- $counts = array();
- foreach ($single as $part) {
- if (!is_string($part)) {
- return false; // hmm
- }
-
- if (isset($this->extendsMap[$part])) {
- foreach ($this->extendsMap[$part] as $idx) {
- $counts[$idx] =
- isset($counts[$idx]) ? $counts[$idx] + 1 : 1;
- }
- }
- }
+ $this->rootBlock = $this->scope = $this->makeOutputBlock(Type::T_ROOT);
- $outOrigin = array();
- $found = false;
-
- foreach ($counts as $idx => $count) {
- list($target, $origin) = $this->extends[$idx];
+ $this->compileChildrenNoReturn($rootBlock->children, $this->scope);
+ $this->flattenSelectors($this->scope);
+ $this->missingSelectors();
+ }
- // check count
- if ($count != count($target)) {
+ /**
+ * Report missing selectors
+ */
+ protected function missingSelectors()
+ {
+ foreach ($this->extends as $extend) {
+ if (isset($extend[3])) {
continue;
}
- // check if target is subset of single
- if (array_diff(array_intersect($single, $target), $target)) {
+ list($target, $origin, $block) = $extend;
+
+ // ignore if !optional
+ if ($block[2]) {
continue;
}
- $rem = array_diff($single, $target);
+ $target = implode(' ', $target);
+ $origin = $this->collapseSelectors($origin);
- foreach ($origin as $j => $new) {
- // prevent infinite loop when target extends itself
- foreach ($new as $new_selector) {
- if (!array_diff($single, $new_selector)) {
- continue 2;
- }
+ $this->sourceLine = $block[Parser::SOURCE_LINE];
+ $this->throwError("\"$origin\" failed to @extend \"$target\". The selector \"$target\" was not found.");
+ }
+ }
+
+ /**
+ * Flatten selectors
+ *
+ * @param \Leafo\ScssPhp\Formatter\OutputBlock $block
+ * @param string $parentKey
+ */
+ protected function flattenSelectors(OutputBlock $block, $parentKey = null)
+ {
+ if ($block->selectors) {
+ $selectors = [];
+
+ foreach ($block->selectors as $s) {
+ $selectors[] = $s;
+
+ if (! is_array($s)) {
+ continue;
}
- $origin[$j][count($origin[$j]) - 1] = $this->combineSelectorSingle(end($new), $rem);
- }
+ // check extends
+ if (! empty($this->extendsMap)) {
+ $this->matchExtends($s, $selectors);
- $outOrigin = array_merge($outOrigin, $origin);
+ // remove duplicates
+ array_walk($selectors, function (&$value) {
+ $value = serialize($value);
+ });
- $found = true;
- }
+ $selectors = array_unique($selectors);
- return $found;
- }
+ array_walk($selectors, function (&$value) {
+ $value = unserialize($value);
+ });
+ }
+ }
- protected function combineSelectorSingle($base, $other)
- {
- $tag = null;
- $out = array();
+ $block->selectors = [];
+ $placeholderSelector = false;
- foreach (array($base, $other) as $single) {
- foreach ($single as $part) {
- if (preg_match('/^[^\[.#:]/', $part)) {
- $tag = $part;
- } else {
- $out[] = $part;
+ foreach ($selectors as $selector) {
+ if ($this->hasSelectorPlaceholder($selector)) {
+ $placeholderSelector = true;
+ continue;
}
+
+ $block->selectors[] = $this->compileSelector($selector);
}
- }
- if ($tag) {
- array_unshift($out, $tag);
+ if ($placeholderSelector && 0 === count($block->selectors) && null !== $parentKey) {
+ unset($block->parent->children[$parentKey]);
+
+ return;
+ }
}
- return $out;
+ foreach ($block->children as $key => $child) {
+ $this->flattenSelectors($child, $key);
+ }
}
+ /**
+ * Match extends
+ *
+ * @param array $selector
+ * @param array $out
+ * @param integer $from
+ * @param boolean $initial
+ */
protected function matchExtends($selector, &$out, $from = 0, $initial = true)
{
foreach ($selector as $i => $part) {
@@ -267,16 +399,15 @@ protected function matchExtends($selector, &$out, $from = 0, $initial = true)
if ($this->matchExtendsSingle($part, $origin)) {
$before = array_slice($selector, 0, $i);
$after = array_slice($selector, $i + 1);
+ $s = count($before);
foreach ($origin as $new) {
$k = 0;
// remove shared parts
if ($initial) {
- foreach ($before as $k => $val) {
- if (!isset($new[$k]) || $val != $new[$k]) {
- break;
- }
+ while ($k < $s && isset($new[$k]) && $before[$k] === $new[$k]) {
+ $k++;
}
}
@@ -286,7 +417,7 @@ protected function matchExtends($selector, &$out, $from = 0, $initial = true)
$after
);
- if ($result == $selector) {
+ if ($result === $selector) {
continue;
}
@@ -296,7 +427,7 @@ protected function matchExtends($selector, &$out, $from = 0, $initial = true)
$this->matchExtends($result, $out, $i, false);
// selector sequence merging
- if (!empty($before) && count($new) > 1) {
+ if (! empty($before) && count($new) > 1) {
$result2 = array_merge(
array_slice($new, 0, -1),
$k > 0 ? array_slice($before, $k) : $before,
@@ -311,64 +442,126 @@ protected function matchExtends($selector, &$out, $from = 0, $initial = true)
}
}
- protected function flattenSelectors($block, $parentKey = null)
+ /**
+ * Match extends single
+ *
+ * @param array $rawSingle
+ * @param array $outOrigin
+ *
+ * @return boolean
+ */
+ protected function matchExtendsSingle($rawSingle, &$outOrigin)
{
- if ($block->selectors) {
- $selectors = array();
+ $counts = [];
+ $single = [];
- foreach ($block->selectors as $s) {
- $selectors[] = $s;
+ foreach ($rawSingle as $part) {
+ // matches Number
+ if (! is_string($part)) {
+ return false;
+ }
- if (!is_array($s)) {
- continue;
- }
+ if (! preg_match('/^[\[.:#%]/', $part) && count($single)) {
+ $single[count($single) - 1] .= $part;
+ } else {
+ $single[] = $part;
+ }
+ }
- // check extends
- if (!empty($this->extendsMap)) {
- $this->matchExtends($s, $selectors);
+ foreach ($single as $part) {
+ if (isset($this->extendsMap[$part])) {
+ foreach ($this->extendsMap[$part] as $idx) {
+ $counts[$idx] = isset($counts[$idx]) ? $counts[$idx] + 1 : 1;
}
}
+ }
- $block->selectors = array();
- $placeholderSelector = false;
+ $outOrigin = [];
+ $found = false;
- foreach ($selectors as $selector) {
- if ($this->hasSelectorPlaceholder($selector)) {
- $placeholderSelector = true;
- continue;
- }
+ foreach ($counts as $idx => $count) {
+ list($target, $origin, /* $block */) = $this->extends[$idx];
- $block->selectors[] = $this->compileSelector($selector);
+ // check count
+ if ($count !== count($target)) {
+ continue;
}
- if ($placeholderSelector && 0 == count($block->selectors) && null !== $parentKey) {
- unset($block->parent->children[$parentKey]);
+ $this->extends[$idx][3] = true;
- return;
+ $rem = array_diff($single, $target);
+
+ foreach ($origin as $j => $new) {
+ // prevent infinite loop when target extends itself
+ if ($this->isSelfExtend($single, $origin)) {
+ return false;
+ }
+
+ $combined = $this->combineSelectorSingle(end($new), $rem);
+
+ if (count(array_diff($combined, $origin[$j][count($origin[$j]) - 1]))) {
+ $origin[$j][count($origin[$j]) - 1] = $combined;
+ }
}
- }
- foreach ($block->children as $key => $child) {
- $this->flattenSelectors($child, $key);
+ $outOrigin = array_merge($outOrigin, $origin);
+
+ $found = true;
}
+
+ return $found;
}
- protected function compileRoot($rootBlock)
+ /**
+ * Combine selector single
+ *
+ * @param array $base
+ * @param array $other
+ *
+ * @return array
+ */
+ protected function combineSelectorSingle($base, $other)
{
- $this->scope = $this->makeOutputBlock('root');
+ $tag = [];
+ $out = [];
+ $wasTag = true;
- $this->compileChildren($rootBlock->children, $this->scope);
- $this->flattenSelectors($this->scope);
+ foreach ([$base, $other] as $single) {
+ foreach ($single as $part) {
+ if (preg_match('/^[\[.:#]/', $part)) {
+ $out[] = $part;
+ $wasTag = false;
+ } elseif (preg_match('/^[^_-]/', $part)) {
+ $tag[] = $part;
+ $wasTag = true;
+ } elseif ($wasTag) {
+ $tag[count($tag) - 1] .= $part;
+ } else {
+ $out[count($out) - 1] .= $part;
+ }
+ }
+ }
+
+ if (count($tag)) {
+ array_unshift($out, $tag[0]);
+ }
+
+ return $out;
}
- protected function compileMedia($media)
+ /**
+ * Compile media
+ *
+ * @param \Leafo\ScssPhp\Block $media
+ */
+ protected function compileMedia(Block $media)
{
$this->pushEnv($media);
$mediaQuery = $this->compileMediaQuery($this->multiplyMedia($this->env));
- if (!empty($mediaQuery)) {
- $this->scope = $this->makeOutputBlock('media', array($mediaQuery));
+ if (! empty($mediaQuery)) {
+ $this->scope = $this->makeOutputBlock(Type::T_MEDIA, [$mediaQuery]);
$parentScope = $this->mediaParent($this->scope);
$parentScope->children[] = $this->scope;
@@ -378,21 +571,31 @@ protected function compileMedia($media)
foreach ($media->children as $child) {
$type = $child[0];
- if ($type !== 'block' && $type !== 'media' && $type !== 'directive') {
+
+ if ($type !== Type::T_BLOCK &&
+ $type !== Type::T_MEDIA &&
+ $type !== Type::T_DIRECTIVE &&
+ $type !== Type::T_IMPORT
+ ) {
$needsWrap = true;
break;
}
}
if ($needsWrap) {
- $wrapped = (object)array(
- 'selectors' => array(),
- 'children' => $media->children
- );
- $media->children = array(array('block', $wrapped));
+ $wrapped = new Block;
+ $wrapped->sourceIndex = $media->sourceIndex;
+ $wrapped->sourceLine = $media->sourceLine;
+ $wrapped->sourceColumn = $media->sourceColumn;
+ $wrapped->selectors = [];
+ $wrapped->comments = [];
+ $wrapped->parent = $media;
+ $wrapped->children = $media->children;
+
+ $media->children = [[Type::T_BLOCK, $wrapped]];
}
- $this->compileChildren($media->children, $this->scope);
+ $this->compileChildrenNoReturn($media->children, $this->scope);
$this->scope = $this->scope->parent;
}
@@ -400,148 +603,542 @@ protected function compileMedia($media)
$this->popEnv();
}
- protected function mediaParent($scope)
+ /**
+ * Media parent
+ *
+ * @param \Leafo\ScssPhp\Formatter\OutputBlock $scope
+ *
+ * @return \Leafo\ScssPhp\Formatter\OutputBlock
+ */
+ protected function mediaParent(OutputBlock $scope)
{
- while (!empty($scope->parent)) {
- if (!empty($scope->type) && $scope->type != 'media') {
+ while (! empty($scope->parent)) {
+ if (! empty($scope->type) && $scope->type !== Type::T_MEDIA) {
break;
}
+
$scope = $scope->parent;
}
return $scope;
}
- // TODO refactor compileNestedBlock and compileMedia into same thing
- protected function compileNestedBlock($block, $selectors)
+ /**
+ * Compile directive
+ *
+ * @param \Leafo\ScssPhp\Block $block
+ */
+ protected function compileDirective(Block $block)
{
- $this->pushEnv($block);
+ $s = '@' . $block->name;
- $this->scope = $this->makeOutputBlock($block->type, $selectors);
- $this->scope->parent->children[] = $this->scope;
- $this->compileChildren($block->children, $this->scope);
+ if (! empty($block->value)) {
+ $s .= ' ' . $this->compileValue($block->value);
+ }
- $this->scope = $this->scope->parent;
- $this->popEnv();
+ if ($block->name === 'keyframes' || substr($block->name, -10) === '-keyframes') {
+ $this->compileKeyframeBlock($block, [$s]);
+ } else {
+ $this->compileNestedBlock($block, [$s]);
+ }
}
/**
- * Recursively compiles a block.
- *
- * A block is analogous to a CSS block in most cases. A single SCSS document
- * is encapsulated in a block when parsed, but it does not have parent tags
- * so all of its children appear on the root level when compiled.
- *
- * Blocks are made up of selectors and children.
- *
- * The children of a block are just all the blocks that are defined within.
+ * Compile at-root
*
- * Compiling the block involves pushing a fresh environment on the stack,
- * and iterating through the props, compiling each one.
- *
- * @see Compiler::compileChild()
- *
- * @param \StdClass $block
+ * @param \Leafo\ScssPhp\Block $block
*/
- protected function compileBlock($block)
- {
- $env = $this->pushEnv($block);
+ protected function compileAtRoot(Block $block)
+ {
+ $env = $this->pushEnv($block);
+ $envs = $this->compactEnv($env);
+ $without = isset($block->with) ? $this->compileWith($block->with) : self::WITH_RULE;
+
+ // wrap inline selector
+ if ($block->selector) {
+ $wrapped = new Block;
+ $wrapped->sourceIndex = $block->sourceIndex;
+ $wrapped->sourceLine = $block->sourceLine;
+ $wrapped->sourceColumn = $block->sourceColumn;
+ $wrapped->selectors = $block->selector;
+ $wrapped->comments = [];
+ $wrapped->parent = $block;
+ $wrapped->children = $block->children;
+
+ $block->children = [[Type::T_BLOCK, $wrapped]];
+ }
- $env->selectors =
- array_map(array($this, 'evalSelector'), $block->selectors);
+ $this->env = $this->filterWithout($envs, $without);
+ $newBlock = $this->spliceTree($envs, $block, $without);
- $out = $this->makeOutputBlock(null, $this->multiplySelectors($env));
- $this->scope->children[] = $out;
- $this->compileChildren($block->children, $out);
+ $saveScope = $this->scope;
+ $this->scope = $this->rootBlock;
+
+ $this->compileChild($newBlock, $this->scope);
+
+ $this->scope = $saveScope;
+ $this->env = $this->extractEnv($envs);
$this->popEnv();
}
- // root level comment
- protected function compileComment($block)
+ /**
+ * Splice parse tree
+ *
+ * @param array $envs
+ * @param \Leafo\ScssPhp\Block $block
+ * @param integer $without
+ *
+ * @return array
+ */
+ private function spliceTree($envs, Block $block, $without)
{
- $out = $this->makeOutputBlock('comment');
- $out->lines[] = $block[1];
- $this->scope->children[] = $out;
- }
+ $newBlock = null;
- // joins together .classes and #ids
- protected function flattenSelectorSingle($single)
- {
- $joined = array();
- foreach ($single as $part) {
- if (empty($joined) ||
- !is_string($part) ||
- preg_match('/[\[.:#%]/', $part)
- ) {
- $joined[] = $part;
+ foreach ($envs as $e) {
+ if (! isset($e->block)) {
continue;
}
- if (is_array(end($joined))) {
- $joined[] = $part;
- } else {
- $joined[count($joined) - 1] .= $part;
+ if ($e->block === $block) {
+ continue;
}
- }
- return $joined;
- }
-
- // replaces all the interpolates
- protected function evalSelector($selector)
- {
- return array_map(array($this, 'evalSelectorPart'), $selector);
- }
-
- protected function evalSelectorPart($piece)
- {
- foreach ($piece as &$p) {
- if (!is_array($p)) {
+ if (isset($e->block->type) && $e->block->type === Type::T_AT_ROOT) {
continue;
}
- switch ($p[0]) {
- case 'interpolate':
- $p = $this->compileValue($p);
- break;
- case 'string':
- $p = $this->compileValue($p);
- break;
+ if ($e->block && $this->isWithout($without, $e->block)) {
+ continue;
}
- }
- return $this->flattenSelectorSingle($piece);
+ $b = new Block;
+ $b->sourceIndex = $e->block->sourceIndex;
+ $b->sourceLine = $e->block->sourceLine;
+ $b->sourceColumn = $e->block->sourceColumn;
+ $b->selectors = [];
+ $b->comments = $e->block->comments;
+ $b->parent = null;
+
+ if ($newBlock) {
+ $type = isset($newBlock->type) ? $newBlock->type : Type::T_BLOCK;
+
+ $b->children = [[$type, $newBlock]];
+
+ $newBlock->parent = $b;
+ } elseif (count($block->children)) {
+ foreach ($block->children as $child) {
+ if ($child[0] === Type::T_BLOCK) {
+ $child[1]->parent = $b;
+ }
+ }
+
+ $b->children = $block->children;
+ }
+
+ if (isset($e->block->type)) {
+ $b->type = $e->block->type;
+ }
+
+ if (isset($e->block->name)) {
+ $b->name = $e->block->name;
+ }
+
+ if (isset($e->block->queryList)) {
+ $b->queryList = $e->block->queryList;
+ }
+
+ if (isset($e->block->value)) {
+ $b->value = $e->block->value;
+ }
+
+ $newBlock = $b;
+ }
+
+ $type = isset($newBlock->type) ? $newBlock->type : Type::T_BLOCK;
+
+ return [$type, $newBlock];
+ }
+
+ /**
+ * Compile @at-root's with: inclusion / without: exclusion into filter flags
+ *
+ * @param array $with
+ *
+ * @return integer
+ */
+ private function compileWith($with)
+ {
+ static $mapping = [
+ 'rule' => self::WITH_RULE,
+ 'media' => self::WITH_MEDIA,
+ 'supports' => self::WITH_SUPPORTS,
+ 'all' => self::WITH_ALL,
+ ];
+
+ // exclude selectors by default
+ $without = self::WITH_RULE;
+
+ if ($this->libMapHasKey([$with, self::$with])) {
+ $without = self::WITH_ALL;
+
+ $list = $this->coerceList($this->libMapGet([$with, self::$with]));
+
+ foreach ($list[2] as $item) {
+ $keyword = $this->compileStringContent($this->coerceString($item));
+
+ if (array_key_exists($keyword, $mapping)) {
+ $without &= ~($mapping[$keyword]);
+ }
+ }
+ }
+
+ if ($this->libMapHasKey([$with, self::$without])) {
+ $without = 0;
+
+ $list = $this->coerceList($this->libMapGet([$with, self::$without]));
+
+ foreach ($list[2] as $item) {
+ $keyword = $this->compileStringContent($this->coerceString($item));
+
+ if (array_key_exists($keyword, $mapping)) {
+ $without |= $mapping[$keyword];
+ }
+ }
+ }
+
+ return $without;
+ }
+
+ /**
+ * Filter env stack
+ *
+ * @param array $envs
+ * @param integer $without
+ *
+ * @return \Leafo\ScssPhp\Compiler\Environment
+ */
+ private function filterWithout($envs, $without)
+ {
+ $filtered = [];
+
+ foreach ($envs as $e) {
+ if ($e->block && $this->isWithout($without, $e->block)) {
+ continue;
+ }
+
+ $filtered[] = $e;
+ }
+
+ return $this->extractEnv($filtered);
+ }
+
+ /**
+ * Filter WITH rules
+ *
+ * @param integer $without
+ * @param \Leafo\ScssPhp\Block $block
+ *
+ * @return boolean
+ */
+ private function isWithout($without, Block $block)
+ {
+ if ((($without & self::WITH_RULE) && isset($block->selectors)) ||
+ (($without & self::WITH_MEDIA) &&
+ isset($block->type) && $block->type === Type::T_MEDIA) ||
+ (($without & self::WITH_SUPPORTS) &&
+ isset($block->type) && $block->type === Type::T_DIRECTIVE &&
+ isset($block->name) && $block->name === 'supports')
+ ) {
+ return true;
+ }
+
+ return false;
+ }
+
+ /**
+ * Compile keyframe block
+ *
+ * @param \Leafo\ScssPhp\Block $block
+ * @param array $selectors
+ */
+ protected function compileKeyframeBlock(Block $block, $selectors)
+ {
+ $env = $this->pushEnv($block);
+
+ $envs = $this->compactEnv($env);
+
+ $this->env = $this->extractEnv(array_filter($envs, function (Environment $e) {
+ return ! isset($e->block->selectors);
+ }));
+
+ $this->scope = $this->makeOutputBlock($block->type, $selectors);
+ $this->scope->depth = 1;
+ $this->scope->parent->children[] = $this->scope;
+
+ $this->compileChildrenNoReturn($block->children, $this->scope);
+
+ $this->scope = $this->scope->parent;
+ $this->env = $this->extractEnv($envs);
+
+ $this->popEnv();
+ }
+
+ /**
+ * Compile nested block
+ *
+ * @param \Leafo\ScssPhp\Block $block
+ * @param array $selectors
+ */
+ protected function compileNestedBlock(Block $block, $selectors)
+ {
+ $this->pushEnv($block);
+
+ $this->scope = $this->makeOutputBlock($block->type, $selectors);
+ $this->scope->parent->children[] = $this->scope;
+
+ $this->compileChildrenNoReturn($block->children, $this->scope);
+
+ $this->scope = $this->scope->parent;
+
+ $this->popEnv();
+ }
+
+ /**
+ * Recursively compiles a block.
+ *
+ * A block is analogous to a CSS block in most cases. A single SCSS document
+ * is encapsulated in a block when parsed, but it does not have parent tags
+ * so all of its children appear on the root level when compiled.
+ *
+ * Blocks are made up of selectors and children.
+ *
+ * The children of a block are just all the blocks that are defined within.
+ *
+ * Compiling the block involves pushing a fresh environment on the stack,
+ * and iterating through the props, compiling each one.
+ *
+ * @see Compiler::compileChild()
+ *
+ * @param \Leafo\ScssPhp\Block $block
+ */
+ protected function compileBlock(Block $block)
+ {
+ $env = $this->pushEnv($block);
+ $env->selectors = $this->evalSelectors($block->selectors);
+
+ $out = $this->makeOutputBlock(null);
+
+ if (isset($this->lineNumberStyle) && count($env->selectors) && count($block->children)) {
+ $annotation = $this->makeOutputBlock(Type::T_COMMENT);
+ $annotation->depth = 0;
+
+ $file = $this->sourceNames[$block->sourceIndex];
+ $line = $block->sourceLine;
+
+ switch ($this->lineNumberStyle) {
+ case self::LINE_COMMENTS:
+ $annotation->lines[] = '/* line ' . $line . ', ' . $file . ' */';
+ break;
+
+ case self::DEBUG_INFO:
+ $annotation->lines[] = '@media -sass-debug-info{filename{font-family:"' . $file
+ . '"}line{font-family:' . $line . '}}';
+ break;
+ }
+
+ $this->scope->children[] = $annotation;
+ }
+
+ $this->scope->children[] = $out;
+
+ if (count($block->children)) {
+ $out->selectors = $this->multiplySelectors($env);
+
+ $this->compileChildrenNoReturn($block->children, $out);
+ }
+
+ $this->formatter->stripSemicolon($out->lines);
+
+ $this->popEnv();
+ }
+
+ /**
+ * Compile root level comment
+ *
+ * @param array $block
+ */
+ protected function compileComment($block)
+ {
+ $out = $this->makeOutputBlock(Type::T_COMMENT);
+ $out->lines[] = $block[1];
+ $this->scope->children[] = $out;
+ }
+
+ /**
+ * Evaluate selectors
+ *
+ * @param array $selectors
+ *
+ * @return array
+ */
+ protected function evalSelectors($selectors)
+ {
+ $this->shouldEvaluate = false;
+
+ $selectors = array_map([$this, 'evalSelector'], $selectors);
+
+ // after evaluating interpolates, we might need a second pass
+ if ($this->shouldEvaluate) {
+ $buffer = $this->collapseSelectors($selectors);
+ $parser = $this->parserFactory(__METHOD__);
+
+ if ($parser->parseSelector($buffer, $newSelectors)) {
+ $selectors = array_map([$this, 'evalSelector'], $newSelectors);
+ }
+ }
+
+ return $selectors;
+ }
+
+ /**
+ * Evaluate selector
+ *
+ * @param array $selector
+ *
+ * @return array
+ */
+ protected function evalSelector($selector)
+ {
+ return array_map([$this, 'evalSelectorPart'], $selector);
+ }
+
+ /**
+ * Evaluate selector part; replaces all the interpolates, stripping quotes
+ *
+ * @param array $part
+ *
+ * @return array
+ */
+ protected function evalSelectorPart($part)
+ {
+ foreach ($part as &$p) {
+ if (is_array($p) && ($p[0] === Type::T_INTERPOLATE || $p[0] === Type::T_STRING)) {
+ $p = $this->compileValue($p);
+
+ // force re-evaluation
+ if (strpos($p, '&') !== false || strpos($p, ',') !== false) {
+ $this->shouldEvaluate = true;
+ }
+ } elseif (is_string($p) && strlen($p) >= 2 &&
+ ($first = $p[0]) && ($first === '"' || $first === "'") &&
+ substr($p, -1) === $first
+ ) {
+ $p = substr($p, 1, -1);
+ }
+ }
+
+ return $this->flattenSelectorSingle($part);
+ }
+
+ /**
+ * Collapse selectors
+ *
+ * @param array $selectors
+ *
+ * @return string
+ */
+ protected function collapseSelectors($selectors)
+ {
+ $parts = [];
+
+ foreach ($selectors as $selector) {
+ $output = '';
+
+ array_walk_recursive(
+ $selector,
+ function ($value, $key) use (&$output) {
+ $output .= $value;
+ }
+ );
+
+ $parts[] = $output;
+ }
+
+ return implode(', ', $parts);
+ }
+
+ /**
+ * Flatten selector single; joins together .classes and #ids
+ *
+ * @param array $single
+ *
+ * @return array
+ */
+ protected function flattenSelectorSingle($single)
+ {
+ $joined = [];
+
+ foreach ($single as $part) {
+ if (empty($joined) ||
+ ! is_string($part) ||
+ preg_match('/[\[.:#%]/', $part)
+ ) {
+ $joined[] = $part;
+ continue;
+ }
+
+ if (is_array(end($joined))) {
+ $joined[] = $part;
+ } else {
+ $joined[count($joined) - 1] .= $part;
+ }
+ }
+
+ return $joined;
}
- // compiles to string
- // self(&) should have been replaced by now
+ /**
+ * Compile selector to string; self(&) should have been replaced by now
+ *
+ * @param array $selector
+ *
+ * @return string
+ */
protected function compileSelector($selector)
{
- if (!is_array($selector)) {
+ if (! is_array($selector)) {
return $selector; // media and the like
}
return implode(
' ',
array_map(
- array($this, 'compileSelectorPart'),
+ [$this, 'compileSelectorPart'],
$selector
)
);
}
+ /**
+ * Compile selector part
+ *
+ * @param arary $piece
+ *
+ * @return string
+ */
protected function compileSelectorPart($piece)
{
foreach ($piece as &$p) {
- if (!is_array($p)) {
+ if (! is_array($p)) {
continue;
}
switch ($p[0]) {
- case 'self':
+ case Type::T_SELF:
$p = '&';
break;
+
default:
$p = $this->compileValue($p);
break;
@@ -551,15 +1148,22 @@ protected function compileSelectorPart($piece)
return implode($piece);
}
+ /**
+ * Has selector placeholder?
+ *
+ * @param array $selector
+ *
+ * @return boolean
+ */
protected function hasSelectorPlaceholder($selector)
{
- if (!is_array($selector)) {
+ if (! is_array($selector)) {
return false;
}
foreach ($selector as $parts) {
foreach ($parts as $part) {
- if ('%' == $part[0]) {
+ if (strlen($part) && '%' === $part[0]) {
return true;
}
}
@@ -568,7 +1172,15 @@ protected function hasSelectorPlaceholder($selector)
return false;
}
- protected function compileChildren($stms, $out)
+ /**
+ * Compile children and return result
+ *
+ * @param array $stms
+ * @param \Leafo\ScssPhp\Formatter\OutputBlock $out
+ *
+ * @return array
+ */
+ protected function compileChildren($stms, OutputBlock $out)
{
foreach ($stms as $stm) {
$ret = $this->compileChild($stm, $out);
@@ -579,6 +1191,34 @@ protected function compileChildren($stms, $out)
}
}
+ /**
+ * Compile children and throw exception if unexpected @return
+ *
+ * @param array $stms
+ * @param \Leafo\ScssPhp\Formatter\OutputBlock $out
+ *
+ * @throws \Exception
+ */
+ protected function compileChildrenNoReturn($stms, OutputBlock $out)
+ {
+ foreach ($stms as $stm) {
+ $ret = $this->compileChild($stm, $out);
+
+ if (isset($ret)) {
+ $this->throwError('@return may only be used within a function');
+
+ return;
+ }
+ }
+ }
+
+ /**
+ * Compile media query
+ *
+ * @param array $queryList
+ *
+ * @return string
+ */
protected function compileMediaQuery($queryList)
{
$out = '@media';
@@ -586,25 +1226,26 @@ protected function compileMediaQuery($queryList)
foreach ($queryList as $query) {
$type = null;
- $parts = array();
+ $parts = [];
foreach ($query as $q) {
switch ($q[0]) {
- case 'mediaType':
+ case Type::T_MEDIA_TYPE:
if ($type) {
$type = $this->mergeMediaTypes(
$type,
- array_map(array($this, 'compileValue'), array_slice($q, 1))
+ array_map([$this, 'compileValue'], array_slice($q, 1))
);
if (empty($type)) { // merge failed
return null;
}
} else {
- $type = array_map(array($this, 'compileValue'), array_slice($q, 1));
+ $type = array_map([$this, 'compileValue'], array_slice($q, 1));
}
break;
- case 'mediaExp':
+
+ case Type::T_MEDIA_EXPRESSION:
if (isset($q[2])) {
$parts[] = '('
. $this->compileValue($q[1])
@@ -617,6 +1258,10 @@ protected function compileMediaQuery($queryList)
. ')';
}
break;
+
+ case Type::T_MEDIA_VALUE:
+ $parts[] = $this->compileValue($q[1]);
+ break;
}
}
@@ -624,7 +1269,7 @@ protected function compileMediaQuery($queryList)
array_unshift($parts, implode(' ', array_filter($type)));
}
- if (!empty($parts)) {
+ if (! empty($parts)) {
if ($first) {
$first = false;
$out .= ' ';
@@ -639,6 +1284,14 @@ protected function compileMediaQuery($queryList)
return $out;
}
+ /**
+ * Merge media types
+ *
+ * @param array $type1
+ * @param array $type2
+ *
+ * @return array|null
+ */
protected function mergeMediaTypes($type1, $type2)
{
if (empty($type1)) {
@@ -669,56 +1322,68 @@ protected function mergeMediaTypes($type1, $type2)
$t2 = strtolower($type2[0]);
}
- if (($m1 == 'not') ^ ($m2 == 'not')) {
- if ($t1 == $t2) {
+ if (($m1 === Type::T_NOT) ^ ($m2 === Type::T_NOT)) {
+ if ($t1 === $t2) {
return null;
}
- return array(
- $m1 == 'not' ? $m2 : $m1,
- $m1 == 'not' ? $t2 : $t1
- );
+ return [
+ $m1 === Type::T_NOT ? $m2 : $m1,
+ $m1 === Type::T_NOT ? $t2 : $t1,
+ ];
}
- if ($m1 == 'not' && $m2 == 'not') {
- # CSS has no way of representing "neither screen nor print"
- if ($t1 != $t2) {
+ if ($m1 === Type::T_NOT && $m2 === Type::T_NOT) {
+ // CSS has no way of representing "neither screen nor print"
+ if ($t1 !== $t2) {
return null;
}
- return array('not', $t1);
+ return [Type::T_NOT, $t1];
}
- if ($t1 != $t2) {
+ if ($t1 !== $t2) {
return null;
}
// t1 == t2, neither m1 nor m2 are "not"
- return array(empty($m1)? $m2 : $m1, $t1);
+ return [empty($m1)? $m2 : $m1, $t1];
}
- // returns true if the value was something that could be imported
- protected function compileImport($rawPath, $out)
+ /**
+ * Compile import; returns true if the value was something that could be imported
+ *
+ * @param array $rawPath
+ * @param array $out
+ * @param boolean $once
+ *
+ * @return boolean
+ */
+ protected function compileImport($rawPath, $out, $once = false)
{
- if ($rawPath[0] == 'string') {
+ if ($rawPath[0] === Type::T_STRING) {
$path = $this->compileStringContent($rawPath);
if ($path = $this->findImport($path)) {
- $this->importFile($path, $out);
+ if (! $once || ! in_array($path, $this->importedFiles)) {
+ $this->importFile($path, $out);
+ $this->importedFiles[] = $path;
+ }
return true;
}
return false;
}
- if ($rawPath[0] == 'list') {
+
+ if ($rawPath[0] === Type::T_LIST) {
// handle a list of strings
- if (count($rawPath[2]) == 0) {
+ if (count($rawPath[2]) === 0) {
return false;
}
foreach ($rawPath[2] as $path) {
- if ($path[0] != 'string') {
+ if ($path[0] !== Type::T_STRING) {
return false;
}
}
@@ -733,135 +1398,224 @@ protected function compileImport($rawPath, $out)
return false;
}
- // return a value to halt execution
- protected function compileChild($child, $out)
+ /**
+ * Compile child; returns a value to halt execution
+ *
+ * @param array $child
+ * @param \Leafo\ScssPhp\Formatter\OutputBlock $out
+ *
+ * @return array
+ */
+ protected function compileChild($child, OutputBlock $out)
{
- $this->sourcePos = isset($child[-1]) ? $child[-1] : -1;
- $this->sourceParser = isset($child[-2]) ? $child[-2] : $this->parser;
+ $this->sourceIndex = isset($child[Parser::SOURCE_INDEX]) ? $child[Parser::SOURCE_INDEX] : null;
+ $this->sourceLine = isset($child[Parser::SOURCE_LINE]) ? $child[Parser::SOURCE_LINE] : -1;
+ $this->sourceColumn = isset($child[Parser::SOURCE_COLUMN]) ? $child[Parser::SOURCE_COLUMN] : -1;
switch ($child[0]) {
- case 'import':
- list(,$rawPath) = $child;
+ case Type::T_SCSSPHP_IMPORT_ONCE:
+ list(, $rawPath) = $child;
$rawPath = $this->reduce($rawPath);
- if (!$this->compileImport($rawPath, $out)) {
+
+ if (! $this->compileImport($rawPath, $out, true)) {
$out->lines[] = '@import ' . $this->compileValue($rawPath) . ';';
}
break;
- case 'directive':
- list(, $directive) = $child;
- $s = '@' . $directive->name;
- if (!empty($directive->value)) {
- $s .= ' ' . $this->compileValue($directive->value);
+ case Type::T_IMPORT:
+ list(, $rawPath) = $child;
+
+ $rawPath = $this->reduce($rawPath);
+
+ if (! $this->compileImport($rawPath, $out)) {
+ $out->lines[] = '@import ' . $this->compileValue($rawPath) . ';';
}
- $this->compileNestedBlock($directive, array($s));
break;
- case 'media':
+
+ case Type::T_DIRECTIVE:
+ $this->compileDirective($child[1]);
+ break;
+
+ case Type::T_AT_ROOT:
+ $this->compileAtRoot($child[1]);
+ break;
+
+ case Type::T_MEDIA:
$this->compileMedia($child[1]);
break;
- case 'block':
+
+ case Type::T_BLOCK:
$this->compileBlock($child[1]);
break;
- case 'charset':
- $out->lines[] = '@charset '.$this->compileValue($child[1]).';';
+
+ case Type::T_CHARSET:
+ if (! $this->charsetSeen) {
+ $this->charsetSeen = true;
+
+ $out->lines[] = '@charset ' . $this->compileValue($child[1]) . ';';
+ }
break;
- case 'assign':
- list(,$name, $value) = $child;
- if ($name[0] == 'var') {
- $isDefault = !empty($child[3]);
+ case Type::T_ASSIGN:
+ list(, $name, $value) = $child;
+
+ if ($name[0] === Type::T_VARIABLE) {
+ $flags = isset($child[3]) ? $child[3] : [];
+ $isDefault = in_array('!default', $flags);
+ $isGlobal = in_array('!global', $flags);
- if ($isDefault) {
- $existingValue = $this->get($name[1], true);
- $shouldSet = $existingValue === true || $existingValue == self::$null;
+ if ($isGlobal) {
+ $this->set($name[1], $this->reduce($value), false, $this->rootEnv);
+ break;
}
+ $shouldSet = $isDefault &&
+ (($result = $this->get($name[1], false)) === null
+ || $result === self::$null);
+
if (! $isDefault || $shouldSet) {
$this->set($name[1], $this->reduce($value));
}
break;
}
+ $compiledName = $this->compileValue($name);
+
+ // handle shorthand syntax: size / line-height
+ if ($compiledName === 'font') {
+ if ($value[0] === Type::T_EXPRESSION && $value[1] === '/') {
+ $value = $this->expToString($value);
+ } elseif ($value[0] === Type::T_LIST) {
+ foreach ($value[2] as &$item) {
+ if ($item[0] === Type::T_EXPRESSION && $item[1] === '/') {
+ $item = $this->expToString($item);
+ }
+ }
+ }
+ }
+
// if the value reduces to null from something else then
// the property should be discarded
- if ($value[0] != 'null') {
+ if ($value[0] !== Type::T_NULL) {
$value = $this->reduce($value);
- if ($value[0] == 'null') {
+
+ if ($value[0] === Type::T_NULL || $value === self::$nullString) {
break;
}
}
$compiledValue = $this->compileValue($value);
+
$out->lines[] = $this->formatter->property(
- $this->compileValue($name),
+ $compiledName,
$compiledValue
);
break;
- case 'comment':
- if ($out->type == 'root') {
+
+ case Type::T_COMMENT:
+ if ($out->type === Type::T_ROOT) {
$this->compileComment($child);
break;
}
- $out->lines[] = $child[1];
- break;
- case 'mixin':
- case 'function':
- list(,$block) = $child;
+ $out->lines[] = $child[1];
+ break;
+
+ case Type::T_MIXIN:
+ case Type::T_FUNCTION:
+ list(, $block) = $child;
+
+ $this->set(self::$namespaces[$block->type] . $block->name, $block);
+ break;
+
+ case Type::T_EXTEND:
+ list(, $selectors) = $child;
+
+ foreach ($selectors as $sel) {
+ $results = $this->evalSelectors([$sel]);
+
+ foreach ($results as $result) {
+ // only use the first one
+ $result = current($result);
+
+ $this->pushExtends($result, $out->selectors, $child);
+ }
+ }
+ break;
+
+ case Type::T_IF:
+ list(, $if) = $child;
+
+ if ($this->isTruthy($this->reduce($if->cond, true))) {
+ return $this->compileChildren($if->children, $out);
+ }
+
+ foreach ($if->cases as $case) {
+ if ($case->type === Type::T_ELSE ||
+ $case->type === Type::T_ELSEIF && $this->isTruthy($this->reduce($case->cond))
+ ) {
+ return $this->compileChildren($case->children, $out);
+ }
+ }
+ break;
+
+ case Type::T_EACH:
+ list(, $each) = $child;
+
+ $list = $this->coerceList($this->reduce($each->list));
+
+ $this->pushEnv();
+
+ foreach ($list[2] as $item) {
+ if (count($each->vars) === 1) {
+ $this->set($each->vars[0], $item, true);
+ } else {
+ list(,, $values) = $this->coerceList($item);
+
+ foreach ($each->vars as $i => $var) {
+ $this->set($var, isset($values[$i]) ? $values[$i] : self::$null, true);
+ }
+ }
+
+ $ret = $this->compileChildren($each->children, $out);
- $this->set(self::$namespaces[$block->type] . $block->name, $block);
- break;
- case 'extend':
- list(, $selectors) = $child;
+ if ($ret) {
+ if ($ret[0] !== Type::T_CONTROL) {
+ $this->popEnv();
- foreach ($selectors as $sel) {
- // only use the first one
- $sel = current($this->evalSelector($sel));
- $this->pushExtends($sel, $out->selectors);
- }
- break;
- case 'if':
- list(, $if) = $child;
+ return $ret;
+ }
- if ($this->isTruthy($this->reduce($if->cond, true))) {
- return $this->compileChildren($if->children, $out);
- } else {
- foreach ($if->cases as $case) {
- if ($case->type == 'else' ||
- $case->type == 'elseif' && $this->isTruthy($this->reduce($case->cond))
- ) {
- return $this->compileChildren($case->children, $out);
+ if ($ret[1]) {
+ break;
}
}
}
- break;
- case 'return':
- return $this->reduce($child[1], true);
- case 'each':
- list(,$each) = $child;
- $list = $this->coerceList($this->reduce($each->list));
- foreach ($list[2] as $item) {
- $this->pushEnv();
- $this->set($each->var, $item);
- // TODO: allow return from here
- $this->compileChildren($each->children, $out);
- $this->popEnv();
- }
+ $this->popEnv();
break;
- case 'while':
- list(,$while) = $child;
+
+ case Type::T_WHILE:
+ list(, $while) = $child;
while ($this->isTruthy($this->reduce($while->cond, true))) {
$ret = $this->compileChildren($while->children, $out);
+
if ($ret) {
- return $ret;
+ if ($ret[0] !== Type::T_CONTROL) {
+ return $ret;
+ }
+
+ if ($ret[1]) {
+ break;
+ }
}
}
break;
- case 'for':
- list(,$for) = $child;
+
+ case Type::T_FOR:
+ list(, $for) = $child;
$start = $this->reduce($for->start, true);
$start = $start[1];
@@ -876,106 +1630,151 @@ protected function compileChild($child, $out)
break;
}
- $this->set($for->var, array('number', $start, ''));
+ $this->set($for->var, new Node\Number($start, ''));
$start += $d;
$ret = $this->compileChildren($for->children, $out);
if ($ret) {
- return $ret;
+ if ($ret[0] !== Type::T_CONTROL) {
+ return $ret;
+ }
+
+ if ($ret[1]) {
+ break;
+ }
}
}
-
break;
- case 'nestedprop':
- list(,$prop) = $child;
- $prefixed = array();
+ case Type::T_BREAK:
+ return [Type::T_CONTROL, true];
+
+ case Type::T_CONTINUE:
+ return [Type::T_CONTROL, false];
+
+ case Type::T_RETURN:
+ return $this->reduce($child[1], true);
+
+ case Type::T_NESTED_PROPERTY:
+ list(, $prop) = $child;
+
+ $prefixed = [];
$prefix = $this->compileValue($prop->prefix) . '-';
foreach ($prop->children as $child) {
- if ($child[0] == 'assign') {
- array_unshift($child[1][2], $prefix);
- }
-
- if ($child[0] == 'nestedprop') {
- array_unshift($child[1]->prefix[2], $prefix);
+ switch ($child[0]) {
+ case Type::T_ASSIGN:
+ array_unshift($child[1][2], $prefix);
+ break;
+
+ case Type::T_NESTED_PROPERTY:
+ array_unshift($child[1]->prefix[2], $prefix);
+ break;
}
$prefixed[] = $child;
}
- $this->compileChildren($prefixed, $out);
+ $this->compileChildrenNoReturn($prefixed, $out);
break;
- case 'include': // including a mixin
- list(,$name, $argValues, $content) = $child;
+
+ case Type::T_INCLUDE:
+ // including a mixin
+ list(, $name, $argValues, $content) = $child;
$mixin = $this->get(self::$namespaces['mixin'] . $name, false);
if (! $mixin) {
$this->throwError("Undefined mixin $name");
+ break;
}
- $callingScope = $this->env;
+ $callingScope = $this->getStoreEnv();
// push scope, apply args
$this->pushEnv();
-
- if ($this->env->depth > 0) {
- $this->env->depth--;
- }
+ $this->env->depth--;
if (isset($content)) {
$content->scope = $callingScope;
- $this->setRaw(self::$namespaces['special'] . 'content', $content);
+
+ $this->setRaw(self::$namespaces['special'] . 'content', $content, $this->env);
}
if (isset($mixin->args)) {
$this->applyArguments($mixin->args, $argValues);
}
- foreach ($mixin->children as $child) {
- $this->compileChild($child, $out);
- }
+ $this->env->marker = 'mixin';
+
+ $this->compileChildrenNoReturn($mixin->children, $out);
$this->popEnv();
break;
- case 'mixin_content':
- $content = $this->get(self::$namespaces['special'] . 'content');
- if (!isset($content)) {
+ case Type::T_MIXIN_CONTENT:
+ $content = $this->get(self::$namespaces['special'] . 'content', false, $this->getStoreEnv())
+ ?: $this->get(self::$namespaces['special'] . 'content', false, $this->env);
+
+ if (! $content) {
$this->throwError('Expected @content inside of mixin');
+ break;
}
- $strongTypes = array('include', 'block', 'for', 'while');
+ $storeEnv = $this->storeEnv;
+ $this->storeEnv = $content->scope;
- foreach ($content->children as $child) {
- $this->storeEnv = (in_array($child[0], $strongTypes))
- ? null
- : $content->scope;
+ $this->compileChildrenNoReturn($content->children, $out);
- $this->compileChild($child, $out);
- }
+ $this->storeEnv = $storeEnv;
+ break;
- unset($this->storeEnv);
+ case Type::T_DEBUG:
+ list(, $value) = $child;
+
+ $line = $this->sourceLine;
+ $value = $this->compileValue($this->reduce($value, true));
+ fwrite($this->stderr, "Line $line DEBUG: $value\n");
+ break;
+
+ case Type::T_WARN:
+ list(, $value) = $child;
+
+ $line = $this->sourceLine;
+ $value = $this->compileValue($this->reduce($value, true));
+ fwrite($this->stderr, "Line $line WARN: $value\n");
break;
- case 'debug':
- list(,$value, $pos) = $child;
- $line = $this->parser->getLineNo($pos);
+ case Type::T_ERROR:
+ list(, $value) = $child;
+
+ $line = $this->sourceLine;
$value = $this->compileValue($this->reduce($value, true));
- fwrite(STDERR, "Line $line DEBUG: $value\n");
+ $this->throwError("Line $line ERROR: $value\n");
+ break;
+
+ case Type::T_CONTROL:
+ $this->throwError('@break/@continue not permitted in this scope');
break;
+
default:
$this->throwError("unknown child type: $child[0]");
}
}
+ /**
+ * Reduce expression to string
+ *
+ * @param array $exp
+ *
+ * @return array
+ */
protected function expToString($exp)
{
- list(, $op, $left, $right, $inParens, $whiteLeft, $whiteRight) = $exp;
+ list(, $op, $left, $right, /* $inParens */, $whiteLeft, $whiteRight) = $exp;
- $content = array($this->reduce($left));
+ $content = [$this->reduce($left)];
if ($whiteLeft) {
$content[] = ' ';
@@ -989,49 +1788,76 @@ protected function expToString($exp)
$content[] = $this->reduce($right);
- return array('string', '', $content);
+ return [Type::T_STRING, '', $content];
}
+ /**
+ * Is truthy?
+ *
+ * @param array $value
+ *
+ * @return array
+ */
protected function isTruthy($value)
{
- return $value != self::$false && $value != self::$null;
+ return $value !== self::$false && $value !== self::$null;
}
- // should $value cause its operand to eval
+ /**
+ * Should $value cause its operand to eval
+ *
+ * @param array $value
+ *
+ * @return boolean
+ */
protected function shouldEval($value)
{
switch ($value[0]) {
- case 'exp':
- if ($value[1] == '/') {
+ case Type::T_EXPRESSION:
+ if ($value[1] === '/') {
return $this->shouldEval($value[2], $value[3]);
}
// fall-thru
- case 'var':
- case 'fncall':
+ case Type::T_VARIABLE:
+ case Type::T_FUNCTION_CALL:
return true;
}
+
return false;
}
+ /**
+ * Reduce value
+ *
+ * @param array $value
+ * @param boolean $inExp
+ *
+ * @return array
+ */
protected function reduce($value, $inExp = false)
{
list($type) = $value;
+
switch ($type) {
- case 'exp':
+ case Type::T_EXPRESSION:
list(, $op, $left, $right, $inParens) = $value;
$opName = isset(self::$operatorNames[$op]) ? self::$operatorNames[$op] : $op;
$inExp = $inExp || $this->shouldEval($left) || $this->shouldEval($right);
$left = $this->reduce($left, true);
- $right = $this->reduce($right, true);
- // only do division in special cases
- if ($opName == 'div' && !$inParens && !$inExp) {
- if ($left[0] != 'color' && $right[0] != 'color') {
- return $this->expToString($value);
- }
+ if ($op !== 'and' && $op !== 'or') {
+ $right = $this->reduce($right, true);
+ }
+
+ // special case: looks like css shorthand
+ if ($opName == 'div' && ! $inParens && ! $inExp && isset($right[2])
+ && (($right[0] !== Type::T_NUMBER && $right[2] != '')
+ || ($right[0] === Type::T_NUMBER && ! $right->unitless()))
+ ) {
+ return $this->expToString($value);
}
$left = $this->coerceForExpression($left);
@@ -1049,47 +1875,50 @@ protected function reduce($value, $inExp = false)
// 2. op[left type][right type] (passing the op as first arg
// 3. op[op name]
$fn = "op${ucOpName}${ucLType}${ucRType}";
- if (is_callable(array($this, $fn)) ||
+
+ if (is_callable([$this, $fn]) ||
(($fn = "op${ucLType}${ucRType}") &&
- is_callable(array($this, $fn)) &&
+ is_callable([$this, $fn]) &&
$passOp = true) ||
(($fn = "op${ucOpName}") &&
- is_callable(array($this, $fn)) &&
+ is_callable([$this, $fn]) &&
$genOp = true)
) {
- $unitChange = false;
+ $coerceUnit = false;
- if (!isset($genOp) &&
- $left[0] == 'number' && $right[0] == 'number'
+ if (! isset($genOp) &&
+ $left[0] === Type::T_NUMBER && $right[0] === Type::T_NUMBER
) {
- if ($opName == 'mod' && $right[2] != '') {
- $this->throwError("Cannot modulo by a number with units: $right[1]$right[2].");
- }
+ $coerceUnit = true;
- $unitChange = true;
- $emptyUnit = $left[2] == '' || $right[2] == '';
- $targetUnit = '' != $left[2] ? $left[2] : $right[2];
+ switch ($opName) {
+ case 'mul':
+ $targetUnit = $left[2];
- if ($opName != 'mul') {
- $left[2] = '' != $left[2] ? $left[2] : $targetUnit;
- $right[2] = '' != $right[2] ? $right[2] : $targetUnit;
- }
+ foreach ($right[2] as $unit => $exp) {
+ $targetUnit[$unit] = (isset($targetUnit[$unit]) ? $targetUnit[$unit] : 0) + $exp;
+ }
+ break;
- if ($opName != 'mod') {
- $left = $this->normalizeNumber($left);
- $right = $this->normalizeNumber($right);
- }
+ case 'div':
+ $targetUnit = $left[2];
+
+ foreach ($right[2] as $unit => $exp) {
+ $targetUnit[$unit] = (isset($targetUnit[$unit]) ? $targetUnit[$unit] : 0) - $exp;
+ }
+ break;
+
+ case 'mod':
+ $targetUnit = $left[2];
+ break;
- if ($opName == 'div' && !$emptyUnit && $left[2] == $right[2]) {
- $targetUnit = '';
+ default:
+ $targetUnit = $left->unitless() ? $right[2] : $left[2];
}
- if ($opName == 'mul') {
- $left[2] = '' != $left[2] ? $left[2] : $right[2];
- $right[2] = '' != $right[2] ? $right[2] : $left[2];
- } elseif ($opName == 'div' && $left[2] == $right[2]) {
- $left[2] = '';
- $right[2] = '';
+ if (! $left->unitless() && ! $right->unitless()) {
+ $left = $left->normalize();
+ $right = $right->normalize();
}
}
@@ -1102,8 +1931,8 @@ protected function reduce($value, $inExp = false)
}
if (isset($out)) {
- if ($unitChange && $out[0] == 'number') {
- $out = $this->coerceUnit($out, $targetUnit);
+ if ($coerceUnit && $out[0] === Type::T_NUMBER) {
+ $out = $out->coerce($targetUnit);
}
return $out;
@@ -1111,115 +1940,146 @@ protected function reduce($value, $inExp = false)
}
return $this->expToString($value);
- case 'unary':
+
+ case Type::T_UNARY:
list(, $op, $exp, $inParens) = $value;
$inExp = $inExp || $this->shouldEval($exp);
$exp = $this->reduce($exp);
- if ($exp[0] == 'number') {
+ if ($exp[0] === Type::T_NUMBER) {
switch ($op) {
case '+':
- return $exp;
- case '-':
- $exp[1] *= -1;
+ return new Node\Number($exp[1], $exp[2]);
- return $exp;
+ case '-':
+ return new Node\Number(-$exp[1], $exp[2]);
}
}
- if ($op == 'not') {
+ if ($op === 'not') {
if ($inExp || $inParens) {
- if ($exp == self::$false) {
+ if ($exp === self::$false || $exp === self::$null) {
return self::$true;
}
return self::$false;
- } else {
- $op = $op . ' ';
}
+
+ $op = $op . ' ';
}
- return array('string', '', array($op, $exp));
- case 'var':
+ return [Type::T_STRING, '', [$op, $exp]];
+
+ case Type::T_VARIABLE:
list(, $name) = $value;
return $this->reduce($this->get($name));
- case 'list':
+
+ case Type::T_LIST:
+ foreach ($value[2] as &$item) {
+ $item = $this->reduce($item);
+ }
+
+ return $value;
+
+ case Type::T_MAP:
+ foreach ($value[1] as &$item) {
+ $item = $this->reduce($item);
+ }
+
foreach ($value[2] as &$item) {
$item = $this->reduce($item);
}
return $value;
- case 'string':
+
+ case Type::T_STRING:
foreach ($value[2] as &$item) {
- if (is_array($item)) {
+ if (is_array($item) || $item instanceof \ArrayAccess) {
$item = $this->reduce($item);
}
}
- return $value;
- case 'interpolate':
- $value[1] = $this->reduce($value[1]);
return $value;
- case 'fncall':
- list(,$name, $argValues) = $value;
- // user defined function?
- $func = $this->get(self::$namespaces['function'] . $name, false);
+ case Type::T_INTERPOLATE:
+ $value[1] = $this->reduce($value[1]);
- if ($func) {
- $this->pushEnv();
+ return $value;
- // set the args
- if (isset($func->args)) {
- $this->applyArguments($func->args, $argValues);
- }
+ case Type::T_FUNCTION_CALL:
+ list(, $name, $argValues) = $value;
- // throw away lines and children
- $tmp = (object)array(
- 'lines' => array(),
- 'children' => array()
- );
+ return $this->fncall($name, $argValues);
- $ret = $this->compileChildren($func->children, $tmp);
+ default:
+ return $value;
+ }
+ }
- $this->popEnv();
+ /**
+ * Function caller
+ *
+ * @param string $name
+ * @param array $argValues
+ *
+ * @return array|null
+ */
+ private function fncall($name, $argValues)
+ {
+ // SCSS @function
+ if ($this->callScssFunction($name, $argValues, $returnValue)) {
+ return $returnValue;
+ }
- return !isset($ret) ? self::$defaultValue : $ret;
- }
+ // native PHP functions
+ if ($this->callNativeFunction($name, $argValues, $returnValue)) {
+ return $returnValue;
+ }
- // built in function
- if ($this->callBuiltin($name, $argValues, $returnValue)) {
- return $returnValue;
- }
+ // for CSS functions, simply flatten the arguments into a list
+ $listArgs = [];
- // need to flatten the arguments into a list
- $listArgs = array();
+ foreach ((array) $argValues as $arg) {
+ if (empty($arg[0])) {
+ $listArgs[] = $this->reduce($arg[1]);
+ }
+ }
- foreach ((array)$argValues as $arg) {
- if (empty($arg[0])) {
- $listArgs[] = $this->reduce($arg[1]);
- }
- }
+ return [Type::T_FUNCTION, $name, [Type::T_LIST, ',', $listArgs]];
+ }
- return array('function', $name, array('list', ',', $listArgs));
- default:
- return $value;
- }
+ /**
+ * Normalize name
+ *
+ * @param string $name
+ *
+ * @return string
+ */
+ protected function normalizeName($name)
+ {
+ return str_replace('-', '_', $name);
}
+ /**
+ * Normalize value
+ *
+ * @param array $value
+ *
+ * @return array
+ */
public function normalizeValue($value)
{
$value = $this->coerceForExpression($this->reduce($value));
list($type) = $value;
switch ($type) {
- case 'list':
+ case Type::T_LIST:
$value = $this->extractInterpolation($value);
- if ($value[0] != 'list') {
- return array('keyword', $this->compileValue($value));
+ if ($value[0] !== Type::T_LIST) {
+ return [Type::T_KEYWORD, $this->compileValue($value)];
}
foreach ($value[2] as $key => $item) {
@@ -1228,70 +2088,101 @@ public function normalizeValue($value)
return $value;
- case 'number':
- return $this->normalizeNumber($value);
-
- default:
- return $value;
- }
- }
-
- // just does physical lengths for now
- protected function normalizeNumber($number)
- {
- list(, $value, $unit) = $number;
-
- if (isset(self::$unitTable['in'][$unit])) {
- $conv = self::$unitTable['in'][$unit];
-
- return array('number', $value / $conv, 'in');
- }
+ case Type::T_STRING:
+ return [$type, '"', [$this->compileStringContent($value)]];
- return $number;
- }
+ case Type::T_NUMBER:
+ return $value->normalize();
- // $number should be normalized
- protected function coerceUnit($number, $unit)
- {
- list(, $value, $baseUnit) = $number;
+ case Type::T_INTERPOLATE:
+ return [Type::T_KEYWORD, $this->compileValue($value)];
- if (isset(self::$unitTable[$baseUnit][$unit])) {
- $value = $value * self::$unitTable[$baseUnit][$unit];
+ default:
+ return $value;
}
-
- return array('number', $value, $unit);
}
+ /**
+ * Add numbers
+ *
+ * @param array $left
+ * @param array $right
+ *
+ * @return array
+ */
protected function opAddNumberNumber($left, $right)
{
- return array('number', $left[1] + $right[1], $left[2]);
+ return new Node\Number($left[1] + $right[1], $left[2]);
}
+ /**
+ * Multiply numbers
+ *
+ * @param array $left
+ * @param array $right
+ *
+ * @return array
+ */
protected function opMulNumberNumber($left, $right)
{
- return array('number', $left[1] * $right[1], $left[2]);
+ return new Node\Number($left[1] * $right[1], $left[2]);
}
+ /**
+ * Subtract numbers
+ *
+ * @param array $left
+ * @param array $right
+ *
+ * @return array
+ */
protected function opSubNumberNumber($left, $right)
{
- return array('number', $left[1] - $right[1], $left[2]);
+ return new Node\Number($left[1] - $right[1], $left[2]);
}
+ /**
+ * Divide numbers
+ *
+ * @param array $left
+ * @param array $right
+ *
+ * @return array
+ */
protected function opDivNumberNumber($left, $right)
{
- return array('number', $left[1] / $right[1], $left[2]);
+ if ($right[1] == 0) {
+ return [Type::T_STRING, '', [$left[1] . $left[2] . '/' . $right[1] . $right[2]]];
+ }
+
+ return new Node\Number($left[1] / $right[1], $left[2]);
}
+ /**
+ * Mod numbers
+ *
+ * @param array $left
+ * @param array $right
+ *
+ * @return array
+ */
protected function opModNumberNumber($left, $right)
{
- return array('number', $left[1] % $right[1], $left[2]);
+ return new Node\Number($left[1] % $right[1], $left[2]);
}
- // adding strings
+ /**
+ * Add strings
+ *
+ * @param array $left
+ * @param array $right
+ *
+ * @return array
+ */
protected function opAdd($left, $right)
{
if ($strLeft = $this->coerceString($left)) {
- if ($right[0] == 'string') {
+ if ($right[0] === Type::T_STRING) {
$right[1] = '';
}
@@ -1301,7 +2192,7 @@ protected function opAdd($left, $right)
}
if ($strRight = $this->coerceString($right)) {
- if ($left[0] == 'string') {
+ if ($left[0] === Type::T_STRING) {
$left[1] = '';
}
@@ -1311,37 +2202,64 @@ protected function opAdd($left, $right)
}
}
+ /**
+ * Boolean and
+ *
+ * @param array $left
+ * @param array $right
+ * @param boolean $shouldEval
+ *
+ * @return array
+ */
protected function opAnd($left, $right, $shouldEval)
{
- if (!$shouldEval) {
+ if (! $shouldEval) {
return;
}
- if ($left != self::$false) {
- return $right;
+ if ($left !== self::$false and $left !== self::$null) {
+ return $this->reduce($right, true);
}
return $left;
}
+ /**
+ * Boolean or
+ *
+ * @param array $left
+ * @param array $right
+ * @param boolean $shouldEval
+ *
+ * @return array
+ */
protected function opOr($left, $right, $shouldEval)
{
- if (!$shouldEval) {
+ if (! $shouldEval) {
return;
}
- if ($left != self::$false) {
+ if ($left !== self::$false and $left !== self::$null) {
return $left;
}
- return $right;
+ return $this->reduce($right, true);
}
+ /**
+ * Compare colors
+ *
+ * @param string $op
+ * @param array $left
+ * @param array $right
+ *
+ * @return array
+ */
protected function opColorColor($op, $left, $right)
{
- $out = array('color');
+ $out = [Type::T_COLOR];
- foreach (range(1, 3) as $i) {
+ foreach ([1, 2, 3] as $i) {
$lval = isset($left[$i]) ? $left[$i] : 0;
$rval = isset($right[$i]) ? $right[$i] : 0;
@@ -1349,27 +2267,37 @@ protected function opColorColor($op, $left, $right)
case '+':
$out[] = $lval + $rval;
break;
+
case '-':
$out[] = $lval - $rval;
break;
+
case '*':
$out[] = $lval * $rval;
break;
+
case '%':
$out[] = $lval % $rval;
break;
+
case '/':
if ($rval == 0) {
$this->throwError("color: Can't divide by zero");
+ break 2;
}
- $out[] = $lval / $rval;
+
+ $out[] = (int) ($lval / $rval);
break;
+
case '==':
return $this->opEq($left, $right);
+
case '!=':
return $this->opNeq($left, $right);
+
default:
$this->throwError("color: unknown op $op");
+ break 2;
}
}
@@ -1382,6 +2310,15 @@ protected function opColorColor($op, $left, $right)
return $this->fixColor($out);
}
+ /**
+ * Compare color and number
+ *
+ * @param string $op
+ * @param array $left
+ * @param array $right
+ *
+ * @return array
+ */
protected function opColorNumber($op, $left, $right)
{
$value = $right[1];
@@ -1389,58 +2326,148 @@ protected function opColorNumber($op, $left, $right)
return $this->opColorColor(
$op,
$left,
- array('color', $value, $value, $value)
+ [Type::T_COLOR, $value, $value, $value]
);
}
+ /**
+ * Compare number and color
+ *
+ * @param string $op
+ * @param array $left
+ * @param array $right
+ *
+ * @return array
+ */
protected function opNumberColor($op, $left, $right)
{
$value = $left[1];
return $this->opColorColor(
$op,
- array('color', $value, $value, $value),
+ [Type::T_COLOR, $value, $value, $value],
$right
);
}
+ /**
+ * Compare number1 == number2
+ *
+ * @param array $left
+ * @param array $right
+ *
+ * @return array
+ */
protected function opEq($left, $right)
{
if (($lStr = $this->coerceString($left)) && ($rStr = $this->coerceString($right))) {
$lStr[1] = '';
$rStr[1] = '';
- return $this->toBool($this->compileValue($lStr) == $this->compileValue($rStr));
+ $left = $this->compileValue($lStr);
+ $right = $this->compileValue($rStr);
}
- return $this->toBool($left == $right);
+ return $this->toBool($left === $right);
}
+ /**
+ * Compare number1 != number2
+ *
+ * @param array $left
+ * @param array $right
+ *
+ * @return array
+ */
protected function opNeq($left, $right)
{
- return $this->toBool($left != $right);
+ if (($lStr = $this->coerceString($left)) && ($rStr = $this->coerceString($right))) {
+ $lStr[1] = '';
+ $rStr[1] = '';
+
+ $left = $this->compileValue($lStr);
+ $right = $this->compileValue($rStr);
+ }
+
+ return $this->toBool($left !== $right);
}
+ /**
+ * Compare number1 >= number2
+ *
+ * @param array $left
+ * @param array $right
+ *
+ * @return array
+ */
protected function opGteNumberNumber($left, $right)
{
return $this->toBool($left[1] >= $right[1]);
}
+ /**
+ * Compare number1 > number2
+ *
+ * @param array $left
+ * @param array $right
+ *
+ * @return array
+ */
protected function opGtNumberNumber($left, $right)
{
return $this->toBool($left[1] > $right[1]);
}
+ /**
+ * Compare number1 <= number2
+ *
+ * @param array $left
+ * @param array $right
+ *
+ * @return array
+ */
protected function opLteNumberNumber($left, $right)
{
- return $this->toBool($left[1] <= $right[1]);
+ return $this->toBool($left[1] <= $right[1]);
+ }
+
+ /**
+ * Compare number1 < number2
+ *
+ * @param array $left
+ * @param array $right
+ *
+ * @return array
+ */
+ protected function opLtNumberNumber($left, $right)
+ {
+ return $this->toBool($left[1] < $right[1]);
}
- protected function opLtNumberNumber($left, $right)
+ /**
+ * Three-way comparison, aka spaceship operator
+ *
+ * @param array $left
+ * @param array $right
+ *
+ * @return array
+ */
+ protected function opCmpNumberNumber($left, $right)
{
- return $this->toBool($left[1] < $right[1]);
+ $n = $left[1] - $right[1];
+
+ return new Node\Number($n ? $n / abs($n) : 0, '');
}
+ /**
+ * Cast to boolean
+ *
+ * @api
+ *
+ * @param mixed $thing
+ *
+ * @return array
+ */
public function toBool($thing)
{
return $thing ? self::$true : self::$false;
@@ -1457,18 +2484,23 @@ public function toBool($thing)
* The input is expected to be reduced. This function will not work on
* things like expressions and variables.
*
+ * @api
+ *
* @param array $value
+ *
+ * @return string
*/
- protected function compileValue($value)
+ public function compileValue($value)
{
$value = $this->reduce($value);
list($type) = $value;
switch ($type) {
- case 'keyword':
+ case Type::T_KEYWORD:
return $value[1];
- case 'color':
+
+ case Type::T_COLOR:
// [1] - red component (either number for a %)
// [2] - green component
// [3] - blue component
@@ -1479,8 +2511,8 @@ protected function compileValue($value)
$g = round($g);
$b = round($b);
- if (count($value) == 5 && $value[4] != 1) { // rgba
- return 'rgba('.$r.', '.$g.', '.$b.', '.$value[4].')';
+ if (count($value) === 5 && $value[4] !== 1) { // rgba
+ return 'rgba(' . $r . ', ' . $g . ', ' . $b . ', ' . $value[4] . ')';
}
$h = sprintf('#%02x%02x%02x', $r, $g, $b);
@@ -1491,72 +2523,122 @@ protected function compileValue($value)
}
return $h;
- case 'number':
- return round($value[1], $this->numberPrecision) . $value[2];
- case 'string':
+
+ case Type::T_NUMBER:
+ return $value->output($this);
+
+ case Type::T_STRING:
return $value[1] . $this->compileStringContent($value) . $value[1];
- case 'function':
- $args = !empty($value[2]) ? $this->compileValue($value[2]) : '';
+
+ case Type::T_FUNCTION:
+ $args = ! empty($value[2]) ? $this->compileValue($value[2]) : '';
+
return "$value[1]($args)";
- case 'list':
+
+ case Type::T_LIST:
$value = $this->extractInterpolation($value);
- if ($value[0] != 'list') {
+ if ($value[0] !== Type::T_LIST) {
return $this->compileValue($value);
}
list(, $delim, $items) = $value;
- $filtered = array();
+ if ($delim !== ' ') {
+ $delim .= ' ';
+ }
+
+ $filtered = [];
+
foreach ($items as $item) {
- if ($item[0] == 'null') {
+ if ($item[0] === Type::T_NULL) {
continue;
}
$filtered[] = $this->compileValue($item);
}
- return implode("$delim ", $filtered);
- case 'interpolated': # node created by extractInterpolation
+ return implode("$delim", $filtered);
+
+ case Type::T_MAP:
+ $keys = $value[1];
+ $values = $value[2];
+ $filtered = [];
+
+ for ($i = 0, $s = count($keys); $i < $s; $i++) {
+ $filtered[$this->compileValue($keys[$i])] = $this->compileValue($values[$i]);
+ }
+
+ array_walk($filtered, function (&$value, $key) {
+ $value = $key . ': ' . $value;
+ });
+
+ return '(' . implode(', ', $filtered) . ')';
+
+ case Type::T_INTERPOLATED:
+ // node created by extractInterpolation
list(, $interpolate, $left, $right) = $value;
list(,, $whiteLeft, $whiteRight) = $interpolate;
$left = count($left[2]) > 0 ?
- $this->compileValue($left).$whiteLeft : '';
+ $this->compileValue($left) . $whiteLeft : '';
$right = count($right[2]) > 0 ?
- $whiteRight.$this->compileValue($right) : '';
+ $whiteRight . $this->compileValue($right) : '';
- return $left.$this->compileValue($interpolate).$right;
+ return $left . $this->compileValue($interpolate) . $right;
- case 'interpolate': # raw parse node
+ case Type::T_INTERPOLATE:
+ // raw parse node
list(, $exp) = $value;
// strip quotes if it's a string
$reduced = $this->reduce($exp);
+
switch ($reduced[0]) {
- case 'string':
- $reduced = array('keyword',
- $this->compileStringContent($reduced));
+ case Type::T_STRING:
+ $reduced = [Type::T_KEYWORD, $this->compileStringContent($reduced)];
break;
- case 'null':
- $reduced = array('keyword', '');
+
+ case Type::T_NULL:
+ $reduced = [Type::T_KEYWORD, ''];
}
return $this->compileValue($reduced);
- case 'null':
+
+ case Type::T_NULL:
return 'null';
+
default:
$this->throwError("unknown value type: $type");
}
}
+ /**
+ * Flatten list
+ *
+ * @param array $list
+ *
+ * @return string
+ */
+ protected function flattenList($list)
+ {
+ return $this->compileValue($list);
+ }
+
+ /**
+ * Compile string content
+ *
+ * @param array $string
+ *
+ * @return string
+ */
protected function compileStringContent($string)
{
- $parts = array();
+ $parts = [];
foreach ($string[2] as $part) {
- if (is_array($part)) {
+ if (is_array($part) || $part instanceof \ArrayAccess) {
$parts[] = $this->compileValue($part);
} else {
$parts[] = $part;
@@ -1566,41 +2648,48 @@ protected function compileStringContent($string)
return implode($parts);
}
- // doesn't need to be recursive, compileValue will handle that
+ /**
+ * Extract interpolation; it doesn't need to be recursive, compileValue will handle that
+ *
+ * @param array $list
+ *
+ * @return array
+ */
protected function extractInterpolation($list)
{
$items = $list[2];
foreach ($items as $i => $item) {
- if ($item[0] == 'interpolate') {
- $before = array('list', $list[1], array_slice($items, 0, $i));
- $after = array('list', $list[1], array_slice($items, $i + 1));
+ if ($item[0] === Type::T_INTERPOLATE) {
+ $before = [Type::T_LIST, $list[1], array_slice($items, 0, $i)];
+ $after = [Type::T_LIST, $list[1], array_slice($items, $i + 1)];
- return array('interpolated', $item, $before, $after);
+ return [Type::T_INTERPOLATED, $item, $before, $after];
}
}
return $list;
}
- // find the final set of selectors
- protected function multiplySelectors($env)
+ /**
+ * Find the final set of selectors
+ *
+ * @param \Leafo\ScssPhp\Compiler\Environment $env
+ *
+ * @return array
+ */
+ protected function multiplySelectors(Environment $env)
{
- $envs = array();
+ $envs = $this->compactEnv($env);
+ $selectors = [];
+ $parentSelectors = [[]];
- while (null !== $env) {
- if (!empty($env->selectors)) {
- $envs[] = $env;
+ while ($env = array_pop($envs)) {
+ if (empty($env->selectors)) {
+ continue;
}
- $env = $env->parent;
- };
-
- $selectors = array();
- $parentSelectors = array(array());
-
- while ($env = array_pop($envs)) {
- $selectors = array();
+ $selectors = [];
foreach ($env->selectors as $selector) {
foreach ($parentSelectors as $parent) {
@@ -1614,23 +2703,30 @@ protected function multiplySelectors($env)
return $selectors;
}
- // looks for & to replace, or append parent before child
+ /**
+ * Join selectors; looks for & to replace, or append parent before child
+ *
+ * @param array $parent
+ * @param array $child
+ *
+ * @return array
+ */
protected function joinSelectors($parent, $child)
{
$setSelf = false;
- $out = array();
+ $out = [];
foreach ($child as $part) {
- $newPart = array();
+ $newPart = [];
foreach ($part as $p) {
- if ($p == self::$selfSelector) {
+ if ($p === self::$selfSelector) {
$setSelf = true;
foreach ($parent as $i => $parentPart) {
if ($i > 0) {
$out[] = $newPart;
- $newPart = array();
+ $newPart = [];
}
foreach ($parentPart as $pp) {
@@ -1648,10 +2744,18 @@ protected function joinSelectors($parent, $child)
return $setSelf ? $out : array_merge($parent, $child);
}
- protected function multiplyMedia($env, $childQueries = null)
+ /**
+ * Multiply media
+ *
+ * @param \Leafo\ScssPhp\Compiler\Environment $env
+ * @param array $childQueries
+ *
+ * @return array
+ */
+ protected function multiplyMedia(Environment $env = null, $childQueries = null)
{
- if (!isset($env) ||
- !empty($env->block->type) && $env->block->type != 'media'
+ if (! isset($env) ||
+ ! empty($env->block->type) && $env->block->type !== Type::T_MEDIA
) {
return $childQueries;
}
@@ -1661,12 +2765,15 @@ protected function multiplyMedia($env, $childQueries = null)
return $this->multiplyMedia($env->parent, $childQueries);
}
- $parentQueries = $env->block->queryList;
- if ($childQueries == null) {
+ $parentQueries = isset($env->block->queryList)
+ ? $env->block->queryList
+ : [[[Type::T_MEDIA_VALUE, $env->block->value]]];
+
+ if ($childQueries === null) {
$childQueries = $parentQueries;
} else {
$originalQueries = $childQueries;
- $childQueries = array();
+ $childQueries = [];
foreach ($parentQueries as $parentQuery) {
foreach ($originalQueries as $childQuery) {
@@ -1678,439 +2785,908 @@ protected function multiplyMedia($env, $childQueries = null)
return $this->multiplyMedia($env->parent, $childQueries);
}
- // convert something to list
- protected function coerceList($item, $delim = ',')
+ /**
+ * Convert env linked list to stack
+ *
+ * @param \Leafo\ScssPhp\Compiler\Environment $env
+ *
+ * @return array
+ */
+ private function compactEnv(Environment $env)
{
- if (isset($item) && $item[0] == 'list') {
- return $item;
+ for ($envs = []; $env; $env = $env->parent) {
+ $envs[] = $env;
}
- return array('list', $delim, !isset($item) ? array(): array($item));
+ return $envs;
}
- protected function applyArguments($argDef, $argValues)
+ /**
+ * Convert env stack to singly linked list
+ *
+ * @param array $envs
+ *
+ * @return \Leafo\ScssPhp\Compiler\Environment
+ */
+ private function extractEnv($envs)
{
- $storeEnv = $this->getStoreEnv();
+ for ($env = null; $e = array_pop($envs);) {
+ $e->parent = $env;
+ $env = $e;
+ }
- $env = new \stdClass;
- $env->store = $storeEnv->store;
+ return $env;
+ }
- $hasVariable = false;
- $args = array();
+ /**
+ * Push environment
+ *
+ * @param \Leafo\ScssPhp\Block $block
+ *
+ * @return \Leafo\ScssPhp\Compiler\Environment
+ */
+ protected function pushEnv(Block $block = null)
+ {
+ $env = new Environment;
+ $env->parent = $this->env;
+ $env->store = [];
+ $env->block = $block;
+ $env->depth = isset($this->env->depth) ? $this->env->depth + 1 : 0;
- foreach ($argDef as $i => $arg) {
- list($name, $default, $isVariable) = $argDef[$i];
+ $this->env = $env;
- $args[$name] = array($i, $name, $default, $isVariable);
- $hasVariable |= $isVariable;
+ return $env;
+ }
+
+ /**
+ * Pop environment
+ */
+ protected function popEnv()
+ {
+ $this->env = $this->env->parent;
+ }
+
+ /**
+ * Get store environment
+ *
+ * @return \Leafo\ScssPhp\Compiler\Environment
+ */
+ protected function getStoreEnv()
+ {
+ return isset($this->storeEnv) ? $this->storeEnv : $this->env;
+ }
+
+ /**
+ * Set variable
+ *
+ * @param string $name
+ * @param mixed $value
+ * @param boolean $shadow
+ * @param \Leafo\ScssPhp\Compiler\Environment $env
+ */
+ protected function set($name, $value, $shadow = false, Environment $env = null)
+ {
+ $name = $this->normalizeName($name);
+
+ if (! isset($env)) {
+ $env = $this->getStoreEnv();
+ }
+
+ if ($shadow) {
+ $this->setRaw($name, $value, $env);
+ } else {
+ $this->setExisting($name, $value, $env);
}
+ }
- $keywordArgs = array();
- $deferredKeywordArgs = array();
- $remaining = array();
+ /**
+ * Set existing variable
+ *
+ * @param string $name
+ * @param mixed $value
+ * @param \Leafo\ScssPhp\Compiler\Environment $env
+ */
+ protected function setExisting($name, $value, Environment $env)
+ {
+ $storeEnv = $env;
- // assign the keyword args
- foreach ((array) $argValues as $arg) {
- if (!empty($arg[0])) {
- if (!isset($args[$arg[0][1]])) {
- if ($hasVariable) {
- $deferredKeywordArgs[$arg[0][1]] = $arg[1];
- } else {
- $this->throwError("Mixin or function doesn't have an argument named $%s.", $arg[0][1]);
- }
- } elseif ($args[$arg[0][1]][0] < count($remaining)) {
- $this->throwError("The argument $%s was passed both by position and by name.", $arg[0][1]);
- } else {
- $keywordArgs[$arg[0][1]] = $arg[1];
- }
- } elseif (count($keywordArgs)) {
- $this->throwError('Positional arguments must come before keyword arguments.');
- } elseif ($arg[2] == true) {
- $val = $this->reduce($arg[1], true);
+ $hasNamespace = $name[0] === '^' || $name[0] === '@' || $name[0] === '%';
- if ($val[0] == 'list') {
- foreach ($val[2] as $name => $item) {
- if (!is_numeric($name)) {
- $keywordArgs[$name] = $item;
- } else {
- $remaining[] = $item;
- }
- }
- } else {
- $remaining[] = $val;
- }
- } else {
- $remaining[] = $arg[1];
+ for (;;) {
+ if (array_key_exists($name, $env->store)) {
+ break;
+ }
+
+ if (! $hasNamespace && isset($env->marker)) {
+ $env = $storeEnv;
+ break;
+ }
+
+ if (! isset($env->parent)) {
+ $env = $storeEnv;
+ break;
}
+
+ $env = $env->parent;
}
- foreach ($args as $arg) {
- list($i, $name, $default, $isVariable) = $arg;
+ $env->store[$name] = $value;
+ }
- if ($isVariable) {
- $val = array('list', ',', array());
- for ($count = count($remaining); $i < $count; $i++) {
- $val[2][] = $remaining[$i];
- }
- foreach ($deferredKeywordArgs as $itemName => $item) {
- $val[2][$itemName] = $item;
- }
- } elseif (isset($remaining[$i])) {
- $val = $remaining[$i];
- } elseif (isset($keywordArgs[$name])) {
- $val = $keywordArgs[$name];
- } elseif (!empty($default)) {
+ /**
+ * Set raw variable
+ *
+ * @param string $name
+ * @param mixed $value
+ * @param \Leafo\ScssPhp\Compiler\Environment $env
+ */
+ protected function setRaw($name, $value, Environment $env)
+ {
+ $env->store[$name] = $value;
+ }
+
+ /**
+ * Get variable
+ *
+ * @api
+ *
+ * @param string $name
+ * @param boolean $shouldThrow
+ * @param \Leafo\ScssPhp\Compiler\Environment $env
+ *
+ * @return mixed
+ */
+ public function get($name, $shouldThrow = true, Environment $env = null)
+ {
+ $name = $this->normalizeName($name);
+
+ if (! isset($env)) {
+ $env = $this->getStoreEnv();
+ }
+
+ $hasNamespace = $name[0] === '^' || $name[0] === '@' || $name[0] === '%';
+ for (;;) {
+ if (array_key_exists($name, $env->store)) {
+ return $env->store[$name];
+ }
+
+ if (! $hasNamespace && isset($env->marker)) {
+ $env = $this->rootEnv;
continue;
- } else {
- $this->throwError("Missing argument $name");
}
- $this->set($name, $this->reduce($val, true), true, $env);
+ if (! isset($env->parent)) {
+ break;
+ }
+
+ $env = $env->parent;
}
- $storeEnv->store = $env->store;
+ if ($shouldThrow) {
+ $this->throwError("Undefined variable \$$name");
+ }
+
+ // found nothing
+ }
+
+ /**
+ * Has variable?
+ *
+ * @param string $name
+ * @param \Leafo\ScssPhp\Compiler\Environment $env
+ *
+ * @return boolean
+ */
+ protected function has($name, Environment $env = null)
+ {
+ return $this->get($name, false, $env) !== null;
+ }
+
+ /**
+ * Inject variables
+ *
+ * @param array $args
+ */
+ protected function injectVariables(array $args)
+ {
+ if (empty($args)) {
+ return;
+ }
+
+ $parser = $this->parserFactory(__METHOD__);
+
+ foreach ($args as $name => $strValue) {
+ if ($name[0] === '$') {
+ $name = substr($name, 1);
+ }
+
+ if (! $parser->parseValue($strValue, $value)) {
+ $value = $this->coerceValue($strValue);
+ }
+
+ $this->set($name, $value);
+ }
+ }
+
+ /**
+ * Set variables
+ *
+ * @api
+ *
+ * @param array $variables
+ */
+ public function setVariables(array $variables)
+ {
+ $this->registeredVars = array_merge($this->registeredVars, $variables);
+ }
- foreach ($args as $arg) {
- list($i, $name, $default, $isVariable) = $arg;
+ /**
+ * Unset variable
+ *
+ * @api
+ *
+ * @param string $name
+ */
+ public function unsetVariable($name)
+ {
+ unset($this->registeredVars[$name]);
+ }
- if ($isVariable || isset($remaining[$i]) || isset($keywordArgs[$name]) || empty($default)) {
- continue;
- }
+ /**
+ * Returns list of variables
+ *
+ * @api
+ *
+ * @return array
+ */
+ public function getVariables()
+ {
+ return $this->registeredVars;
+ }
- $this->set($name, $this->reduce($default, true), true);
+ /**
+ * Adds to list of parsed files
+ *
+ * @api
+ *
+ * @param string $path
+ */
+ public function addParsedFile($path)
+ {
+ if (isset($path) && file_exists($path)) {
+ $this->parsedFiles[realpath($path)] = filemtime($path);
}
}
- protected function pushEnv($block = null)
+ /**
+ * Returns list of parsed files
+ *
+ * @api
+ *
+ * @return array
+ */
+ public function getParsedFiles()
{
- $env = new \stdClass;
- $env->parent = $this->env;
- $env->store = array();
- $env->block = $block;
- $env->depth = isset($this->env->depth) ? $this->env->depth + 1 : 0;
+ return $this->parsedFiles;
+ }
- $this->env = $env;
+ /**
+ * Add import path
+ *
+ * @api
+ *
+ * @param string $path
+ */
+ public function addImportPath($path)
+ {
+ if (! in_array($path, $this->importPaths)) {
+ $this->importPaths[] = $path;
+ }
+ }
- return $env;
+ /**
+ * Set import paths
+ *
+ * @api
+ *
+ * @param string|array $path
+ */
+ public function setImportPaths($path)
+ {
+ $this->importPaths = (array) $path;
}
- protected function normalizeName($name)
+ /**
+ * Set number precision
+ *
+ * @api
+ *
+ * @param integer $numberPrecision
+ */
+ public function setNumberPrecision($numberPrecision)
{
- return str_replace('-', '_', $name);
+ Node\Number::$precision = $numberPrecision;
}
- protected function getStoreEnv()
+ /**
+ * Set formatter
+ *
+ * @api
+ *
+ * @param string $formatterName
+ */
+ public function setFormatter($formatterName)
{
- return isset($this->storeEnv) ? $this->storeEnv : $this->env;
+ $this->formatter = $formatterName;
}
- protected function set($name, $value, $shadow = false, $env = null)
+ /**
+ * Set line number style
+ *
+ * @api
+ *
+ * @param string $lineNumberStyle
+ */
+ public function setLineNumberStyle($lineNumberStyle)
{
- $name = $this->normalizeName($name);
+ $this->lineNumberStyle = $lineNumberStyle;
+ }
- if ($shadow) {
- $this->setRaw($name, $value, $env);
- } else {
- $this->setExisting($name, $value, $env);
- }
+ /**
+ * Register function
+ *
+ * @api
+ *
+ * @param string $name
+ * @param callable $func
+ * @param array $prototype
+ */
+ public function registerFunction($name, $func, $prototype = null)
+ {
+ $this->userFunctions[$this->normalizeName($name)] = [$func, $prototype];
}
- protected function setExisting($name, $value, $env = null)
+ /**
+ * Unregister function
+ *
+ * @api
+ *
+ * @param string $name
+ */
+ public function unregisterFunction($name)
{
- if (!isset($env)) {
- $env = $this->getStoreEnv();
- }
+ unset($this->userFunctions[$this->normalizeName($name)]);
+ }
- if (isset($env->store[$name]) || !isset($env->parent)) {
- $env->store[$name] = $value;
- } else {
- $this->setExisting($name, $value, $env->parent);
- }
+ /**
+ * Add feature
+ *
+ * @api
+ *
+ * @param string $name
+ */
+ public function addFeature($name)
+ {
+ $this->registeredFeatures[$name] = true;
}
- protected function setRaw($name, $value, $env = null)
+ /**
+ * Import file
+ *
+ * @param string $path
+ * @param array $out
+ */
+ protected function importFile($path, $out)
{
- if (!isset($env)) {
- $env = $this->getStoreEnv();
+ // see if tree is cached
+ $realPath = realpath($path);
+
+ if (isset($this->importCache[$realPath])) {
+ $this->handleImportLoop($realPath);
+
+ $tree = $this->importCache[$realPath];
+ } else {
+ $code = file_get_contents($path);
+ $parser = $this->parserFactory($path);
+ $tree = $parser->parse($code);
+
+ $this->importCache[$realPath] = $tree;
}
- $env->store[$name] = $value;
+ $pi = pathinfo($path);
+ array_unshift($this->importPaths, $pi['dirname']);
+ $this->compileChildrenNoReturn($tree->children, $out);
+ array_shift($this->importPaths);
}
- public function get($name, $defaultValue = null, $env = null)
+ /**
+ * Return the file path for an import url if it exists
+ *
+ * @api
+ *
+ * @param string $url
+ *
+ * @return string|null
+ */
+ public function findImport($url)
{
- $name = $this->normalizeName($name);
+ $urls = [];
- if (!isset($env)) {
- $env = $this->getStoreEnv();
+ // for "normal" scss imports (ignore vanilla css and external requests)
+ if (! preg_match('/\.css$|^https?:\/\//', $url)) {
+ // try both normal and the _partial filename
+ $urls = [$url, preg_replace('/[^\/]+$/', '_\0', $url)];
}
- if (! isset($defaultValue)) {
- $defaultValue = self::$defaultValue;
- }
+ foreach ($this->importPaths as $dir) {
+ if (is_string($dir)) {
+ // check urls for normal import paths
+ foreach ($urls as $full) {
+ $full = $dir
+ . (! empty($dir) && substr($dir, -1) !== '/' ? '/' : '')
+ . $full;
- if (isset($env->store[$name])) {
- return $env->store[$name];
- }
+ if ($this->fileExists($file = $full . '.scss') ||
+ $this->fileExists($file = $full)
+ ) {
+ return $file;
+ }
+ }
+ } elseif (is_callable($dir)) {
+ // check custom callback for import path
+ $file = call_user_func($dir, $url);
- if (isset($env->parent)) {
- return $this->get($name, $defaultValue, $env->parent);
+ if ($file !== null) {
+ return $file;
+ }
+ }
}
- return $defaultValue; // found nothing
+ return null;
}
- protected function injectVariables(array $args)
+ /**
+ * Set encoding
+ *
+ * @api
+ *
+ * @param string $encoding
+ */
+ public function setEncoding($encoding)
{
- if (empty($args)) {
+ $this->encoding = $encoding;
+ }
+
+ /**
+ * Ignore errors?
+ *
+ * @api
+ *
+ * @param boolean $ignoreErrors
+ *
+ * @return \Leafo\ScssPhp\Compiler
+ */
+ public function setIgnoreErrors($ignoreErrors)
+ {
+ $this->ignoreErrors = $ignoreErrors;
+ }
+
+ /**
+ * Throw error (exception)
+ *
+ * @api
+ *
+ * @param string $msg Message with optional sprintf()-style vararg parameters
+ *
+ * @throws \Leafo\ScssPhp\Exception\CompilerException
+ */
+ public function throwError($msg)
+ {
+ if ($this->ignoreErrors) {
return;
}
- $parser = new Parser(__METHOD__, false);
+ if (func_num_args() > 1) {
+ $msg = call_user_func_array('sprintf', func_get_args());
+ }
- foreach ($args as $name => $strValue) {
- if ($name[0] === '$') {
- $name = substr($name, 1);
- }
+ $line = $this->sourceLine;
+ $msg = "$msg: line: $line";
- $parser->env = null;
- $parser->count = 0;
- $parser->buffer = (string) $strValue;
- $parser->inParens = false;
- $parser->eatWhiteDefault = true;
- $parser->insertComments = true;
+ throw new CompilerException($msg);
+ }
- if (! $parser->valueList($value)) {
- throw new \Exception("failed to parse passed in variable $name: $strValue");
- }
+ /**
+ * Handle import loop
+ *
+ * @param string $name
+ *
+ * @throws \Exception
+ */
+ protected function handleImportLoop($name)
+ {
+ for ($env = $this->env; $env; $env = $env->parent) {
+ $file = $this->sourceNames[$env->block->sourceIndex];
- $this->set($name, $value);
+ if (realpath($file) === $name) {
+ $this->throwError('An @import loop has been found: %s imports %s', $file, basename($file));
+ break;
+ }
}
}
/**
- * Set variables
+ * Does file exist?
*
- * @param array $variables
+ * @param string $name
+ *
+ * @return boolean
*/
- public function setVariables(array $variables)
+ protected function fileExists($name)
{
- $this->registeredVars = array_merge($this->registeredVars, $variables);
+ return is_file($name);
}
/**
- * Unset variable
+ * Call SCSS @function
*
* @param string $name
+ * @param array $args
+ * @param array $returnValue
+ *
+ * @return boolean Returns true if returnValue is set; otherwise, false
*/
- public function unsetVariable($name)
+ protected function callScssFunction($name, $argValues, &$returnValue)
{
- unset($this->registeredVars[$name]);
- }
+ $func = $this->get(self::$namespaces['function'] . $name, false);
- protected function popEnv()
- {
- $env = $this->env;
- $this->env = $this->env->parent;
+ if (! $func) {
+ return false;
+ }
- return $env;
- }
+ $this->pushEnv();
- public function getParsedFiles()
- {
- return $this->parsedFiles;
- }
+ // set the args
+ if (isset($func->args)) {
+ $this->applyArguments($func->args, $argValues);
+ }
- public function addImportPath($path)
- {
- $this->importPaths[] = $path;
+ // throw away lines and children
+ $tmp = new OutputBlock;
+ $tmp->lines = [];
+ $tmp->children = [];
+
+ $this->env->marker = 'function';
+
+ $ret = $this->compileChildren($func->children, $tmp);
+
+ $this->popEnv();
+
+ $returnValue = ! isset($ret) ? self::$defaultValue : $ret;
+
+ return true;
}
- public function setImportPaths($path)
+ /**
+ * Call built-in and registered (PHP) functions
+ *
+ * @param string $name
+ * @param array $args
+ * @param array $returnValue
+ *
+ * @return boolean Returns true if returnValue is set; otherwise, false
+ */
+ protected function callNativeFunction($name, $args, &$returnValue)
{
- $this->importPaths = (array)$path;
+ // try a lib function
+ $name = $this->normalizeName($name);
+
+ if (isset($this->userFunctions[$name])) {
+ // see if we can find a user function
+ list($f, $prototype) = $this->userFunctions[$name];
+ } elseif (($f = $this->getBuiltinFunction($name)) && is_callable($f)) {
+ $libName = $f[1];
+ $prototype = isset(self::$$libName) ? self::$$libName : null;
+ } else {
+ return false;
+ }
+
+ list($sorted, $kwargs) = $this->sortArgs($prototype, $args);
+
+ if ($name !== 'if' && $name !== 'call') {
+ foreach ($sorted as &$val) {
+ $val = $this->reduce($val, true);
+ }
+ }
+
+ $returnValue = call_user_func($f, $sorted, $kwargs);
+
+ if (! isset($returnValue)) {
+ return false;
+ }
+
+ $returnValue = $this->coerceValue($returnValue);
+
+ return true;
}
- public function setNumberPrecision($numberPrecision)
+ /**
+ * Get built-in function
+ *
+ * @param string $name Normalized name
+ *
+ * @return array
+ */
+ protected function getBuiltinFunction($name)
{
- $this->numberPrecision = $numberPrecision;
- }
+ $libName = 'lib' . preg_replace_callback(
+ '/_(.)/',
+ function ($m) {
+ return ucfirst($m[1]);
+ },
+ ucfirst($name)
+ );
- public function setFormatter($formatterName)
- {
- $this->formatter = $formatterName;
+ return [$this, $libName];
}
- public function registerFunction($name, $func)
+ /**
+ * Sorts keyword arguments
+ *
+ * @param array $prototype
+ * @param array $args
+ *
+ * @return array
+ */
+ protected function sortArgs($prototype, $args)
{
- $this->userFunctions[$this->normalizeName($name)] = $func;
- }
+ $keyArgs = [];
+ $posArgs = [];
- public function unregisterFunction($name)
- {
- unset($this->userFunctions[$this->normalizeName($name)]);
- }
+ // separate positional and keyword arguments
+ foreach ($args as $arg) {
+ list($key, $value) = $arg;
- protected function importFile($path, $out)
- {
- // see if tree is cached
- $realPath = realpath($path);
- if (isset($this->importCache[$realPath])) {
- $tree = $this->importCache[$realPath];
- } else {
- $code = file_get_contents($path);
- $parser = new Parser($path, false);
- $tree = $parser->parse($code);
- $this->parsedFiles[] = $path;
+ $key = $key[1];
- $this->importCache[$realPath] = $tree;
+ if (empty($key)) {
+ $posArgs[] = $value;
+ } else {
+ $keyArgs[$key] = $value;
+ }
}
- $pi = pathinfo($path);
- array_unshift($this->importPaths, $pi['dirname']);
- $this->compileChildren($tree->children, $out);
- array_shift($this->importPaths);
+ if (! isset($prototype)) {
+ return [$posArgs, $keyArgs];
+ }
+
+ // copy positional args
+ $finalArgs = array_pad($posArgs, count($prototype), null);
+
+ // overwrite positional args with keyword args
+ foreach ($prototype as $i => $names) {
+ foreach ((array) $names as $name) {
+ if (isset($keyArgs[$name])) {
+ $finalArgs[$i] = $keyArgs[$name];
+ }
+ }
+ }
+
+ return [$finalArgs, $keyArgs];
}
- // results the file path for an import url if it exists
- public function findImport($url)
+ /**
+ * Apply argument values per definition
+ *
+ * @param array $argDef
+ * @param array $argValues
+ *
+ * @throws \Exception
+ */
+ protected function applyArguments($argDef, $argValues)
{
- $urls = array();
+ $storeEnv = $this->getStoreEnv();
- // for "normal" scss imports (ignore vanilla css and external requests)
- if (!preg_match('/\.css|^http:\/\/$/', $url)) {
- // try both normal and the _partial filename
- $urls = array($url, preg_replace('/[^\/]+$/', '_\0', $url));
+ $env = new Environment;
+ $env->store = $storeEnv->store;
+
+ $hasVariable = false;
+ $args = [];
+
+ foreach ($argDef as $i => $arg) {
+ list($name, $default, $isVariable) = $argDef[$i];
+
+ $args[$name] = [$i, $name, $default, $isVariable];
+ $hasVariable |= $isVariable;
}
- foreach ($this->importPaths as $dir) {
- if (is_string($dir)) {
- // check urls for normal import paths
- foreach ($urls as $full) {
- $full = $dir .
- (!empty($dir) && substr($dir, -1) != '/' ? '/' : '') .
- $full;
+ $keywordArgs = [];
+ $deferredKeywordArgs = [];
+ $remaining = [];
- if ($this->fileExists($file = $full.'.scss') ||
- $this->fileExists($file = $full)
- ) {
- return $file;
+ // assign the keyword args
+ foreach ((array) $argValues as $arg) {
+ if (! empty($arg[0])) {
+ if (! isset($args[$arg[0][1]])) {
+ if ($hasVariable) {
+ $deferredKeywordArgs[$arg[0][1]] = $arg[1];
+ } else {
+ $this->throwError("Mixin or function doesn't have an argument named $%s.", $arg[0][1]);
+ break;
}
+ } elseif ($args[$arg[0][1]][0] < count($remaining)) {
+ $this->throwError("The argument $%s was passed both by position and by name.", $arg[0][1]);
+ break;
+ } else {
+ $keywordArgs[$arg[0][1]] = $arg[1];
}
- } else {
- // check custom callback for import path
- $file = call_user_func($dir, $url, $this);
+ } elseif (count($keywordArgs)) {
+ $this->throwError('Positional arguments must come before keyword arguments.');
+ break;
+ } elseif ($arg[2] === true) {
+ $val = $this->reduce($arg[1], true);
- if ($file !== null) {
- return $file;
+ if ($val[0] === Type::T_LIST) {
+ foreach ($val[2] as $name => $item) {
+ if (! is_numeric($name)) {
+ $keywordArgs[$name] = $item;
+ } else {
+ $remaining[] = $item;
+ }
+ }
+ } elseif ($val[0] === Type::T_MAP) {
+ foreach ($val[1] as $i => $name) {
+ $name = $this->compileStringContent($this->coerceString($name));
+ $item = $val[2][$i];
+
+ if (! is_numeric($name)) {
+ $keywordArgs[$name] = $item;
+ } else {
+ $remaining[] = $item;
+ }
+ }
+ } else {
+ $remaining[] = $val;
}
+ } else {
+ $remaining[] = $arg[1];
}
}
- return null;
- }
+ foreach ($args as $arg) {
+ list($i, $name, $default, $isVariable) = $arg;
- protected function fileExists($name)
- {
- return is_file($name);
- }
+ if ($isVariable) {
+ $val = [Type::T_LIST, ',', [], $isVariable];
- protected function callBuiltin($name, $args, &$returnValue)
- {
- // try a lib function
- $name = $this->normalizeName($name);
- $libName = 'lib' . preg_replace_callback(
- '/_(.)/',
- function ($m) {
- return ucfirst($m[1]);
- },
- ucfirst($name)
- );
+ for ($count = count($remaining); $i < $count; $i++) {
+ $val[2][] = $remaining[$i];
+ }
+
+ foreach ($deferredKeywordArgs as $itemName => $item) {
+ $val[2][$itemName] = $item;
+ }
+ } elseif (isset($remaining[$i])) {
+ $val = $remaining[$i];
+ } elseif (isset($keywordArgs[$name])) {
+ $val = $keywordArgs[$name];
+ } elseif (! empty($default)) {
+ continue;
+ } else {
+ $this->throwError("Missing argument $name");
+ break;
+ }
- $f = array($this, $libName);
+ $this->set($name, $this->reduce($val, true), true, $env);
+ }
- if (is_callable($f)) {
- $prototype = isset(self::$$libName) ? self::$$libName : null;
- $sorted = $this->sortArgs($prototype, $args);
+ $storeEnv->store = $env->store;
- foreach ($sorted as &$val) {
- $val = $this->reduce($val, true);
+ foreach ($args as $arg) {
+ list($i, $name, $default, $isVariable) = $arg;
+
+ if ($isVariable || isset($remaining[$i]) || isset($keywordArgs[$name]) || empty($default)) {
+ continue;
}
- $returnValue = call_user_func($f, $sorted, $this);
- } elseif (isset($this->userFunctions[$name])) {
- // see if we can find a user function
- $fn = $this->userFunctions[$name];
+ $this->set($name, $this->reduce($default, true), true);
+ }
+ }
- foreach ($args as &$val) {
- $val = $this->reduce($val[1], true);
- }
+ /**
+ * Coerce a php value into a scss one
+ *
+ * @param mixed $value
+ *
+ * @return array
+ */
+ private function coerceValue($value)
+ {
+ if (is_array($value) || $value instanceof \ArrayAccess) {
+ return $value;
+ }
- $returnValue = call_user_func($fn, $args, $this);
+ if (is_bool($value)) {
+ return $this->toBool($value);
}
- if (isset($returnValue)) {
- // coerce a php value into a scss one
- if (is_numeric($returnValue)) {
- $returnValue = array('number', $returnValue, '');
- } elseif (is_bool($returnValue)) {
- $returnValue = $returnValue ? self::$true : self::$false;
- } elseif (!is_array($returnValue)) {
- $returnValue = array('keyword', $returnValue);
- }
+ if ($value === null) {
+ $value = self::$null;
+ }
- return true;
+ if (is_numeric($value)) {
+ return new Node\Number($value, '');
}
- return false;
+ if ($value === '') {
+ return self::$emptyString;
+ }
+
+ return [Type::T_KEYWORD, $value];
}
- // sorts any keyword arguments
- // TODO: merge with apply arguments
- protected function sortArgs($prototype, $args)
+ /**
+ * Coerce something to map
+ *
+ * @param array $item
+ *
+ * @return array
+ */
+ protected function coerceMap($item)
{
- $keyArgs = array();
- $posArgs = array();
+ if ($item[0] === Type::T_MAP) {
+ return $item;
+ }
- foreach ($args as $arg) {
- list($key, $value) = $arg;
- $key = $key[1];
- if (empty($key)) {
- $posArgs[] = $value;
- } else {
- $keyArgs[$key] = $value;
- }
+ if ($item === self::$emptyList) {
+ return self::$emptyMap;
}
- if (!isset($prototype)) {
- return $posArgs;
+ return [Type::T_MAP, [$item], [self::$null]];
+ }
+
+ /**
+ * Coerce something to list
+ *
+ * @param array $item
+ *
+ * @return array
+ */
+ protected function coerceList($item, $delim = ',')
+ {
+ if (isset($item) && $item[0] === Type::T_LIST) {
+ return $item;
}
- $finalArgs = array();
+ if (isset($item) && $item[0] === Type::T_MAP) {
+ $keys = $item[1];
+ $values = $item[2];
+ $list = [];
- foreach ($prototype as $i => $names) {
- if (isset($posArgs[$i])) {
- $finalArgs[] = $posArgs[$i];
- continue;
- }
+ for ($i = 0, $s = count($keys); $i < $s; $i++) {
+ $key = $keys[$i];
+ $value = $values[$i];
- $set = false;
- foreach ((array)$names as $name) {
- if (isset($keyArgs[$name])) {
- $finalArgs[] = $keyArgs[$name];
- $set = true;
- break;
- }
+ $list[] = [
+ Type::T_LIST,
+ '',
+ [[Type::T_KEYWORD, $this->compileStringContent($this->coerceString($key))], $value]
+ ];
}
- if (!$set) {
- $finalArgs[] = null;
- }
+ return [Type::T_LIST, ',', $list];
}
- return $finalArgs;
+ return [Type::T_LIST, $delim, ! isset($item) ? []: [$item]];
}
+ /**
+ * Coerce color for expression
+ *
+ * @param array $value
+ *
+ * @return array|null
+ */
protected function coerceForExpression($value)
{
if ($color = $this->coerceColor($value)) {
@@ -2120,21 +3696,28 @@ protected function coerceForExpression($value)
return $value;
}
+ /**
+ * Coerce value to color
+ *
+ * @param array $value
+ *
+ * @return array|null
+ */
protected function coerceColor($value)
{
switch ($value[0]) {
- case 'color':
+ case Type::T_COLOR:
return $value;
- case 'keyword':
- $name = $value[1];
+ case Type::T_KEYWORD:
+ $name = strtolower($value[1]);
if (isset(Colors::$cssColors[$name])) {
$rgba = explode(',', Colors::$cssColors[$name]);
return isset($rgba[3])
- ? array('color', (int) $rgba[0], (int) $rgba[1], (int) $rgba[2], (int) $rgba[3])
- : array('color', (int) $rgba[0], (int) $rgba[1], (int) $rgba[2]);
+ ? [Type::T_COLOR, (int) $rgba[0], (int) $rgba[1], (int) $rgba[2], (int) $rgba[3]]
+ : [Type::T_COLOR, (int) $rgba[0], (int) $rgba[1], (int) $rgba[2]];
}
return null;
@@ -2143,26 +3726,95 @@ protected function coerceColor($value)
return null;
}
+ /**
+ * Coerce value to string
+ *
+ * @param array $value
+ *
+ * @return array|null
+ */
protected function coerceString($value)
{
- switch ($value[0]) {
- case 'string':
- return $value;
- case 'keyword':
- return array('string', '', array($value[1]));
+ if ($value[0] === Type::T_STRING) {
+ return $value;
}
- return null;
+
+ return [Type::T_STRING, '', [$this->compileValue($value)]];
+ }
+
+ /**
+ * Coerce value to a percentage
+ *
+ * @param array $value
+ *
+ * @return integer|float
+ */
+ protected function coercePercent($value)
+ {
+ if ($value[0] === Type::T_NUMBER) {
+ if (! empty($value[2]['%'])) {
+ return $value[1] / 100;
+ }
+
+ return $value[1];
+ }
+
+ return 0;
+ }
+
+ /**
+ * Assert value is a map
+ *
+ * @api
+ *
+ * @param array $value
+ *
+ * @return array
+ *
+ * @throws \Exception
+ */
+ public function assertMap($value)
+ {
+ $value = $this->coerceMap($value);
+
+ if ($value[0] !== Type::T_MAP) {
+ $this->throwError('expecting map');
+ }
+
+ return $value;
}
+ /**
+ * Assert value is a list
+ *
+ * @api
+ *
+ * @param array $value
+ *
+ * @return array
+ *
+ * @throws \Exception
+ */
public function assertList($value)
{
- if ($value[0] != 'list') {
+ if ($value[0] !== Type::T_LIST) {
$this->throwError('expecting list');
}
return $value;
}
+ /**
+ * Assert value is a color
+ *
+ * @api
+ *
+ * @param array $value
+ *
+ * @return array
+ *
+ * @throws \Exception
+ */
public function assertColor($value)
{
if ($color = $this->coerceColor($value)) {
@@ -2172,32 +3824,36 @@ public function assertColor($value)
$this->throwError('expecting color');
}
+ /**
+ * Assert value is a number
+ *
+ * @api
+ *
+ * @param array $value
+ *
+ * @return integer|float
+ *
+ * @throws \Exception
+ */
public function assertNumber($value)
{
- if ($value[0] != 'number') {
+ if ($value[0] !== Type::T_NUMBER) {
$this->throwError('expecting number');
}
return $value[1];
}
- protected function coercePercent($value)
- {
- if ($value[0] == 'number') {
- if ($value[2] == '%') {
- return $value[1] / 100;
- }
-
- return $value[1];
- }
-
- return 0;
- }
-
- // make sure a color's components don't go out of bounds
+ /**
+ * Make sure a color's components don't go out of bounds
+ *
+ * @param array $c
+ *
+ * @return array
+ */
protected function fixColor($c)
{
- foreach (range(1, 3) as $i) {
+ foreach ([1, 2, 3] as $i) {
if ($c[$i] < 0) {
$c[$i] = 0;
}
@@ -2210,18 +3866,28 @@ protected function fixColor($c)
return $c;
}
+ /**
+ * Convert RGB to HSL
+ *
+ * @api
+ *
+ * @param integer $red
+ * @param integer $green
+ * @param integer $blue
+ *
+ * @return array
+ */
public function toHSL($red, $green, $blue)
{
$min = min($red, $green, $blue);
$max = max($red, $green, $blue);
$l = $min + $max;
+ $d = $max - $min;
- if ($min == $max) {
- $s = $h = 0;
+ if ((int) $d === 0) {
+ $h = $s = 0;
} else {
- $d = $max - $min;
-
if ($l < 255) {
$s = $d / $l;
} else {
@@ -2237,10 +3903,19 @@ public function toHSL($red, $green, $blue)
}
}
- return array('hsl', fmod($h, 360), $s * 100, $l / 5.1);
+ return [Type::T_HSL, fmod($h, 360), $s * 100, $l / 5.1];
}
- public function hueToRGB($m1, $m2, $h)
+ /**
+ * Hue to RGB helper
+ *
+ * @param float $m1
+ * @param float $m2
+ * @param float $h
+ *
+ * @return float
+ */
+ private function hueToRGB($m1, $m2, $h)
{
if ($h < 0) {
$h += 1;
@@ -2263,7 +3938,17 @@ public function hueToRGB($m1, $m2, $h)
return $m1;
}
- // H from 0 to 360, S and L from 0 to 100
+ /**
+ * Convert HSL to RGB
+ *
+ * @api
+ *
+ * @param integer $hue H from 0 to 360
+ * @param integer $saturation S from 0 to 100
+ * @param integer $lightness L from 0 to 100
+ *
+ * @return array
+ */
public function toRGB($hue, $saturation, $lightness)
{
if ($hue < 0) {
@@ -2281,33 +3966,68 @@ public function toRGB($hue, $saturation, $lightness)
$g = $this->hueToRGB($m1, $m2, $h) * 255;
$b = $this->hueToRGB($m1, $m2, $h - 1/3) * 255;
- $out = array('color', $r, $g, $b);
+ $out = [Type::T_COLOR, $r, $g, $b];
return $out;
}
// Built in functions
- protected static $libIf = array('condition', 'if-true', 'if-false');
+ //protected static $libCall = ['name', 'args...'];
+ protected function libCall($args, $kwargs)
+ {
+ $name = $this->compileStringContent($this->coerceString($this->reduce(array_shift($args), true)));
+
+ $args = array_map(
+ function ($a) {
+ return [null, $a, false];
+ },
+ $args
+ );
+
+ if (count($kwargs)) {
+ foreach ($kwargs as $key => $value) {
+ $args[] = [[Type::T_VARIABLE, $key], $value, false];
+ }
+ }
+
+ return $this->reduce([Type::T_FUNCTION_CALL, $name, $args]);
+ }
+
+ protected static $libIf = ['condition', 'if-true', 'if-false'];
protected function libIf($args)
{
- list($cond,$t, $f) = $args;
+ list($cond, $t, $f) = $args;
- if (!$this->isTruthy($cond)) {
- return $f;
+ if (! $this->isTruthy($this->reduce($cond, true))) {
+ return $this->reduce($f, true);
}
- return $t;
+ return $this->reduce($t, true);
}
- protected static $libIndex = array('list', 'value');
+ protected static $libIndex = ['list', 'value'];
protected function libIndex($args)
{
list($list, $value) = $args;
- $list = $this->assertList($list);
+ if ($value[0] === Type::T_MAP) {
+ return self::$null;
+ }
+
+ if ($list[0] === Type::T_MAP ||
+ $list[0] === Type::T_STRING ||
+ $list[0] === Type::T_KEYWORD ||
+ $list[0] === Type::T_INTERPOLATE
+ ) {
+ $list = $this->coerceList($list, ' ');
+ }
+
+ if ($list[0] !== Type::T_LIST) {
+ return self::$null;
+ }
- $values = array();
+ $values = [];
foreach ($list[2] as $item) {
$values[] = $this->normalizeValue($item);
@@ -2315,33 +4035,33 @@ protected function libIndex($args)
$key = array_search($this->normalizeValue($value), $values);
- return false === $key ? false : $key + 1;
+ return false === $key ? self::$null : $key + 1;
}
- protected static $libRgb = array('red', 'green', 'blue');
+ protected static $libRgb = ['red', 'green', 'blue'];
protected function libRgb($args)
{
- list($r,$g,$b) = $args;
+ list($r, $g, $b) = $args;
- return array('color', $r[1], $g[1], $b[1]);
+ return [Type::T_COLOR, $r[1], $g[1], $b[1]];
}
- protected static $libRgba = array(
- array('red', 'color'),
- 'green', 'blue', 'alpha');
+ protected static $libRgba = [
+ ['red', 'color'],
+ 'green', 'blue', 'alpha'];
protected function libRgba($args)
{
if ($color = $this->coerceColor($args[0])) {
- $num = !isset($args[1]) ? $args[3] : $args[1];
+ $num = ! isset($args[1]) ? $args[3] : $args[1];
$alpha = $this->assertNumber($num);
$color[4] = $alpha;
return $color;
}
- list($r,$g,$b, $a) = $args;
+ list($r, $g, $b, $a) = $args;
- return array('color', $r[1], $g[1], $b[1], $a[1]);
+ return [Type::T_COLOR, $r[1], $g[1], $b[1], $a[1]];
}
// helper function for adjust_color, change_color, and scale_color
@@ -2349,22 +4069,21 @@ protected function alterColor($args, $fn)
{
$color = $this->assertColor($args[0]);
- foreach (array(1,2,3,7) as $i) {
+ foreach ([1, 2, 3, 7] as $i) {
if (isset($args[$i])) {
$val = $this->assertNumber($args[$i]);
- $ii = $i == 7 ? 4 : $i; // alpha
- $color[$ii] =
- $this->$fn(isset($color[$ii]) ? $color[$ii] : 0, $val, $i);
+ $ii = $i === 7 ? 4 : $i; // alpha
+ $color[$ii] = call_user_func($fn, isset($color[$ii]) ? $color[$ii] : 0, $val, $i);
}
}
if (isset($args[4]) || isset($args[5]) || isset($args[6])) {
$hsl = $this->toHSL($color[1], $color[2], $color[3]);
- foreach (array(4,5,6) as $i) {
+ foreach ([4, 5, 6] as $i) {
if (isset($args[$i])) {
$val = $this->assertNumber($args[$i]);
- $hsl[$i - 3] = $this->$fn($hsl[$i - 3], $val, $i);
+ $hsl[$i - 3] = call_user_func($fn, $hsl[$i - 3], $val, $i);
}
}
@@ -2380,80 +4099,77 @@ protected function alterColor($args, $fn)
return $color;
}
- protected static $libAdjustColor = array(
+ protected static $libAdjustColor = [
'color', 'red', 'green', 'blue',
'hue', 'saturation', 'lightness', 'alpha'
- );
- protected function adjustColorHelper($base, $alter, $i)
- {
- return $base += $alter;
- }
+ ];
protected function libAdjustColor($args)
{
- return $this->alterColor($args, 'adjustColorHelper');
+ return $this->alterColor($args, function ($base, $alter, $i) {
+ return $base + $alter;
+ });
}
- protected static $libChangeColor = array(
+ protected static $libChangeColor = [
'color', 'red', 'green', 'blue',
'hue', 'saturation', 'lightness', 'alpha'
- );
- protected function changeColorHelper($base, $alter, $i)
- {
- return $alter;
- }
+ ];
protected function libChangeColor($args)
{
- return $this->alterColor($args, 'changeColorHelper');
+ return $this->alterColor($args, function ($base, $alter, $i) {
+ return $alter;
+ });
}
- protected static $libScaleColor = array(
+ protected static $libScaleColor = [
'color', 'red', 'green', 'blue',
'hue', 'saturation', 'lightness', 'alpha'
- );
- protected function scaleColorHelper($base, $scale, $i)
- {
- // 1,2,3 - rgb
- // 4, 5, 6 - hsl
- // 7 - a
- switch ($i) {
- case 1:
- case 2:
- case 3:
- $max = 255;
- break;
- case 4:
- $max = 360;
- break;
- case 7:
- $max = 1;
- break;
- default:
- $max = 100;
- }
+ ];
+ protected function libScaleColor($args)
+ {
+ return $this->alterColor($args, function ($base, $scale, $i) {
+ // 1, 2, 3 - rgb
+ // 4, 5, 6 - hsl
+ // 7 - a
+ switch ($i) {
+ case 1:
+ case 2:
+ case 3:
+ $max = 255;
+ break;
+
+ case 4:
+ $max = 360;
+ break;
- $scale = $scale / 100;
+ case 7:
+ $max = 1;
+ break;
- if ($scale < 0) {
- return $base * $scale + $base;
- }
+ default:
+ $max = 100;
+ }
- return ($max - $base) * $scale + $base;
- }
- protected function libScaleColor($args)
- {
- return $this->alterColor($args, 'scaleColorHelper');
+ $scale = $scale / 100;
+
+ if ($scale < 0) {
+ return $base * $scale + $base;
+ }
+
+ return ($max - $base) * $scale + $base;
+ });
}
- protected static $libIeHexStr = array('color');
+ protected static $libIeHexStr = ['color'];
protected function libIeHexStr($args)
{
$color = $this->coerceColor($args[0]);
- $color[4] = isset($color[4]) ? round(255*$color[4]) : 255;
+ $color[4] = isset($color[4]) ? round(255 * $color[4]) : 255;
return sprintf('#%02X%02X%02X%02X', $color[4], $color[1], $color[2], $color[3]);
}
- protected static $libRed = array('color');
+ protected static $libRed = ['color'];
protected function libRed($args)
{
$color = $this->coerceColor($args[0]);
@@ -2461,7 +4177,7 @@ protected function libRed($args)
return $color[1];
}
- protected static $libGreen = array('color');
+ protected static $libGreen = ['color'];
protected function libGreen($args)
{
$color = $this->coerceColor($args[0]);
@@ -2469,7 +4185,7 @@ protected function libGreen($args)
return $color[2];
}
- protected static $libBlue = array('color');
+ protected static $libBlue = ['color'];
protected function libBlue($args)
{
$color = $this->coerceColor($args[0]);
@@ -2477,7 +4193,7 @@ protected function libBlue($args)
return $color[3];
}
- protected static $libAlpha = array('color');
+ protected static $libAlpha = ['color'];
protected function libAlpha($args)
{
if ($color = $this->coerceColor($args[0])) {
@@ -2488,12 +4204,12 @@ protected function libAlpha($args)
return null;
}
- protected static $libOpacity = array('color');
+ protected static $libOpacity = ['color'];
protected function libOpacity($args)
{
$value = $args[0];
- if ($value[0] === 'number') {
+ if ($value[0] === Type::T_NUMBER) {
return null;
}
@@ -2501,14 +4217,15 @@ protected function libOpacity($args)
}
// mix two colors
- protected static $libMix = array('color-1', 'color-2', 'weight');
+ protected static $libMix = ['color-1', 'color-2', 'weight'];
protected function libMix($args)
{
list($first, $second, $weight) = $args;
+
$first = $this->assertColor($first);
$second = $this->assertColor($second);
- if (!isset($weight)) {
+ if (! isset($weight)) {
$weight = 0.5;
} else {
$weight = $this->coercePercent($weight);
@@ -2520,14 +4237,14 @@ protected function libMix($args)
$w = $weight * 2 - 1;
$a = $firstAlpha - $secondAlpha;
- $w1 = (($w * $a == -1 ? $w : ($w + $a)/(1 + $w * $a)) + 1) / 2.0;
+ $w1 = (($w * $a === -1 ? $w : ($w + $a) / (1 + $w * $a)) + 1) / 2.0;
$w2 = 1.0 - $w1;
- $new = array('color',
+ $new = [Type::T_COLOR,
$w1 * $first[1] + $w2 * $second[1],
$w1 * $first[2] + $w2 * $second[2],
$w1 * $first[3] + $w2 * $second[3],
- );
+ ];
if ($firstAlpha != 1.0 || $secondAlpha != 1.0) {
$new[] = $firstAlpha * $weight + $secondAlpha * ($weight - 1);
@@ -2536,7 +4253,7 @@ protected function libMix($args)
return $this->fixColor($new);
}
- protected static $libHsl = array('hue', 'saturation', 'lightness');
+ protected static $libHsl = ['hue', 'saturation', 'lightness'];
protected function libHsl($args)
{
list($h, $s, $l) = $args;
@@ -2544,8 +4261,7 @@ protected function libHsl($args)
return $this->toRGB($h[1], $s[1], $l[1]);
}
- protected static $libHsla = array('hue', 'saturation',
- 'lightness', 'alpha');
+ protected static $libHsla = ['hue', 'saturation', 'lightness', 'alpha'];
protected function libHsla($args)
{
list($h, $s, $l, $a) = $args;
@@ -2556,31 +4272,31 @@ protected function libHsla($args)
return $color;
}
- protected static $libHue = array('color');
+ protected static $libHue = ['color'];
protected function libHue($args)
{
$color = $this->assertColor($args[0]);
$hsl = $this->toHSL($color[1], $color[2], $color[3]);
- return array('number', $hsl[1], 'deg');
+ return new Node\Number($hsl[1], 'deg');
}
- protected static $libSaturation = array('color');
+ protected static $libSaturation = ['color'];
protected function libSaturation($args)
{
$color = $this->assertColor($args[0]);
$hsl = $this->toHSL($color[1], $color[2], $color[3]);
- return array('number', $hsl[2], '%');
+ return new Node\Number($hsl[2], '%');
}
- protected static $libLightness = array('color');
+ protected static $libLightness = ['color'];
protected function libLightness($args)
{
$color = $this->assertColor($args[0]);
$hsl = $this->toHSL($color[1], $color[2], $color[3]);
- return array('number', $hsl[3], '%');
+ return new Node\Number($hsl[3], '%');
}
protected function adjustHsl($color, $idx, $amount)
@@ -2596,7 +4312,7 @@ protected function adjustHsl($color, $idx, $amount)
return $out;
}
- protected static $libAdjustHue = array('color', 'degrees');
+ protected static $libAdjustHue = ['color', 'degrees'];
protected function libAdjustHue($args)
{
$color = $this->assertColor($args[0]);
@@ -2605,72 +4321,72 @@ protected function libAdjustHue($args)
return $this->adjustHsl($color, 1, $degrees);
}
- protected static $libLighten = array('color', 'amount');
+ protected static $libLighten = ['color', 'amount'];
protected function libLighten($args)
{
$color = $this->assertColor($args[0]);
- $amount = 100*$this->coercePercent($args[1]);
+ $amount = Util::checkRange('amount', new Range(0, 100), $args[1], '%');
return $this->adjustHsl($color, 3, $amount);
}
- protected static $libDarken = array('color', 'amount');
+ protected static $libDarken = ['color', 'amount'];
protected function libDarken($args)
{
$color = $this->assertColor($args[0]);
- $amount = 100*$this->coercePercent($args[1]);
+ $amount = Util::checkRange('amount', new Range(0, 100), $args[1], '%');
return $this->adjustHsl($color, 3, -$amount);
}
- protected static $libSaturate = array('color', 'amount');
+ protected static $libSaturate = ['color', 'amount'];
protected function libSaturate($args)
{
$value = $args[0];
- if ($value[0] === 'number') {
+ if ($value[0] === Type::T_NUMBER) {
return null;
}
$color = $this->assertColor($value);
- $amount = 100*$this->coercePercent($args[1]);
+ $amount = 100 * $this->coercePercent($args[1]);
return $this->adjustHsl($color, 2, $amount);
}
- protected static $libDesaturate = array('color', 'amount');
+ protected static $libDesaturate = ['color', 'amount'];
protected function libDesaturate($args)
{
$color = $this->assertColor($args[0]);
- $amount = 100*$this->coercePercent($args[1]);
+ $amount = 100 * $this->coercePercent($args[1]);
return $this->adjustHsl($color, 2, -$amount);
}
- protected static $libGrayscale = array('color');
+ protected static $libGrayscale = ['color'];
protected function libGrayscale($args)
{
$value = $args[0];
- if ($value[0] === 'number') {
+ if ($value[0] === Type::T_NUMBER) {
return null;
}
return $this->adjustHsl($this->assertColor($value), 2, -100);
}
- protected static $libComplement = array('color');
+ protected static $libComplement = ['color'];
protected function libComplement($args)
{
return $this->adjustHsl($this->assertColor($args[0]), 1, 180);
}
- protected static $libInvert = array('color');
+ protected static $libInvert = ['color'];
protected function libInvert($args)
{
$value = $args[0];
- if ($value[0] === 'number') {
+ if ($value[0] === Type::T_NUMBER) {
return null;
}
@@ -2683,7 +4399,7 @@ protected function libInvert($args)
}
// increases opacity by amount
- protected static $libOpacify = array('color', 'amount');
+ protected static $libOpacify = ['color', 'amount'];
protected function libOpacify($args)
{
$color = $this->assertColor($args[0]);
@@ -2695,14 +4411,14 @@ protected function libOpacify($args)
return $color;
}
- protected static $libFadeIn = array('color', 'amount');
+ protected static $libFadeIn = ['color', 'amount'];
protected function libFadeIn($args)
{
return $this->libOpacify($args);
}
// decreases opacity by amount
- protected static $libTransparentize = array('color', 'amount');
+ protected static $libTransparentize = ['color', 'amount'];
protected function libTransparentize($args)
{
$color = $this->assertColor($args[0]);
@@ -2714,45 +4430,43 @@ protected function libTransparentize($args)
return $color;
}
- protected static $libFadeOut = array('color', 'amount');
+ protected static $libFadeOut = ['color', 'amount'];
protected function libFadeOut($args)
{
return $this->libTransparentize($args);
}
- protected static $libUnquote = array('string');
+ protected static $libUnquote = ['string'];
protected function libUnquote($args)
{
$str = $args[0];
- if ($str[0] == 'string') {
+ if ($str[0] === Type::T_STRING) {
$str[1] = '';
}
return $str;
}
- protected static $libQuote = array('string');
+ protected static $libQuote = ['string'];
protected function libQuote($args)
{
$value = $args[0];
- if ($value[0] == 'string' && !empty($value[1])) {
+ if ($value[0] === Type::T_STRING && ! empty($value[1])) {
return $value;
}
- return array('string', '"', array($value));
+ return [Type::T_STRING, '"', [$value]];
}
- protected static $libPercentage = array('value');
+ protected static $libPercentage = ['value'];
protected function libPercentage($args)
{
- return array('number',
- $this->coercePercent($args[0]) * 100,
- '%');
+ return new Node\Number($this->coercePercent($args[0]) * 100, '%');
}
- protected static $libRound = array('value');
+ protected static $libRound = ['value'];
protected function libRound($args)
{
$num = $args[0];
@@ -2761,7 +4475,7 @@ protected function libRound($args)
return $num;
}
- protected static $libFloor = array('value');
+ protected static $libFloor = ['value'];
protected function libFloor($args)
{
$num = $args[0];
@@ -2770,7 +4484,7 @@ protected function libFloor($args)
return $num;
}
- protected static $libCeil = array('value');
+ protected static $libCeil = ['value'];
protected function libCeil($args)
{
$num = $args[0];
@@ -2779,7 +4493,7 @@ protected function libCeil($args)
return $num;
}
- protected static $libAbs = array('value');
+ protected static $libAbs = ['value'];
protected function libAbs($args)
{
$num = $args[0];
@@ -2795,7 +4509,7 @@ protected function libMin($args)
foreach ($numbers as $key => $number) {
if (null === $min || $number[1] <= $min[1]) {
- $min = array($key, $number[1]);
+ $min = [$key, $number[1]];
}
}
@@ -2809,31 +4523,40 @@ protected function libMax($args)
foreach ($numbers as $key => $number) {
if (null === $max || $number[1] >= $max[1]) {
- $max = array($key, $number[1]);
+ $max = [$key, $number[1]];
}
}
return $args[$max[0]];
}
+ /**
+ * Helper to normalize args containing numbers
+ *
+ * @param array $args
+ *
+ * @return array
+ */
protected function getNormalizedNumbers($args)
{
$unit = null;
$originalUnit = null;
- $numbers = array();
+ $numbers = [];
foreach ($args as $key => $item) {
- if ('number' != $item[0]) {
+ if ($item[0] !== Type::T_NUMBER) {
$this->throwError('%s is not a number', $item[0]);
+ break;
}
- $number = $this->normalizeNumber($item);
+ $number = $item->normalize();
if (null === $unit) {
$unit = $number[2];
- $originalUnit = $item[2];
+ $originalUnit = $item->unitStr();
} elseif ($unit !== $number[2]) {
- $this->throwError('Incompatible units: "%s" and "%s".', $originalUnit, $item[2]);
+ $this->throwError('Incompatible units: "%s" and "%s".', $originalUnit, $item->unitStr());
+ break;
}
$numbers[$key] = $number;
@@ -2842,7 +4565,7 @@ protected function getNormalizedNumbers($args)
return $numbers;
}
- protected static $libLength = array('list');
+ protected static $libLength = ['list'];
protected function libLength($args)
{
$list = $this->coerceList($args[0]);
@@ -2850,32 +4573,172 @@ protected function libLength($args)
return count($list[2]);
}
- protected static $libNth = array('list', 'n');
+ //protected static $libListSeparator = ['list...'];
+ protected function libListSeparator($args)
+ {
+ if (count($args) > 1) {
+ return 'comma';
+ }
+
+ $list = $this->coerceList($args[0]);
+
+ if (count($list[2]) <= 1) {
+ return 'space';
+ }
+
+ if ($list[1] === ',') {
+ return 'comma';
+ }
+
+ return 'space';
+ }
+
+ protected static $libNth = ['list', 'n'];
protected function libNth($args)
{
$list = $this->coerceList($args[0]);
- $n = $this->assertNumber($args[1]) - 1;
+ $n = $this->assertNumber($args[1]);
+
+ if ($n > 0) {
+ $n--;
+ } elseif ($n < 0) {
+ $n += count($list[2]);
+ }
return isset($list[2][$n]) ? $list[2][$n] : self::$defaultValue;
}
+ protected static $libSetNth = ['list', 'n', 'value'];
+ protected function libSetNth($args)
+ {
+ $list = $this->coerceList($args[0]);
+ $n = $this->assertNumber($args[1]);
+
+ if ($n > 0) {
+ $n--;
+ } elseif ($n < 0) {
+ $n += count($list[2]);
+ }
+
+ if (! isset($list[2][$n])) {
+ $this->throwError('Invalid argument for "n"');
+
+ return;
+ }
+
+ $list[2][$n] = $args[2];
+
+ return $list;
+ }
+
+ protected static $libMapGet = ['map', 'key'];
+ protected function libMapGet($args)
+ {
+ $map = $this->assertMap($args[0]);
+ $key = $this->compileStringContent($this->coerceString($args[1]));
+
+ for ($i = count($map[1]) - 1; $i >= 0; $i--) {
+ if ($key === $this->compileStringContent($this->coerceString($map[1][$i]))) {
+ return $map[2][$i];
+ }
+ }
+
+ return self::$null;
+ }
+
+ protected static $libMapKeys = ['map'];
+ protected function libMapKeys($args)
+ {
+ $map = $this->assertMap($args[0]);
+ $keys = $map[1];
+
+ return [Type::T_LIST, ',', $keys];
+ }
+
+ protected static $libMapValues = ['map'];
+ protected function libMapValues($args)
+ {
+ $map = $this->assertMap($args[0]);
+ $values = $map[2];
+
+ return [Type::T_LIST, ',', $values];
+ }
+
+ protected static $libMapRemove = ['map', 'key'];
+ protected function libMapRemove($args)
+ {
+ $map = $this->assertMap($args[0]);
+ $key = $this->compileStringContent($this->coerceString($args[1]));
+
+ for ($i = count($map[1]) - 1; $i >= 0; $i--) {
+ if ($key === $this->compileStringContent($this->coerceString($map[1][$i]))) {
+ array_splice($map[1], $i, 1);
+ array_splice($map[2], $i, 1);
+ }
+ }
+
+ return $map;
+ }
+
+ protected static $libMapHasKey = ['map', 'key'];
+ protected function libMapHasKey($args)
+ {
+ $map = $this->assertMap($args[0]);
+ $key = $this->compileStringContent($this->coerceString($args[1]));
+
+ for ($i = count($map[1]) - 1; $i >= 0; $i--) {
+ if ($key === $this->compileStringContent($this->coerceString($map[1][$i]))) {
+ return true;
+ }
+ }
+
+ return false;
+ }
+
+ protected static $libMapMerge = ['map-1', 'map-2'];
+ protected function libMapMerge($args)
+ {
+ $map1 = $this->assertMap($args[0]);
+ $map2 = $this->assertMap($args[1]);
+
+ return [Type::T_MAP, array_merge($map1[1], $map2[1]), array_merge($map1[2], $map2[2])];
+ }
+
+ protected static $libKeywords = ['args'];
+ protected function libKeywords($args)
+ {
+ $this->assertList($args[0]);
+
+ $keys = [];
+ $values = [];
+
+ foreach ($args[0][2] as $name => $arg) {
+ $keys[] = [Type::T_KEYWORD, $name];
+ $values[] = $arg;
+ }
+
+ return [Type::T_MAP, $keys, $values];
+ }
+
protected function listSeparatorForJoin($list1, $sep)
{
- if (!isset($sep)) {
+ if (! isset($sep)) {
return $list1[1];
}
switch ($this->compileValue($sep)) {
case 'comma':
return ',';
+
case 'space':
return '';
+
default:
return $list1[1];
}
}
- protected static $libJoin = array('list1', 'list2', 'separator');
+ protected static $libJoin = ['list1', 'list2', 'separator'];
protected function libJoin($args)
{
list($list1, $list2, $sep) = $args;
@@ -2884,10 +4747,10 @@ protected function libJoin($args)
$list2 = $this->coerceList($list2, ' ');
$sep = $this->listSeparatorForJoin($list1, $sep);
- return array('list', $sep, array_merge($list1[2], $list2[2]));
+ return [Type::T_LIST, $sep, array_merge($list1[2], $list2[2])];
}
- protected static $libAppend = array('list', 'val', 'separator');
+ protected static $libAppend = ['list', 'val', 'separator'];
protected function libAppend($args)
{
list($list1, $value, $sep) = $args;
@@ -2895,7 +4758,7 @@ protected function libAppend($args)
$list1 = $this->coerceList($list1, ' ');
$sep = $this->listSeparatorForJoin($list1, $sep);
- return array('list', $sep, array_merge($list1[2], array($value)));
+ return [Type::T_LIST, $sep, array_merge($list1[2], [$value])];
}
protected function libZip($args)
@@ -2904,11 +4767,11 @@ protected function libZip($args)
$this->assertList($arg);
}
- $lists = array();
+ $lists = [];
$firstList = array_shift($args);
foreach ($firstList[2] as $key => $item) {
- $list = array('list', '', array($item));
+ $list = [Type::T_LIST, '', [$item]];
foreach ($args as $arg) {
if (isset($arg[2][$key])) {
@@ -2917,20 +4780,21 @@ protected function libZip($args)
break 2;
}
}
+
$lists[] = $list;
}
- return array('list', ',', $lists);
+ return [Type::T_LIST, ',', $lists];
}
- protected static $libTypeOf = array('value');
+ protected static $libTypeOf = ['value'];
protected function libTypeOf($args)
{
$value = $args[0];
switch ($value[0]) {
- case 'keyword':
- if ($value == self::$true || $value == self::$false) {
+ case Type::T_KEYWORD:
+ if ($value === self::$true || $value === self::$false) {
return 'bool';
}
@@ -2938,45 +4802,206 @@ protected function libTypeOf($args)
return 'color';
}
+ // fall-thru
+ case Type::T_FUNCTION:
return 'string';
+
+ case Type::T_LIST:
+ if (isset($value[3]) && $value[3]) {
+ return 'arglist';
+ }
+
+ // fall-thru
default:
return $value[0];
}
}
- protected static $libUnit = array('number');
+ protected static $libUnit = ['number'];
protected function libUnit($args)
{
$num = $args[0];
- if ($num[0] == 'number') {
- return array('string', '"', array($num[2]));
+ if ($num[0] === Type::T_NUMBER) {
+ return [Type::T_STRING, '"', [$num->unitStr()]];
}
return '';
}
- protected static $libUnitless = array('number');
+ protected static $libUnitless = ['number'];
protected function libUnitless($args)
{
$value = $args[0];
- return $value[0] == 'number' && empty($value[2]);
+ return $value[0] === Type::T_NUMBER && $value->unitless();
}
- protected static $libComparable = array('number-1', 'number-2');
+ protected static $libComparable = ['number-1', 'number-2'];
protected function libComparable($args)
{
list($number1, $number2) = $args;
- if (!isset($number1[0]) || $number1[0] != 'number' || !isset($number2[0]) || $number2[0] != 'number') {
+ if (! isset($number1[0]) || $number1[0] !== Type::T_NUMBER ||
+ ! isset($number2[0]) || $number2[0] !== Type::T_NUMBER
+ ) {
$this->throwError('Invalid argument(s) for "comparable"');
+
+ return;
+ }
+
+ $number1 = $number1->normalize();
+ $number2 = $number2->normalize();
+
+ return $number1[2] === $number2[2] || $number1->unitless() || $number2->unitless();
+ }
+
+ protected static $libStrIndex = ['string', 'substring'];
+ protected function libStrIndex($args)
+ {
+ $string = $this->coerceString($args[0]);
+ $stringContent = $this->compileStringContent($string);
+
+ $substring = $this->coerceString($args[1]);
+ $substringContent = $this->compileStringContent($substring);
+
+ $result = strpos($stringContent, $substringContent);
+
+ return $result === false ? self::$null : new Node\Number($result + 1, '');
+ }
+
+ protected static $libStrInsert = ['string', 'insert', 'index'];
+ protected function libStrInsert($args)
+ {
+ $string = $this->coerceString($args[0]);
+ $stringContent = $this->compileStringContent($string);
+
+ $insert = $this->coerceString($args[1]);
+ $insertContent = $this->compileStringContent($insert);
+
+ list(, $index) = $args[2];
+
+ $string[2] = [substr_replace($stringContent, $insertContent, $index - 1, 0)];
+
+ return $string;
+ }
+
+ protected static $libStrLength = ['string'];
+ protected function libStrLength($args)
+ {
+ $string = $this->coerceString($args[0]);
+ $stringContent = $this->compileStringContent($string);
+
+ return new Node\Number(strlen($stringContent), '');
+ }
+
+ protected static $libStrSlice = ['string', 'start-at', 'end-at'];
+ protected function libStrSlice($args)
+ {
+ if (isset($args[2]) && $args[2][1] == 0) {
+ return self::$nullString;
+ }
+
+ $string = $this->coerceString($args[0]);
+ $stringContent = $this->compileStringContent($string);
+
+ $start = (int) $args[1][1];
+
+ if ($start > 0) {
+ $start--;
+ }
+
+ $end = (int) $args[2][1];
+ $length = $end < 0 ? $end + 1 : ($end > 0 ? $end - $start : $end);
+
+ $string[2] = $length
+ ? [substr($stringContent, $start, $length)]
+ : [substr($stringContent, $start)];
+
+ return $string;
+ }
+
+ protected static $libToLowerCase = ['string'];
+ protected function libToLowerCase($args)
+ {
+ $string = $this->coerceString($args[0]);
+ $stringContent = $this->compileStringContent($string);
+
+ $string[2] = [mb_strtolower($stringContent)];
+
+ return $string;
+ }
+
+ protected static $libToUpperCase = ['string'];
+ protected function libToUpperCase($args)
+ {
+ $string = $this->coerceString($args[0]);
+ $stringContent = $this->compileStringContent($string);
+
+ $string[2] = [mb_strtoupper($stringContent)];
+
+ return $string;
+ }
+
+ protected static $libFeatureExists = ['feature'];
+ protected function libFeatureExists($args)
+ {
+ $string = $this->coerceString($args[0]);
+ $name = $this->compileStringContent($string);
+
+ return $this->toBool(
+ array_key_exists($name, $this->registeredFeatures) ? $this->registeredFeatures[$name] : false
+ );
+ }
+
+ protected static $libFunctionExists = ['name'];
+ protected function libFunctionExists($args)
+ {
+ $string = $this->coerceString($args[0]);
+ $name = $this->compileStringContent($string);
+
+ // user defined functions
+ if ($this->has(self::$namespaces['function'] . $name)) {
+ return true;
+ }
+
+ $name = $this->normalizeName($name);
+
+ if (isset($this->userFunctions[$name])) {
+ return true;
}
- $number1 = $this->normalizeNumber($number1);
- $number2 = $this->normalizeNumber($number2);
+ // built-in functions
+ $f = $this->getBuiltinFunction($name);
+
+ return $this->toBool(is_callable($f));
+ }
+
+ protected static $libGlobalVariableExists = ['name'];
+ protected function libGlobalVariableExists($args)
+ {
+ $string = $this->coerceString($args[0]);
+ $name = $this->compileStringContent($string);
+
+ return $this->has($name, $this->rootEnv);
+ }
+
+ protected static $libMixinExists = ['name'];
+ protected function libMixinExists($args)
+ {
+ $string = $this->coerceString($args[0]);
+ $name = $this->compileStringContent($string);
+
+ return $this->has(self::$namespaces['mixin'] . $name);
+ }
+
+ protected static $libVariableExists = ['name'];
+ protected function libVariableExists($args)
+ {
+ $string = $this->coerceString($args[0]);
+ $name = $this->compileStringContent($string);
- return $number1[2] == $number2[2] || $number1[2] == '' || $number2[2] == '';
+ return $this->has($name);
}
/**
@@ -2986,21 +5011,49 @@ protected function libComparable($args)
*/
protected function libCounter($args)
{
- $list = array_map(array($this, 'compileValue'), $args);
+ $list = array_map([$this, 'compileValue'], $args);
- return array('string', '', array('counter(' . implode(',', $list) . ')'));
+ return [Type::T_STRING, '', ['counter(' . implode(',', $list) . ')']];
}
- public function throwError($msg = null)
+ protected static $libRandom = ['limit'];
+ protected function libRandom($args)
{
- if (func_num_args() > 1) {
- $msg = call_user_func_array('sprintf', func_get_args());
+ if (isset($args[0])) {
+ $n = $this->assertNumber($args[0]);
+
+ if ($n < 1) {
+ $this->throwError("limit must be greater than or equal to 1");
+
+ return;
+ }
+
+ return new Node\Number(mt_rand(1, $n), '');
+ }
+
+ return new Node\Number(mt_rand(1, mt_getrandmax()), '');
+ }
+
+ protected function libUniqueId()
+ {
+ static $id;
+
+ if (! isset($id)) {
+ $id = mt_rand(0, pow(36, 8));
}
- if ($this->sourcePos >= 0 && isset($this->sourceParser)) {
- $this->sourceParser->throwParseError($msg, $this->sourcePos);
+ $id += mt_rand(0, 10) + 1;
+
+ return [Type::T_STRING, '', ['u' . str_pad(base_convert($id, 10, 36), 8, '0', STR_PAD_LEFT)]];
+ }
+
+ protected static $libInspect = ['value'];
+ protected function libInspect($args)
+ {
+ if ($args[0] === self::$null) {
+ return [Type::T_KEYWORD, 'null'];
}
- throw new \Exception($msg);
+ return $args[0];
}
}
diff --git a/lib/scssphp/src/Compiler/Environment.php b/lib/scssphp/src/Compiler/Environment.php
new file mode 100755
index 0000000..d44bff7
--- /dev/null
+++ b/lib/scssphp/src/Compiler/Environment.php
@@ -0,0 +1,40 @@
+
+ */
+class Environment
+{
+ /**
+ * @var \Leafo\ScssPhp\Block
+ */
+ public $block;
+
+ /**
+ * @var \Leafo\ScssPhp\Compiler\Environment
+ */
+ public $parent;
+
+ /**
+ * @var array
+ */
+ public $store;
+
+ /**
+ * @var integer
+ */
+ public $depth;
+}
diff --git a/lib/scssphp/src/Exception/CompilerException.php b/lib/scssphp/src/Exception/CompilerException.php
new file mode 100755
index 0000000..777e40a
--- /dev/null
+++ b/lib/scssphp/src/Exception/CompilerException.php
@@ -0,0 +1,21 @@
+
+ */
+class CompilerException extends \Exception
+{
+}
diff --git a/lib/scssphp/src/Exception/ParserException.php b/lib/scssphp/src/Exception/ParserException.php
new file mode 100755
index 0000000..fbe6388
--- /dev/null
+++ b/lib/scssphp/src/Exception/ParserException.php
@@ -0,0 +1,21 @@
+
+ */
+class ParserException extends \Exception
+{
+}
diff --git a/lib/scssphp/src/Exception/ServerException.php b/lib/scssphp/src/Exception/ServerException.php
new file mode 100755
index 0000000..5a878d2
--- /dev/null
+++ b/lib/scssphp/src/Exception/ServerException.php
@@ -0,0 +1,21 @@
+
+ */
+class ServerException extends \Exception
+{
+}
diff --git a/lib/scssphp/src/Formatter.php b/lib/scssphp/src/Formatter.php
index c28ce34..2770bb2 100755
--- a/lib/scssphp/src/Formatter.php
+++ b/lib/scssphp/src/Formatter.php
@@ -2,76 +2,188 @@
/**
* SCSSPHP
*
- * @copyright 2012-2014 Leaf Corcoran
+ * @copyright 2012-2015 Leaf Corcoran
*
- * @license http://opensource.org/licenses/gpl-license GPL-3.0
* @license http://opensource.org/licenses/MIT MIT
*
- * @link http://leafo.net/scssphp
+ * @link http://leafo.github.io/scssphp
*/
namespace Leafo\ScssPhp;
+use Leafo\ScssPhp\Formatter\OutputBlock;
+
/**
- * SCSS base formatter
+ * Base formatter
*
* @author Leaf Corcoran
*/
abstract class Formatter
{
+ /**
+ * @var integer
+ */
public $indentLevel;
+
+ /**
+ * @var string
+ */
public $indentChar;
+
+ /**
+ * @var string
+ */
public $break;
+
+ /**
+ * @var string
+ */
public $open;
+
+ /**
+ * @var string
+ */
public $close;
+
+ /**
+ * @var string
+ */
public $tagSeparator;
+
+ /**
+ * @var string
+ */
public $assignSeparator;
- protected function indentStr($n = 0)
+ /**
+ * @var boolea
+ */
+ public $keepSemicolons;
+
+ /**
+ * Initialize formatter
+ *
+ * @api
+ */
+ abstract public function __construct();
+
+ /**
+ * Return indentation (whitespace)
+ *
+ * @return string
+ */
+ protected function indentStr()
{
- return str_repeat($this->indentChar, max($this->indentLevel + $n, 0));
+ return '';
}
+ /**
+ * Return property assignment
+ *
+ * @api
+ *
+ * @param string $name
+ * @param mixed $value
+ *
+ * @return string
+ */
public function property($name, $value)
{
- return $name . $this->assignSeparator . $value . ';';
+ return rtrim($name) . $this->assignSeparator . $value . ';';
+ }
+
+ /**
+ * Strip semi-colon appended by property(); it's a separator, not a terminator
+ *
+ * @api
+ *
+ * @param array $lines
+ */
+ public function stripSemicolon(&$lines)
+ {
+ if ($this->keepSemicolons) {
+ return;
+ }
+
+ if (($count = count($lines))
+ && substr($lines[$count - 1], -1) === ';'
+ ) {
+ $lines[$count - 1] = substr($lines[$count - 1], 0, -1);
+ }
}
- protected function blockLines($inner, $block)
+ /**
+ * Output lines inside a block
+ *
+ * @param \Leafo\ScssPhp\Formatter\OutputBlock $block
+ */
+ protected function blockLines(OutputBlock $block)
{
- $glue = $this->break.$inner;
+ $inner = $this->indentStr();
+
+ $glue = $this->break . $inner;
+
echo $inner . implode($glue, $block->lines);
- if (!empty($block->children)) {
+ if (! empty($block->children)) {
echo $this->break;
}
}
- protected function block($block)
+ /**
+ * Output block selectors
+ *
+ * @param \Leafo\ScssPhp\Formatter\OutputBlock $block
+ */
+ protected function blockSelectors(OutputBlock $block)
+ {
+ $inner = $this->indentStr();
+
+ echo $inner
+ . implode($this->tagSeparator, $block->selectors)
+ . $this->open . $this->break;
+ }
+
+ /**
+ * Output block children
+ *
+ * @param \Leafo\ScssPhp\Formatter\OutputBlock $block
+ */
+ protected function blockChildren(OutputBlock $block)
+ {
+ foreach ($block->children as $child) {
+ $this->block($child);
+ }
+ }
+
+ /**
+ * Output non-empty block
+ *
+ * @param \Leafo\ScssPhp\Formatter\OutputBlock $block
+ */
+ protected function block(OutputBlock $block)
{
if (empty($block->lines) && empty($block->children)) {
return;
}
- $inner = $pre = $this->indentStr();
+ $pre = $this->indentStr();
+
+ if (! empty($block->selectors)) {
+ $this->blockSelectors($block);
- if (!empty($block->selectors)) {
- echo $pre .
- implode($this->tagSeparator, $block->selectors) .
- $this->open . $this->break;
$this->indentLevel++;
- $inner = $this->indentStr();
}
- if (!empty($block->lines)) {
- $this->blockLines($inner, $block);
+ if (! empty($block->lines)) {
+ $this->blockLines($block);
}
- foreach ($block->children as $child) {
- $this->block($child);
+ if (! empty($block->children)) {
+ $this->blockChildren($block);
}
- if (!empty($block->selectors)) {
+ if (! empty($block->selectors)) {
$this->indentLevel--;
if (empty($block->children)) {
@@ -82,10 +194,21 @@ protected function block($block)
}
}
- public function format($block)
+ /**
+ * Entry point to formatting a block
+ *
+ * @api
+ *
+ * @param \Leafo\ScssPhp\Formatter\OutputBlock $block An abstract syntax tree
+ *
+ * @return string
+ */
+ public function format(OutputBlock $block)
{
ob_start();
+
$this->block($block);
+
$out = ob_get_clean();
return $out;
diff --git a/lib/scssphp/src/Formatter/Compact.php b/lib/scssphp/src/Formatter/Compact.php
new file mode 100755
index 0000000..94abe32
--- /dev/null
+++ b/lib/scssphp/src/Formatter/Compact.php
@@ -0,0 +1,45 @@
+
+ */
+class Compact extends Formatter
+{
+ /**
+ * {@inheritdoc}
+ */
+ public function __construct()
+ {
+ $this->indentLevel = 0;
+ $this->indentChar = '';
+ $this->break = '';
+ $this->open = ' {';
+ $this->close = "}\n\n";
+ $this->tagSeparator = ',';
+ $this->assignSeparator = ':';
+ $this->keepSemicolons = true;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function indentStr()
+ {
+ return ' ';
+ }
+}
diff --git a/lib/scssphp/src/Formatter/Compressed.php b/lib/scssphp/src/Formatter/Compressed.php
index 5610ac1..df7bc75 100755
--- a/lib/scssphp/src/Formatter/Compressed.php
+++ b/lib/scssphp/src/Formatter/Compressed.php
@@ -2,25 +2,28 @@
/**
* SCSSPHP
*
- * @copyright 2012-2014 Leaf Corcoran
+ * @copyright 2012-2015 Leaf Corcoran
*
- * @license http://opensource.org/licenses/gpl-license GPL-3.0
* @license http://opensource.org/licenses/MIT MIT
*
- * @link http://leafo.net/scssphp
+ * @link http://leafo.github.io/scssphp
*/
namespace Leafo\ScssPhp\Formatter;
use Leafo\ScssPhp\Formatter;
+use Leafo\ScssPhp\Formatter\OutputBlock;
/**
- * SCSS compressed formatter
+ * Compressed formatter
*
* @author Leaf Corcoran
*/
class Compressed extends Formatter
{
+ /**
+ * {@inheritdoc}
+ */
public function __construct()
{
$this->indentLevel = 0;
@@ -30,16 +33,17 @@ public function __construct()
$this->close = '}';
$this->tagSeparator = ',';
$this->assignSeparator = ':';
+ $this->keepSemicolons = false;
}
- public function indentStr($n = 0)
+ /**
+ * {@inheritdoc}
+ */
+ public function blockLines(OutputBlock $block)
{
- return '';
- }
+ $inner = $this->indentStr();
- public function blockLines($inner, $block)
- {
- $glue = $this->break.$inner;
+ $glue = $this->break . $inner;
foreach ($block->lines as $index => $line) {
if (substr($line, 0, 2) === '/*' && substr($line, 2, 1) !== '!') {
@@ -51,7 +55,7 @@ public function blockLines($inner, $block)
echo $inner . implode($glue, $block->lines);
- if (!empty($block->children)) {
+ if (! empty($block->children)) {
echo $this->break;
}
}
diff --git a/lib/scssphp/src/Formatter/Crunched.php b/lib/scssphp/src/Formatter/Crunched.php
index 1f34352..ccba133 100755
--- a/lib/scssphp/src/Formatter/Crunched.php
+++ b/lib/scssphp/src/Formatter/Crunched.php
@@ -2,25 +2,28 @@
/**
* SCSSPHP
*
- * @copyright 2012-2014 Leaf Corcoran
+ * @copyright 2012-2015 Leaf Corcoran
*
- * @license http://opensource.org/licenses/gpl-license GPL-3.0
* @license http://opensource.org/licenses/MIT MIT
*
- * @link http://leafo.net/scssphp
+ * @link http://leafo.github.io/scssphp
*/
namespace Leafo\ScssPhp\Formatter;
use Leafo\ScssPhp\Formatter;
+use Leafo\ScssPhp\Formatter\OutputBlock;
/**
- * SCSS crunched formatter
+ * Crunched formatter
*
* @author Anthon Pang
*/
class Crunched extends Formatter
{
+ /**
+ * {@inheritdoc}
+ */
public function __construct()
{
$this->indentLevel = 0;
@@ -30,16 +33,17 @@ public function __construct()
$this->close = '}';
$this->tagSeparator = ',';
$this->assignSeparator = ':';
+ $this->keepSemicolons = false;
}
- public function indentStr($n = 0)
+ /**
+ * {@inheritdoc}
+ */
+ public function blockLines(OutputBlock $block)
{
- return '';
- }
+ $inner = $this->indentStr();
- public function blockLines($inner, $block)
- {
- $glue = $this->break.$inner;
+ $glue = $this->break . $inner;
foreach ($block->lines as $index => $line) {
if (substr($line, 0, 2) === '/*') {
@@ -49,7 +53,7 @@ public function blockLines($inner, $block)
echo $inner . implode($glue, $block->lines);
- if (!empty($block->children)) {
+ if (! empty($block->children)) {
echo $this->break;
}
}
diff --git a/lib/scssphp/src/Formatter/Debug.php b/lib/scssphp/src/Formatter/Debug.php
new file mode 100755
index 0000000..855742e
--- /dev/null
+++ b/lib/scssphp/src/Formatter/Debug.php
@@ -0,0 +1,119 @@
+
+ */
+class Debug extends Formatter
+{
+ /**
+ * {@inheritdoc}
+ */
+ public function __construct()
+ {
+ $this->indentLevel = 0;
+ $this->indentChar = '';
+ $this->break = "\n";
+ $this->open = ' {';
+ $this->close = ' }';
+ $this->tagSeparator = ', ';
+ $this->assignSeparator = ': ';
+ $this->keepSemicolons = true;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ protected function indentStr()
+ {
+ return str_repeat(' ', $this->indentLevel);
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ protected function blockLines(OutputBlock $block)
+ {
+ $indent = $this->indentStr();
+
+ if (empty($block->lines)) {
+ echo "{$indent}block->lines: []\n";
+
+ return;
+ }
+
+ foreach ($block->lines as $index => $line) {
+ echo "{$indent}block->lines[{$index}]: $line\n";
+ }
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ protected function blockSelectors(OutputBlock $block)
+ {
+ $indent = $this->indentStr();
+
+ if (empty($block->selectors)) {
+ echo "{$indent}block->selectors: []\n";
+
+ return;
+ }
+
+ foreach ($block->selectors as $index => $selector) {
+ echo "{$indent}block->selectors[{$index}]: $selector\n";
+ }
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ protected function blockChildren(OutputBlock $block)
+ {
+ $indent = $this->indentStr();
+
+ if (empty($block->children)) {
+ echo "{$indent}block->children: []\n";
+
+ return;
+ }
+
+ $this->indentLevel++;
+
+ foreach ($block->children as $i => $child) {
+ $this->block($child);
+ }
+
+ $this->indentLevel--;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ protected function block(OutputBlock $block)
+ {
+ $indent = $this->indentStr();
+
+ echo "{$indent}block->type: {$block->type}\n" .
+ "{$indent}block->depth: {$block->depth}\n";
+
+ $this->blockSelectors($block);
+ $this->blockLines($block);
+ $this->blockChildren($block);
+ }
+}
diff --git a/lib/scssphp/src/Formatter/Expanded.php b/lib/scssphp/src/Formatter/Expanded.php
index 785f9de..54db742 100755
--- a/lib/scssphp/src/Formatter/Expanded.php
+++ b/lib/scssphp/src/Formatter/Expanded.php
@@ -2,25 +2,28 @@
/**
* SCSSPHP
*
- * @copyright 2012-2014 Leaf Corcoran
+ * @copyright 2012-2015 Leaf Corcoran
*
- * @license http://opensource.org/licenses/gpl-license GPL-3.0
* @license http://opensource.org/licenses/MIT MIT
*
- * @link http://leafo.net/scssphp
+ * @link http://leafo.github.io/scssphp
*/
namespace Leafo\ScssPhp\Formatter;
use Leafo\ScssPhp\Formatter;
+use Leafo\ScssPhp\Formatter\OutputBlock;
/**
- * SCSS expanded formatter
+ * Expanded formatter
*
* @author Leaf Corcoran
*/
class Expanded extends Formatter
{
+ /**
+ * {@inheritdoc}
+ */
public function __construct()
{
$this->indentLevel = 0;
@@ -30,5 +33,36 @@ public function __construct()
$this->close = '}';
$this->tagSeparator = ', ';
$this->assignSeparator = ': ';
+ $this->keepSemicolons = true;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ protected function indentStr()
+ {
+ return str_repeat($this->indentChar, $this->indentLevel);
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ protected function blockLines(OutputBlock $block)
+ {
+ $inner = $this->indentStr();
+
+ $glue = $this->break . $inner;
+
+ foreach ($block->lines as $index => $line) {
+ if (substr($line, 0, 2) === '/*') {
+ $block->lines[$index] = preg_replace('/(\r|\n)+/', $glue, $line);
+ }
+ }
+
+ echo $inner . implode($glue, $block->lines);
+
+ if (empty($block->selectors) || ! empty($block->children)) {
+ echo $this->break;
+ }
}
}
diff --git a/lib/scssphp/src/Formatter/Nested.php b/lib/scssphp/src/Formatter/Nested.php
index 43744aa..9fdb4dd 100755
--- a/lib/scssphp/src/Formatter/Nested.php
+++ b/lib/scssphp/src/Formatter/Nested.php
@@ -2,25 +2,33 @@
/**
* SCSSPHP
*
- * @copyright 2012-2014 Leaf Corcoran
+ * @copyright 2012-2015 Leaf Corcoran
*
- * @license http://opensource.org/licenses/gpl-license GPL-3.0
* @license http://opensource.org/licenses/MIT MIT
*
- * @link http://leafo.net/scssphp
+ * @link http://leafo.github.io/scssphp
*/
namespace Leafo\ScssPhp\Formatter;
use Leafo\ScssPhp\Formatter;
+use Leafo\ScssPhp\Formatter\OutputBlock;
/**
- * SCSS nested formatter
+ * Nested formatter
*
* @author Leaf Corcoran
*/
class Nested extends Formatter
{
+ /**
+ * @var integer
+ */
+ private $depth;
+
+ /**
+ * {@inheritdoc}
+ */
public function __construct()
{
$this->indentLevel = 0;
@@ -30,48 +38,26 @@ public function __construct()
$this->close = ' }';
$this->tagSeparator = ', ';
$this->assignSeparator = ': ';
+ $this->keepSemicolons = true;
}
- // adjust the depths of all children, depth first
- public function adjustAllChildren($block)
+ /**
+ * {@inheritdoc}
+ */
+ protected function indentStr()
{
- // flatten empty nested blocks
- $children = array();
- foreach ($block->children as $i => $child) {
- if (empty($child->lines) && empty($child->children)) {
- if (isset($block->children[$i + 1])) {
- $block->children[$i + 1]->depth = $child->depth;
- }
- continue;
- }
- $children[] = $child;
- }
-
- $count = count($children);
- for ($i = 0; $i < $count; $i++) {
- $depth = $children[$i]->depth;
- $j = $i + 1;
- if (isset($children[$j]) && $depth < $children[$j]->depth) {
- $childDepth = $children[$j]->depth;
- for (; $j < $count; $j++) {
- if ($depth < $children[$j]->depth && $childDepth >= $children[$j]->depth) {
- $children[$j]->depth = $depth + 1;
- }
- }
- }
- }
-
- $block->children = $children;
+ $n = $this->depth - 1;
- // make relative to parent
- foreach ($block->children as $child) {
- $this->adjustAllChildren($child);
- $child->depth = $child->depth - $block->depth;
- }
+ return str_repeat($this->indentChar, max($this->indentLevel + $n, 0));
}
- protected function blockLines($inner, $block)
+ /**
+ * {@inheritdoc}
+ */
+ protected function blockLines(OutputBlock $block)
{
+ $inner = $this->indentStr();
+
$glue = $this->break . $inner;
foreach ($block->lines as $index => $line) {
@@ -82,52 +68,131 @@ protected function blockLines($inner, $block)
echo $inner . implode($glue, $block->lines);
- if (!empty($block->children)) {
+ if (! empty($block->children)) {
echo $this->break;
}
}
- protected function block($block)
+ /**
+ * {@inheritdoc}
+ */
+ protected function blockSelectors(OutputBlock $block)
{
- if ($block->type == 'root') {
- $this->adjustAllChildren($block);
- }
-
- $inner = $pre = $this->indentStr($block->depth - 1);
- if (!empty($block->selectors)) {
- echo $pre .
- implode($this->tagSeparator, $block->selectors) .
- $this->open . $this->break;
- $this->indentLevel++;
- $inner = $this->indentStr($block->depth - 1);
- }
+ $inner = $this->indentStr();
- if (!empty($block->lines)) {
- $this->blockLines($inner, $block);
- }
+ echo $inner
+ . implode($this->tagSeparator, $block->selectors)
+ . $this->open . $this->break;
+ }
+ /**
+ * {@inheritdoc}
+ */
+ protected function blockChildren(OutputBlock $block)
+ {
foreach ($block->children as $i => $child) {
- // echo "*** block: ".$block->depth." child: ".$child->depth."\n";
$this->block($child);
+
if ($i < count($block->children) - 1) {
echo $this->break;
if (isset($block->children[$i + 1])) {
$next = $block->children[$i + 1];
- if ($next->depth == max($block->depth, 1) && $child->depth >= $next->depth) {
+
+ if ($next->depth === max($block->depth, 1) && $child->depth >= $next->depth) {
echo $this->break;
}
}
}
}
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ protected function block(OutputBlock $block)
+ {
+ if ($block->type === 'root') {
+ $this->adjustAllChildren($block);
+ }
+
+ if (empty($block->lines) && empty($block->children)) {
+ return;
+ }
+
+ $this->depth = $block->depth;
+
+ if (! empty($block->selectors)) {
+ $this->blockSelectors($block);
- if (!empty($block->selectors)) {
+ $this->indentLevel++;
+ }
+
+ if (! empty($block->lines)) {
+ $this->blockLines($block);
+ }
+
+ if (! empty($block->children)) {
+ $this->blockChildren($block);
+ }
+
+ if (! empty($block->selectors)) {
$this->indentLevel--;
+
echo $this->close;
}
- if ($block->type == 'root') {
+ if ($block->type === 'root') {
echo $this->break;
}
}
+
+ /**
+ * Adjust the depths of all children, depth first
+ *
+ * @param \Leafo\ScssPhp\Formatter\OutputBlock $block
+ */
+ private function adjustAllChildren(OutputBlock $block)
+ {
+ // flatten empty nested blocks
+ $children = [];
+
+ foreach ($block->children as $i => $child) {
+ if (empty($child->lines) && empty($child->children)) {
+ if (isset($block->children[$i + 1])) {
+ $block->children[$i + 1]->depth = $child->depth;
+ }
+
+ continue;
+ }
+
+ $children[] = $child;
+ }
+
+ $count = count($children);
+
+ for ($i = 0; $i < $count; $i++) {
+ $depth = $children[$i]->depth;
+ $j = $i + 1;
+
+ if (isset($children[$j]) && $depth < $children[$j]->depth) {
+ $childDepth = $children[$j]->depth;
+
+ for (; $j < $count; $j++) {
+ if ($depth < $children[$j]->depth && $childDepth >= $children[$j]->depth) {
+ $children[$j]->depth = $depth + 1;
+ }
+ }
+ }
+ }
+
+ $block->children = $children;
+
+ // make relative to parent
+ foreach ($block->children as $child) {
+ $this->adjustAllChildren($child);
+
+ $child->depth = $child->depth - $block->depth;
+ }
+ }
}
diff --git a/lib/scssphp/src/Formatter/OutputBlock.php b/lib/scssphp/src/Formatter/OutputBlock.php
new file mode 100755
index 0000000..bb8d99b
--- /dev/null
+++ b/lib/scssphp/src/Formatter/OutputBlock.php
@@ -0,0 +1,50 @@
+
+ */
+class OutputBlock
+{
+ /**
+ * @var string
+ */
+ public $type;
+
+ /**
+ * @var integer
+ */
+ public $depth;
+
+ /**
+ * @var array
+ */
+ public $selectors;
+
+ /**
+ * @var array
+ */
+ public $lines;
+
+ /**
+ * @var array
+ */
+ public $children;
+
+ /**
+ * @var \Leafo\ScssPhp\Formatter\OutputBlock
+ */
+ public $parent;
+}
diff --git a/lib/scssphp/src/Node.php b/lib/scssphp/src/Node.php
new file mode 100755
index 0000000..e6ed178
--- /dev/null
+++ b/lib/scssphp/src/Node.php
@@ -0,0 +1,40 @@
+
+ */
+abstract class Node
+{
+ /**
+ * @var string
+ */
+ public $type;
+
+ /**
+ * @var integer
+ */
+ public $sourceIndex;
+
+ /**
+ * @var integer
+ */
+ public $sourceLine;
+
+ /**
+ * @var integer
+ */
+ public $sourceColumn;
+}
diff --git a/lib/scssphp/src/Node/Number.php b/lib/scssphp/src/Node/Number.php
new file mode 100755
index 0000000..a803a6c
--- /dev/null
+++ b/lib/scssphp/src/Node/Number.php
@@ -0,0 +1,329 @@
+
+ */
+class Number extends Node implements \ArrayAccess
+{
+ /**
+ * @var integer
+ */
+ static public $precision = 5;
+
+ /**
+ * @see http://www.w3.org/TR/2012/WD-css3-values-20120308/
+ *
+ * @var array
+ */
+ static protected $unitTable = [
+ 'in' => [
+ 'in' => 1,
+ 'pc' => 6,
+ 'pt' => 72,
+ 'px' => 96,
+ 'cm' => 2.54,
+ 'mm' => 25.4,
+ 'q' => 101.6,
+ ],
+ 'turn' => [
+ 'deg' => 360,
+ 'grad' => 400,
+ 'rad' => 6.28318530717958647692528676, // 2 * M_PI
+ 'turn' => 1,
+ ],
+ 's' => [
+ 's' => 1,
+ 'ms' => 1000,
+ ],
+ 'Hz' => [
+ 'Hz' => 1,
+ 'kHz' => 0.001,
+ ],
+ 'dpi' => [
+ 'dpi' => 1,
+ 'dpcm' => 2.54,
+ 'dppx' => 96,
+ ],
+ ];
+
+ /**
+ * @var integer|float
+ */
+ public $dimension;
+
+ /**
+ * @var array
+ */
+ public $units;
+
+ /**
+ * Initialize number
+ *
+ * @param mixed $dimension
+ * @param mixed $initialUnit
+ */
+ public function __construct($dimension, $initialUnit)
+ {
+ $this->type = Type::T_NUMBER;
+ $this->dimension = $dimension;
+ $this->units = is_array($initialUnit)
+ ? $initialUnit
+ : ($initialUnit ? [$initialUnit => 1]
+ : []);
+ }
+
+ /**
+ * Coerce number to target units
+ *
+ * @param array $units
+ *
+ * @return \Leafo\ScssPhp\Node\Number
+ */
+ public function coerce($units)
+ {
+ if ($this->unitless()) {
+ return new Number($this->dimension, $units);
+ }
+
+ $dimension = $this->dimension;
+
+ foreach (self::$unitTable['in'] as $unit => $conv) {
+ $from = isset($this->units[$unit]) ? $this->units[$unit] : 0;
+ $to = isset($units[$unit]) ? $units[$unit] : 0;
+ $factor = pow($conv, $from - $to);
+ $dimension /= $factor;
+ }
+
+ return new Number($dimension, $units);
+ }
+
+ /**
+ * Normalize number
+ *
+ * @return \Leafo\ScssPhp\Node\Number
+ */
+ public function normalize()
+ {
+ $dimension = $this->dimension;
+ $units = [];
+
+ $this->normalizeUnits($dimension, $units, 'in');
+
+ return new Number($dimension, $units);
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function offsetExists($offset)
+ {
+ if ($offset === -3) {
+ return $this->sourceColumn !== null;
+ }
+
+ if ($offset === -2) {
+ return $this->sourceLine !== null;
+ }
+
+ if ($offset === -1
+ || $offset === 0
+ || $offset === 1
+ || $offset === 2
+ ) {
+ return true;
+ }
+
+ return false;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function offsetGet($offset)
+ {
+ switch ($offset) {
+ case -3:
+ return $this->sourceColumn;
+
+ case -2:
+ return $this->sourceLine;
+
+ case -1:
+ return $this->sourceIndex;
+
+ case 0:
+ return $this->type;
+
+ case 1:
+ return $this->dimension;
+
+ case 2:
+ return $this->units;
+ }
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function offsetSet($offset, $value)
+ {
+ if ($offset === 1) {
+ $this->dimension = $value;
+ } elseif ($offset === 2) {
+ $this->units = $value;
+ } elseif ($offset == -1) {
+ $this->sourceIndex = $value;
+ } elseif ($offset == -2) {
+ $this->sourceLine = $value;
+ } elseif ($offset == -3) {
+ $this->sourceColumn = $value;
+ }
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function offsetUnset($offset)
+ {
+ if ($offset === 1) {
+ $this->dimension = null;
+ } elseif ($offset === 2) {
+ $this->units = null;
+ } elseif ($offset === -1) {
+ $this->sourceIndex = null;
+ } elseif ($offset === -2) {
+ $this->sourceLine = null;
+ } elseif ($offset === -3) {
+ $this->sourceColumn = null;
+ }
+ }
+
+ /**
+ * Returns true if the number is unitless
+ *
+ * @return boolean
+ */
+ public function unitless()
+ {
+ return ! array_sum($this->units);
+ }
+
+ /**
+ * Returns unit(s) as the product of numerator units divided by the product of denominator units
+ *
+ * @return string
+ */
+ public function unitStr()
+ {
+ $numerators = [];
+ $denominators = [];
+
+ foreach ($this->units as $unit => $unitSize) {
+ if ($unitSize > 0) {
+ $numerators = array_pad($numerators, count($numerators) + $unitSize, $unit);
+ continue;
+ }
+
+ if ($unitSize < 0) {
+ $denominators = array_pad($denominators, count($denominators) + $unitSize, $unit);
+ continue;
+ }
+ }
+
+ return implode('*', $numerators) . (count($denominators) ? '/' . implode('*', $denominators) : '');
+ }
+
+ /**
+ * Output number
+ *
+ * @param \Leafo\ScssPhp\Compiler $compiler
+ *
+ * @return string
+ */
+ public function output(Compiler $compiler = null)
+ {
+ $dimension = round($this->dimension, self::$precision);
+
+ $units = array_filter($this->units, function ($unitSize) {
+ return $unitSize;
+ });
+
+ if (count($units) > 1 && array_sum($units) === 0) {
+ $dimension = $this->dimension;
+ $units = [];
+
+ $this->normalizeUnits($dimension, $units, 'in');
+
+ $dimension = round($dimension, self::$precision);
+ $units = array_filter($units, function ($unitSize) {
+ return $unitSize;
+ });
+ }
+
+ $unitSize = array_sum($units);
+
+ if ($compiler && ($unitSize > 1 || $unitSize < 0 || count($units) > 1)) {
+ $compiler->throwError((string) $dimension . $this->unitStr() . " isn't a valid CSS value.");
+ }
+
+ reset($units);
+ list($unit, ) = each($units);
+
+ return (string) $dimension . $unit;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function __toString()
+ {
+ return $this->output();
+ }
+
+ /**
+ * Normalize units
+ *
+ * @param integer|float $dimension
+ * @param array $units
+ * @param string $baseUnit
+ */
+ private function normalizeUnits(&$dimension, &$units, $baseUnit = 'in')
+ {
+ $dimension = $this->dimension;
+ $units = [];
+
+ foreach ($this->units as $unit => $exp) {
+ if (isset(self::$unitTable[$baseUnit][$unit])) {
+ $factor = pow(self::$unitTable[$baseUnit][$unit], $exp);
+
+ $unit = $baseUnit;
+ $dimension /= $factor;
+ }
+
+ $units[$unit] = $exp + (isset($units[$unit]) ? $units[$unit] : 0);
+ }
+ }
+}
diff --git a/lib/scssphp/src/Parser.php b/lib/scssphp/src/Parser.php
index 5f0275b..3cdd2c7 100755
--- a/lib/scssphp/src/Parser.php
+++ b/lib/scssphp/src/Parser.php
@@ -2,90 +2,143 @@
/**
* SCSSPHP
*
- * @copyright 2012-2014 Leaf Corcoran
+ * @copyright 2012-2015 Leaf Corcoran
*
- * @license http://opensource.org/licenses/gpl-license GPL-3.0
* @license http://opensource.org/licenses/MIT MIT
*
- * @link http://leafo.net/scssphp
+ * @link http://leafo.github.io/scssphp
*/
namespace Leafo\ScssPhp;
+use Leafo\ScssPhp\Block;
use Leafo\ScssPhp\Compiler;
+use Leafo\ScssPhp\Exception\ParserException;
+use Leafo\ScssPhp\Node;
+use Leafo\ScssPhp\Type;
/**
- * SCSS parser
+ * Parser
*
* @author Leaf Corcoran
*/
class Parser
{
- protected static $precedence = array(
- 'or' => 0,
- 'and' => 1,
-
- '==' => 2,
- '!=' => 2,
- '<=' => 2,
- '>=' => 2,
- '=' => 2,
- '<' => 3,
- '>' => 2,
-
- '+' => 3,
- '-' => 3,
- '*' => 4,
- '/' => 4,
- '%' => 4,
- );
-
- protected static $operators = array('+', '-', '*', '/', '%',
- '==', '!=', '<=', '>=', '<', '>', 'and', 'or');
-
- protected static $operatorStr;
+ const SOURCE_INDEX = -1;
+ const SOURCE_LINE = -2;
+ const SOURCE_COLUMN = -3;
+
+ /**
+ * @var array
+ */
+ protected static $precedence = [
+ '=' => 0,
+ 'or' => 1,
+ 'and' => 2,
+ '==' => 3,
+ '!=' => 3,
+ '<=>' => 3,
+ '<=' => 4,
+ '>=' => 4,
+ '<' => 4,
+ '>' => 4,
+ '+' => 5,
+ '-' => 5,
+ '*' => 6,
+ '/' => 6,
+ '%' => 6,
+ ];
+
+ protected static $commentPattern;
+ protected static $operatorPattern;
protected static $whitePattern;
- protected static $commentMulti;
- protected static $commentSingle = '//';
- protected static $commentMultiLeft = '/*';
- protected static $commentMultiRight = '*/';
+ private $sourceName;
+ private $sourceIndex;
+ private $sourcePositions;
+ private $charset;
+ private $count;
+ private $env;
+ private $inParens;
+ private $eatWhiteDefault;
+ private $buffer;
+ private $utf8;
+ private $encoding;
+ private $patternModifiers;
/**
* Constructor
*
+ * @api
+ *
* @param string $sourceName
- * @param boolean $rootParser
+ * @param integer $sourceIndex
+ * @param string $encoding
*/
- public function __construct($sourceName = null, $rootParser = true)
+ public function __construct($sourceName, $sourceIndex = 0, $encoding = 'utf-8')
{
- $this->sourceName = $sourceName;
- $this->rootParser = $rootParser;
+ $this->sourceName = $sourceName ?: '(stdin)';
+ $this->sourceIndex = $sourceIndex;
+ $this->charset = null;
+ $this->utf8 = ! $encoding || strtolower($encoding) === 'utf-8';
+ $this->patternModifiers = $this->utf8 ? 'Aisu' : 'Ais';
- if (empty(self::$operatorStr)) {
- self::$operatorStr = $this->makeOperatorStr(self::$operators);
+ if (empty(self::$operatorPattern)) {
+ self::$operatorPattern = '([*\/%+-]|[!=]\=|\>\=?|\<\=\>|\<\=?|and|or)';
- $commentSingle = $this->pregQuote(self::$commentSingle);
- $commentMultiLeft = $this->pregQuote(self::$commentMultiLeft);
- $commentMultiRight = $this->pregQuote(self::$commentMultiRight);
- self::$commentMulti = $commentMultiLeft.'.*?'.$commentMultiRight;
- self::$whitePattern = '/'.$commentSingle.'[^\n]*\s*|('.self::$commentMulti.')\s*|\s+/Ais';
+ $commentSingle = '\/\/';
+ $commentMultiLeft = '\/\*';
+ $commentMultiRight = '\*\/';
+
+ self::$commentPattern = $commentMultiLeft . '.*?' . $commentMultiRight;
+ self::$whitePattern = $this->utf8
+ ? '/' . $commentSingle . '[^\n]*\s*|(' . self::$commentPattern . ')\s*|\s+/AisuS'
+ : '/' . $commentSingle . '[^\n]*\s*|(' . self::$commentPattern . ')\s*|\s+/AisS';
}
}
- protected static function makeOperatorStr($operators)
+ /**
+ * Get source file name
+ *
+ * @api
+ *
+ * @return string
+ */
+ public function getSourceName()
+ {
+ return $this->sourceName;
+ }
+
+ /**
+ * Throw parser error
+ *
+ * @api
+ *
+ * @param string $msg
+ *
+ * @throws \Leafo\ScssPhp\Exception\ParserException
+ */
+ public function throwParseError($msg = 'parse error')
{
- return '('
- . implode('|', array_map(array('Leafo\ScssPhp\Parser','pregQuote'), $operators))
- . ')';
+ list($line, /* $column */) = $this->getSourcePosition($this->count);
+
+ $loc = empty($this->sourceName) ? "line: $line" : "$this->sourceName on line $line";
+
+ if ($this->peek("(.*?)(\n|$)", $m, $this->count)) {
+ throw new ParserException("$msg: failed at `$m[1]` $loc");
+ }
+
+ throw new ParserException("$msg: $loc");
}
/**
* Parser buffer
*
- * @param string $buffer;
+ * @api
*
- * @return \StdClass
+ * @param string $buffer
+ *
+ * @return \Leafo\ScssPhp\Block
*/
public function parse($buffer)
{
@@ -93,31 +146,93 @@ public function parse($buffer)
$this->env = null;
$this->inParens = false;
$this->eatWhiteDefault = true;
- $this->buffer = $buffer;
+ $this->buffer = rtrim($buffer, "\x00..\x1f");
- $this->pushBlock(null); // root block
+ $this->saveEncoding();
+ $this->extractLineNumbers($buffer);
+ $this->pushBlock(null); // root block
$this->whitespace();
$this->pushBlock(null);
$this->popBlock();
- while (false !== $this->parseChunk()) {
+ while ($this->parseChunk()) {
;
}
- if ($this->count != strlen($this->buffer)) {
+ if ($this->count !== strlen($this->buffer)) {
$this->throwParseError();
}
- if (!empty($this->env->parent)) {
+ if (! empty($this->env->parent)) {
$this->throwParseError('unclosed block');
}
+ if ($this->charset) {
+ array_unshift($this->env->children, $this->charset);
+ }
+
$this->env->isRoot = true;
+ $this->restoreEncoding();
+
return $this->env;
}
+ /**
+ * Parse a value or value list
+ *
+ * @api
+ *
+ * @param string $buffer
+ * @param string $out
+ *
+ * @return boolean
+ */
+ public function parseValue($buffer, &$out)
+ {
+ $this->count = 0;
+ $this->env = null;
+ $this->inParens = false;
+ $this->eatWhiteDefault = true;
+ $this->buffer = (string) $buffer;
+
+ $this->saveEncoding();
+
+ $list = $this->valueList($out);
+
+ $this->restoreEncoding();
+
+ return $list;
+ }
+
+ /**
+ * Parse a selector or selector list
+ *
+ * @api
+ *
+ * @param string $buffer
+ * @param string $out
+ *
+ * @return boolean
+ */
+ public function parseSelector($buffer, &$out)
+ {
+ $this->count = 0;
+ $this->env = null;
+ $this->inParens = false;
+ $this->eatWhiteDefault = true;
+ $this->buffer = (string) $buffer;
+
+ $this->saveEncoding();
+
+ $selector = $this->selectors($out);
+
+ $this->restoreEncoding();
+
+ return $selector;
+ }
+
/**
* Parse a single chunk off the head of the buffer and append it to the
* current parse environment.
@@ -162,9 +277,23 @@ protected function parseChunk()
$s = $this->seek();
// the directives
- if (isset($this->buffer[$this->count]) && $this->buffer[$this->count] == '@') {
+ if (isset($this->buffer[$this->count]) && $this->buffer[$this->count] === '@') {
+ if ($this->literal('@at-root') &&
+ ($this->selectors($selector) || true) &&
+ ($this->map($with) || true) &&
+ $this->literal('{')
+ ) {
+ $atRoot = $this->pushSpecialBlock(Type::T_AT_ROOT, $s);
+ $atRoot->selector = $selector;
+ $atRoot->with = $with;
+
+ return true;
+ }
+
+ $this->seek($s);
+
if ($this->literal('@media') && $this->mediaQueryList($mediaQueryList) && $this->literal('{')) {
- $media = $this->pushSpecialBlock('media');
+ $media = $this->pushSpecialBlock(Type::T_MEDIA, $s);
$media->queryList = $mediaQueryList[2];
return true;
@@ -177,7 +306,7 @@ protected function parseChunk()
($this->argumentDef($args) || true) &&
$this->literal('{')
) {
- $mixin = $this->pushSpecialBlock('mixin');
+ $mixin = $this->pushSpecialBlock(Type::T_MIXIN, $s);
$mixin->name = $mixinName;
$mixin->args = $args;
@@ -194,11 +323,10 @@ protected function parseChunk()
($this->end() ||
$this->literal('{') && $hasBlock = true)
) {
- $child = array('include',
- $mixinName, isset($argValues) ? $argValues : null, null);
+ $child = [Type::T_INCLUDE, $mixinName, isset($argValues) ? $argValues : null, null];
- if (!empty($hasBlock)) {
- $include = $this->pushSpecialBlock('include');
+ if (! empty($hasBlock)) {
+ $include = $this->pushSpecialBlock(Type::T_INCLUDE, $s);
$include->child = $child;
} else {
$this->append($child, $s);
@@ -209,11 +337,33 @@ protected function parseChunk()
$this->seek($s);
+ if ($this->literal('@scssphp-import-once') &&
+ $this->valueList($importPath) &&
+ $this->end()
+ ) {
+ $this->append([Type::T_SCSSPHP_IMPORT_ONCE, $importPath], $s);
+
+ return true;
+ }
+
+ $this->seek($s);
+
if ($this->literal('@import') &&
$this->valueList($importPath) &&
$this->end()
) {
- $this->append(array('import', $importPath), $s);
+ $this->append([Type::T_IMPORT, $importPath], $s);
+
+ return true;
+ }
+
+ $this->seek($s);
+
+ if ($this->literal('@import') &&
+ $this->url($importPath) &&
+ $this->end()
+ ) {
+ $this->append([Type::T_IMPORT, $importPath], $s);
return true;
}
@@ -221,10 +371,12 @@ protected function parseChunk()
$this->seek($s);
if ($this->literal('@extend') &&
- $this->selectors($selector) &&
+ $this->selectors($selectors) &&
$this->end()
) {
- $this->append(array('extend', $selector), $s);
+ // check for '!flag'
+ $optional = $this->stripOptionalFlag($selectors);
+ $this->append([Type::T_EXTEND, $selectors, $optional], $s);
return true;
}
@@ -236,7 +388,7 @@ protected function parseChunk()
$this->argumentDef($args) &&
$this->literal('{')
) {
- $func = $this->pushSpecialBlock('function');
+ $func = $this->pushSpecialBlock(Type::T_FUNCTION, $s);
$func->name = $fnName;
$func->args = $args;
@@ -245,8 +397,25 @@ protected function parseChunk()
$this->seek($s);
- if ($this->literal('@return') && $this->valueList($retVal) && $this->end()) {
- $this->append(array('return', $retVal), $s);
+ if ($this->literal('@break') && $this->end()) {
+ $this->append([Type::T_BREAK], $s);
+
+ return true;
+ }
+
+ $this->seek($s);
+
+ if ($this->literal('@continue') && $this->end()) {
+ $this->append([Type::T_CONTINUE], $s);
+
+ return true;
+ }
+
+ $this->seek($s);
+
+
+ if ($this->literal('@return') && ($this->valueList($retVal) || true) && $this->end()) {
+ $this->append([Type::T_RETURN, isset($retVal) ? $retVal : [Type::T_NULL]], $s);
return true;
}
@@ -254,13 +423,17 @@ protected function parseChunk()
$this->seek($s);
if ($this->literal('@each') &&
- $this->variable($varName) &&
+ $this->genericList($varNames, 'variable', ',', false) &&
$this->literal('in') &&
$this->valueList($list) &&
$this->literal('{')
) {
- $each = $this->pushSpecialBlock('each');
- $each->var = $varName[1];
+ $each = $this->pushSpecialBlock(Type::T_EACH, $s);
+
+ foreach ($varNames[2] as $varName) {
+ $each->vars[] = $varName[1];
+ }
+
$each->list = $list;
return true;
@@ -272,7 +445,7 @@ protected function parseChunk()
$this->expression($cond) &&
$this->literal('{')
) {
- $while = $this->pushSpecialBlock('while');
+ $while = $this->pushSpecialBlock(Type::T_WHILE, $s);
$while->cond = $cond;
return true;
@@ -289,7 +462,7 @@ protected function parseChunk()
$this->expression($end) &&
$this->literal('{')
) {
- $for = $this->pushSpecialBlock('for');
+ $for = $this->pushSpecialBlock(Type::T_FOR, $s);
$for->var = $varName[1];
$for->start = $start;
$for->end = $end;
@@ -301,19 +474,42 @@ protected function parseChunk()
$this->seek($s);
if ($this->literal('@if') && $this->valueList($cond) && $this->literal('{')) {
- $if = $this->pushSpecialBlock('if');
+ $if = $this->pushSpecialBlock(Type::T_IF, $s);
$if->cond = $cond;
- $if->cases = array();
+ $if->cases = [];
+
+ return true;
+ }
+
+ $this->seek($s);
+
+ if ($this->literal('@debug') &&
+ $this->valueList($value) &&
+ $this->end()
+ ) {
+ $this->append([Type::T_DEBUG, $value], $s);
+
+ return true;
+ }
+
+ $this->seek($s);
+
+ if ($this->literal('@warn') &&
+ $this->valueList($value) &&
+ $this->end()
+ ) {
+ $this->append([Type::T_WARN, $value], $s);
return true;
}
$this->seek($s);
- if (($this->literal('@debug') || $this->literal('@warn')) &&
+ if ($this->literal('@error') &&
$this->valueList($value) &&
- $this->end()) {
- $this->append(array('debug', $value, $s), $s);
+ $this->end()
+ ) {
+ $this->append([Type::T_ERROR, $value], $s);
return true;
}
@@ -321,7 +517,7 @@ protected function parseChunk()
$this->seek($s);
if ($this->literal('@content') && $this->end()) {
- $this->append(array('mixin_content'), $s);
+ $this->append([Type::T_MIXIN_CONTENT], $s);
return true;
}
@@ -329,14 +525,15 @@ protected function parseChunk()
$this->seek($s);
$last = $this->last();
- if (isset($last) && $last[0] == 'if') {
+
+ if (isset($last) && $last[0] === Type::T_IF) {
list(, $if) = $last;
if ($this->literal('@else')) {
if ($this->literal('{')) {
- $else = $this->pushSpecialBlock('else');
+ $else = $this->pushSpecialBlock(Type::T_ELSE, $s);
} elseif ($this->literal('if') && $this->valueList($cond) && $this->literal('{')) {
- $else = $this->pushSpecialBlock('elseif');
+ $else = $this->pushSpecialBlock(Type::T_ELSEIF, $s);
$else->cond = $cond;
}
@@ -351,10 +548,22 @@ protected function parseChunk()
$this->seek($s);
}
+ // only retain the first @charset directive encountered
if ($this->literal('@charset') &&
- $this->valueList($charset) && $this->end()
+ $this->valueList($charset) &&
+ $this->end()
) {
- $this->append(array('charset', $charset), $s);
+ if (! isset($this->charset)) {
+ $statement = [Type::T_CHARSET, $charset];
+
+ list($line, $column) = $this->getSourcePosition($s);
+
+ $statement[self::SOURCE_LINE] = $line;
+ $statement[self::SOURCE_COLUMN] = $column;
+ $statement[self::SOURCE_INDEX] = $this->sourceIndex;
+
+ $this->charset = $statement;
+ }
return true;
}
@@ -362,12 +571,17 @@ protected function parseChunk()
$this->seek($s);
// doesn't match built in directive, do generic one
- if ($this->literal('@', false) && $this->keyword($dirName) &&
+ if ($this->literal('@', false) &&
+ $this->keyword($dirName) &&
($this->variable($dirValue) || $this->openString('{', $dirValue) || true) &&
$this->literal('{')
) {
- $directive = $this->pushSpecialBlock('directive');
- $directive->name = $dirName;
+ if ($dirName === 'media') {
+ $directive = $this->pushSpecialBlock(Type::T_MEDIA, $s);
+ } else {
+ $directive = $this->pushSpecialBlock(Type::T_DIRECTIVE, $s);
+ $directive->name = $dirName;
+ }
if (isset($dirValue)) {
$directive->value = $dirValue;
@@ -388,8 +602,8 @@ protected function parseChunk()
$this->valueList($value) &&
$this->end()
) {
- $name = array('string', '', array($name));
- $this->append(array('assign', $name, $value), $s);
+ $name = [Type::T_STRING, '', [$name]];
+ $this->append([Type::T_ASSIGN, $name, $value], $s);
return true;
}
@@ -399,11 +613,12 @@ protected function parseChunk()
// variable assigns
if ($this->variable($name) &&
$this->literal(':') &&
- $this->valueList($value) && $this->end()
+ $this->valueList($value) &&
+ $this->end()
) {
- // check for !default
- $defaultVar = $value[0] == 'list' && $this->stripDefault($value);
- $this->append(array('assign', $name, $value, $defaultVar), $s);
+ // check for '!flag'
+ $assignmentFlags = $this->stripAssignmentFlags($value);
+ $this->append([Type::T_ASSIGN, $name, $value, $assignmentFlags], $s);
return true;
}
@@ -417,7 +632,7 @@ protected function parseChunk()
// opening css block
if ($this->selectors($selectors) && $this->literal('{')) {
- $b = $this->pushBlock($selectors);
+ $this->pushBlock($selectors, $s);
return true;
}
@@ -427,13 +642,14 @@ protected function parseChunk()
// property assign, or nested assign
if ($this->propertyName($name) && $this->literal(':')) {
$foundSomething = false;
+
if ($this->valueList($value)) {
- $this->append(array('assign', $name, $value), $s);
+ $this->append([Type::T_ASSIGN, $name, $value], $s);
$foundSomething = true;
}
if ($this->literal('{')) {
- $propBlock = $this->pushSpecialBlock('nestedprop');
+ $propBlock = $this->pushSpecialBlock(Type::T_NESTED_PROPERTY, $s);
$propBlock->prefix = $name;
$foundSomething = true;
} elseif ($foundSomething) {
@@ -451,14 +667,14 @@ protected function parseChunk()
if ($this->literal('}')) {
$block = $this->popBlock();
- if (isset($block->type) && $block->type == 'include') {
+ if (isset($block->type) && $block->type === Type::T_INCLUDE) {
$include = $block->child;
unset($block->child);
$include[3] = $block;
$this->append($include, $s);
} elseif (empty($block->dontAppend)) {
- $type = isset($block->type) ? $block->type : 'block';
- $this->append(array($type, $block), $s);
+ $type = isset($block->type) ? $block->type : Type::T_BLOCK;
+ $this->append([$type, $block], $s);
}
return true;
@@ -474,66 +690,35 @@ protected function parseChunk()
return false;
}
- protected function stripDefault(&$value)
- {
- $def = end($value[2]);
-
- if ($def[0] == 'keyword' && $def[1] == '!default') {
- array_pop($value[2]);
- $value = $this->flattenList($value);
-
- return true;
- }
-
- if ($def[0] == 'list') {
- return $this->stripDefault($value[2][count($value[2]) - 1]);
- }
-
- return false;
- }
-
- protected function literal($what, $eatWhitespace = null)
- {
- if (!isset($eatWhitespace)) {
- $eatWhitespace = $this->eatWhiteDefault;
- }
-
- // shortcut on single letter
- if (!isset($what[1]) && isset($this->buffer[$this->count])) {
- if ($this->buffer[$this->count] == $what) {
- if (!$eatWhitespace) {
- $this->count++;
-
- return true;
- }
- // goes below...
- } else {
- return false;
- }
- }
-
- return $this->match($this->pregQuote($what), $m, $eatWhitespace);
- }
-
- // tree builders
-
- protected function pushBlock($selectors)
+ /**
+ * Push block onto parse tree
+ *
+ * @param array $selectors
+ * @param integer $pos
+ *
+ * @return \Leafo\ScssPhp\Block
+ */
+ protected function pushBlock($selectors, $pos = 0)
{
- $b = new \stdClass;
- $b->parent = $this->env; // not sure if we need this yet
-
- $b->selectors = $selectors;
- $b->comments = array();
-
- if (!$this->env) {
- $b->children = array();
+ list($line, $column) = $this->getSourcePosition($pos);
+
+ $b = new Block;
+ $b->sourceLine = $line;
+ $b->sourceColumn = $column;
+ $b->sourceIndex = $this->sourceIndex;
+ $b->selectors = $selectors;
+ $b->comments = [];
+ $b->parent = $this->env;
+
+ if (! $this->env) {
+ $b->children = [];
} elseif (empty($this->env->children)) {
$this->env->children = $this->env->comments;
- $b->children = array();
- $this->env->comments = array();
+ $b->children = [];
+ $this->env->comments = [];
} else {
$b->children = $this->env->comments;
- $this->env->comments = array();
+ $this->env->comments = [];
}
$this->env = $b;
@@ -541,14 +726,29 @@ protected function pushBlock($selectors)
return $b;
}
- protected function pushSpecialBlock($type)
+ /**
+ * Push special (named) block onto parse tree
+ *
+ * @param string $type
+ * @param integer $pos
+ *
+ * @return \Leafo\ScssPhp\Block
+ */
+ protected function pushSpecialBlock($type, $pos)
{
- $block = $this->pushBlock(null);
+ $block = $this->pushBlock(null, $pos);
$block->type = $type;
return $block;
}
+ /**
+ * Pop scope and return last block
+ *
+ * @return \Leafo\ScssPhp\Block
+ *
+ * @throws \Exception
+ */
protected function popBlock()
{
$block = $this->env;
@@ -569,81 +769,269 @@ protected function popBlock()
return $block;
}
- protected function appendComment($comment)
- {
- $comment[1] = substr(preg_replace(array('/^\s+/m', '/^(.)/m'), array('', ' \1'), $comment[1]), 1);
-
- $this->env->comments[] = $comment;
- }
-
- protected function append($statement, $pos = null)
+ /**
+ * Peek input stream
+ *
+ * @param string $regex
+ * @param array $out
+ * @param integer $from
+ *
+ * @return integer
+ */
+ protected function peek($regex, &$out, $from = null)
{
- if ($pos !== null) {
- $statement[-1] = $pos;
-
- if (!$this->rootParser) {
- $statement[-2] = $this;
- }
+ if (! isset($from)) {
+ $from = $this->count;
}
- $this->env->children[] = $statement;
+ $r = '/' . $regex . '/' . $this->patternModifiers;
+ $result = preg_match($r, $this->buffer, $out, null, $from);
- $comments = $this->env->comments;
- if (count($comments)) {
- $this->env->children = array_merge($this->env->children, $comments);
- $this->env->comments = array();
- }
+ return $result;
}
- // last child that was appended
- protected function last()
+ /**
+ * Seek to position in input stream (or return current position in input stream)
+ *
+ * @param integer $where
+ *
+ * @return integer
+ */
+ protected function seek($where = null)
{
- $i = count($this->env->children) - 1;
-
- if (isset($this->env->children[$i])) {
- return $this->env->children[$i];
+ if ($where === null) {
+ return $this->count;
}
- }
- // high level parsers (they return parts of ast)
+ $this->count = $where;
- protected function mediaQueryList(&$out)
- {
- return $this->genericList($out, 'mediaQuery', ',', false);
+ return true;
}
- protected function mediaQuery(&$out)
+ /**
+ * Match string looking for either ending delim, escape, or string interpolation
+ *
+ * {@internal This is a workaround for preg_match's 250K string match limit. }}
+ *
+ * @param array $m Matches (passed by reference)
+ * @param string $delim Delimeter
+ *
+ * @return boolean True if match; false otherwise
+ */
+ protected function matchString(&$m, $delim)
{
- $s = $this->seek();
-
- $expressions = null;
- $parts = array();
-
- if (($this->literal('only') && ($only = true) || $this->literal('not') && ($not = true) || true) &&
- $this->mixedKeyword($mediaType)
- ) {
- $prop = array('mediaType');
-
- if (isset($only)) {
- $prop[] = array('keyword', 'only');
- }
+ $token = null;
- if (isset($not)) {
- $prop[] = array('keyword', 'not');
- }
+ $end = strlen($this->buffer);
- $media = array('list', '', array());
+ // look for either ending delim, escape, or string interpolation
+ foreach (['#{', '\\', $delim] as $lookahead) {
+ $pos = strpos($this->buffer, $lookahead, $this->count);
- foreach ((array)$mediaType as $type) {
- if (is_array($type)) {
- $media[2][] = $type;
- } else {
- $media[2][] = array('keyword', $type);
- }
+ if ($pos !== false && $pos < $end) {
+ $end = $pos;
+ $token = $lookahead;
}
+ }
- $prop[] = $media;
- $parts[] = $prop;
+ if (! isset($token)) {
+ return false;
+ }
+
+ $match = substr($this->buffer, $this->count, $end - $this->count);
+ $m = [
+ $match . $token,
+ $match,
+ $token
+ ];
+ $this->count = $end + strlen($token);
+
+ return true;
+ }
+
+ /**
+ * Try to match something on head of buffer
+ *
+ * @param string $regex
+ * @param array $out
+ * @param boolean $eatWhitespace
+ *
+ * @return boolean
+ */
+ protected function match($regex, &$out, $eatWhitespace = null)
+ {
+ if (! isset($eatWhitespace)) {
+ $eatWhitespace = $this->eatWhiteDefault;
+ }
+
+ $r = '/' . $regex . '/' . $this->patternModifiers;
+
+ if (preg_match($r, $this->buffer, $out, null, $this->count)) {
+ $this->count += strlen($out[0]);
+
+ if ($eatWhitespace) {
+ $this->whitespace();
+ }
+
+ return true;
+ }
+
+ return false;
+ }
+
+ /**
+ * Match literal string
+ *
+ * @param string $what
+ * @param boolean $eatWhitespace
+ *
+ * @return boolean
+ */
+ protected function literal($what, $eatWhitespace = null)
+ {
+ if (! isset($eatWhitespace)) {
+ $eatWhitespace = $this->eatWhiteDefault;
+ }
+
+ $len = strlen($what);
+
+ if (strcasecmp(substr($this->buffer, $this->count, $len), $what) === 0) {
+ $this->count += $len;
+
+ if ($eatWhitespace) {
+ $this->whitespace();
+ }
+
+ return true;
+ }
+
+ return false;
+ }
+
+ /**
+ * Match some whitespace
+ *
+ * @return boolean
+ */
+ protected function whitespace()
+ {
+ $gotWhite = false;
+
+ while (preg_match(self::$whitePattern, $this->buffer, $m, null, $this->count)) {
+ if (isset($m[1]) && empty($this->commentsSeen[$this->count])) {
+ $this->appendComment([Type::T_COMMENT, $m[1]]);
+
+ $this->commentsSeen[$this->count] = true;
+ }
+
+ $this->count += strlen($m[0]);
+ $gotWhite = true;
+ }
+
+ return $gotWhite;
+ }
+
+ /**
+ * Append comment to current block
+ *
+ * @param array $comment
+ */
+ protected function appendComment($comment)
+ {
+ $comment[1] = substr(preg_replace(['/^\s+/m', '/^(.)/m'], ['', ' \1'], $comment[1]), 1);
+
+ $this->env->comments[] = $comment;
+ }
+
+ /**
+ * Append statement to current block
+ *
+ * @param array $statement
+ * @param integer $pos
+ */
+ protected function append($statement, $pos = null)
+ {
+ if ($pos !== null) {
+ list($line, $column) = $this->getSourcePosition($pos);
+
+ $statement[self::SOURCE_LINE] = $line;
+ $statement[self::SOURCE_COLUMN] = $column;
+ $statement[self::SOURCE_INDEX] = $this->sourceIndex;
+ }
+
+ $this->env->children[] = $statement;
+
+ $comments = $this->env->comments;
+
+ if (count($comments)) {
+ $this->env->children = array_merge($this->env->children, $comments);
+ $this->env->comments = [];
+ }
+ }
+
+ /**
+ * Returns last child was appended
+ *
+ * @return array|null
+ */
+ protected function last()
+ {
+ $i = count($this->env->children) - 1;
+
+ if (isset($this->env->children[$i])) {
+ return $this->env->children[$i];
+ }
+ }
+
+ /**
+ * Parse media query list
+ *
+ * @param array $out
+ *
+ * @return boolean
+ */
+ protected function mediaQueryList(&$out)
+ {
+ return $this->genericList($out, 'mediaQuery', ',', false);
+ }
+
+ /**
+ * Parse media query
+ *
+ * @param array $out
+ *
+ * @return boolean
+ */
+ protected function mediaQuery(&$out)
+ {
+ $expressions = null;
+ $parts = [];
+
+ if (($this->literal('only') && ($only = true) || $this->literal('not') && ($not = true) || true) &&
+ $this->mixedKeyword($mediaType)
+ ) {
+ $prop = [Type::T_MEDIA_TYPE];
+
+ if (isset($only)) {
+ $prop[] = [Type::T_KEYWORD, 'only'];
+ }
+
+ if (isset($not)) {
+ $prop[] = [Type::T_KEYWORD, 'not'];
+ }
+
+ $media = [Type::T_LIST, '', []];
+
+ foreach ((array) $mediaType as $type) {
+ if (is_array($type)) {
+ $media[2][] = $type;
+ } else {
+ $media[2][] = [Type::T_KEYWORD, $type];
+ }
+ }
+
+ $prop[] = $media;
+ $parts[] = $prop;
}
if (empty($parts) || $this->literal('and')) {
@@ -659,6 +1047,13 @@ protected function mediaQuery(&$out)
return true;
}
+ /**
+ * Parse media expression
+ *
+ * @param array $out
+ *
+ * @return boolean
+ */
protected function mediaExpression(&$out)
{
$s = $this->seek();
@@ -669,7 +1064,7 @@ protected function mediaExpression(&$out)
($this->literal(':') && $this->expression($value) || true) &&
$this->literal(')')
) {
- $out = array('mediaExp', $feature);
+ $out = [Type::T_MEDIA_EXPRESSION, $feature];
if ($value) {
$out[] = $value;
@@ -683,6 +1078,13 @@ protected function mediaExpression(&$out)
return false;
}
+ /**
+ * Parse argument values
+ *
+ * @param array $out
+ *
+ * @return boolean
+ */
protected function argValues(&$out)
{
if ($this->genericList($list, 'argValue', ',', false)) {
@@ -694,18 +1096,26 @@ protected function argValues(&$out)
return false;
}
+ /**
+ * Parse argument value
+ *
+ * @param array $out
+ *
+ * @return boolean
+ */
protected function argValue(&$out)
{
$s = $this->seek();
$keyword = null;
- if (!$this->variable($keyword) || !$this->literal(':')) {
+
+ if (! $this->variable($keyword) || ! $this->literal(':')) {
$this->seek($s);
$keyword = null;
}
if ($this->genericList($value, 'expression')) {
- $out = array($keyword, $value, false);
+ $out = [$keyword, $value, false];
$s = $this->seek();
if ($this->literal('...')) {
@@ -721,64 +1131,94 @@ protected function argValue(&$out)
}
/**
- * Parse list
+ * Parse comma separated value list
*
* @param string $out
*
* @return boolean
*/
- public function valueList(&$out)
+ protected function valueList(&$out)
{
return $this->genericList($out, 'spaceList', ',');
}
+ /**
+ * Parse space separated value list
+ *
+ * @param array $out
+ *
+ * @return boolean
+ */
protected function spaceList(&$out)
{
return $this->genericList($out, 'expression');
}
+ /**
+ * Parse generic list
+ *
+ * @param array $out
+ * @param callable $parseItem
+ * @param string $delim
+ * @param boolean $flatten
+ *
+ * @return boolean
+ */
protected function genericList(&$out, $parseItem, $delim = '', $flatten = true)
{
$s = $this->seek();
- $items = array();
+ $items = [];
while ($this->$parseItem($value)) {
$items[] = $value;
if ($delim) {
- if (!$this->literal($delim)) {
+ if (! $this->literal($delim)) {
break;
}
}
}
- if (count($items) == 0) {
+ if (count($items) === 0) {
$this->seek($s);
return false;
}
- if ($flatten && count($items) == 1) {
+ if ($flatten && count($items) === 1) {
$out = $items[0];
} else {
- $out = array('list', $delim, $items);
+ $out = [Type::T_LIST, $delim, $items];
}
return true;
}
+ /**
+ * Parse expression
+ *
+ * @param array $out
+ *
+ * @return boolean
+ */
protected function expression(&$out)
{
$s = $this->seek();
if ($this->literal('(')) {
if ($this->literal(')')) {
- $out = array('list', '', array());
+ $out = [Type::T_LIST, '', []];
+
+ return true;
+ }
+ if ($this->valueList($out) && $this->literal(')') && $out[0] === Type::T_LIST) {
return true;
}
- if ($this->valueList($out) && $this->literal(')') && $out[0] == 'list') {
+ $this->seek($s);
+
+ if ($this->map($out)) {
return true;
}
@@ -794,37 +1234,47 @@ protected function expression(&$out)
return false;
}
+ /**
+ * Parse left-hand side of subexpression
+ *
+ * @param array $lhs
+ * @param integer $minP
+ *
+ * @return array
+ */
protected function expHelper($lhs, $minP)
{
- $opstr = self::$operatorStr;
+ $operators = self::$operatorPattern;
$ss = $this->seek();
$whiteBefore = isset($this->buffer[$this->count - 1]) &&
ctype_space($this->buffer[$this->count - 1]);
- while ($this->match($opstr, $m) && self::$precedence[$m[1]] >= $minP) {
- $whiteAfter = isset($this->buffer[$this->count - 1]) &&
- ctype_space($this->buffer[$this->count - 1]);
+ while ($this->match($operators, $m, false) && self::$precedence[$m[1]] >= $minP) {
+ $whiteAfter = isset($this->buffer[$this->count]) &&
+ ctype_space($this->buffer[$this->count]);
+ $varAfter = isset($this->buffer[$this->count]) &&
+ $this->buffer[$this->count] === '$';
+
+ $this->whitespace();
$op = $m[1];
// don't turn negative numbers into expressions
- if ($op == '-' && $whiteBefore) {
- if (!$whiteAfter) {
- break;
- }
+ if ($op === '-' && $whiteBefore && ! $whiteAfter && ! $varAfter) {
+ break;
}
- if (!$this->value($rhs)) {
+ if (! $this->value($rhs)) {
break;
}
// peek and see if rhs belongs to next operator
- if ($this->peek($opstr, $next) && self::$precedence[$next[1]] > self::$precedence[$op]) {
+ if ($this->peek($operators, $next) && self::$precedence[$next[1]] > self::$precedence[$op]) {
$rhs = $this->expHelper($rhs, self::$precedence[$next[1]]);
}
- $lhs = array('exp', $op, $lhs, $rhs, $this->inParens, $whiteBefore, $whiteAfter);
+ $lhs = [Type::T_EXPRESSION, $op, $lhs, $rhs, $this->inParens, $whiteBefore, $whiteAfter];
$ss = $this->seek();
$whiteBefore = isset($this->buffer[$this->count - 1]) &&
ctype_space($this->buffer[$this->count - 1]);
@@ -835,12 +1285,27 @@ protected function expHelper($lhs, $minP)
return $lhs;
}
+ /**
+ * Parse value
+ *
+ * @param array $out
+ *
+ * @return boolean
+ */
protected function value(&$out)
{
$s = $this->seek();
if ($this->literal('not', false) && $this->whitespace() && $this->value($inner)) {
- $out = array('unary', 'not', $inner, $this->inParens);
+ $out = [Type::T_UNARY, 'not', $inner, $this->inParens];
+
+ return true;
+ }
+
+ $this->seek($s);
+
+ if ($this->literal('not', false) && $this->parenValue($inner)) {
+ $out = [Type::T_UNARY, 'not', $inner, $this->inParens];
return true;
}
@@ -848,7 +1313,7 @@ protected function value(&$out)
$this->seek($s);
if ($this->literal('+') && $this->value($inner)) {
- $out = array('unary', '+', $inner, $this->inParens);
+ $out = [Type::T_UNARY, '+', $inner, $this->inParens];
return true;
}
@@ -861,7 +1326,7 @@ protected function value(&$out)
$this->unit($inner) ||
$this->parenValue($inner))
) {
- $out = array('unary', '-', $inner, $this->inParens);
+ $out = [Type::T_UNARY, '-', $inner, $this->inParens];
return true;
}
@@ -881,10 +1346,10 @@ protected function value(&$out)
}
if ($this->keyword($keyword)) {
- if ($keyword == 'null') {
- $out = array('null');
+ if ($keyword === 'null') {
+ $out = [Type::T_NULL];
} else {
- $out = array('keyword', $keyword);
+ $out = [Type::T_KEYWORD, $keyword];
}
return true;
@@ -893,21 +1358,34 @@ protected function value(&$out)
return false;
}
- // value wrappen in parentheses
+ /**
+ * Parse parenthesized value
+ *
+ * @param array $out
+ *
+ * @return boolean
+ */
protected function parenValue(&$out)
{
$s = $this->seek();
$inParens = $this->inParens;
- if ($this->literal('(') &&
- ($this->inParens = true) && $this->expression($exp) &&
- $this->literal(')')
- ) {
- $out = $exp;
- $this->inParens = $inParens;
+ if ($this->literal('(')) {
+ if ($this->literal(')')) {
+ $out = [Type::T_LIST, '', []];
- return true;
+ return true;
+ }
+
+ $this->inParens = true;
+
+ if ($this->expression($exp) && $this->literal(')')) {
+ $out = $exp;
+ $this->inParens = $inParens;
+
+ return true;
+ }
}
$this->inParens = $inParens;
@@ -916,6 +1394,13 @@ protected function parenValue(&$out)
return false;
}
+ /**
+ * Parse "progid:"
+ *
+ * @param array $out
+ *
+ * @return boolean
+ */
protected function progid(&$out)
{
$s = $this->seek();
@@ -925,10 +1410,11 @@ protected function progid(&$out)
$this->literal('(')
) {
$this->openString(')', $args, '(');
+
if ($this->literal(')')) {
- $out = array('string', '', array(
+ $out = [Type::T_STRING, '', [
'progid:', $fn, '(', $args, ')'
- ));
+ ]];
return true;
}
@@ -939,6 +1425,13 @@ protected function progid(&$out)
return false;
}
+ /**
+ * Parse function call
+ *
+ * @param array $out
+ *
+ * @return boolean
+ */
protected function func(&$func)
{
$s = $this->seek();
@@ -946,17 +1439,17 @@ protected function func(&$func)
if ($this->keyword($name, false) &&
$this->literal('(')
) {
- if ($name == 'alpha' && $this->argumentList($args)) {
- $func = array('function', $name, array('string', '', $args));
+ if ($name === 'alpha' && $this->argumentList($args)) {
+ $func = [Type::T_FUNCTION, $name, [Type::T_STRING, '', $args]];
return true;
}
- if ($name != 'expression' && !preg_match('/^(-[a-z]+-)?calc$/', $name)) {
+ if ($name !== 'expression' && ! preg_match('/^(-[a-z]+-)?calc$/', $name)) {
$ss = $this->seek();
if ($this->argValues($args) && $this->literal(')')) {
- $func = array('fncall', $name, $args);
+ $func = [Type::T_FUNCTION_CALL, $name, $args];
return true;
}
@@ -964,16 +1457,16 @@ protected function func(&$func)
$this->seek($ss);
}
- if (($this->openString(')', $str, '(') || true ) &&
+ if (($this->openString(')', $str, '(') || true) &&
$this->literal(')')
) {
- $args = array();
+ $args = [];
- if (!empty($str)) {
- $args[] = array(null, array('string', '', array($str)));
+ if (! empty($str)) {
+ $args[] = [null, [Type::T_STRING, '', [$str]]];
}
- $func = array('fncall', $name, $args);
+ $func = [Type::T_FUNCTION_CALL, $name, $args];
return true;
}
@@ -984,18 +1477,23 @@ protected function func(&$func)
return false;
}
+ /**
+ * Parse function call argument list
+ *
+ * @param array $out
+ *
+ * @return boolean
+ */
protected function argumentList(&$out)
{
$s = $this->seek();
$this->literal('(');
- $args = array();
+ $args = [];
while ($this->keyword($var)) {
- $ss = $this->seek();
-
if ($this->literal('=') && $this->expression($exp)) {
- $args[] = array('string', '', array($var.'='));
+ $args[] = [Type::T_STRING, '', [$var . '=']];
$arg = $exp;
} else {
break;
@@ -1003,14 +1501,14 @@ protected function argumentList(&$out)
$args[] = $arg;
- if (!$this->literal(',')) {
+ if (! $this->literal(',')) {
break;
}
- $args[] = array('string', '', array(', '));
+ $args[] = [Type::T_STRING, '', [', ']];
}
- if (!$this->literal(')') || !count($args)) {
+ if (! $this->literal(')') || ! count($args)) {
$this->seek($s);
return false;
@@ -1021,15 +1519,22 @@ protected function argumentList(&$out)
return true;
}
+ /**
+ * Parse mixin/function definition argument list
+ *
+ * @param array $out
+ *
+ * @return boolean
+ */
protected function argumentDef(&$out)
{
$s = $this->seek();
$this->literal('(');
- $args = array();
+ $args = [];
while ($this->variable($var)) {
- $arg = array($var[1], null, false);
+ $arg = [$var[1], null, false];
$ss = $this->seek();
@@ -1044,7 +1549,7 @@ protected function argumentDef(&$out)
if ($this->literal('...')) {
$sss = $this->seek();
- if (!$this->literal(')')) {
+ if (! $this->literal(')')) {
$this->throwParseError('... has to be after the final argument');
}
@@ -1056,12 +1561,12 @@ protected function argumentDef(&$out)
$args[] = $arg;
- if (!$this->literal(',')) {
+ if (! $this->literal(',')) {
break;
}
}
- if (!$this->literal(')')) {
+ if (! $this->literal(')')) {
$this->seek($s);
return false;
@@ -1072,26 +1577,73 @@ protected function argumentDef(&$out)
return true;
}
- protected function color(&$out)
- {
- $color = array('color');
-
- if ($this->match('(#([0-9a-f]{6})|#([0-9a-f]{3}))', $m)) {
- if (isset($m[3])) {
- $num = $m[3];
- $width = 16;
- } else {
- $num = $m[2];
- $width = 256;
+ /**
+ * Parse map
+ *
+ * @param array $out
+ *
+ * @return boolean
+ */
+ protected function map(&$out)
+ {
+ $s = $this->seek();
+
+ if (! $this->literal('(')) {
+ return false;
+ }
+
+ $keys = [];
+ $values = [];
+
+ while ($this->genericList($key, 'expression') && $this->literal(':') &&
+ $this->genericList($value, 'expression')
+ ) {
+ $keys[] = $key;
+ $values[] = $value;
+
+ if (! $this->literal(',')) {
+ break;
}
+ }
+
+ if (! count($keys) || ! $this->literal(')')) {
+ $this->seek($s);
- $num = hexdec($num);
+ return false;
+ }
- foreach (array(3,2,1) as $i) {
- $t = $num % $width;
- $num /= $width;
+ $out = [Type::T_MAP, $keys, $values];
- $color[$i] = $t * (256/$width) + $t * floor(16/$width);
+ return true;
+ }
+
+ /**
+ * Parse color
+ *
+ * @param array $out
+ *
+ * @return boolean
+ */
+ protected function color(&$out)
+ {
+ $color = [Type::T_COLOR];
+
+ if ($this->match('(#([0-9a-f]{6})|#([0-9a-f]{3}))', $m)) {
+ if (isset($m[3])) {
+ $num = hexdec($m[3]);
+
+ foreach ([3, 2, 1] as $i) {
+ $t = $num & 0xf;
+ $color[$i] = $t << 4 | $t;
+ $num >>= 4;
+ }
+ } else {
+ $num = hexdec($m[2]);
+
+ foreach ([3, 2, 1] as $i) {
+ $color[$i] = $num & 0xff;
+ $num >>= 8;
+ }
}
$out = $color;
@@ -1102,10 +1654,17 @@ protected function color(&$out)
return false;
}
+ /**
+ * Parse number with unit
+ *
+ * @param array $out
+ *
+ * @return boolean
+ */
protected function unit(&$unit)
{
if ($this->match('([0-9]*(\.)?[0-9]+)([%a-zA-Z]+)?', $m)) {
- $unit = array('number', $m[1], empty($m[3]) ? '' : $m[3]);
+ $unit = new Node\Number($m[1], empty($m[3]) ? '' : $m[3]);
return true;
}
@@ -1113,39 +1672,52 @@ protected function unit(&$unit)
return false;
}
+ /**
+ * Parse string
+ *
+ * @param array $out
+ *
+ * @return boolean
+ */
protected function string(&$out)
{
$s = $this->seek();
if ($this->literal('"', false)) {
$delim = '"';
- } elseif ($this->literal('\'', false)) {
- $delim = '\'';
+ } elseif ($this->literal("'", false)) {
+ $delim = "'";
} else {
return false;
}
- $content = array();
+ $content = [];
$oldWhite = $this->eatWhiteDefault;
$this->eatWhiteDefault = false;
+ $hasInterpolation = false;
while ($this->matchString($m, $delim)) {
- $content[] = $m[1];
+ if ($m[1] !== '') {
+ $content[] = $m[1];
+ }
- if ($m[2] == '#{') {
+ if ($m[2] === '#{') {
$this->count -= strlen($m[2]);
if ($this->interpolation($inter, false)) {
$content[] = $inter;
+ $hasInterpolation = true;
} else {
$this->count += strlen($m[2]);
$content[] = '#{'; // ignore it
}
- } elseif ($m[2] == '\\') {
- $content[] = $m[2];
-
- if ($this->literal($delim, false)) {
- $content[] = $delim;
+ } elseif ($m[2] === '\\') {
+ if ($this->literal('"', false)) {
+ $content[] = $m[2] . '"';
+ } elseif ($this->literal("'", false)) {
+ $content[] = $m[2] . "'";
+ } else {
+ $content[] = $m[2];
}
} else {
$this->count -= strlen($delim);
@@ -1156,7 +1728,19 @@ protected function string(&$out)
$this->eatWhiteDefault = $oldWhite;
if ($this->literal($delim)) {
- $out = array('string', $delim, $content);
+ if ($hasInterpolation) {
+ $delim = '"';
+
+ foreach ($content as &$string) {
+ if ($string === "\\'") {
+ $string = "'";
+ } elseif ($string === '\\"') {
+ $string = '"';
+ }
+ }
+ }
+
+ $out = [Type::T_STRING, $delim, $content];
return true;
}
@@ -1166,16 +1750,21 @@ protected function string(&$out)
return false;
}
+ /**
+ * Parse keyword or interpolation
+ *
+ * @param array $out
+ *
+ * @return boolean
+ */
protected function mixedKeyword(&$out)
{
- $s = $this->seek();
-
- $parts = array();
+ $parts = [];
$oldWhite = $this->eatWhiteDefault;
$this->eatWhiteDefault = false;
- while (true) {
+ for (;;) {
if ($this->keyword($key)) {
$parts[] = $key;
continue;
@@ -1191,7 +1780,7 @@ protected function mixedKeyword(&$out)
$this->eatWhiteDefault = $oldWhite;
- if (count($parts) == 0) {
+ if (count($parts) === 0) {
return false;
}
@@ -1204,24 +1793,30 @@ protected function mixedKeyword(&$out)
return true;
}
- // an unbounded string stopped by $end
+ /**
+ * Parse an unbounded string stopped by $end
+ *
+ * @param string $end
+ * @param array $out
+ * @param string $nestingOpen
+ *
+ * @return boolean
+ */
protected function openString($end, &$out, $nestingOpen = null)
{
$oldWhite = $this->eatWhiteDefault;
$this->eatWhiteDefault = false;
- $stop = array('\'', '"', '#{', $end);
- $stop = array_map(array($this, 'pregQuote'), $stop);
- $stop[] = self::$commentMulti;
-
- $patt = '(.*?)('.implode('|', $stop).')';
+ $patt = '(.*?)([\'"]|#\{|' . $this->pregQuote($end) . '|' . self::$commentPattern . ')';
$nestingLevel = 0;
- $content = array();
+ $content = [];
+
while ($this->match($patt, $m, false)) {
if (isset($m[1]) && $m[1] !== '') {
$content[] = $m[1];
+
if ($nestingOpen) {
$nestingLevel += substr_count($m[1], $nestingOpen);
}
@@ -1230,20 +1825,17 @@ protected function openString($end, &$out, $nestingOpen = null)
$tok = $m[2];
$this->count-= strlen($tok);
- if ($tok == $end) {
- if ($nestingLevel == 0) {
- break;
- } else {
- $nestingLevel--;
- }
+
+ if ($tok === $end && ! $nestingLevel--) {
+ break;
}
- if (($tok == '\'' || $tok == '"') && $this->string($str)) {
+ if (($tok === "'" || $tok === '"') && $this->string($str)) {
$content[] = $str;
continue;
}
- if ($tok == '#{' && $this->interpolation($inter)) {
+ if ($tok === '#{' && $this->interpolation($inter)) {
$content[] = $inter;
continue;
}
@@ -1254,7 +1846,7 @@ protected function openString($end, &$out, $nestingOpen = null)
$this->eatWhiteDefault = $oldWhite;
- if (count($content) == 0) {
+ if (count($content) === 0) {
return false;
}
@@ -1263,22 +1855,27 @@ protected function openString($end, &$out, $nestingOpen = null)
$content[count($content) - 1] = rtrim(end($content));
}
- $out = array('string', '', $content);
+ $out = [Type::T_STRING, '', $content];
return true;
}
- // $lookWhite: save information about whitespace before and after
+ /**
+ * Parser interpolation
+ *
+ * @param array $out
+ * @param boolean $lookWhite save information about whitespace before and after
+ *
+ * @return boolean
+ */
protected function interpolation(&$out, $lookWhite = true)
{
$oldWhite = $this->eatWhiteDefault;
$this->eatWhiteDefault = true;
$s = $this->seek();
- if ($this->literal('#{') && $this->valueList($value) && $this->literal('}', false)) {
-
- // TODO: don't error if out of bounds
+ if ($this->literal('#{') && $this->valueList($value) && $this->literal('}', false)) {
if ($lookWhite) {
$left = preg_match('/\s/', $this->buffer[$s - 1]) ? ' ' : '';
$right = preg_match('/\s/', $this->buffer[$this->count]) ? ' ': '';
@@ -1286,45 +1883,59 @@ protected function interpolation(&$out, $lookWhite = true)
$left = $right = false;
}
- $out = array('interpolate', $value, $left, $right);
+ $out = [Type::T_INTERPOLATE, $value, $left, $right];
$this->eatWhiteDefault = $oldWhite;
+
if ($this->eatWhiteDefault) {
$this->whitespace();
}
+
return true;
}
$this->seek($s);
$this->eatWhiteDefault = $oldWhite;
+
return false;
}
- // low level parsers
-
- // returns an array of parts or a string
+ /**
+ * Parse property name (as an array of parts or a string)
+ *
+ * @param array $out
+ *
+ * @return boolean
+ */
protected function propertyName(&$out)
{
- $s = $this->seek();
- $parts = array();
+ $parts = [];
$oldWhite = $this->eatWhiteDefault;
$this->eatWhiteDefault = false;
- while (true) {
+ for (;;) {
if ($this->interpolation($inter)) {
$parts[] = $inter;
- } elseif ($this->keyword($text)) {
+ continue;
+ }
+
+ if ($this->keyword($text)) {
$parts[] = $text;
- } elseif (count($parts) == 0 && $this->match('[:.#]', $m, false)) {
+ continue;
+ }
+
+ if (count($parts) === 0 && $this->match('[:.#]', $m, false)) {
// css hacks
$parts[] = $m[0];
- } else {
- break;
+ continue;
}
+
+ break;
}
$this->eatWhiteDefault = $oldWhite;
- if (count($parts) == 0) {
+
+ if (count($parts) === 0) {
return false;
}
@@ -1336,7 +1947,7 @@ protected function propertyName(&$out)
null,
$this->count
)) {
- if (!empty($m[0])) {
+ if (! empty($m[0])) {
$parts[] = $m[0];
$this->count += strlen($m[0]);
}
@@ -1344,21 +1955,27 @@ protected function propertyName(&$out)
$this->whitespace(); // get any extra whitespace
- $out = array('string', '', $parts);
+ $out = [Type::T_STRING, '', $parts];
return true;
}
- // comma separated list of selectors
+ /**
+ * Parse comma separated selector list
+ *
+ * @param array $out
+ *
+ * @return boolean
+ */
protected function selectors(&$out)
{
$s = $this->seek();
- $selectors = array();
+ $selectors = [];
while ($this->selector($sel)) {
$selectors[] = $sel;
- if (!$this->literal(',')) {
+ if (! $this->literal(',')) {
break;
}
@@ -1367,7 +1984,7 @@ protected function selectors(&$out)
}
}
- if (count($selectors) == 0) {
+ if (count($selectors) === 0) {
$this->seek($s);
return false;
@@ -1378,26 +1995,38 @@ protected function selectors(&$out)
return true;
}
- // whitespace separated list of selectorSingle
+ /**
+ * Parse whitespace separated selector list
+ *
+ * @param array $out
+ *
+ * @return boolean
+ */
protected function selector(&$out)
{
- $selector = array();
+ $selector = [];
- while (true) {
+ for (;;) {
if ($this->match('[>+~]+', $m)) {
- $selector[] = array($m[0]);
- } elseif ($this->selectorSingle($part)) {
+ $selector[] = [$m[0]];
+ continue;
+ }
+
+ if ($this->selectorSingle($part)) {
$selector[] = $part;
$this->match('\s+', $m);
- } elseif ($this->match('\/[^\/]+\/', $m)) {
- $selector[] = array($m[0]);
- } else {
- break;
+ continue;
}
+ if ($this->match('\/[^\/]+\/', $m)) {
+ $selector[] = [$m[0]];
+ continue;
+ }
+
+ break;
}
- if (count($selector) == 0) {
+ if (count($selector) === 0) {
return false;
}
@@ -1405,20 +2034,29 @@ protected function selector(&$out)
return true;
}
- // the parts that make up
- // div[yes=no]#something.hello.world:nth-child(-2n+1)%placeholder
+ /**
+ * Parse the parts that make up a selector
+ *
+ * {@internal
+ * div[yes=no]#something.hello.world:nth-child(-2n+1)%placeholder
+ * }}
+ *
+ * @param array $out
+ *
+ * @return boolean
+ */
protected function selectorSingle(&$out)
{
$oldWhite = $this->eatWhiteDefault;
$this->eatWhiteDefault = false;
- $parts = array();
+ $parts = [];
if ($this->literal('*', false)) {
$parts[] = '*';
}
- while (true) {
+ for (;;) {
// see if we can stop early
if ($this->match('\s*[{,]', $m)) {
$this->count--;
@@ -1426,6 +2064,7 @@ protected function selectorSingle(&$out)
}
$s = $this->seek();
+
// self
if ($this->literal('&', false)) {
$parts[] = Compiler::$selfSelector;
@@ -1477,6 +2116,7 @@ protected function selectorSingle(&$out)
// a pseudo selector
if ($this->match('::?', $m) && $this->mixedKeyword($nameParts)) {
$parts[] = $m[0];
+
foreach ($nameParts as $sub) {
$parts[] = $sub;
}
@@ -1484,12 +2124,12 @@ protected function selectorSingle(&$out)
$ss = $this->seek();
if ($this->literal('(') &&
- ($this->openString(')', $str, '(') || true ) &&
+ ($this->openString(')', $str, '(') || true) &&
$this->literal(')')
) {
$parts[] = '(';
- if (!empty($str)) {
+ if (! empty($str)) {
$parts[] = $str;
}
@@ -1499,69 +2139,34 @@ protected function selectorSingle(&$out)
}
continue;
- } else {
- $this->seek($s);
}
- // attribute selector
- // TODO: replace with open string?
- if ($this->literal('[', false)) {
- $attrParts = array('[');
- // keyword, string, operator
- while (true) {
- if ($this->literal(']', false)) {
- $this->count--;
- break; // get out early
- }
-
- if ($this->match('\s+', $m)) {
- $attrParts[] = ' ';
- continue;
- }
- if ($this->string($str)) {
- $attrParts[] = $str;
- continue;
- }
-
- if ($this->keyword($word)) {
- $attrParts[] = $word;
- continue;
- }
-
- if ($this->interpolation($inter, false)) {
- $attrParts[] = $inter;
- continue;
- }
+ $this->seek($s);
- // operator, handles attr namespace too
- if ($this->match('[|-~\$\*\^=]+', $m)) {
- $attrParts[] = $m[0];
- continue;
- }
+ // attribute selector
+ if ($this->literal('[') &&
+ ($this->openString(']', $str, '[') || true) &&
+ $this->literal(']')
+ ) {
+ $parts[] = '[';
- break;
+ if (! empty($str)) {
+ $parts[] = $str;
}
- if ($this->literal(']', false)) {
- $attrParts[] = ']';
-
- foreach ($attrParts as $part) {
- $parts[] = $part;
- }
-
- continue;
- }
+ $parts[] = ']';
- $this->seek($s);
- // should just break here?
+ continue;
}
+ $this->seek($s);
+
break;
}
$this->eatWhiteDefault = $oldWhite;
- if (count($parts) == 0) {
+ if (count($parts) === 0) {
return false;
}
@@ -1570,12 +2175,19 @@ protected function selectorSingle(&$out)
return true;
}
+ /**
+ * Parse a variable
+ *
+ * @param array $out
+ *
+ * @return boolean
+ */
protected function variable(&$out)
{
$s = $this->seek();
if ($this->literal('$', false) && $this->keyword($name)) {
- $out = array('var', $name);
+ $out = [Type::T_VARIABLE, $name];
return true;
}
@@ -1585,10 +2197,20 @@ protected function variable(&$out)
return false;
}
+ /**
+ * Parse a keyword
+ *
+ * @param string $word
+ * @param boolean $eatWhitespace
+ *
+ * @return boolean
+ */
protected function keyword(&$word, $eatWhitespace = null)
{
if ($this->match(
- '(([\w_\-\*!"\']|[\\\\].)([\w\-_"\']|[\\\\].)*)',
+ $this->utf8
+ ? '(([\pL\w_\-\*!"\']|[\\\\].)([\pL\w\-_"\']|[\\\\].)*)'
+ : '(([\w_\-\*!"\']|[\\\\].)([\w\-_"\']|[\\\\].)*)',
$m,
$eatWhitespace
)) {
@@ -1600,9 +2222,21 @@ protected function keyword(&$word, $eatWhitespace = null)
return false;
}
+ /**
+ * Parse a placeholder
+ *
+ * @param string $placeholder
+ *
+ * @return boolean
+ */
protected function placeholder(&$placeholder)
{
- if ($this->match('([\w\-_]+)', $m)) {
+ if ($this->match(
+ $this->utf8
+ ? '([\pL\w\-_]+|#[{][$][\pL\w\-_]+[}])'
+ : '([\w\-_]+|#[{][$][\w\-_]+[}])',
+ $m
+ )) {
$placeholder = $m[1];
return true;
@@ -1611,14 +2245,36 @@ protected function placeholder(&$placeholder)
return false;
}
- // consume an end of statement delimiter
+ /**
+ * Parse a url
+ *
+ * @param array $out
+ *
+ * @return boolean
+ */
+ protected function url(&$out)
+ {
+ if ($this->match('(url\(\s*(["\']?)([^)]+)\2\s*\))', $m)) {
+ $out = [Type::T_STRING, '', ['url(' . $m[2] . $m[3] . $m[2] . ')']];
+
+ return true;
+ }
+
+ return false;
+ }
+
+ /**
+ * Consume an end of statement delimiter
+ *
+ * @return boolean
+ */
protected function end()
{
if ($this->literal(';')) {
return true;
}
- if ($this->count == strlen($this->buffer) || $this->buffer[$this->count] == '}') {
+ if ($this->count === strlen($this->buffer) || $this->buffer[$this->count] === '}') {
// if there is end of file or a closing block next then we don't need a ;
return true;
}
@@ -1626,186 +2282,201 @@ protected function end()
return false;
}
- // advance counter to next occurrence of $what
- // $until - don't include $what in advance
- // $allowNewline, if string, will be used as valid char set
- protected function to($what, &$out, $until = false, $allowNewline = false)
+ /**
+ * Strip assignment flag from the list
+ *
+ * @param array $value
+ *
+ * @return array
+ */
+ protected function stripAssignmentFlags(&$value)
{
- if (is_string($allowNewline)) {
- $validChars = $allowNewline;
- } else {
- $validChars = $allowNewline ? '.' : "[^\n]";
- }
+ $flags = [];
- if (!$this->match('('.$validChars.'*?)'.$this->pregQuote($what), $m, !$until)) {
- return false;
- }
+ for ($token = &$value; $token[0] === Type::T_LIST && ($s = count($token[2])); $token = &$lastNode) {
+ $lastNode = &$token[2][$s - 1];
- if ($until) {
- $this->count -= strlen($what); // give back $what
- }
+ while ($lastNode[0] === Type::T_KEYWORD && in_array($lastNode[1], ['!default', '!global'])) {
+ array_pop($token[2]);
- $out = $m[1];
+ $node = end($token[2]);
- return true;
+ $token = $this->flattenList($token);
+
+ $flags[] = $lastNode[1];
+
+ $lastNode = $node;
+ }
+ }
+
+ return $flags;
}
- public function throwParseError($msg = 'parse error', $count = null)
+ /**
+ * Strip optional flag from selector list
+ *
+ * @param array $selectors
+ *
+ * @return string
+ */
+ protected function stripOptionalFlag(&$selectors)
{
- $count = !isset($count) ? $this->count : $count;
+ $optional = false;
- $line = $this->getLineNo($count);
+ $selector = end($selectors);
+ $part = end($selector);
- if (!empty($this->sourceName)) {
- $loc = "$this->sourceName on line $line";
- } else {
- $loc = "line: $line";
- }
+ if ($part === ['!optional']) {
+ array_pop($selectors[count($selectors) - 1]);
- if ($this->peek("(.*?)(\n|$)", $m, $count)) {
- throw new \Exception("$msg: failed at `$m[1]` $loc");
+ $optional = true;
}
- throw new \Exception("$msg: $loc");
- }
-
- public function getLineNo($pos)
- {
- return 1 + substr_count(substr($this->buffer, 0, $pos), "\n");
+ return $optional;
}
/**
- * Match string looking for either ending delim, escape, or string interpolation
+ * Turn list of length 1 into value type
*
- * {@internal This is a workaround for preg_match's 250K string match limit. }}
- *
- * @param array $m Matches (passed by reference)
- * @param string $delim Delimeter
+ * @param array $value
*
- * @return boolean True if match; false otherwise
+ * @return array
*/
- protected function matchString(&$m, $delim)
+ protected function flattenList($value)
{
- $token = null;
-
- $end = strpos($this->buffer, "\n", $this->count);
-
- if ($end === false ||
- $this->buffer[$end - 1] == '\\' ||
- $this->buffer[$end - 2] == '\\' && $this->buffer[$end - 1] == "\r"
- ) {
- $end = strlen($this->buffer);
+ if ($value[0] === Type::T_LIST && count($value[2]) === 1) {
+ return $this->flattenList($value[2][0]);
}
- // look for either ending delim, escape, or string interpolation
- foreach (array('#{', '\\', $delim) as $lookahead) {
- $pos = strpos($this->buffer, $lookahead, $this->count);
+ return $value;
+ }
- if ($pos !== false && $pos < $end) {
- $end = $pos;
- $token = $lookahead;
- }
+ /**
+ * @deprecated
+ *
+ * {@internal
+ * advance counter to next occurrence of $what
+ * $until - don't include $what in advance
+ * $allowNewline, if string, will be used as valid char set
+ * }}
+ */
+ protected function to($what, &$out, $until = false, $allowNewline = false)
+ {
+ if (is_string($allowNewline)) {
+ $validChars = $allowNewline;
+ } else {
+ $validChars = $allowNewline ? '.' : "[^\n]";
}
- if (!isset($token)) {
+ if (! $this->match('(' . $validChars . '*?)' . $this->pregQuote($what), $m, ! $until)) {
return false;
}
- $match = substr($this->buffer, $this->count, $end - $this->count);
- $m = array(
- $match . $token,
- $match,
- $token
- );
- $this->count = $end + strlen($token);
+ if ($until) {
+ $this->count -= strlen($what); // give back $what
+ }
+
+ $out = $m[1];
return true;
}
- // try to match something on head of buffer
- protected function match($regex, &$out, $eatWhitespace = null)
+ /**
+ * @deprecated
+ */
+ protected function show()
{
- if (!isset($eatWhitespace)) {
- $eatWhitespace = $this->eatWhiteDefault;
- }
-
- $r = '/'.$regex.'/Ais';
-
- if (preg_match($r, $this->buffer, $out, null, $this->count)) {
- $this->count += strlen($out[0]);
-
- if ($eatWhitespace) {
- $this->whitespace();
- }
-
- return true;
+ if ($this->peek("(.*?)(\n|$)", $m, $this->count)) {
+ return $m[1];
}
- return false;
+ return '';
}
- // match some whitespace
- protected function whitespace()
+ /**
+ * Quote regular expression
+ *
+ * @param string $what
+ *
+ * @return string
+ */
+ private function pregQuote($what)
{
- $gotWhite = false;
+ return preg_quote($what, '/');
+ }
- while (preg_match(self::$whitePattern, $this->buffer, $m, null, $this->count)) {
- if (isset($m[1]) && empty($this->commentsSeen[$this->count])) {
- $this->appendComment(array('comment', $m[1]));
- $this->commentsSeen[$this->count] = true;
- }
+ /**
+ * Extract line numbers from buffer
+ *
+ * @param string $buffer
+ */
+ private function extractLineNumbers($buffer)
+ {
+ $this->sourcePositions = [0 => 0];
+ $prev = 0;
- $this->count += strlen($m[0]);
- $gotWhite = true;
+ while (($pos = strpos($buffer, "\n", $prev)) !== false) {
+ $this->sourcePositions[] = $pos;
+ $prev = $pos + 1;
}
- return $gotWhite;
+ $this->sourcePositions[] = strlen($buffer);
+
+ if (substr($buffer, -1) !== "\n") {
+ $this->sourcePositions[] = strlen($buffer) + 1;
+ }
}
- protected function peek($regex, &$out, $from = null)
+ /**
+ * Get source line number and column (given character position in the buffer)
+ *
+ * @param integer $pos
+ *
+ * @return integer
+ */
+ private function getSourcePosition($pos)
{
- if (!isset($from)) {
- $from = $this->count;
- }
+ $low = 0;
+ $high = count($this->sourcePositions);
- $r = '/'.$regex.'/Ais';
- $result = preg_match($r, $this->buffer, $out, null, $from);
+ while ($low < $high) {
+ $mid = (int) (($high + $low) / 2);
- return $result;
- }
+ if ($pos < $this->sourcePositions[$mid]) {
+ $high = $mid - 1;
+ continue;
+ }
- protected function seek($where = null)
- {
- if ($where === null) {
- return $this->count;
- }
+ if ($pos >= $this->sourcePositions[$mid + 1]) {
+ $low = $mid + 1;
+ continue;
+ }
- $this->count = $where;
+ return [$mid + 1, $pos - $this->sourcePositions[$mid]];
+ }
- return true;
+ return [$low + 1, $pos - $this->sourcePositions[$low]];
}
- public static function pregQuote($what)
+ /**
+ * Save internal encoding
+ */
+ private function saveEncoding()
{
- return preg_quote($what, '/');
- }
+ if (ini_get('mbstring.func_overload') & 2) {
+ $this->encoding = mb_internal_encoding();
- protected function show()
- {
- if ($this->peek("(.*?)(\n|$)", $m, $this->count)) {
- return $m[1];
+ mb_internal_encoding('iso-8859-1');
}
-
- return '';
}
- // turn list of length 1 into value type
- protected function flattenList($value)
+ /**
+ * Restore internal encoding
+ */
+ private function restoreEncoding()
{
- if ($value[0] == 'list' && count($value[2]) == 1) {
- return $this->flattenList($value[2][0]);
+ if ($this->encoding) {
+ mb_internal_encoding($this->encoding);
}
-
- return $value;
}
}
diff --git a/lib/scssphp/src/Server.php b/lib/scssphp/src/Server.php
index 81d1e38..221655c 100755
--- a/lib/scssphp/src/Server.php
+++ b/lib/scssphp/src/Server.php
@@ -2,25 +2,46 @@
/**
* SCSSPHP
*
- * @copyright 2012-2014 Leaf Corcoran
+ * @copyright 2012-2015 Leaf Corcoran
*
- * @license http://opensource.org/licenses/gpl-license GPL-3.0
* @license http://opensource.org/licenses/MIT MIT
*
- * @link http://leafo.net/scssphp
+ * @link http://leafo.github.io/scssphp
*/
namespace Leafo\ScssPhp;
use Leafo\ScssPhp\Compiler;
+use Leafo\ScssPhp\Exception\ServerException;
+use Leafo\ScssPhp\Version;
/**
- * SCSS server
+ * Server
*
* @author Leaf Corcoran
*/
class Server
{
+ /**
+ * @var boolean
+ */
+ private $showErrorsAsCSS;
+
+ /**
+ * @var string
+ */
+ private $dir;
+
+ /**
+ * @var string
+ */
+ private $cacheDir;
+
+ /**
+ * @var \Leafo\ScssPhp\Compiler
+ */
+ private $scss;
+
/**
* Join path components
*
@@ -95,13 +116,12 @@ protected function metadataName($out)
/**
* Determine whether .scss file needs to be re-compiled.
*
- * @param string $in Input path
* @param string $out Output path
* @param string $etag ETag
*
* @return boolean True if compile required.
*/
- protected function needsCompile($in, $out, &$etag)
+ protected function needsCompile($out, &$etag)
{
if (! is_file($out)) {
return true;
@@ -109,25 +129,25 @@ protected function needsCompile($in, $out, &$etag)
$mtime = filemtime($out);
- if (filemtime($in) > $mtime) {
- return true;
- }
-
$metadataName = $this->metadataName($out);
if (is_readable($metadataName)) {
$metadata = unserialize(file_get_contents($metadataName));
- if ($metadata['etag'] === $etag) {
- return false;
- }
+ foreach ($metadata['imports'] as $import => $originalMtime) {
+ $currentMtime = filemtime($import);
- foreach ($metadata['imports'] as $import) {
- if (filemtime($import) > $mtime) {
+ if ($currentMtime !== $originalMtime || $currentMtime > $mtime) {
return true;
}
}
+ $metaVars = crc32(serialize($this->scss->getVariables()));
+
+ if ($metaVars !== $metadata['vars']) {
+ return true;
+ }
+
$etag = $metadata['etag'];
return false;
@@ -186,21 +206,108 @@ protected function compile($in, $out)
$css = $this->scss->compile(file_get_contents($in), $in);
$elapsed = round((microtime(true) - $start), 4);
- $v = Compiler::$VERSION;
- $t = @date('r');
+ $v = Version::VERSION;
+ $t = date('r');
$css = "/* compiled by scssphp $v on $t (${elapsed}s) */\n\n" . $css;
$etag = md5($css);
file_put_contents($out, $css);
file_put_contents(
$this->metadataName($out),
- serialize(array(
+ serialize([
'etag' => $etag,
'imports' => $this->scss->getParsedFiles(),
- ))
+ 'vars' => crc32(serialize($this->scss->getVariables())),
+ ])
+ );
+
+ return [$css, $etag];
+ }
+
+ /**
+ * Format error as a pseudo-element in CSS
+ *
+ * @param \Exception $error
+ *
+ * @return string
+ */
+ protected function createErrorCSS(\Exception $error)
+ {
+ $message = str_replace(
+ ["'", "\n"],
+ ["\\'", "\\A"],
+ $error->getfile() . ":\n\n" . $error->getMessage()
);
- return array($css, $etag);
+ return "body { display: none !important; }
+ html:after {
+ background: white;
+ color: black;
+ content: '$message';
+ display: block !important;
+ font-family: mono;
+ padding: 1em;
+ white-space: pre;
+ }";
+ }
+
+ /**
+ * Render errors as a pseudo-element within valid CSS, displaying the errors on any
+ * page that includes this CSS.
+ *
+ * @param boolean $show
+ */
+ public function showErrorsAsCSS($show = true)
+ {
+ $this->showErrorsAsCSS = $show;
+ }
+
+ /**
+ * Compile .scss file
+ *
+ * @param string $in Input file (.scss)
+ * @param string $out Output file (.css) optional
+ *
+ * @return string|bool
+ *
+ * @throws \Leafo\ScssPhp\Exception\ServerException
+ */
+ public function compileFile($in, $out = null)
+ {
+ if (! is_readable($in)) {
+ throw new ServerException('load error: failed to find ' . $in);
+ }
+
+ $pi = pathinfo($in);
+
+ $this->scss->addImportPath($pi['dirname'] . '/');
+
+ $compiled = $this->scss->compile(file_get_contents($in), $in);
+
+ if ($out !== null) {
+ return file_put_contents($out, $compiled);
+ }
+
+ return $compiled;
+ }
+
+ /**
+ * Check if file need compiling
+ *
+ * @param string $in Input file (.scss)
+ * @param string $out Output file (.css)
+ *
+ * @return bool
+ */
+ public function checkedCompile($in, $out)
+ {
+ if (! is_file($out) || filemtime($in) > filemtime($out)) {
+ $this->compileFile($in, $out);
+
+ return true;
+ }
+
+ return false;
}
/**
@@ -218,7 +325,7 @@ public function serve($salt = '')
$output = $this->cacheName($salt . $input);
$etag = $noneMatch = trim($this->getIfNoneMatchHeader(), '"');
- if ($this->needsCompile($input, $output, $etag)) {
+ if ($this->needsCompile($output, $etag)) {
try {
list($css, $etag) = $this->compile($input, $output);
@@ -229,14 +336,20 @@ public function serve($salt = '')
header('ETag: "' . $etag . '"');
echo $css;
-
- return;
} catch (\Exception $e) {
- header($protocol . ' 500 Internal Server Error');
- header('Content-type: text/plain');
+ if ($this->showErrorsAsCSS) {
+ header('Content-type: text/css');
+
+ echo $this->createErrorCSS($e);
+ } else {
+ header($protocol . ' 500 Internal Server Error');
+ header('Content-type: text/plain');
- echo 'Parse error: ' . $e->getMessage() . "\n";
+ echo 'Parse error: ' . $e->getMessage() . "\n";
+ }
}
+
+ return;
}
header('X-SCSS-Cache: true');
@@ -252,7 +365,7 @@ public function serve($salt = '')
$modifiedSince = $this->getIfModifiedSinceHeader();
$mtime = filemtime($output);
- if (@strtotime($modifiedSince) === $mtime) {
+ if (strtotime($modifiedSince) === $mtime) {
header($protocol . ' 304 Not Modified');
return;
@@ -269,10 +382,40 @@ public function serve($salt = '')
header($protocol . ' 404 Not Found');
header('Content-type: text/plain');
- $v = Compiler::$VERSION;
+ $v = Version::VERSION;
echo "/* INPUT NOT FOUND scss $v */\n";
}
+ /**
+ * Based on explicit input/output files does a full change check on cache before compiling.
+ *
+ * @param string $in
+ * @param string $out
+ * @param boolean $force
+ *
+ * @return string Compiled CSS results
+ *
+ * @throws \Leafo\ScssPhp\Exception\ServerException
+ */
+ public function checkedCachedCompile($in, $out, $force = false)
+ {
+ if (! is_file($in) || ! is_readable($in)) {
+ throw new ServerException('Invalid or unreadable input file specified.');
+ }
+
+ if (is_dir($out) || ! is_writable(file_exists($out) ? $out : dirname($out))) {
+ throw new ServerException('Invalid or unwritable output file specified.');
+ }
+
+ if ($force || $this->needsCompile($out, $etag)) {
+ list($css, $etag) = $this->compile($in, $out);
+ } else {
+ $css = file_get_contents($out);
+ }
+
+ return $css;
+ }
+
/**
* Constructor
*
@@ -284,22 +427,27 @@ public function __construct($dir, $cacheDir = null, $scss = null)
{
$this->dir = $dir;
- if (!isset($cacheDir)) {
+ if (! isset($cacheDir)) {
$cacheDir = $this->join($dir, 'scss_cache');
}
$this->cacheDir = $cacheDir;
- if (!is_dir($this->cacheDir)) {
+ if (! is_dir($this->cacheDir)) {
mkdir($this->cacheDir, 0755, true);
}
- if (!isset($scss)) {
+ if (! isset($scss)) {
$scss = new Compiler();
$scss->setImportPaths($this->dir);
}
$this->scss = $scss;
+ $this->showErrorsAsCSS = false;
+
+ if (! ini_get('date.timezone')) {
+ date_default_timezone_set('UTC');
+ }
}
/**
diff --git a/lib/scssphp/src/Type.php b/lib/scssphp/src/Type.php
new file mode 100755
index 0000000..8c3886c
--- /dev/null
+++ b/lib/scssphp/src/Type.php
@@ -0,0 +1,69 @@
+
+ */
+class Type
+{
+ const T_ASSIGN = 'assign';
+ const T_AT_ROOT = 'at-root';
+ const T_BLOCK = 'block';
+ const T_BREAK = 'break';
+ const T_CHARSET = 'charset';
+ const T_COLOR = 'color';
+ const T_COMMENT = 'comment';
+ const T_CONTINUE = 'continue';
+ const T_CONTROL = 'control';
+ const T_DEBUG = 'debug';
+ const T_DIRECTIVE = 'directive';
+ const T_EACH = 'each';
+ const T_ELSE = 'else';
+ const T_ELSEIF = 'elseif';
+ const T_ERROR = 'error';
+ const T_EXPRESSION = 'exp';
+ const T_EXTEND = 'extend';
+ const T_FOR = 'for';
+ const T_FUNCTION = 'function';
+ const T_FUNCTION_CALL = 'fncall';
+ const T_HSL = 'hsl';
+ const T_IF = 'if';
+ const T_IMPORT = 'import';
+ const T_INCLUDE = 'include';
+ const T_INTERPOLATE = 'interpolate';
+ const T_INTERPOLATED = 'interpolated';
+ const T_KEYWORD = 'keyword';
+ const T_LIST = 'list';
+ const T_MAP = 'map';
+ const T_MEDIA = 'media';
+ const T_MEDIA_EXPRESSION = 'mediaExp';
+ const T_MEDIA_TYPE = 'mediaType';
+ const T_MEDIA_VALUE = 'mediaValue';
+ const T_MIXIN = 'mixin';
+ const T_MIXIN_CONTENT = 'mixin_content';
+ const T_NESTED_PROPERTY = 'nestedprop';
+ const T_NOT = 'not';
+ const T_NULL = 'null';
+ const T_NUMBER = 'number';
+ const T_RETURN = 'return';
+ const T_ROOT = 'root';
+ const T_SCSSPHP_IMPORT_ONCE = 'scssphp-import-once';
+ const T_SELF = 'self';
+ const T_STRING = 'string';
+ const T_UNARY = 'unary';
+ const T_VARIABLE = 'var';
+ const T_WARN = 'warn';
+ const T_WHILE = 'while';
+}
diff --git a/lib/scssphp/src/Util.php b/lib/scssphp/src/Util.php
new file mode 100755
index 0000000..9f47c1d
--- /dev/null
+++ b/lib/scssphp/src/Util.php
@@ -0,0 +1,55 @@
+
+ */
+class Util
+{
+ /**
+ * Asserts that `value` falls within `range` (inclusive), leaving
+ * room for slight floating-point errors.
+ *
+ * @param string $name The name of the value. Used in the error message.
+ * @param Range $range Range of values.
+ * @param array $value The value to check.
+ * @param string $unit The unit of the value. Used in error reporting.
+ *
+ * @return mixed `value` adjusted to fall within range, if it was outside by a floating-point margin.
+ *
+ * @throws \Exception
+ */
+ public static function checkRange($name, Range $range, $value, $unit = '')
+ {
+ $val = $value[1];
+ $grace = new Range(-0.00001, 0.00001);
+
+ if ($range->includes($val)) {
+ return $val;
+ }
+
+ if ($grace->includes($val - $range->first)) {
+ return $range->first;
+ }
+
+ if ($grace->includes($val - $range->last)) {
+ return $range->last;
+ }
+
+ throw new \Exception("$name {$val} must be between {$range->first} and {$range->last}$unit");
+ }
+}
diff --git a/lib/scssphp/src/Version.php b/lib/scssphp/src/Version.php
new file mode 100755
index 0000000..8dfa0e9
--- /dev/null
+++ b/lib/scssphp/src/Version.php
@@ -0,0 +1,22 @@
+
+ */
+class Version
+{
+ const VERSION = 'v0.6.3';
+}
diff --git a/lib/scssphp/tests/ApiTest.php b/lib/scssphp/tests/ApiTest.php
deleted file mode 100755
index 3099963..0000000
--- a/lib/scssphp/tests/ApiTest.php
+++ /dev/null
@@ -1,82 +0,0 @@
-scss = new Compiler();
- }
-
- public function testUserFunction()
- {
- $this->scss->registerFunction('add-two', function ($args) {
- list($a, $b) = $args;
- return $a[1] + $b[1];
- });
-
- $this->assertEquals(
- 'result: 30;',
- $this->compile('result: add-two(10, 20);')
- );
- }
-
- public function testImportMissing()
- {
- $this->assertEquals(
- '@import "missing";',
- $this->compile('@import "missing";')
- );
- }
-
- public function testImportCustomCallback()
- {
- $this->scss->addImportPath(function ($path) {
- return __DIR__ . '/inputs/' . str_replace('.css', '.scss', $path);
- });
-
- $this->assertEquals(
- trim(file_get_contents(__DIR__ . '/outputs/variables.css')),
- $this->compile('@import "variables.css";')
- );
- }
-
- /**
- * @dataProvider provideSetVariables
- */
- public function testSetVariables($expected, $scss, $variables)
- {
- $this->scss->setVariables($variables);
-
- $this->assertEquals($expected, $this->compile($scss));
- }
-
- public function provideSetVariables()
- {
- return array(
- array(
- ".magic {\n color: red;\n width: 760px; }",
- '.magic { color: $color; width: $base - 200; }',
- array(
- 'color' => 'red',
- 'base' => '960px',
- ),
- ),
- array(
- ".logo {\n color: #808080; }",
- '.logo { color: desaturate($primary, 100%); }',
- array(
- 'primary' => '#ff0000',
- ),
- ),
- );
- }
-
- public function compile($str)
- {
- return trim($this->scss->compile($str));
- }
-}
diff --git a/lib/scssphp/tests/ExceptionTest.php b/lib/scssphp/tests/ExceptionTest.php
deleted file mode 100755
index 8bd0677..0000000
--- a/lib/scssphp/tests/ExceptionTest.php
+++ /dev/null
@@ -1,93 +0,0 @@
-scss = new Compiler();
- }
-
- /**
- * @param string $scss
- * @param string $expectedExceptionMessage
- *
- * @dataProvider provideScss
- */
- public function testThrowError($scss, $expectedExceptionMessage)
- {
- try {
- $this->compile($scss);
- } catch (\Exception $e) {
- if (strpos($e->getMessage(), $expectedExceptionMessage) !== false) {
- return;
- };
- }
-
- $this->fail('Expected exception to be raised: ' . $expectedExceptionMessage);
- }
-
- /**
- * @return array
- */
- public function provideScss()
- {
- return array(
- array(<<scss->compile($str));
- }
-}
diff --git a/lib/scssphp/tests/InputTest.php b/lib/scssphp/tests/InputTest.php
deleted file mode 100755
index 09c4d12..0000000
--- a/lib/scssphp/tests/InputTest.php
+++ /dev/null
@@ -1,98 +0,0 @@
-scss = new Compiler();
- $this->scss->addImportPath(__DIR__ . '/' . self::$inputDir);
- }
-
- /**
- * @dataProvider fileNameProvider
- */
- public function testInputFile($inFname, $outFname)
- {
- if (getenv('BUILD')) {
- return $this->buildInput($inFname, $outFname);
- }
-
- if (!is_readable($outFname)) {
- $this->fail("$outFname is missing, consider building tests with BUILD=true");
- }
-
- $input = file_get_contents($inFname);
- $output = file_get_contents($outFname);
-
- $this->assertEquals($output, $this->scss->compile($input));
- }
-
- public function fileNameProvider()
- {
- return array_map(
- function ($a) {
- return array($a, InputTest::outputNameFor($a));
- },
- self::findInputNames()
- );
- }
-
- // only run when env is set
- public function buildInput($inFname, $outFname)
- {
- $css = $this->scss->compile(file_get_contents($inFname));
- file_put_contents($outFname, $css);
- }
-
- public static function findInputNames($pattern = '*')
- {
- $files = glob(__DIR__ . '/' . self::$inputDir . '/' . $pattern);
- $files = array_filter($files, 'is_file');
- if ($pattern = getenv('MATCH')) {
- $files = array_filter($files, function ($fname) use ($pattern) {
- return preg_match("/$pattern/", $fname);
- });
- }
-
- return $files;
- }
-
- public static function outputNameFor($input)
- {
- $front = _quote(__DIR__ . '/');
- $out = preg_replace("/^$front/", '', $input);
-
- $in = _quote(self::$inputDir . '/');
- $out = preg_replace("/$in/", self::$outputDir . '/', $out);
- $out = preg_replace("/.scss$/", '.css', $out);
-
- return __DIR__ . '/' . $out;
- }
-
- public static function buildTests($pattern)
- {
- $files = self::findInputNames($pattern);
-
- foreach ($files as $file) {
- }
- }
-}
diff --git a/lib/scssphp/tests/compare-scss.sh b/lib/scssphp/tests/compare-scss.sh
deleted file mode 100755
index 3b04292..0000000
--- a/lib/scssphp/tests/compare-scss.sh
+++ /dev/null
@@ -1,25 +0,0 @@
-#!/bin/bash
-
-diff_tool="$1"
-
-for file in $(ls inputs/*.scss); do
- out_file=$(echo $file | sed -e 's/inputs/outputs/' -e 's/\.scss$/\.css/')
- sass=$(scss < $file 2> /dev/null)
- if [ $? = "0" ]; then
- # echo $file
- # echo "$sass"
- # echo
-
- if [ "$(cat $out_file)" != "$sass" ]; then
- echo "* [FAIL] $file"
- if [ -n "$diff_tool" ]; then
- $diff_tool $out_file <(echo "$sass") 2> /dev/null
- fi
- else
- echo " [PASS] $file"
- fi
- else
- echo " $file"
- fi
-done
-
diff --git a/lib/scssphp/tests/inputs/builtins.scss b/lib/scssphp/tests/inputs/builtins.scss
deleted file mode 100755
index ef93a03..0000000
--- a/lib/scssphp/tests/inputs/builtins.scss
+++ /dev/null
@@ -1,171 +0,0 @@
-
-#color {
- color: rgb(34,234,24);
-
- red: red(rgb(34,234,24));
- green: green(rgb(34,234,24));
- blue: blue(rgb(34,234,24));
-
- color: rgba(1,2,4, 0.5);
- a1: alpha(rgb(1,2,4));
- a2: alpha(rgba(1,2,4, 0.5));
-
- mix: mix(rgb(1,2,3), rgb(3,4,5));
-
- rgba: rgba($color: #a7c, $alpha: 0.4);
- rgba: rgba(#a7c, 0.4);
-}
-
-#hsl {
- color: hsl(100, 50, 55);
- color: hsla(100, 50, 55, 0.5);
-
- hue: hue(hsl(100, 50, 55));
- sat: saturation(hsl(100, 50, 55));
- lig: lightness(hsl(100, 50, 55));
-}
-
-#more-color {
- $color: hsl(-80,44,33);
-
- light: lighten($color, 10%);
- dark: darken($color, 10%);
-
- sat: saturate($color, 10%);
- desat: desaturate($color, 10%);
-
- gray: grayscale($color);
- comp: complement($color);
- inv: invert($color);
-}
-
-#more-more-color {
- $color: rgba(1,2,3,0.5);
- op: opacity($color);
-
- opacify: opacify($color, 0.1);
- opacify: fade-in($color, 0.1);
-
- transparentize: transparentize($color, 0.1);
- transparentize: fade-out($color, 0.1);
- transparentize: transparentize(#348203, 0.1);
-}
-
-#more-more-more-color {
- $color: rgba(10,10,10,0);
- color: adjust-color($color, $blue: 69, $red: 55, $green: 100, $alpha: 0.4);
- color: adjust-color($color, $hue: 170, $saturation: 100, $lightness: 50);
-
- color: change-color($color, $blue: 69, $red: 55, $green: 100, $alpha: 0.4);
- color: change-color($color, $hue: 170, $saturation: 100, $lightness: 50);
-
- color: scale-color($color, $red: 55%);
- color: scale-color($color, $red: -55%);
-
- color: scale-color($color, $lightness: 55%);
- color: scale-color($color, $lightness: -55%);
-
- color: ie-hex-str($color);
- color: ie-hex-str(#abc);
-}
-
-#string {
- color: unquote("hello what is going on");
- // color: quote(yeah you know it); // **
- color: quote(yeah);
- color: quote("I do?");
-}
-
-#number {
- color: percentage(100/40);
- color: round(3.4);
- color: floor(3.4);
- color: ceil(3.4);
-
- top: floor(10.4px);
- top: ceil(.4ex);
- width: percentage(100px / 50px);
- bottom: abs(-10px);
- padding: min(5em, 3em, 4em) max(2px, 1in) min(1in, 96px) max(1in, 72pt);
-}
-
-#list {
- len: length(hello world what);
- len: length(thing);
-
- n: nth(hello world what, 1);
- // n: nth(hello world what, 100); // **
-
- hello: join(one two three, hello, comma);
- hello: join(one two three, hello world what is going, comma);
- hello: append(one two three, hello, comma);
-
- index: index(1px solid red, solid);
- index: index(1px solid red, dashed);
- index: index(1px solid red, #f00);
- index: index(96px solid red, 1in);
- index: index((1in 2) a b, 1in);
- index: index((1in 2) a b, (96px 2));
- index: index((1in 2) a b, (1in, 2));
- index: index((1px solid red), solid);
- index: index(1px 3px + 3px, 4+2px);
- $var: oo;
- index: index(foo bar, f#{$var});
-
- $yes: one, two, three;
- $no: great job;
- world: join($yes, $no);
- world: append($yes, $no);
-
- cool: join($yes, $no, space);
- cool: join($no, $yes);
-
- zip: zip((1px, 2px), (solid dashed));
- zip: zip(1px 2px 3px, solid dashed, red green blue);
-}
-
-#introspection {
- t: type-of(100px);
- t: type-of(asdf);
- t: type-of("asdf");
- t: type-of(true);
- t: type-of(#fff);
- t: type-of(blue);
- t: type-of(one two three);
-
- u: unit(12);
- u: unit(12px);
- u: unit(12em);
-
- l: unitless(23);
- l: unitless(23deg);
-
- c: comparable(2px, 1px);
- c: comparable(100px, 3em);
- c: comparable(10cm, 3mm);
- c: comparable(1, 4);
- c: comparable(1ex, 4em);
- c: comparable(2em, 5em);
-}
-
-#if {
- color: if(true, yes, no);
- color: if(false, yes, no);
- color: if(false or true, yes, no);
- color: if(10px, yes, no);
-}
-
-.transparent {
- r: red(transparent);
- g: green(transparent);
- b: blue(transparent);
- a: alpha(transparent);
-}
-
-.alpha {
- a: alpha(black);
- a: alpha(#fff);
- a: alpha(rgb(0, 0, 0));
- a: alpha(rgba(0, 0, 0, 0.5));
- a: alpha(currentColor);
-}
diff --git a/lib/scssphp/tests/inputs/comments.scss b/lib/scssphp/tests/inputs/comments.scss
deleted file mode 100755
index 80ab6c7..0000000
--- a/lib/scssphp/tests/inputs/comments.scss
+++ /dev/null
@@ -1,44 +0,0 @@
-
-// what is going on?
-
-/** what the heck **/
-
-/**
-
-Here is a block comment
-
-**/
-
-
-// this is a comment
-
-// trailing backslash \
-/*hello*/div /*yeah*/ { //surew
- border: 1px solid red; // world
- /* another property */
- color: url('http://mage-page.com');
- string: "hello /* this is not a comment */";
- world: "// neither is this";
- string: 'hello /* this is not a comment */' /*what if this is a comment */;
- world: '// neither is this' // hell world;
- ;
- what-ever: 100px;
- background: url(/*this is not a comment?*/); // uhh what happens here
-}
-
-// begin
-
-.dummy {
- color: blue;
-}
-
-/* comment 1 */
-a {
- /* comment 2 */
- /* comment 3 */ color: red; /* comment 4 */
- background-color: red; /* comment 5 */
- /* comment 6 */
-}
-/* comment 7 */
-
-// end
diff --git a/lib/scssphp/tests/inputs/compass_extract.scss b/lib/scssphp/tests/inputs/compass_extract.scss
deleted file mode 100755
index fba4572..0000000
--- a/lib/scssphp/tests/inputs/compass_extract.scss
+++ /dev/null
@@ -1,248 +0,0 @@
-// Extracted from compass/typography/vertical_rhythm.scss
-
-
-// The base font size.
-$base-font-size: 16px !default;
-
-// The base line height determines the basic unit of vertical rhythm.
-$base-line-height: 24px !default;
-
-// Set the default border style for rhythm borders.
-$default-rhythm-border-style: solid !default;
-
-// The default font size in all browsers.
-$browser-default-font-size: 16px;
-
-// Set to false if you want to use absolute pixels in sizing your typography.
-$relative-font-sizing: true !default;
-
-// Allows the `adjust-font-size-to` mixin and the `lines-for-font-size` function
-// to round the line height to the nearest half line height instead of the
-// nearest integral line height to avoid large spacing between lines.
-$round-to-nearest-half-line: false !default;
-
-// Ensure there is at least this many pixels
-// of vertical padding above and below the text.
-$min-line-padding: 2px !default;
-
-// $base-font-size but in your output unit of choice.
-// Defaults to 1em when `$relative-font-sizing` is true.
-$font-unit: if($relative-font-sizing, 1em, $base-font-size) !default;
-
-// The basic unit of font rhythm.
-$base-rhythm-unit: $base-line-height / $base-font-size * $font-unit;
-
-// The leader is the amount of whitespace in a line.
-// It might be useful in your calculations.
-$base-leader: ($base-line-height - $base-font-size) * $font-unit / $base-font-size;
-
-// The half-leader is the amount of whitespace above and below a line.
-// It might be useful in your calculations.
-$base-half-leader: $base-leader / 2;
-
-// True if a number has a relative unit.
-@function relative-unit($number) {
- @return unit($number) == "%" or unit($number) == "em" or unit($number) == "rem"
-}
-
-// True if a number has an absolute unit.
-@function absolute-unit($number) {
- @return not (relative-unit($number) or unitless($number));
-}
-
-@if $relative-font-sizing and not relative-unit($font-unit) {
- @warn "$relative-font-sizing is true but $font-unit is set to #{$font-unit} which is not a relative unit.";
-}
-
-// Establishes a font baseline for the given font-size.
-@mixin establish-baseline($font-size: $base-font-size) {
- // IE 6 refuses to resize fonts set in pixels and it weirdly resizes fonts
- // whose root is set in ems. So we set the root font size in percentages of
- // the default font size.
- * html {
- font-size: 100% * ($font-size / $browser-default-font-size);
- }
- html {
- font-size: $font-size;
- @include adjust-leading-to(1, if($relative-font-sizing, $font-size, $base-font-size));
- }
-}
-
-// Resets the line-height to 1 vertical rhythm unit.
-// Does not work on elements whose font-size is different from $base-font-size.
-//
-// @deprecated This mixin will be removed in the next release.
-// Please use the `adjust-leading-to` mixin instead.
-@mixin reset-baseline {
- @include adjust-leading-to(1, if($relative-font-sizing, $base-font-size, $base-font-size));
-}
-
-// Show a background image that can be used to debug your alignments.
-// Include the $img argument if you would rather use your own image than the
-// Compass default gradient image.
-@mixin debug-vertical-alignment($img: false) {
- @if $img {
- background: image-url($img);
- } @else {
- @include baseline-grid-background($base-rhythm-unit);
- }
-}
-
-// Adjust a block to have a different font size and line height to maintain the
-// rhythm. $lines specifies how many multiples of the baseline rhythm each line
-// of this font should use up. It does not have to be an integer, but it
-// defaults to the smallest integer that is large enough to fit the font.
-// Use $from-size to adjust from a font-size other than the base font-size.
-@mixin adjust-font-size-to($to-size, $lines: lines-for-font-size($to-size), $from-size: $base-font-size) {
- @if not $relative-font-sizing and $from-size != $base-font-size {
- @warn "$relative-font-sizing is false but a relative font size was passed to adjust-font-size-to";
- }
- font-size: $font-unit * $to-size / $from-size;
- @include adjust-leading-to($lines, if($relative-font-sizing, $to-size, $base-font-size));
-}
-
-// Adjust a block to have different line height to maintain the rhythm.
-// $lines specifies how many multiples of the baseline rhythm each line of this
-// font should use up. It does not have to be an integer, but it defaults to the
-// smallest integer that is large enough to fit the font.
-@mixin adjust-leading-to($lines, $font-size: $base-font-size) {
- line-height: rhythm($lines, $font-size);
-}
-
-// Calculate rhythm units.
-@function rhythm(
- $lines: 1,
- $font-size: $base-font-size,
- $offset: 0
-) {
- @if not $relative-font-sizing and $font-size != $base-font-size {
- @warn "$relative-font-sizing is false but a relative font size was passed to the rhythm function";
- }
- $rhythm: $font-unit * ($lines * $base-line-height - $offset) / $font-size;
- // Round the pixels down to nearest integer.
- @if unit($rhythm) == px {
- $rhythm: floor($rhythm);
- }
- @return $rhythm;
-}
-
-// Calculate the minimum multiple of rhythm units needed to contain the font-size.
-@function lines-for-font-size($font-size) {
- $lines: if($round-to-nearest-half-line,
- ceil(2 * $font-size / $base-line-height) / 2,
- ceil($font-size / $base-line-height));
- @if $lines * $base-line-height - $font-size < $min-line-padding * 2 {
- $lines: $lines + if($round-to-nearest-half-line, 0.5, 1);
- }
- @return $lines;
-}
-
-// Apply leading whitespace. The $property can be margin or padding.
-@mixin leader($lines: 1, $font-size: $base-font-size, $property: margin) {
- #{$property}-top: rhythm($lines, $font-size);
-}
-
-// Apply leading whitespace as padding.
-@mixin padding-leader($lines: 1, $font-size: $base-font-size) {
- padding-top: rhythm($lines, $font-size);
-}
-
-// Apply leading whitespace as margin.
-@mixin margin-leader($lines: 1, $font-size: $base-font-size) {
- margin-top: rhythm($lines, $font-size);
-}
-
-// Apply trailing whitespace. The $property can be margin or padding.
-@mixin trailer($lines: 1, $font-size: $base-font-size, $property: margin) {
- #{$property}-bottom: rhythm($lines, $font-size);
-}
-
-// Apply trailing whitespace as padding.
-@mixin padding-trailer($lines: 1, $font-size: $base-font-size) {
- padding-bottom: rhythm($lines, $font-size);
-}
-
-// Apply trailing whitespace as margin.
-@mixin margin-trailer($lines: 1, $font-size: $base-font-size) {
- margin-bottom: rhythm($lines, $font-size);
-}
-
-// Shorthand mixin to apply whitespace for top and bottom margins and padding.
-@mixin rhythm($leader: 0, $padding-leader: 0, $padding-trailer: 0, $trailer: 0, $font-size: $base-font-size) {
- @include leader($leader, $font-size);
- @include padding-leader($padding-leader, $font-size);
- @include padding-trailer($padding-trailer, $font-size);
- @include trailer($trailer, $font-size);
-}
-
-// Apply a border and whitespace to any side without destroying the vertical
-// rhythm. The whitespace must be greater than the width of the border.
-@mixin apply-side-rhythm-border($side, $width: 1px, $lines: 1, $font-size: $base-font-size, $border-style: $default-rhythm-border-style) {
- @if not $relative-font-sizing and $font-size != $base-font-size {
- @warn "$relative-font-sizing is false but a relative font size was passed to apply-side-rhythm-border";
- }
- border-#{$side}: {
- style: $border-style;
- width: $font-unit * $width / $font-size;
- };
- padding-#{$side}: rhythm($lines, $font-size, $offset: $width);
-}
-
-// Apply borders and whitespace equally to all sides.
-@mixin rhythm-borders($width: 1px, $lines: 1, $font-size: $base-font-size, $border-style: $default-rhythm-border-style) {
- @if not $relative-font-sizing and $font-size != $base-font-size {
- @warn "$relative-font-sizing is false but a relative font size was passed to rhythm-borders";
- }
- border: {
- style: $border-style;
- width: $font-unit * $width / $font-size;
- };
- padding: rhythm($lines, $font-size, $offset: $width);
-}
-
-// Apply a leading border.
-@mixin leading-border($width: 1px, $lines: 1, $font-size: $base-font-size, $border-style: $default-rhythm-border-style) {
- @include apply-side-rhythm-border(top, $width, $lines, $font-size, $border-style);
-}
-
-// Apply a trailing border.
-@mixin trailing-border($width: 1px, $lines: 1, $font-size: $base-font-size, $border-style: $default-rhythm-border-style) {
- @include apply-side-rhythm-border(bottom, $width, $lines, $font-size, $border-style);
-}
-
-// Apply both leading and trailing borders.
-@mixin horizontal-borders($width: 1px, $lines: 1, $font-size: $base-font-size, $border-style: $default-rhythm-border-style) {
- @include leading-border($width, $lines, $font-size, $border-style);
- @include trailing-border($width, $lines, $font-size, $border-style);
-}
-
-// Alias for `horizontal-borders` mixin.
-@mixin h-borders($width: 1px, $lines: 1, $font-size: $base-font-size, $border-style: $default-rhythm-border-style) {
- @include horizontal-borders($width, $lines, $font-size, $border-style);
-}
-
-#test-0 {
- unit: relative-unit(10px);
- unit: relative-unit(50%);
- rhythm: rhythm();
- size: lines-for-font-size(15px);
- size: lines-for-font-size(16px);
- size: lines-for-font-size(17px);
- size: lines-for-font-size(27px);
- size: lines-for-font-size(37px);
-}
-
-
-#test-1 {
- @include rhythm(5, 6, 7);
-}
-
-#test-2 {
- @include rhythm-borders;
-}
-
-#test-3 {
- @include horizontal-borders;
-}
-
-
diff --git a/lib/scssphp/tests/inputs/content.scss b/lib/scssphp/tests/inputs/content.scss
deleted file mode 100755
index 55ca04e..0000000
--- a/lib/scssphp/tests/inputs/content.scss
+++ /dev/null
@@ -1,61 +0,0 @@
-
-@mixin apply-to-ie6-only {
- * html {
- @content;
- }
-}
-@include apply-to-ie6-only {
- #logo {
- background-image: url(/logo.gif);
- }
-}
-
-
-$color: white;
-@mixin colors($color: blue) {
- background-color: $color;
- @content;
- border-color: $color;
-}
-.colors {
- @include colors { color: $color; }
-}
-
-
-@mixin iphone {
- @media only screen and (max-width: 480px) {
- @content;
- }
-}
-
-@include iphone {
- body { color: red }
-}
-
-
-#sidebar {
- $sidebar-width: 300px;
- width: $sidebar-width;
- @include iphone {
- width: $sidebar-width / 3;
- }
-}
-
-
-@mixin respond-to($width) {
- @media only screen and (min-width: $width) { @content; }
-}
-
-@include respond-to(40em) {
- @for $i from 1 through 2 {
- .grid-#{$i} { width: 100%; }
- }
-}
-
-@include respond-to(40em) {
- $i: 1;
- @while $i <= 2 {
- .grid-#{$i} { width: 100%; }
- $i: $i + 1;
- }
-}
diff --git a/lib/scssphp/tests/inputs/content_with_function.scss b/lib/scssphp/tests/inputs/content_with_function.scss
deleted file mode 100755
index f1462d6..0000000
--- a/lib/scssphp/tests/inputs/content_with_function.scss
+++ /dev/null
@@ -1,17 +0,0 @@
-$test-var: true;
-
-@mixin mixin-using-content() {
- @content;
-}
-
-@function test-function($value) {
- @return $value;
-}
-
-@include mixin-using-content {
- @if $test-var {
- body {
- padding: test-function(1 px);
- }
- }
-}
diff --git a/lib/scssphp/tests/inputs/default_args.scss b/lib/scssphp/tests/inputs/default_args.scss
deleted file mode 100755
index dbc8880..0000000
--- a/lib/scssphp/tests/inputs/default_args.scss
+++ /dev/null
@@ -1,15 +0,0 @@
-
-
-@mixin cool($color: blue) {
- margin: 100px;
-}
-
-@function what($height: red) {
- @return $height;
-}
-
-div {
- height: what();
- @include cool;
-}
-
diff --git a/lib/scssphp/tests/inputs/directives.scss b/lib/scssphp/tests/inputs/directives.scss
deleted file mode 100755
index 65f1c51..0000000
--- a/lib/scssphp/tests/inputs/directives.scss
+++ /dev/null
@@ -1,108 +0,0 @@
-
-@charset "hello-world";
-
-@page :left {
- div {
- color: red;
- }
-}
-
-@page test {
- @media yes {
- div {
- color: red;
- }
-
- @media no {
- pre {
- color: blue;
- }
- }
- }
-}
-
-@media something {
- @page {
- @media else {
- div {
- height: 200px;
- }
- }
- }
-}
-
-
-div {
- color: red;
- @page yeah {
- pre {
- height: 20px;
- }
- }
-}
-
-@font-face {
- color: red;
- height: 20px;
-}
-
-
-@keyframes 'bounce' {
- from {
- top: 100px;
- animation-timing-function: ease-out;
- }
-
- 25% {
- top: 50px;
- animation-timing-function: ease-in;
- }
-
- 50% {
- top: 100px;
- animation-timing-function: ease-out;
- }
-
- 75% {
- top: 75px;
- animation-timing-function: ease-in;
- }
-
- to {
- top: 100px;
- }
-}
-
-@-webkit-keyframes flowouttoleft {
- 0% { -webkit-transform: translateX(0) scale(1); }
- 60%, 70% { -webkit-transform: translateX(0) scale(.7); }
- 100% { -webkit-transform: translateX(-100%) scale(.7); }
-}
-
-div {
- animation-name: 'diagonal-slide';
- animation-duration: 5s;
- animation-iteration-count: 10;
-}
-
-@keyframes 'diagonal-slide' {
-
- from {
- left: 0;
- top: 0;
- }
-
- to {
- left: 100px;
- top: 100px;
- }
-
-}
-
-@document url(http://www.w3.org/),
- url-prefix(http://www.w3.org/Style/),
- domain(mozilla.org),
- regexp("https:.*")
-{
- body { color: purple; background: yellow; }
-}
diff --git a/lib/scssphp/tests/inputs/extends.scss b/lib/scssphp/tests/inputs/extends.scss
deleted file mode 100755
index 74a5160..0000000
--- a/lib/scssphp/tests/inputs/extends.scss
+++ /dev/null
@@ -1,184 +0,0 @@
-
-error, other {
- border: 1px #f00;
- background-color: #fdd;
-}
-
-pre, span {
- seriousError {
- @extend error;
- font-size: 20px;
- }
-}
-
-hello {
- @extend other;
- color: green;
- div {
- margin: 10px;
- }
-}
-
-.cool {
- color: red;
-}
-
-.blue {
- color: purple;
-}
-
-.me {
- @extend .cool, .blue;
-}
-
-.hoverlink { @extend a:hover }
-a:hover { text-decoration: underline }
-
-
-// partial matching and selector merging:
-
-div.hello.world.hmm {
- color: blue;
-}
-
-pre, code {
- .okay.span {
- @extend .hello;
- }
-}
-
-// multiple matches per selector
-.xxxxx .xxxxx .xxxxx {
- color: green;
-}
-
-code {
- @extend .xxxxx;
- color: red;
-}
-
-
-// chained
-
-.alpha {
- color: red;
-}
-
-.beta {
- @extend .alpha;
- color: white;
-}
-
-.gama {
- @extend .beta;
- color: blue;
-}
-
-// merging selector sequences
-
-#admin .tabbar a {font-weight: bold}
-#demo .overview .fakelink {@extend a}
-
-a1 b1 c1 d1 { color: red; }
-x1 y1 z1 w1 { @extend a1; }
-
-a2 b2 c2 d2 { color: red; }
-x2 y2 z2 w2 { @extend b2; }
-
-
-a3 b3 c3 d3 { color: red; }
-x3 y3 z3 w3 { @extend c3; }
-
-
-a4 b4 c4 d4 { color: red; }
-x4 y4 z4 w4 { @extend d4; }
-
-// removing common prefix
-
-#butt .yeah .okay { font-weight: bold }
-#butt .umm .sure { @extend .okay }
-
-a9 b9 s9 t9 v9 { color: red; }
-
-a9 b9 x9 y9 z9 {
- @extend v9;
-}
-
-// extends & media
-
-@media print {
- horse {
- color: blue;
- }
-}
-
-man {
- color: red;
- @extend horse;
-}
-
-
-// result == match
-
-wassup {
- color: blue;
- @extend wassup;
-}
-
-.foo {
- .wassup {
- @extend .wassup;
- color: blue;
- }
-}
-
-// multi-extend
-
-#something {
- color: red;
-}
-
-.x {
- @extend #something;
-}
-
-.y {
- @extend #something;
-}
-
-// twitter-sass-bootstrap infinite loop
-
-.nav-tabs {
- &.nav-justified {
- @extend .nav-justified;
- }
-}
-.nav-justified {
- text-align: justify;
-}
-
-// multi-extend with nesting
-
-.btn:hover,
-.btn:active,
-.btn.active,
-.btn.disabled,
-.btn[disabled] {
- color: red;
-}
-.edit .actions {
- button {
- float: right;
- @extend .btn;
- }
-}
-.edit {
- .new {
- .actions {
- padding: 0;
- }
- .actions button {
- @extend .btn;
- }
- }
-}
diff --git a/lib/scssphp/tests/inputs/filter_effects.scss b/lib/scssphp/tests/inputs/filter_effects.scss
deleted file mode 100755
index e8f9a3b..0000000
--- a/lib/scssphp/tests/inputs/filter_effects.scss
+++ /dev/null
@@ -1,48 +0,0 @@
-#number {
- -webkit-filter: grayscale(1)
- sepia(0.5)
- saturate(0.1)
- invert(1)
- opacity(0.5)
- brightness(0.5)
- contrast(0.5);
-}
-
-#percentage {
- -webkit-filter: grayscale(100%)
- sepia(50%)
- saturate(10%)
- invert(100%)
- opacity(50%)
- brightness(50%)
- contrast(50%);
-}
-
-#misc {
- -webkit-filter: hue-rotate(90deg)
- blur(10px)
- drop-shadow(10px -16px 30px purple);
-}
-
-@mixin opacity($opacity, $style: 0) {
- @if ($opacity < 1) {
- opacity: $opacity;
- filter: alpha(opacity=$opacity * 100, style=$style);
- } @else {
- opacity: $opacity / 100;
- filter: alpha(opacity=$opacity);
- }
-}
-
-#decimal {
- @include opacity(.5, 1);
-}
-
-#percent {
- @include opacity(50);
-}
-
-.row {
- background-color: darken(#2ba6cb, 40%);
- color: darken(#2ba6cb, 10%);
-}
diff --git a/lib/scssphp/tests/inputs/functions.scss b/lib/scssphp/tests/inputs/functions.scss
deleted file mode 100755
index 030f967..0000000
--- a/lib/scssphp/tests/inputs/functions.scss
+++ /dev/null
@@ -1,89 +0,0 @@
-
-@function hello($x) {
- @return $x + 4;
-}
-
-@function add($a, $b) {
- @return $a + $b;
-}
-
-div {
- color: hello(10px);
- sum: add(11, 12);
-}
-
-// make sure values are being reduced before being passed up to previous scope
-
-@function one($a, $b) {
- @return $a $b;
-}
-
-@function two($a, $b) {
- @return $a#{$a} $b;
-}
-
-@function three($a, $b: default) {
- @return "hello #{$a} and #{$b}"
-}
-
-@function all($a...) {
- @return "hello #{$a}"
-}
-
-div {
- hello: one(10, 55);
- hello: two(10, 55);
- hello: three(10, 55);
-}
-
-
-@function hello_world() {
- @return 1000;
-}
-
-del {
- color: hello-world();
-}
-
-div {
- $args: foo bar;
- hello: three($args...);
- hello: three(bar...);
- hello: all(Alice, Bob, Tom);
-}
-
-@function stringConcatCompassStyle($start,$last)
-{
- // Compass still uses it like this
- @return #{$start}-#{$last};
-}
-
-.foo
-{
- test2: stringConcatCompassStyle(-moz,art);
-}
-
-@mixin content_test {
- span {
- $color: green;
- @content;
- }
-}
-
-@function func_test($c) {
- @return $c + 1;
-}
-
-div {
- @include content_test {
- height: func_test(2px);
- }
-}
-
-@function test ($a, $b: $a/2) {
- @return $b;
-}
-
-div {
- width: test(4);
-}
diff --git a/lib/scssphp/tests/inputs/ie7.scss b/lib/scssphp/tests/inputs/ie7.scss
deleted file mode 100755
index 3d4771b..0000000
--- a/lib/scssphp/tests/inputs/ie7.scss
+++ /dev/null
@@ -1,12 +0,0 @@
-// http://jes.st/2013/ie7s-css-breaking-content-counter-bug/
-#foo:before {
- content: counter(item, ".") ": ";
-}
-
-#bar:before {
- content: counter(item,".");
-}
-
-#fu:before {
- content: counter(item);
-}
diff --git a/lib/scssphp/tests/inputs/if.scss b/lib/scssphp/tests/inputs/if.scss
deleted file mode 100755
index d62b056..0000000
--- a/lib/scssphp/tests/inputs/if.scss
+++ /dev/null
@@ -1,76 +0,0 @@
-
-@function conds($val) {
- @if $val {
- @return "red";
- }
-
- @return "blue";
-}
-
-div {
- @if something {
- color: blue;
- }
-}
-
-pre {
- val-1: conds(true);
- val-2: conds(false);
- val-3: conds(null);
- val-4: conds(1);
- val-5: conds(0);
-}
-
-
-span {
- @if false {
- color: red;
- } @else {
- color: blue;
- }
-
- @if true {
- height: 10px;
- } @else {
- color: 20px;
- }
-
- @if false {
- height: 10px;
- } @elseif false {
- color: 20px;
- } @else {
- width: 20px;
- }
-}
-
-div {
- @if false {
- color: red;
- } @else if false {
- color: green;
- } @else {
- color: blue;
- }
-
- @if false {
- border-color: red;
- } @else if true {
- border-color: green;
- } @else {
- border-color: blue;
- }
-
-}
-
-// doesn't work in scss, thing loses scope
-del {
- @if false {
- $thing: yes;
- } @else {
- $thing: no;
- }
-
- thing: $thing;
-}
-
diff --git a/lib/scssphp/tests/inputs/if_on_null.scss b/lib/scssphp/tests/inputs/if_on_null.scss
deleted file mode 100755
index 1688706..0000000
--- a/lib/scssphp/tests/inputs/if_on_null.scss
+++ /dev/null
@@ -1,8 +0,0 @@
-@function testfunc($pseudo: null) {
- $output: if($pseudo, "green", "red");
- @return $output;
-}
-
-body {
- background-color: testfunc();
-}
diff --git a/lib/scssphp/tests/inputs/import.scss b/lib/scssphp/tests/inputs/import.scss
deleted file mode 100755
index 61625cd..0000000
--- a/lib/scssphp/tests/inputs/import.scss
+++ /dev/null
@@ -1,23 +0,0 @@
-
-@import "foo.css";
-@import "foo" screen;
-@import "http://foo.com/bar";
-@import url(foo);
-
-@import "imports/simple";
-
-pre {
- color: red;
- @import "imports/simple.scss";
-}
-
-code {
- @import "imports/simple", "imports/simple";
-}
-
-@import "imports/partial";
-
-body {
- color: $variable;
- @include partial-mixin();
-}
diff --git a/lib/scssphp/tests/inputs/imports/_partial.scss b/lib/scssphp/tests/inputs/imports/_partial.scss
deleted file mode 100755
index 010c3c4..0000000
--- a/lib/scssphp/tests/inputs/imports/_partial.scss
+++ /dev/null
@@ -1,10 +0,0 @@
-
-#partial {
- color: blue;
-}
-
-$variable: #7C2;
-
-@mixin partial-mixin() {
- background: gray;
-}
diff --git a/lib/scssphp/tests/inputs/imports/simple.scss b/lib/scssphp/tests/inputs/imports/simple.scss
deleted file mode 100755
index 4b3e1f9..0000000
--- a/lib/scssphp/tests/inputs/imports/simple.scss
+++ /dev/null
@@ -1,4 +0,0 @@
-div {
- height: 200px;
- color: red;
-}
diff --git a/lib/scssphp/tests/inputs/interpolation.scss b/lib/scssphp/tests/inputs/interpolation.scss
deleted file mode 100755
index 3ac51cf..0000000
--- a/lib/scssphp/tests/inputs/interpolation.scss
+++ /dev/null
@@ -1,86 +0,0 @@
-
-div {
- color: red#{white} blue;
- color: red #{white} blue;
- color: red #{white}blue;
- color: red#{white}blue;
- color: #{umm}#{yeah}#{what};
- color: #{stacked};
-
- font-size: 10px/#{something};
- font-size: 10px / #{something};
-
- test: "what#{"world"}wrong";
- test: "what#{'world'}wrong";
- test: "what#{world}wrong";
- test: "what"#{world}"wrong";
-
- hi: "what is #{4 + 12} end"
-}
-
-
-// interpolation in selectors
-
-pre {
- $var: cool;
-
- #{var} {
- color: red;
- }
-
- #{var} dad {
- color: red;
- }
-
- bed#{var}dad {
- color: red;
- }
-}
-
-cool {
- @for $x from 1 through 5 {
- .thing-#{$x} {
- color: red;
- }
- }
-}
-
-a#{b}c#{d}e {
- color: red;
-}
-
-##{hello}, .#{world}{
- color: red;
-}
-
-#abc#{hello}yeah, .cool#{world}yes{
- color: red;
-}
-
-$scope: 2;
-
-div.element:nth-child(#{$scope}n)
-{
- display: none;
-}
-
-// property interpolation
-
-div {
- $var: hello;
- #{$var}: world;
- cool#{$var}:world;
- #{$var}one:world;
- two#{$var}one:world;
-
- one#{a + b}two: cool;
-
- #{hello}: {
- #{world}: red;
- #{mold}: white;
- #{$var}: blue;
- }
-
-}
-
-
diff --git a/lib/scssphp/tests/inputs/keyword_args.scss b/lib/scssphp/tests/inputs/keyword_args.scss
deleted file mode 100755
index 0b8e475..0000000
--- a/lib/scssphp/tests/inputs/keyword_args.scss
+++ /dev/null
@@ -1,24 +0,0 @@
-
-// mixins
-
-@mixin hello($a: one, $b:two, $c:three, $d: four) {
- out: $a $b $c $d;
-}
-
-pre {
- @include hello(alpha, $d: palace, $b: fort);
-}
-
-
-// functions
-
-@function cool($a, $b) {
- @return $a - $b;
-}
-
-div {
- hello: cool($b: 5, $a: 10);
- world: cool(5, 10);
-}
-
-
diff --git a/lib/scssphp/tests/inputs/list.scss b/lib/scssphp/tests/inputs/list.scss
deleted file mode 100755
index afeb742..0000000
--- a/lib/scssphp/tests/inputs/list.scss
+++ /dev/null
@@ -1,15 +0,0 @@
-$list: (black);
-$list: join($list, white, comma);
-
-div {
- padding: join(10px 20px, 30px 40px);
- margin: join((0, 10px), (10px, 10px), space);
- background: linear-gradient($list);
-}
-
-$list: ();
-$list: join($list, (red, blue), comma);
-
-p {
- background: linear-gradient($list);
-}
\ No newline at end of file
diff --git a/lib/scssphp/tests/inputs/looping.scss b/lib/scssphp/tests/inputs/looping.scss
deleted file mode 100755
index 6f25e72..0000000
--- a/lib/scssphp/tests/inputs/looping.scss
+++ /dev/null
@@ -1,51 +0,0 @@
-
-div {
- @each $var in what is this {
- color: $var;
- }
-
- @each $var in what, is, this {
- font: $var;
- }
-
- $list: what is this;
- @each $var in $list {
- background: $var;
- }
-
- $list: what, is, this;
- @each $var in $list {
- border: $var;
- }
-}
-
-
-span {
- $i: 0;
- @while $i <= 10 {
- color: $i;
- $i: $i + 1;
- }
-}
-
-pre {
- @for $x from 1 to 5 {
- color: $x;
- }
-
- @for $x from 1 through 5 {
- height: $x;
- }
-
- $y: 10;
- @for $x from $y through 3 {
- cool: $x;
- }
-
-}
-
-$j: null;
-@while $j {
- .item { width: 2em; }
- $j: false;
-}
diff --git a/lib/scssphp/tests/inputs/media.scss b/lib/scssphp/tests/inputs/media.scss
deleted file mode 100755
index 3c2c147..0000000
--- a/lib/scssphp/tests/inputs/media.scss
+++ /dev/null
@@ -1,208 +0,0 @@
-
-// media syntax
-@media {
- div { color: blue; }
-}
-@media what {
- div { color: blue; }
-}
-
-@media (cool) {
- div { color: blue; }
-}
-@media (cool: blue) {
- div { color: blue; }
-}
-
-@media hello and (world) and (butt: man) {
- div { color: blue; }
-}
-
-$navbarCollapseWidth: 940px;
-
-@media (max-width: $navbarCollapseWidth) {
- color: red;
-}
-
-// media bubbling
-@media not hello and (world) {
- color: blue;
- pre {
- color: blue;
- }
-
- @media butt {
- color: red;
- div {
- color: red;
- }
- }
-}
-
-@media a, b {
- @media c {
- color: blue;
- }
-}
-
-@media a{
- @media b, c {
- color: blue;
- }
-}
-
-@media a, b{
- @media c, d {
- color: blue;
- }
-}
-
-$media: cree;
-$feature: -webkit-min-device-pixel-ratio;
-$value: 1.5;
-
-div {
- color: blue;
- @media s#{$media}n and ($feature: $value) {
- .sidebar {
- width: 500px;
- }
- }
-}
-
-// @media + @mixin
-@mixin color {
- color: red;
- .success {
- color: green;
- }
-}
-
-div {
- position: absolute;
- $y: 2em;
- @media screen {
- top: 0;
- $x: 5px;
- p {
- margin: $x;
- }
- bottom: 6em + $y;
- @include color;
- }
-}
-
-.button {
- width: 300px;
- height: 100px;
- background: #eee;
-
- :hover {
- background: #aaa;
- }
-
- @media only screen and (max-width : 300px){
- width: 100px;
- height: 100px;
- }
-}
-
-code {
- position: absolute;
- @media screen {
- pre {
- height: 20px;
- }
- height: 10px;
- }
-}
-
-dt {
- @media screen {
- @media (color: blue) {
- height: 10px;
- }
- }
-}
-
-// nesting media queries
-@media screen {
- .screen {
- width: 12px;
- }
- @media only screen {
- .only-screen {
- height: 11px;
- }
- }
-}
-
-@media only screen {
- .only-screen {
- width: 14px;
- }
- @media only screen {
- .only-screen {
- height: 16px;
- }
- }
-}
-
-@media not screen {
- @media screen {
- .invalid {
- height: 12px;
- }
- }
-}
-
-@media not screen {
- @media print {
- .only-print {
- height: 12px;
- }
- }
-}
-
-@media screen {
- @media not print {
- .only-print {
- height: 12px;
- }
- }
-}
-
-@media not screen {
- @media not print {
- .invalid {
- height: 12px;
- }
- }
-}
-
-@media not screen {
- @media not screen {
- .not-screen {
- height: 15px;
- }
- }
-}
-
-@media only screen {
- @media print {
- .invalid {
- height: 15px;
- }
- }
-}
-
-@media only screen {
- @media screen and (color: blue) {
- @media screen and (width: 13) {
- .only-screen {
- height: 15px;
- }
- }
- }
-}
-
diff --git a/lib/scssphp/tests/inputs/mixins.scss b/lib/scssphp/tests/inputs/mixins.scss
deleted file mode 100755
index 1b6550c..0000000
--- a/lib/scssphp/tests/inputs/mixins.scss
+++ /dev/null
@@ -1,183 +0,0 @@
-
-@mixin something {
- color: red;
- pre {
- height: 200px;
- }
-}
-
-div {
- color: blue;
- @include something;
-}
-
-@mixin something($color) {
- color: $color;
-
- div {
- height: 20px;
- }
-}
-
-@mixin cool($a, $b, $c) {
- height: $a + $b + $c;
-}
-
-span {
- @include something(blue);
-}
-
-html {
- @include cool(10px, 12px, 21px);
-}
-
-
-@mixin hello_world {
- height: 20px;
-}
-
-del {
- @include hello-world;
-}
-
-
-// variable shadowing
-
-
-$color: white;
-@mixin colors($color: blue) {
- color: $color;
-}
-
-div {
- color: $color;
- @include colors();
- color: $color;
-}
-
-@mixin linear-gradient($from, $to, $pos: left top) {
- background-image: linear-gradient($pos, $from, $to);
-}
-
-div {
- @include linear-gradient(red, green);
-}
-
-@mixin box-shadow($shadows...) {
- -moz-box-shadow: $shadows;
- -webkit-box-shadow: $shadows;
- box-shadow: $shadows;
-}
-
-div {
- @include box-shadow(10px 10px 5px #888);
- @include box-shadow(inset 10px 10px #888, -10px -10px #f4f4f4);
-}
-
-@mixin nested {
- @include something(red);
-}
-
-div {
- p {
- .class {
- @include nested;
- }
-
- @include nested;
-
- .top {
- top: 0;
-
- div {
- color: red;
- }
- }
-
- color: blue;
- }
-}
-
-// mixin content (http://sass-lang.com/docs/yardoc/file.SASS_REFERENCE.html#mixin-content)
-@mixin content-simple {
- div.mixin-content-simple {
- @content;
- }
-}
-
-@mixin content-with-arg ( $background ) {
- div.mixin-content-with-arg {
- background: $background;
- @content;
- }
-}
-
-@include content-simple {
- color: red;
-}
-
-@include content-with-arg($background: blue) {
- color: red;
-}
-
-@include content-with-arg($background: purple) {
- @include hello_world;
-}
-
-@include content-simple {
- @include cool(10px, 12px, 21px);
-}
-
-@include content-simple {
- @include something(orange);
-}
-
-@include content-with-arg($background: purple) {
- @include cool(10px, 12px, 21px);
-}
-
-@include content-with-arg($background: purple) {
- @include something(orange);
-}
-
-@mixin wallpaper($image, $top: 0, $right: 0, $bottom: 0, $left: 0) {
- background: $image;
- position: absolute;
- top: $top;
- right: $right;
- bottom: $bottom;
- left: $left;
-}
-
-@mixin logo($offsets...) {
- @include wallpaper(url(/images/logo.png), $offsets...);
-}
-
-#please-wait {
- @include logo(1em, $left: 4em, $bottom: 3em);
-}
-
-@mixin prefixer($property, $value) {
--webkit-#{$property}: $value;
-}
-
-@mixin transform($property: none) {
- @include prefixer(transform, $property);
-}
-
-div.parameter-name-scope {
- @include transform(translateX(50px));
-}
-
-@mixin keyframes( $name )
-{
- @-webkit-keyframes $name {
- @content;
- }
-}
-
-@include keyframes( change-color )
-{
- 0% { color: green; }
- 100% { color: red; }
-}
diff --git a/lib/scssphp/tests/inputs/nesting.scss b/lib/scssphp/tests/inputs/nesting.scss
deleted file mode 100755
index 68e3117..0000000
--- a/lib/scssphp/tests/inputs/nesting.scss
+++ /dev/null
@@ -1,45 +0,0 @@
-
-
-body {
- color: red;
-}
-
-
-div {
- color: red;
- height: yes;
-
- pre {
- color: blue;
- }
-}
-
-
-div: blue;
-
-
-div {
- font: 10px hello world {
- size: 10px;
- color: blue;
- }
-
- border: {
- left: 1px solid blue;
- right: 2px dashed green;
- }
-}
-
-
-#nested-nesting {
- bar: baz;
- bang: {
- bop: bar;
- bip: 1px;
- blat: {
- baf: bort
- }
- }
-}
-
-
diff --git a/lib/scssphp/tests/inputs/null.scss b/lib/scssphp/tests/inputs/null.scss
deleted file mode 100755
index 147dc2e..0000000
--- a/lib/scssphp/tests/inputs/null.scss
+++ /dev/null
@@ -1,41 +0,0 @@
-$list: null;
-.div {
- one: null;
- one: null world;
- one: NULL world;
- one: a null, b;
- two: a $list $list, $list, b;
- three: $list;
-}
-
-$value: null;
- p:before {
- content: "I ate #{$value} pies!";
-}
-
-@mixin Rounded($radius1, $direction: null, $radius2: false) {
- $corner: null;
- @if $direction == TL { $corner: top-left-; }
- @if $direction == TR { $corner: top-right-; }
- @if $direction == BL { $corner: bottom-left-; }
- @if $direction == BR { $corner: bottom-right-; }
- @if $radius2 {
- -webkit-border-#{$corner}radius: $radius1 $radius2;
- border-#{$corner}radius: $radius1 $radius2;
- } @else {
- -webkit-border-#{$corner}radius: $radius1;
- border-#{$corner}radius: $radius1;
- }
-}
-
-.foo {
- @include Rounded(10);
-}
-
-.fu {
- @include Rounded(20, null);
-}
-
-.bar {
- @include Rounded(30, TL);
-}
diff --git a/lib/scssphp/tests/inputs/operators.scss b/lib/scssphp/tests/inputs/operators.scss
deleted file mode 100755
index eb6e20e..0000000
--- a/lib/scssphp/tests/inputs/operators.scss
+++ /dev/null
@@ -1,143 +0,0 @@
-
-
-body {
- color: 1 + 2 + 5;
- color: 1 + 2 * 5 + 5;
- height: 10px/10px;
- color: 10px/2 + 1;
- color: (10px/2);
- bottom: (4/2px);
- top: 1em * (1 * 24px - 0) / 16px;
- left: 1 - 2cm;
- top: (2cm/12px);
-}
-
-div {
- color: 4 == 3;
- color: hello == hello;
-
- color: 4 > 3;
- color: 4 < 3;
- color: what > 3;
-}
-
-
-#units {
- test: 1in + 4cm;
- test: 12mm + 1;
- test: 1 + 3em;
- test: 1mm + 1cm;
- test: 1cm + 1mm;
-}
-
-#modulo {
- test: 3 % 2;
- test: 4cm % 3;
-}
-
-#colors {
- color: red + rgb(1,2,3);
- color: red - rgb(1,2,3);
- color: rgba(1,2,3, 0.5) * rgba(3,4,5, 0.5);
- color: rgba(10,15,20, 0.5) / rgba(2,2,2, 0.5);
-
- color: rgba(1,2,3, 0.5) * 2;
- color: rgba(1,2,3, 0.5) / 2;
- color: rgba(1,2,3, 0.5) + 2;
- color: rgba(1,2,3, 0.5) - 2;
-
- color: blue + 34;
-
- color: #fff == #000;
- color: #fff == #fff;
-
- color: #fff != #000;
- color: #fff != #fff;
-}
-
-
-#preserve {
- hello: what -going;
- hello: what - going;
-}
-
-#strings {
- hello: what -going;
-
- hello: what +going;
- hello: what+going;
- hello: what+ going;
- hello: what + going;
-
- hello: "what" + going;
- hello: going + "what";
- hello: "what" + "what";
-}
-
-#negation {
- $num: 100;
- a: -$num + 40;
- b: 10 -$num;
- b: 10 - $num;
-}
-
-#bools-fail {
- and: false and two;
- and: one and two;
- and: one and false;
-
- or: false or two;
- or: one or two;
- or: one or false;
-}
-
-#bools {
- and: (false and two);
- and: (one and two);
- and: (one and false);
-
- or: (false or two);
- or: (one or two);
- or: (one or false);
-}
-
-
-#nots-fail {
- not: not true + 2;
- not: not false;
- not: not 0;
- not: not 1;
- not: not "";
- not: not hello;
-}
-
-#nots {
- not: (not true) + 2;
- not: (not false);
- not: (not 0);
- not: (not 1);
- not: (not "");
- not: (not hello);
-}
-
-#string-test {
- str: hi == "hi";
- str: hi == "no";
- str: 'yes' == 'yes';
-
- $var1: "hello";
- $var2: hello;
-
- str: "#{$var1}" == '#{$var2}';
-
- str: xhello#{$var1}x == "x#{$var2}hellox"; // xhellohellofalse
-
- str: unit(10px) == px;
-}
-
-
-#special {
- cancel-unit: (10px / 10px);
-}
-
-
diff --git a/lib/scssphp/tests/inputs/parsing_comments.scss b/lib/scssphp/tests/inputs/parsing_comments.scss
deleted file mode 100755
index ce58d79..0000000
--- a/lib/scssphp/tests/inputs/parsing_comments.scss
+++ /dev/null
@@ -1,59 +0,0 @@
-/* comment 1 */
-a {
- /* comment 2 */
- color: red; /* comment 3 */
- /* comment 4 */
-}
-/* comment 5 */
-
-/*! comment 1 */
-b {
- /*! comment 2 */
- color: red; /*! comment 3 */
- /*! comment 4 */
-}
-/*! comment 5 */
-
-/*
- * multi-line comment 1
- */
-c {
- /*
- * multi-line comment 2
- */
- color: red; /*
- * multi-line comment 3
- */
- /*
- * multi-line comment 4
- */
-}
-/*
- * multi-line comment 5
- */
-
-/*!
- * multi-line comment 1
- */
-d {
- /*!
- * multi-line comment 2
- */
- color: red; /*!
- * multi-line comment 3
- */
- /*!
- * multi-line comment 4
- */
-}
-/*!
- * multi-line comment 5
- */
-
-// comment 1
-e {
- // comment 2
- color: red; // comment 3
- // comment 4
-}
-// comment 5
diff --git a/lib/scssphp/tests/inputs/placeholder_selector.scss b/lib/scssphp/tests/inputs/placeholder_selector.scss
deleted file mode 100755
index da3cda1..0000000
--- a/lib/scssphp/tests/inputs/placeholder_selector.scss
+++ /dev/null
@@ -1,18 +0,0 @@
-#context a%extreme span {
- color: blue;
- font-weight: bold;
- font-size: 2em;
-}
-
-.notice, .error { @extend %extreme; }
-
-.hidden %placeholder {
- margin: 0;
-}
-
-p {
- @extend #context;
- padding: 2em;
-}
-
-div { @extend .hidden; }
\ No newline at end of file
diff --git a/lib/scssphp/tests/inputs/scss_css.scss b/lib/scssphp/tests/inputs/scss_css.scss
deleted file mode 100755
index 03d63d0..0000000
--- a/lib/scssphp/tests/inputs/scss_css.scss
+++ /dev/null
@@ -1,986 +0,0 @@
-[foo~=bar] {
- a: b; }
-
-
-[foo^=bar] {
- a: b; }
-
-
-[foo$=bar] {
- a: b; }
-
-
-[foo*=bar] {
- a: b; }
-
-
-[foo|=en] {
- a: b; }
-
-
-foo {
- a: 2;
- b: 2.3em;
- c: 50%;
- d: "fraz bran";
- e: flanny-blanny-blan;
- f: url(http://sass-lang.com);
- // g: U+ffa?;
- h: #aabbcc; }
-
-
-selector {
- property: value;
- property2: value; }
-
-
-sel{p:v}
-
-.foo {
- /* Foo
-Bar
- Baz */
- a: b; }
-
-
-.foo {
- /* Foo
-Bar
- Baz */
- a: b; }
-
-
-.foo {/* Foo
- Bar */
- a: b; }
-
-
-.foo {/* Foo
- Bar
- Baz */
- a: b; }
-
-
-@foo {
- rule {
- a: b; }
-
- a: b; }
-
-
-@foo {a:b};
-@bar {a:b};
-
-
-@foo "bar"
-
-foo {
- a: 12px calc(100%/3 - 2*1em - 2*1px);
- b: 12px -moz-calc(100%/3 - 2*1em - 2*1px);
- b: 12px -webkit-calc(100%/3 - 2*1em - 2*1px);
- b: 12px -foobar-calc(100%/3 - 2*1em - 2*1px); }
-
-
-foo {bar: baz}
-
-baz {bar: baz}
-
-
-/*
- * foo
- */
-bar {baz: bang}
-
-
-E, F {
- a: b; }
-
-
-E F, G H {
- a: b; }
-
-
-E > F, G > H {
- a: b; }
-
-
-/* This is a CSS comment. */
-.one {color: green;} /* Another comment */
-/* The following should not be used:
-.two {color: red;} */
-.three {color: green; /* color: red; */}
-/**
-.four {color: red;} */
-.five {color: green;}
-/**/
-.six {color: green;}
-/*********/
-.seven {color: green;}
-/* a comment **/
-.eight {color: green;}
-
-
-foo {
- a: \foo bar;
- b: foo\ bar;
- c: \2022 \0020;
- d: foo\\bar;
- e: foo\"\'bar; }
-
-
-foo {
- a: "\foo bar";
- b: "foo\ bar";
- c: "\2022 \0020";
- d: "foo\\bar";
- e: "foo\"'bar"; }
-
-
-foo {
- _name: val;
- *name: val;
- :name: val;
- .name: val;
- #name: val;
- name/**/: val;
- name/*\**/: val;
- name: val; }
-
-
-@foo "bar" ;
-
-foo {
- a: -moz-element(#foo);
- b: -webkit-element(#foo);
- b: -foobar-element(#foo); }
-
-
-@foo {}
-
-@foo {
-}
-
-
-@foo;
-
-foo {;;;;
- bar: baz;;;;
- ;;}
-
-
-#foo .bar {}
-
-#foo .bar {
-}
-
-
-0% {
- a: b; }
-
-
-60% {
- a: b; }
-
-
-100% {
- a: b; }
-
-
-12px {
- a: b; }
-
-
-"foo" {
- a: b; }
-
-
-foo {
- a: 12px expression(1 + (3 / Foo.bar("baz" + "bang") + function() {return 12;}) % 12); }
-
-
-:foo("bar") {
- a: b; }
-
-
-:foo(bar) {
- a: b; }
-
-
-:foo(12px) {
- a: b; }
-
-
-:foo(+) {
- a: b; }
-
-
-:foo(-) {
- a: b; }
-
-
-:foo(+"bar") {
- a: b; }
-
-
-:foo(-++--baz-"bar"12px) {
- a: b; }
-
-
-foo {
- a: foo-bar(12);
- b: -foo-bar-baz(13, 14 15); }
-
-
-@import "foo.css";
-
-@import 'foo.css';
-
-@import url("foo.css");
-
-@import url('foo.css');
-
-@import url(foo.css);
-
-@import "foo.css" screen;
-
-@import "foo.css" screen, print;
-
-@import "foo.css" screen, print and (foo: 0);
-
-@import "foo.css" screen, only print, screen and (foo: 0);
-
-foo {
- a: foo !important;
- b: foo bar !important;
- b: foo, bar !important; }
-
-
-foo {
- a: -moz-bar-baz;
- b: foo -o-bar-baz; }
-
-
-foo {a: /* b; c: */ d}
-
-
-foo {a /*: b; c */: d}
-
-
-/* Foo
- * Bar */
-
-
-.foo {
- /* Foo
- * Bar */ }
-
-
-[foo] {
- a: b; }
-
-
-[foo="bar"] {
- a: b; }
-
-
-[foo~="bar"] {
- a: b; }
-
-
-[foo^="bar"] {
- a: b; }
-
-
-[foo$="bar"] {
- a: b; }
-
-
-[foo*="bar"] {
- a: b; }
-
-
-[foo|="en"] {
- a: b; }
-
-
-:root {
- a: b; }
-
-
-:nth-child(n) {
- a: b; }
-
-
-:nth-last-child(n) {
- a: b; }
-
-
-:nth-of-type(n) {
- a: b; }
-
-
-:nth-last-of-type(n) {
- a: b; }
-
-
-:first-child {
- a: b; }
-
-
-:last-child {
- a: b; }
-
-
-:first-of-type {
- a: b; }
-
-
-:last-of-type {
- a: b; }
-
-
-:only-child {
- a: b; }
-
-
-:only-of-type {
- a: b; }
-
-
-:empty {
- a: b; }
-
-
-:link {
- a: b; }
-
-
-:visited {
- a: b; }
-
-
-:active {
- a: b; }
-
-
-:hover {
- a: b; }
-
-
-:focus {
- a: b; }
-
-
-:target {
- a: b; }
-
-
-:lang(fr) {
- a: b; }
-
-
-:enabled {
- a: b; }
-
-
-:disabled {
- a: b; }
-
-
-:checked {
- a: b; }
-
-
-::first-line {
- a: b; }
-
-
-::first-letter {
- a: b; }
-
-
-::before {
- a: b; }
-
-
-::after {
- a: b; }
-
-
-.warning {
- a: b; }
-
-
-#myid {
- a: b; }
-
-
-:not(s) {
- a: b; }
-
-
-@media all {
- rule1 {
- prop: val; }
-
- rule2 {
- prop: val; } }
-
-
-@media screen, print {
- rule1 {
- prop: val; }
-
- rule2 {
- prop: val; } }
-
-
-@media screen and (-webkit-min-device-pixel-ratio:0) {
- a: b; }
-
-
-@media only screen, print and (foo: 0px) and (bar: flam(12px solid)) {
- a: b; }
-
-
-:-moz-any(h1, h2, h3) {
- a: b; }
-
-
-:-moz-any(.foo) {
- a: b; }
-
-
-:-moz-any(foo bar, .baz > .bang) {
- a: b; }
-
-
-@-moz-document url(http://www.w3.org/),
- url-prefix(http://www.w3.org/Style/),
- domain(mozilla.org),
- regexp("^https:.*") {
- .foo {a: b}
-}
-
-
-foo {
- filter: progid:DXImageTransform.Microsoft.gradient(GradientType=1, startColorstr=#c0ff3300, endColorstr=#ff000000);
- filter:progid:DXImageTransform.Microsoft.gradient(GradientType=1, startColorstr=#c0ff3300, endColorstr=#ff000000); }
-
-
-foo {
- filter: alpha(opacity=20);
- filter: alpha(opacity=20, enabled=true);
- filter: blaznicate(foo=bar, baz=bang bip, bart=#fa4600); }
-
-
-@foo bar {
- a: b; }
-
-@bar baz {
- c: d; }
-
-
-@foo bar;
-@bar baz;
-
-
-/* Foo
- * Bar */
-/* Baz
- * Bang */
-
-
-.foo {
- /* Foo
- * Bar */
- /* Baz
- * Bang */ }
-
-
-.foo {
- /* Foo Bar *//* Baz Bang */ }
-
-
-@namespace "http://www.w3.org/Profiles/xhtml1-strict";
-
-@namespace url(http://www.w3.org/Profiles/xhtml1-strict);
-
-@namespace html url("http://www.w3.org/Profiles/xhtml1-strict");
-
-[foo|bar=baz] {
- a: b; }
-
-
-[*|bar=baz] {
- a: b; }
-
-
-[foo|bar|=baz] {
- a: b; }
-
-
-foo|E {
- a: b; }
-
-
-*|E {
- a: b; }
-
-
-foo|* {
- a: b; }
-
-
-*|* {
- a: b; }
-
-
-:not(foo|bar) {
- a: b; }
-
-
-:not(*|bar) {
- a: b; }
-
-
-:not(foo|*) {
- a: b; }
-
-
-:not(*|*) {
- a: b; }
-
-
-:not(#blah) {
- a: b; }
-
-
-:not(.blah) {
- a: b; }
-
-
-:not([foo]) {
- a: b; }
-
-
-:not([foo^="bar"]) {
- a: b; }
-
-
-:not([baz|foo~="bar"]) {
- a: b; }
-
-
-:not(:hover) {
- a: b; }
-
-
-:not(:nth-child(2n + 3)) {
- a: b; }
-
-
-:not(:not(#foo)) {
- a: b; }
-
-
-:not(a#foo.bar) {
- a: b; }
-
-
-:not(#foo .bar > baz) {
- a: b; }
-
-
-:not(h1, h2, h3) {
- a: b; }
-
-
-@mixin foo {
- a: b; }
-
-
-foo {
- a: "bang #{1 + " bar "} bip"; }
-
-
-:nth-child(-n) {
- a: b; }
-
-
-:nth-child(+n) {
- a: b; }
-
-
-:nth-child(even) {
- a: b; }
-
-
-:nth-child(odd) {
- a: b; }
-
-
-:nth-child(50) {
- a: b; }
-
-
-:nth-child(-50) {
- a: b; }
-
-
-:nth-child(+50) {
- a: b; }
-
-
-:nth-child(2n+3) {
- a: b; }
-
-
-:nth-child(2n-3) {
- a: b; }
-
-
-:nth-child(+2n-3) {
- a: b; }
-
-
-:nth-child(-2n+3) {
- a: b; }
-
-
-:nth-child(-2n+ 3) {
- a: b; }
-
-
-:nth-child( 2n + 3 ) {
- a: b; }
-
-
-foo {
- a: foo bar baz;
- b: foo, #aabbcc, -12;
- c: 1px/2px/-3px;
- d: foo bar, baz/bang; }
-
-
-@page {
- prop1: val;
- prop2: val; }
-
-
-@page flap {
- prop1: val;
- prop2: val; }
-
-
-@page :first {
- prop1: val;
- prop2: val; }
-
-
-@page flap:first {
- prop1: val;
- prop2: val; }
-
-
-.foo {
- /* Foo */
- a: b; }
-
-
-.foo {
- /* Foo
- * Bar */a: b; }
-
-
-/* Foo */
-.foo {
- a: b; }
-
-
-/* Foo
- * Bar */.foo {
- a: b; }
-
-
-.foo /* .a #foo */ #bar:baz(/* bang )*/ bip) {
- a: b; }
-
-
-> E {
- a: b; }
-
-
-+ E {
- a: b; }
-
-
-~ E {
- a: b; }
-
-
-> > E {
- a: b; }
-
-
->> E {
- a: b; }
-
-
-E* {
- a: b; }
-
-
-E*.foo {
- a: b; }
-
-
-E*:hover {
- a: b; }
-
-
-E,
-F {
- a: b; }
-
-
-E
-F {
- a: b; }
-
-
-E, F
-G, H {
- a: b; }
-
-
-body {
- /*
- //comment here
- */
-}
-
-
-E>F { a: b;}
-
-E~F { a: b;}
-
-E+F { a: b;}
-
-* {
- a: b; }
-
-
-E {
- a: b; }
-
-
-E[foo] {
- a: b; }
-
-
-E[foo="bar"] {
- a: b; }
-
-
-E[foo~="bar"] {
- a: b; }
-
-
-E[foo^="bar"] {
- a: b; }
-
-
-E[foo$="bar"] {
- a: b; }
-
-
-E[foo*="bar"] {
- a: b; }
-
-
-E[foo|="en"] {
- a: b; }
-
-
-E:root {
- a: b; }
-
-
-E:nth-child(n) {
- a: b; }
-
-
-E:nth-last-child(n) {
- a: b; }
-
-
-E:nth-of-type(n) {
- a: b; }
-
-
-E:nth-last-of-type(n) {
- a: b; }
-
-
-E:first-child {
- a: b; }
-
-
-E:last-child {
- a: b; }
-
-
-E:first-of-type {
- a: b; }
-
-
-E:last-of-type {
- a: b; }
-
-
-E:only-child {
- a: b; }
-
-
-E:only-of-type {
- a: b; }
-
-
-E:empty {
- a: b; }
-
-
-E:link {
- a: b; }
-
-
-E:visited {
- a: b; }
-
-
-E:active {
- a: b; }
-
-
-E:hover {
- a: b; }
-
-
-E:focus {
- a: b; }
-
-
-E:target {
- a: b; }
-
-
-E:lang(fr) {
- a: b; }
-
-
-E:enabled {
- a: b; }
-
-
-E:disabled {
- a: b; }
-
-
-E:checked {
- a: b; }
-
-
-E::first-line {
- a: b; }
-
-
-E::first-letter {
- a: b; }
-
-
-E::before {
- a: b; }
-
-
-E::after {
- a: b; }
-
-
-E.warning {
- a: b; }
-
-
-E#myid {
- a: b; }
-
-
-E:not(s) {
- a: b; }
-
-
-E F {
- a: b; }
-
-
-E > F {
- a: b; }
-
-
-E + F {
- a: b; }
-
-
-E ~ F {
- a: b; }
-
-
-@supports (a: b) and (c: d) or (not (d: e)) and ((not (f: g)) or (not ((h: i) and (j: k)))) {
- .foo {
- a: b;
- }
-}
-
-
-@-prefix-supports (a: b) and (c: d) or (not (d: e)) and ((not (f: g)) or (not ((h: i) and (j: k)))) {
- .foo {
- a: b;
- }
-}
-
-
-foo {
- foo: bar;
- #baz: bang;
- #bip: bop; }
-
-
-foo {
- a: -2;
- b: -2.3em;
- c: -50%;
- d: -foo(bar baz); }
-
-
-foo {
- a: -0.5em;
- b: +0.5em;
- c: -foo(12px);
- d: +foo(12px);
- }
-
-
-@charset "UTF-8";
-
-foo {
- -moz-foo-bar: blat;
- -o-flat-blang: wibble; }
-
-
-foo {
- a: foo();
- b: bar baz-bang() bip; }
-
-
diff --git a/lib/scssphp/tests/inputs/selectors.scss b/lib/scssphp/tests/inputs/selectors.scss
deleted file mode 100755
index a0e7bbf..0000000
--- a/lib/scssphp/tests/inputs/selectors.scss
+++ /dev/null
@@ -1,195 +0,0 @@
-* { color: blue; }
-E { color: blue; }
-
-E:not(:link) { color: blue; }
-E:not(:link):not(:visited) { color: blue; }
-E:not(:link, :visited) { color: blue; }
-E:matches(:hover, :focus) { color: blue; }
-
-E.warning { color: blue; }
-E#id { color: blue; }
-E[foo] { color: blue; }
-E[foo="barbar"] { color: blue; }
-E[foo="barbar" i] { color: blue; }
-E[foo~="hello#$@%@$#^"] { color: blue; }
-E[foo^="color: green;"] { color: blue; }
-E[foo$="239023"] { color: blue; }
-E[foo*="29302"] { color: blue; }
-E[foo|="239032"] { color: blue; }
-
-[foo] { color: blue; }
-[foo] .helloWorld { color: blue; }
-[foo].helloWorld { color: blue; }
-[foo="barbar"] { color: blue; }
-[foo~="hello#$@%@$#^"] { color: blue; }
-[foo^="color: green;"] { color: blue; }
-[foo$="239023"] { color: blue; }
-[foo*="29302"] { color: blue; }
-[foo|="239032"] { color: blue; }
-
-E:dir(ltr) { color: blue; }
-E:lang(en) { color: blue; }
-E:lang(en, fr) { color: blue; }
-
-E:any-link { color: blue; }
-E:link { color: blue; }
-E:visited { color: blue; }
-E:local-link { color: blue; }
-E:local-link(0) { color: red; }
-E:local-link(1) { color: white; }
-E:local-link(2) { color: red; }
-E:target { color: blue; }
-E:scope { color: blue; }
-
-E:current { color: blue; }
-E:current(:link) { color: blue; }
-E:past { color: blue; }
-E:future { color: blue; }
-
-E:active { color: blue; }
-E:hover { color: blue; }
-E:focus { color: blue; }
-E:enabled { color: blue; }
-E:disabled { color: blue; }
-E:indeterminate { color: blue; }
-E:default { color: blue; }
-E:in-range { color: blue; }
-E:out-of-range { color: blue; }
-E:required { color: blue; }
-E:optional { color: blue; }
-E:read-only { color: blue; }
-E:read-write { color: blue; }
-
-E:root { color: blue; }
-E:empty { color: blue; }
-E:first-child { color: blue; }
-E:nth-child(odd) { color: blue; }
-E:nth-child(2n+1) { color: blue; }
-E:nth-child(5) { color: blue; }
-E:last-child { color: blue; }
-E:nth-last-child(-n+2) { color: blue; }
-E:only-child { color: blue; }
-E:first-of-type { color: blue; }
-E:nth-of-type(2n) { color: blue; }
-E:last-of-type { color: blue; }
-E:nth-last-of-type(n) { color: blue; }
-E:only-of-type { color: blue; }
-E:nth-match(odd) { color: blue; }
-E:nth-last-match(odd) { color: blue; }
-
-E:column(n) { color: blue; }
-E:nth-column(n) { color: blue; }
-E:nth-last-column(n) { color: blue; }
-
-E F { color: blue; }
-E > F { color: blue; }
-E + F { color: blue; }
-E ~ F { color: blue; }
-E /foo/ F { color: blue; }
-E! > F { color: blue; }
-
-// namespaces
-[foo|att=val] { color: blue }
-[*|att] { color: yellow }
-[|att] { color: green }
-[att] { color: green }
-
-// CSS2.1
-E::first-line { color: blue; }
-E::first-letter { color: blue; }
-E::before { color: blue; }
-E::after { color: blue; }
-
-// CSS3 UI (at risk)
-E::choices { color: blue; }
-E::value { color: blue; }
-E::repeat-index { color: blue; }
-E::repeat-item { color: blue; }
-
-E:first { color: blue; }
-E:first-line { color: blue; }
-E:first-letter { color: blue; }
-E:before{ color: blue; }
-E:after { color: blue; }
-E:checked { color: blue; }
-E:invalid { color: blue; }
-E:valid { color: blue; }
-E:left { color: blue; }
-E:right { color: blue; }
-
-// -moz experimental
-E:any(ol) { color: blue; }
-E::selection { color: blue; }
-
-// one of these is nested property,
-// the other is a css block.
-div {
- font:something {
- size: 30em;
- }
-
- font: something {
- size: 30em;
- }
-
-}
-
-// self selector
-
-.something {
- &.world {
- color: blue;
- }
-
- & .mold {
- height: 200px;
- }
-
- .dog & {
- color: blue;
- }
-}
-
-.simple {
- .dad & .wolf {
- color: blue;
- }
-
- .rad&.bad {
- color: blue;
- }
-
-}
-
-div {
- .something & .what {
- &.world {
- color: blue;
- }
- }
-}
-
-div {
- &.foo & {
- color: blue;
- }
-}
-
-.main, div {
- .message div {
- .title {
- .nice-fonts & {
- font-size: 24px;
- }
- }
- }
-}
-
-$name: escape;
-.#{$name}\% {
- color: red;
-}
-
-.escape-plan\% {
- color: green;
-}
diff --git a/lib/scssphp/tests/inputs/values.scss b/lib/scssphp/tests/inputs/values.scss
deleted file mode 100755
index 45123a5..0000000
--- a/lib/scssphp/tests/inputs/values.scss
+++ /dev/null
@@ -1,43 +0,0 @@
-
-#values {
- color: #eee;
- color: #eeeeee;
- height: 20px;
- width: 80%;
- color: "hello world";
- height: url("http://google.com");
- dads: url(http://leafo.net);
- padding: 10px 10px 10px 10px, 3px 3px 3px;
- textblock: "This is a \
-multiline block \
-#not { color: #eee;}";
- margin: 4,3,1;
- content: "This is a \
-multiline string.";
- border-radius: -1px -1px -1px black;
-}
-
-#subtraction {
- lit: 10 -11;
- lit: 10 - 11;
- lit: 10- 11;
- lit: 10-11;
-
- $num: 100;
- var: 10 -$num;
- var: 10 - $num;
- var: 10- $num;
- var: 10-$num;
-}
-
-
-#special {
- a: 12px expression(1 + (3 / Foo.bar("baz" + "bang") + function() {return 12;}) % 12);
-}
-
-#unary {
- b: +0.5em;
- c: -foo(12px);
- d: +foo(12px);
-}
-
diff --git a/lib/scssphp/tests/inputs/variables.scss b/lib/scssphp/tests/inputs/variables.scss
deleted file mode 100755
index bebd4dc..0000000
--- a/lib/scssphp/tests/inputs/variables.scss
+++ /dev/null
@@ -1,56 +0,0 @@
-
-$color: red, two, three;
-
-div {
- height: $color;
-}
-
-$a: 1000;
-
-div {
- $a: 2000 !default;
- num: $a;
-}
-
-div {
- $b: 2000 !default;
- num: $b;
-}
-
-$cool_color: null;
-$cool_color: blue !default;
-
-pre {
- color: $cool_color;
-}
-
-$something_man: 100px;
-cool: $something_man;
-
-
-del {
- $something: blue;
-
- div {
- $something: red;
- pre {
- color: $something;
- }
- }
-
- color: $something;
-}
-
-$font-family-simple: Arial !default;
-$font-family-spaces: Helvetica Neue !default;
-$font-family-quotes: "Helvetica Neue" !default;
-$font-family-commas: Helvetica, Arial, sans-serif !default;
-$font-family-sans: "Helvetica Neue", Helvetica, Arial, sans-serif !default;
-
-body {
- font-family: $font-family-simple;
- font-family: $font-family-spaces;
- font-family: $font-family-quotes;
- font-family: $font-family-commas;
- font-family: $font-family-sans;
-}
diff --git a/lib/scssphp/tests/outputs/builtins.css b/lib/scssphp/tests/outputs/builtins.css
deleted file mode 100755
index b7884c2..0000000
--- a/lib/scssphp/tests/outputs/builtins.css
+++ /dev/null
@@ -1,126 +0,0 @@
-#color {
- color: #22ea18;
- red: 34;
- green: 234;
- blue: 24;
- color: rgba(1, 2, 4, 0.5);
- a1: 1;
- a2: 0.5;
- mix: #020304;
- rgba: rgba(170, 119, 204, 0.4);
- rgba: rgba(170, 119, 204, 0.4); }
-
-#hsl {
- color: #79c653;
- color: rgba(121, 198, 83, 0.5);
- hue: 100deg;
- sat: 50%;
- lig: 55%; }
-
-#more-color {
- light: #7e3d9e;
- dark: #432154;
- sat: #632782;
- desat: #5e3871;
- gray: #545454;
- comp: #48792f;
- inv: #9fd086; }
-
-#more-more-color {
- op: 0.5;
- opacify: rgba(1, 2, 3, 0.6);
- opacify: rgba(1, 2, 3, 0.6);
- transparentize: rgba(1, 2, 3, 0.4);
- transparentize: rgba(1, 2, 3, 0.4);
- transparentize: rgba(52, 130, 3, 0.9); }
-
-#more-more-more-color {
- color: rgba(65, 110, 79, 0.4);
- color: rgba(20, 255, 216, 0);
- color: rgba(55, 100, 69, 0.4);
- color: rgba(0, 255, 213, 0);
- color: rgba(145, 10, 10, 0);
- color: rgba(5, 10, 10, 0);
- color: rgba(145, 145, 145, 0);
- color: rgba(5, 5, 5, 0);
- color: #000A0A0A;
- color: #FFAABBCC; }
-
-#string {
- color: hello what is going on;
- color: "yeah";
- color: "I do?"; }
-
-#number {
- color: 250%;
- color: 3;
- color: 3;
- color: 4;
- top: 10px;
- top: 1ex;
- width: 200%;
- bottom: 10px;
- padding: 3em 1in 96px 72pt; }
-
-#list {
- len: 3;
- len: 1;
- n: hello;
- hello: one, two, three, hello;
- hello: one, two, three, hello, world, what, is, going;
- hello: one, two, three, hello;
- index: 2;
- index: false;
- index: 3;
- index: 1;
- index: false;
- index: 1;
- index: false;
- index: 2;
- index: 2;
- index: 1;
- world: one, two, three, great, job;
- world: one, two, three, great job;
- cool: one two three great job;
- cool: great job one two three;
- zip: 1px solid, 2px dashed;
- zip: 1px solid red, 2px dashed green; }
-
-#introspection {
- t: number;
- t: string;
- t: string;
- t: bool;
- t: color;
- t: color;
- t: list;
- u: "";
- u: "px";
- u: "em";
- l: true;
- l: false;
- c: true;
- c: false;
- c: true;
- c: true;
- c: false;
- c: true; }
-
-#if {
- color: yes;
- color: no;
- color: yes;
- color: yes; }
-
-.transparent {
- r: 0;
- g: 0;
- b: 0;
- a: 0; }
-
-.alpha {
- a: 1;
- a: 1;
- a: 1;
- a: 0.5;
- a: alpha(currentColor); }
diff --git a/lib/scssphp/tests/outputs/comments.css b/lib/scssphp/tests/outputs/comments.css
deleted file mode 100755
index 6535554..0000000
--- a/lib/scssphp/tests/outputs/comments.css
+++ /dev/null
@@ -1,31 +0,0 @@
-/** what the heck **/
-/**
- Here is a block comment
- **/
-/*hello*/
-div {
- /*yeah*/
- border: 1px solid red;
- /* another property */
- color: url('http://mage-page.com');
- string: "hello /* this is not a comment */";
- world: "// neither is this";
- string: 'hello /* this is not a comment */';
- /*what if this is a comment */
- world: '// neither is this';
- what-ever: 100px;
- background: url();
- /*this is not a comment?*/ }
-
-.dummy {
- color: blue; }
-/* comment 1 */
-a {
- /* comment 2 */
- /* comment 3 */
- color: red;
- /* comment 4 */
- background-color: red;
- /* comment 5 */
- /* comment 6 */ }
-/* comment 7 */
diff --git a/lib/scssphp/tests/outputs/compass_extract.css b/lib/scssphp/tests/outputs/compass_extract.css
deleted file mode 100755
index 8ae7f37..0000000
--- a/lib/scssphp/tests/outputs/compass_extract.css
+++ /dev/null
@@ -1,28 +0,0 @@
-#test-0 {
- unit: false;
- unit: true;
- rhythm: 1.5em;
- size: 1;
- size: 1;
- size: 1;
- size: 2;
- size: 2; }
-
-#test-1 {
- margin-top: 7.5em;
- padding-top: 9em;
- padding-bottom: 10.5em;
- margin-bottom: 0em; }
-
-#test-2 {
- border-style: solid;
- border-width: 0.0625em;
- padding: 1.4375em; }
-
-#test-3 {
- border-top-style: solid;
- border-top-width: 0.0625em;
- padding-top: 1.4375em;
- border-bottom-style: solid;
- border-bottom-width: 0.0625em;
- padding-bottom: 1.4375em; }
diff --git a/lib/scssphp/tests/outputs/content.css b/lib/scssphp/tests/outputs/content.css
deleted file mode 100755
index 6657a21..0000000
--- a/lib/scssphp/tests/outputs/content.css
+++ /dev/null
@@ -1,29 +0,0 @@
-* html #logo {
- background-image: url(/logo.gif); }
-
-.colors {
- background-color: blue;
- color: white;
- border-color: blue; }
-
-@media only screen and (max-width: 480px) {
- body {
- color: red; } }
-
-#sidebar {
- width: 300px; }
- @media only screen and (max-width: 480px) {
- #sidebar {
- width: 100px; } }
-
-@media only screen and (min-width: 40em) {
- .grid-1 {
- width: 100%; }
- .grid-2 {
- width: 100%; } }
-
-@media only screen and (min-width: 40em) {
- .grid-1 {
- width: 100%; }
- .grid-2 {
- width: 100%; } }
diff --git a/lib/scssphp/tests/outputs/content_with_function.css b/lib/scssphp/tests/outputs/content_with_function.css
deleted file mode 100755
index 185fe66..0000000
--- a/lib/scssphp/tests/outputs/content_with_function.css
+++ /dev/null
@@ -1,2 +0,0 @@
-body {
- padding: 1 px; }
diff --git a/lib/scssphp/tests/outputs/default_args.css b/lib/scssphp/tests/outputs/default_args.css
deleted file mode 100755
index 19379e0..0000000
--- a/lib/scssphp/tests/outputs/default_args.css
+++ /dev/null
@@ -1,3 +0,0 @@
-div {
- height: red;
- margin: 100px; }
diff --git a/lib/scssphp/tests/outputs/directives.css b/lib/scssphp/tests/outputs/directives.css
deleted file mode 100755
index 2b71558..0000000
--- a/lib/scssphp/tests/outputs/directives.css
+++ /dev/null
@@ -1,77 +0,0 @@
-@charset "hello-world";
-@page :left {
- div {
- color: red; } }
-
-@page test {
- @media yes {
- div {
- color: red; } } }
-
-@media something {
- @page {
- @media else {
- div {
- height: 200px; } } } }
-
-div {
- color: red; }
- @page yeah {
- div pre {
- height: 20px; } }
-
-@font-face {
- color: red;
- height: 20px; }
-
-@keyframes 'bounce' {
- from {
- top: 100px;
- animation-timing-function: ease-out; }
-
- 25% {
- top: 50px;
- animation-timing-function: ease-in; }
-
- 50% {
- top: 100px;
- animation-timing-function: ease-out; }
-
- 75% {
- top: 75px;
- animation-timing-function: ease-in; }
-
- to {
- top: 100px; } }
-
-@-webkit-keyframes flowouttoleft {
- 0% {
- -webkit-transform: translateX(0) scale(1); }
-
- 60%, 70% {
- -webkit-transform: translateX(0) scale(0.7); }
-
- 100% {
- -webkit-transform: translateX(-100%) scale(0.7); } }
-
-div {
- animation-name: 'diagonal-slide';
- animation-duration: 5s;
- animation-iteration-count: 10; }
-
-@keyframes 'diagonal-slide' {
- from {
- left: 0;
- top: 0; }
-
- to {
- left: 100px;
- top: 100px; } }
-
-@document url(http://www.w3.org/),
- url-prefix(http://www.w3.org/Style/),
- domain(mozilla.org),
- regexp("https:.*") {
- body {
- color: purple;
- background: yellow; } }
diff --git a/lib/scssphp/tests/outputs/extends.css b/lib/scssphp/tests/outputs/extends.css
deleted file mode 100755
index e40cd86..0000000
--- a/lib/scssphp/tests/outputs/extends.css
+++ /dev/null
@@ -1,87 +0,0 @@
-error, pre seriousError, span seriousError, other, hello {
- border: 1px #f00;
- background-color: #fdd; }
-
-pre seriousError, span seriousError {
- font-size: 20px; }
-
-hello {
- color: green; }
- hello div {
- margin: 10px; }
-
-.cool, .me {
- color: red; }
-
-.blue, .me {
- color: purple; }
-
-a:hover, .hoverlink, #demo .overview .fakelink:hover {
- text-decoration: underline; }
-
-div.hello.world.hmm, pre div.okay.span.world.hmm, pre #butt .umm div.sure.span.world.hmm, #butt .umm pre div.sure.span.world.hmm, code div.okay.span.world.hmm, code #butt .umm div.sure.span.world.hmm, #butt .umm code div.sure.span.world.hmm {
- color: blue; }
-
-.xxxxx .xxxxx .xxxxx, code .xxxxx .xxxxx, code code .xxxxx, code code code, code .xxxxx code, .xxxxx code .xxxxx, .xxxxx code code, .xxxxx .xxxxx code {
- color: green; }
-
-code {
- color: red; }
-
-.alpha, .beta, .gama {
- color: red; }
-
-.beta, .gama {
- color: white; }
-
-.gama {
- color: blue; }
-
-#admin .tabbar a, #admin .tabbar #demo .overview .fakelink, #demo .overview #admin .tabbar .fakelink {
- font-weight: bold; }
-
-a1 b1 c1 d1, x1 y1 z1 w1 b1 c1 d1 {
- color: red; }
-
-a2 b2 c2 d2, a2 x2 y2 z2 w2 c2 d2, x2 y2 z2 a2 w2 c2 d2 {
- color: red; }
-
-a3 b3 c3 d3, a3 b3 x3 y3 z3 w3 d3, x3 y3 z3 a3 b3 w3 d3 {
- color: red; }
-
-a4 b4 c4 d4, a4 b4 c4 x4 y4 z4 w4, x4 y4 z4 a4 b4 c4 w4 {
- color: red; }
-
-#butt .yeah .okay, #butt .yeah .umm .sure, #butt .umm .yeah .sure {
- font-weight: bold; }
-
-a9 b9 s9 t9 v9, a9 b9 s9 t9 x9 y9 z9, a9 b9 x9 y9 s9 t9 z9 {
- color: red; }
-
-@media print {
- horse, man {
- color: blue; } }
-
-man {
- color: red; }
-
-wassup {
- color: blue; }
-
-.foo .wassup {
- color: blue; }
-
-#something, .x, .y {
- color: red; }
-
-.nav-justified, .nav-tabs.nav-justified {
- text-align: justify; }
-
-.btn:hover, .edit .actions button:hover, .edit .new .actions button:hover, .btn:active, .edit .actions button:active, .edit .new .actions button:active, .btn.active, .edit .actions button.active, .edit .new .actions button.active, .btn.disabled, .edit .actions button.disabled, .edit .new .actions button.disabled, .btn[disabled], .edit .actions button[disabled], .edit .new .actions button[disabled] {
- color: red; }
-
-.edit .actions button {
- float: right; }
-
-.edit .new .actions {
- padding: 0; }
diff --git a/lib/scssphp/tests/outputs/filter_effects.css b/lib/scssphp/tests/outputs/filter_effects.css
deleted file mode 100755
index 7d0bee8..0000000
--- a/lib/scssphp/tests/outputs/filter_effects.css
+++ /dev/null
@@ -1,20 +0,0 @@
-#number {
- -webkit-filter: grayscale(1) sepia(0.5) saturate(0.1) invert(1) opacity(0.5) brightness(0.5) contrast(0.5); }
-
-#percentage {
- -webkit-filter: grayscale(100%) sepia(50%) saturate(10%) invert(100%) opacity(50%) brightness(50%) contrast(50%); }
-
-#misc {
- -webkit-filter: hue-rotate(90deg) blur(10px) drop-shadow(10px -16px 30px purple); }
-
-#decimal {
- opacity: 0.5;
- filter: alpha(opacity=50, style=1); }
-
-#percent {
- opacity: 0.5;
- filter: alpha(opacity=50); }
-
-.row {
- background-color: #071c23;
- color: #2284a1; }
diff --git a/lib/scssphp/tests/outputs/functions.css b/lib/scssphp/tests/outputs/functions.css
deleted file mode 100755
index 0961f76..0000000
--- a/lib/scssphp/tests/outputs/functions.css
+++ /dev/null
@@ -1,25 +0,0 @@
-div {
- color: 14px;
- sum: 23; }
-
-div {
- hello: 10 55;
- hello: 1010 55;
- hello: "hello 10 and 55"; }
-
-del {
- color: 1000; }
-
-div {
- hello: "hello foo and bar";
- hello: "hello bar and default";
- hello: "hello Alice, Bob, Tom"; }
-
-.foo {
- test2: -moz-art; }
-
-div span {
- height: 3px; }
-
-div {
- width: 2; }
diff --git a/lib/scssphp/tests/outputs/ie7.css b/lib/scssphp/tests/outputs/ie7.css
deleted file mode 100755
index 7196fb1..0000000
--- a/lib/scssphp/tests/outputs/ie7.css
+++ /dev/null
@@ -1,8 +0,0 @@
-#foo:before {
- content: counter(item,".") ": "; }
-
-#bar:before {
- content: counter(item,"."); }
-
-#fu:before {
- content: counter(item); }
diff --git a/lib/scssphp/tests/outputs/if.css b/lib/scssphp/tests/outputs/if.css
deleted file mode 100755
index b9d0520..0000000
--- a/lib/scssphp/tests/outputs/if.css
+++ /dev/null
@@ -1,21 +0,0 @@
-div {
- color: blue; }
-
-pre {
- val-1: "red";
- val-2: "blue";
- val-3: "blue";
- val-4: "red";
- val-5: "red"; }
-
-span {
- color: blue;
- height: 10px;
- width: 20px; }
-
-div {
- color: blue;
- border-color: green; }
-
-del {
- thing: no; }
diff --git a/lib/scssphp/tests/outputs/if_on_null.css b/lib/scssphp/tests/outputs/if_on_null.css
deleted file mode 100755
index 2dfca95..0000000
--- a/lib/scssphp/tests/outputs/if_on_null.css
+++ /dev/null
@@ -1,2 +0,0 @@
-body {
- background-color: "red"; }
diff --git a/lib/scssphp/tests/outputs/import.css b/lib/scssphp/tests/outputs/import.css
deleted file mode 100755
index 1cd9b6b..0000000
--- a/lib/scssphp/tests/outputs/import.css
+++ /dev/null
@@ -1,27 +0,0 @@
-@import "foo.css";
-@import "foo" screen;
-@import "http://foo.com/bar";
-@import url(foo);
-div {
- height: 200px;
- color: red; }
-
-pre {
- color: red; }
- pre div {
- height: 200px;
- color: red; }
-
-code div {
- height: 200px;
- color: red; }
- code div {
- height: 200px;
- color: red; }
-
-#partial {
- color: blue; }
-
-body {
- color: #7c2;
- background: gray; }
diff --git a/lib/scssphp/tests/outputs/interpolation.css b/lib/scssphp/tests/outputs/interpolation.css
deleted file mode 100755
index 89dc81c..0000000
--- a/lib/scssphp/tests/outputs/interpolation.css
+++ /dev/null
@@ -1,54 +0,0 @@
-div {
- color: redwhite blue;
- color: red white blue;
- color: red whiteblue;
- color: redwhiteblue;
- color: ummyeahwhat;
- color: stacked;
- font-size: 10px/something;
- font-size: 10px / something;
- test: "whatworldwrong";
- test: "whatworldwrong";
- test: "whatworldwrong";
- test: "what"world"wrong";
- hi: "what is 16 end"; }
-
-pre var {
- color: red; }
- pre var dad {
- color: red; }
- pre bedvardad {
- color: red; }
-
-cool .thing-1 {
- color: red; }
- cool .thing-2 {
- color: red; }
- cool .thing-3 {
- color: red; }
- cool .thing-4 {
- color: red; }
- cool .thing-5 {
- color: red; }
-
-abcde {
- color: red; }
-
-#hello, .world {
- color: red; }
-
-#abchelloyeah, .coolworldyes {
- color: red; }
-
-div.element:nth-child(2n) {
- display: none; }
-
-div {
- hello: world;
- coolhello: world;
- helloone: world;
- twohelloone: world;
- oneabtwo: cool;
- hello-world: red;
- hello-mold: white;
- hello-hello: blue; }
diff --git a/lib/scssphp/tests/outputs/keyword_args.css b/lib/scssphp/tests/outputs/keyword_args.css
deleted file mode 100755
index 441c4ab..0000000
--- a/lib/scssphp/tests/outputs/keyword_args.css
+++ /dev/null
@@ -1,6 +0,0 @@
-pre {
- out: alpha fort three palace; }
-
-div {
- hello: 5;
- world: -5; }
diff --git a/lib/scssphp/tests/outputs/list.css b/lib/scssphp/tests/outputs/list.css
deleted file mode 100755
index 4e54729..0000000
--- a/lib/scssphp/tests/outputs/list.css
+++ /dev/null
@@ -1,7 +0,0 @@
-div {
- padding: 10px 20px 30px 40px;
- margin: 0 10px 10px 10px;
- background: linear-gradient(black, white); }
-
-p {
- background: linear-gradient(red, blue); }
diff --git a/lib/scssphp/tests/outputs/looping.css b/lib/scssphp/tests/outputs/looping.css
deleted file mode 100755
index db58f4a..0000000
--- a/lib/scssphp/tests/outputs/looping.css
+++ /dev/null
@@ -1,45 +0,0 @@
-div {
- color: what;
- color: is;
- color: this;
- font: what;
- font: is;
- font: this;
- background: what;
- background: is;
- background: this;
- border: what;
- border: is;
- border: this; }
-
-span {
- color: 0;
- color: 1;
- color: 2;
- color: 3;
- color: 4;
- color: 5;
- color: 6;
- color: 7;
- color: 8;
- color: 9;
- color: 10; }
-
-pre {
- color: 1;
- color: 2;
- color: 3;
- color: 4;
- height: 1;
- height: 2;
- height: 3;
- height: 4;
- height: 5;
- cool: 10;
- cool: 9;
- cool: 8;
- cool: 7;
- cool: 6;
- cool: 5;
- cool: 4;
- cool: 3; }
diff --git a/lib/scssphp/tests/outputs/media.css b/lib/scssphp/tests/outputs/media.css
deleted file mode 100755
index 6627652..0000000
--- a/lib/scssphp/tests/outputs/media.css
+++ /dev/null
@@ -1,103 +0,0 @@
-@media {
- div {
- color: blue; } }
-
-@media what {
- div {
- color: blue; } }
-
-@media (cool) {
- div {
- color: blue; } }
-
-@media (cool: blue) {
- div {
- color: blue; } }
-
-@media hello and (world) and (butt: man) {
- div {
- color: blue; } }
-
-@media (max-width: 940px) {
- color: red; }
-
-@media not hello and (world) {
- color: blue;
- pre {
- color: blue; } }
- @media butt and (world) {
- color: red;
- div {
- color: red; } }
-
-div {
- color: blue; }
- @media screen and (-webkit-min-device-pixel-ratio: 1.5) {
- div .sidebar {
- width: 500px; } }
-
-div {
- position: absolute; }
- @media screen {
- div {
- top: 0;
- bottom: 8em;
- color: red; }
- div p {
- margin: 5px; }
-
- div .success {
- color: green; } }
-
-.button {
- width: 300px;
- height: 100px;
- background: #eee; }
- .button :hover {
- background: #aaa; }
- @media only screen and (max-width: 300px) {
- .button {
- width: 100px;
- height: 100px; } }
-
-code {
- position: absolute; }
- @media screen {
- code {
- height: 10px; }
- code pre {
- height: 20px; } }
-
-@media screen and (color: blue) {
- dt {
- height: 10px; } }
-
-@media screen {
- .screen {
- width: 12px; } }
- @media only screen {
- .only-screen {
- height: 11px; } }
-
-@media only screen {
- .only-screen {
- width: 14px; } }
- @media only screen {
- .only-screen {
- height: 16px; } }
-
-@media print {
- .only-print {
- height: 12px; } }
-
-@media screen {
- .only-print {
- height: 12px; } }
-
-@media not screen {
- .not-screen {
- height: 15px; } }
-
-@media only screen and (color: blue) and (width: 13) {
- .only-screen {
- height: 15px; } }
diff --git a/lib/scssphp/tests/outputs/mixins.css b/lib/scssphp/tests/outputs/mixins.css
deleted file mode 100755
index 55feee4..0000000
--- a/lib/scssphp/tests/outputs/mixins.css
+++ /dev/null
@@ -1,93 +0,0 @@
-div {
- color: blue;
- color: red; }
- div pre {
- height: 200px; }
-
-span {
- color: blue; }
- span div {
- height: 20px; }
-
-html {
- height: 43px; }
-
-del {
- height: 20px; }
-
-div {
- color: white;
- color: blue;
- color: white; }
-
-div {
- background-image: linear-gradient(left top, red, green); }
-
-div {
- -moz-box-shadow: 10px 10px 5px #888;
- -webkit-box-shadow: 10px 10px 5px #888;
- box-shadow: 10px 10px 5px #888;
- -moz-box-shadow: inset 10px 10px #888, -10px -10px #f4f4f4;
- -webkit-box-shadow: inset 10px 10px #888, -10px -10px #f4f4f4;
- box-shadow: inset 10px 10px #888, -10px -10px #f4f4f4; }
-
-div p {
- color: red;
- color: blue; }
- div p .class {
- color: red; }
- div p .class div {
- height: 20px; }
- div p div {
- height: 20px; }
- div p .top {
- top: 0; }
- div p .top div {
- color: red; }
-
-div.mixin-content-simple {
- color: red; }
-
-div.mixin-content-with-arg {
- background: blue;
- color: red; }
-
-div.mixin-content-with-arg {
- background: purple;
- height: 20px; }
-
-div.mixin-content-simple {
- height: 43px; }
-
-div.mixin-content-simple {
- color: orange; }
- div.mixin-content-simple div {
- height: 20px; }
-
-div.mixin-content-with-arg {
- background: purple;
- height: 43px; }
-
-div.mixin-content-with-arg {
- background: purple;
- color: orange; }
- div.mixin-content-with-arg div {
- height: 20px; }
-
-#please-wait {
- background: url(/images/logo.png);
- position: absolute;
- top: 1em;
- right: 0;
- bottom: 3em;
- left: 4em; }
-
-div.parameter-name-scope {
- -webkit-transform: translateX(50px); }
-
-@-webkit-keyframes change-color {
- 0% {
- color: green; }
-
- 100% {
- color: red; } }
diff --git a/lib/scssphp/tests/outputs/nesting.css b/lib/scssphp/tests/outputs/nesting.css
deleted file mode 100755
index 23be188..0000000
--- a/lib/scssphp/tests/outputs/nesting.css
+++ /dev/null
@@ -1,22 +0,0 @@
-div: blue;
-body {
- color: red; }
-
-div {
- color: red;
- height: yes; }
- div pre {
- color: blue; }
-
-div {
- font: 10px hello world;
- font-size: 10px;
- font-color: blue;
- border-left: 1px solid blue;
- border-right: 2px dashed green; }
-
-#nested-nesting {
- bar: baz;
- bang-bop: bar;
- bang-bip: 1px;
- bang-blat-baf: bort; }
diff --git a/lib/scssphp/tests/outputs/null.css b/lib/scssphp/tests/outputs/null.css
deleted file mode 100755
index b21aa46..0000000
--- a/lib/scssphp/tests/outputs/null.css
+++ /dev/null
@@ -1,21 +0,0 @@
-.div {
- one: null;
- one: world;
- one: NULL world;
- one: a, b;
- two: a, b; }
-
-p:before {
- content: "I ate pies!"; }
-
-.foo {
- -webkit-border-radius: 10;
- border-radius: 10; }
-
-.fu {
- -webkit-border-radius: 20;
- border-radius: 20; }
-
-.bar {
- -webkit-border-top-left-radius: 30;
- border-top-left-radius: 30; }
diff --git a/lib/scssphp/tests/outputs/operators.css b/lib/scssphp/tests/outputs/operators.css
deleted file mode 100755
index 3cae96a..0000000
--- a/lib/scssphp/tests/outputs/operators.css
+++ /dev/null
@@ -1,105 +0,0 @@
-body {
- color: 8;
- color: 16;
- height: 10px/10px;
- color: 6px;
- color: 5px;
- bottom: 2px;
- top: 1.5em;
- left: -1cm;
- top: 6.29921; }
-
-div {
- color: false;
- color: true;
- color: true;
- color: false;
- color: what > 3; }
-
-#units {
- test: 2.5748in;
- test: 13mm;
- test: 4em;
- test: 11mm;
- test: 1.1cm; }
-
-#modulo {
- test: 1;
- test: 1cm; }
-
-#colors {
- color: #ff0203;
- color: #fe0000;
- color: rgba(3, 8, 15, 0.5);
- color: rgba(5, 8, 10, 0.5);
- color: rgba(2, 4, 6, 0.5);
- color: rgba(1, 1, 2, 0.5);
- color: rgba(3, 4, 5, 0.5);
- color: rgba(0, 0, 1, 0.5);
- color: #22f;
- color: false;
- color: true;
- color: true;
- color: false; }
-
-#preserve {
- hello: what -going;
- hello: what - going; }
-
-#strings {
- hello: what -going;
- hello: whatgoing;
- hello: whatgoing;
- hello: whatgoing;
- hello: whatgoing;
- hello: "whatgoing";
- hello: goingwhat;
- hello: "whatwhat"; }
-
-#negation {
- a: -60;
- b: 10 -100;
- b: -90; }
-
-#bools-fail {
- and: false and two;
- and: one and two;
- and: one and false;
- or: false or two;
- or: one or two;
- or: one or false; }
-
-#bools {
- and: false;
- and: two;
- and: false;
- or: two;
- or: one;
- or: one; }
-
-#nots-fail {
- not: false2;
- not: not false;
- not: not 0;
- not: not 1;
- not: not "";
- not: not hello; }
-
-#nots {
- not: false2;
- not: true;
- not: false;
- not: false;
- not: false;
- not: false; }
-
-#string-test {
- str: true;
- str: false;
- str: true;
- str: true;
- str: xhellohellofalse;
- str: true; }
-
-#special {
- cancel-unit: 1; }
diff --git a/lib/scssphp/tests/outputs/parsing_comments.css b/lib/scssphp/tests/outputs/parsing_comments.css
deleted file mode 100755
index 67d6337..0000000
--- a/lib/scssphp/tests/outputs/parsing_comments.css
+++ /dev/null
@@ -1,50 +0,0 @@
-/* comment 1 */
-a {
- /* comment 2 */
- color: red;
- /* comment 3 */
- /* comment 4 */ }
-/* comment 5 */
-/*! comment 1 */
-b {
- /*! comment 2 */
- color: red;
- /*! comment 3 */
- /*! comment 4 */ }
-/*! comment 5 */
-/*
- * multi-line comment 1
- */
-c {
- /*
- * multi-line comment 2
- */
- color: red;
- /*
- * multi-line comment 3
- */
- /*
- * multi-line comment 4
- */ }
-/*
- * multi-line comment 5
- */
-/*!
- * multi-line comment 1
- */
-d {
- /*!
- * multi-line comment 2
- */
- color: red;
- /*!
- * multi-line comment 3
- */
- /*!
- * multi-line comment 4
- */ }
-/*!
- * multi-line comment 5
- */
-e {
- color: red; }
diff --git a/lib/scssphp/tests/outputs/placeholder_selector.css b/lib/scssphp/tests/outputs/placeholder_selector.css
deleted file mode 100755
index 938ffeb..0000000
--- a/lib/scssphp/tests/outputs/placeholder_selector.css
+++ /dev/null
@@ -1,7 +0,0 @@
-p a.notice span, p a.error span, #context a.notice span, #context a.error span {
- color: blue;
- font-weight: bold;
- font-size: 2em; }
-
-p {
- padding: 2em; }
diff --git a/lib/scssphp/tests/outputs/scss_css.css b/lib/scssphp/tests/outputs/scss_css.css
deleted file mode 100755
index df76dec..0000000
--- a/lib/scssphp/tests/outputs/scss_css.css
+++ /dev/null
@@ -1,771 +0,0 @@
-@import "foo.css";
-@import 'foo.css';
-@import url("foo.css");
-@import url('foo.css');
-@import url(foo.css);
-@import "foo.css" screen;
-@import "foo.css" screen, print;
-@charset "UTF-8";
-[foo~=bar] {
- a: b; }
-
-[foo^=bar] {
- a: b; }
-
-[foo$=bar] {
- a: b; }
-
-[foo*=bar] {
- a: b; }
-
-[foo|=en] {
- a: b; }
-
-foo {
- a: 2;
- b: 2.3em;
- c: 50%;
- d: "fraz bran";
- e: flanny-blanny-blan;
- f: url(http://sass-lang.com);
- h: #abc; }
-
-selector {
- property: value;
- property2: value; }
-
-sel {
- p: v; }
-
-.foo {
- /* Foo
- Bar
- Baz */
- a: b; }
-
-.foo {
- /* Foo
- Bar
- Baz */
- a: b; }
-
-.foo {
- /* Foo
- Bar */
- a: b; }
-
-.foo {
- /* Foo
- Bar
- Baz */
- a: b; }
-
-@foo {
- a: b;
- rule {
- a: b; } }
-
-@foo {
- a: b; }
-
-@bar {
- a: b; }
-
-@foo "bar"
-
-foo {
- a: 12px calc(100%/3 - 2*1em - 2*1px);
- b: 12px -moz-calc(100%/3 - 2*1em - 2*1px);
- b: 12px -webkit-calc(100%/3 - 2*1em - 2*1px);
- b: 12px -foobar-calc(100%/3 - 2*1em - 2*1px); }
-
-foo {
- bar: baz; }
-
-bar {
- bar: baz; }
-
-baz {
- bar: baz; }
-/*
- * foo
- */
-bar {
- baz: bang; }
-
-E, F {
- a: b; }
-
-E F, G H {
- a: b; }
-
-E > F, G > H {
- a: b; }
-/* This is a CSS comment. */
-.one {
- color: green; }
-/* Another comment */
-/* The following should not be used:
- .two {color: red;} */
-.three {
- color: green;
- /* color: red; */ }
-/**
- .four {color: red;} */
-.five {
- color: green; }
-/**/
-.six {
- color: green; }
-/*********/
-.seven {
- color: green; }
-/* a comment **/
-.eight {
- color: green; }
-
-foo {
- a: \foo bar;
- b: foo\ bar;
- c: \2022 \0020;
- d: foo\\bar;
- e: foo\"\'bar; }
-
-foo {
- a: "\foo bar";
- b: "foo\ bar";
- c: "\2022 \0020";
- d: "foo\\bar";
- e: "foo\"'bar"; }
-
-foo {
- _name: val;
- *name: val;
- :name: val;
- .name: val;
- #name: val;
- name/**/: val;
- name/*\**/: val;
- name: val; }
-
-@foo "bar" ;
-
-foo {
- a: -moz-element(#foo);
- b: -webkit-element(#foo);
- b: -foobar-element(#foo); }
-
-@foo ;
-
-foo {
- bar: baz; }
-
-0% {
- a: b; }
-
-60% {
- a: b; }
-
-100% {
- a: b; }
-
-12px {
- a: b; }
-
-"foo" {
- a: b; }
-
-foo {
- a: 12px expression(1 + (3 / Foo.bar("baz" + "bang") + function() {return 12;}) % 12); }
-
-:foo("bar") {
- a: b; }
-
-:foo(bar) {
- a: b; }
-
-:foo(12px) {
- a: b; }
-
-:foo(+) {
- a: b; }
-
-:foo(-) {
- a: b; }
-
-:foo(+"bar") {
- a: b; }
-
-:foo(-++--baz-"bar"12px) {
- a: b; }
-
-foo {
- a: foo-bar(12);
- b: -foo-bar-baz(13, 14 15); }
-
-@import "foo.css" screen, print and (foo: 0);
-
-@import "foo.css" screen, only print, screen and (foo: 0);
-
-foo {
- a: foo !important;
- b: foo bar !important;
- b: foo, bar !important; }
-
-foo {
- a: -moz-bar-baz;
- b: foo -o-bar-baz; }
-
-foo {
- a: d;
- /* b; c: */ }
-
-foo {
- a : d;
- /*: b; c */ }
-/* Foo
- * Bar */
-.foo {
- /* Foo
- * Bar */ }
-
-[foo] {
- a: b; }
-
-[foo="bar"] {
- a: b; }
-
-[foo~="bar"] {
- a: b; }
-
-[foo^="bar"] {
- a: b; }
-
-[foo$="bar"] {
- a: b; }
-
-[foo*="bar"] {
- a: b; }
-
-[foo|="en"] {
- a: b; }
-
-:root {
- a: b; }
-
-:nth-child(n) {
- a: b; }
-
-:nth-last-child(n) {
- a: b; }
-
-:nth-of-type(n) {
- a: b; }
-
-:nth-last-of-type(n) {
- a: b; }
-
-:first-child {
- a: b; }
-
-:last-child {
- a: b; }
-
-:first-of-type {
- a: b; }
-
-:last-of-type {
- a: b; }
-
-:only-child {
- a: b; }
-
-:only-of-type {
- a: b; }
-
-:empty {
- a: b; }
-
-:link {
- a: b; }
-
-:visited {
- a: b; }
-
-:active {
- a: b; }
-
-:hover {
- a: b; }
-
-:focus {
- a: b; }
-
-:target {
- a: b; }
-
-:lang(fr) {
- a: b; }
-
-:enabled {
- a: b; }
-
-:disabled {
- a: b; }
-
-:checked {
- a: b; }
-
-::first-line {
- a: b; }
-
-::first-letter {
- a: b; }
-
-::before {
- a: b; }
-
-::after {
- a: b; }
-
-.warning {
- a: b; }
-
-#myid {
- a: b; }
-
-:not(s) {
- a: b; }
-
-@media all {
- rule1 {
- prop: val; }
-
- rule2 {
- prop: val; } }
-
-@media screen, print {
- rule1 {
- prop: val; }
-
- rule2 {
- prop: val; } }
-
-@media screen and (-webkit-min-device-pixel-ratio: 0) {
- a: b; }
-
-@media only screen, print and (foo: 0px) and (bar: flam(12px solid)) {
- a: b; }
-
-:-moz-any(h1, h2, h3) {
- a: b; }
-
-:-moz-any(.foo) {
- a: b; }
-
-:-moz-any(foo bar, .baz > .bang) {
- a: b; }
-
-@-moz-document url(http://www.w3.org/),
- url-prefix(http://www.w3.org/Style/),
- domain(mozilla.org),
- regexp("^https:.*") {
- .foo {
- a: b; } }
-
-foo {
- filter: progid:DXImageTransform.Microsoft.gradient(GradientType=1, startColorstr=#c0ff3300, endColorstr=#ff000000);
- filter: progid:DXImageTransform.Microsoft.gradient(GradientType=1, startColorstr=#c0ff3300, endColorstr=#ff000000); }
-
-foo {
- filter: alpha(opacity=20);
- filter: alpha(opacity=20, enabled=true);
- filter: blaznicate(foo=bar, baz=bang bip, bart=#fa4600); }
-
-@foo bar {
- a: b; }
-
-@bar baz {
- c: d; }
-
-@foo bar;
-@bar baz;
-
-
-/* Foo
- * Bar */
-/* Baz
- * Bang */
-
-
-.foo {
- /* Foo
- * Bar */
- /* Baz
- * Bang */ }
-
-.foo {
- /* Foo Bar */
- /* Baz Bang */ }
-
-@namespace "http://www.w3.org/Profiles/xhtml1-strict";
-
-@namespace url(http://www.w3.org/Profiles/xhtml1-strict);
-
-@namespace html url("http://www.w3.org/Profiles/xhtml1-strict");
-
-[foo|bar=baz] {
- a: b; }
-
-[*|bar=baz] {
- a: b; }
-
-[foo|bar|=baz] {
- a: b; }
-
-foo|E {
- a: b; }
-
-*|E {
- a: b; }
-
-foo|* {
- a: b; }
-
-*|* {
- a: b; }
-
-:not(foo|bar) {
- a: b; }
-
-:not(*|bar) {
- a: b; }
-
-:not(foo|*) {
- a: b; }
-
-:not(*|*) {
- a: b; }
-
-:not(#blah) {
- a: b; }
-
-:not(.blah) {
- a: b; }
-
-:not([foo]) {
- a: b; }
-
-:not([foo^="bar"]) {
- a: b; }
-
-:not([baz|foo~="bar"]) {
- a: b; }
-
-:not(:hover) {
- a: b; }
-
-:not(:nth-child(2n + 3)) {
- a: b; }
-
-:not(:not(#foo)) {
- a: b; }
-
-:not(a#foo.bar) {
- a: b; }
-
-:not(#foo .bar > baz) {
- a: b; }
-
-:not(h1, h2, h3) {
- a: b; }
-
-foo {
- a: "bang 1 bar bip"; }
-
-:nth-child(-n) {
- a: b; }
-
-:nth-child(+n) {
- a: b; }
-
-:nth-child(even) {
- a: b; }
-
-:nth-child(odd) {
- a: b; }
-
-:nth-child(50) {
- a: b; }
-
-:nth-child(-50) {
- a: b; }
-
-:nth-child(+50) {
- a: b; }
-
-:nth-child(2n+3) {
- a: b; }
-
-:nth-child(2n-3) {
- a: b; }
-
-:nth-child(+2n-3) {
- a: b; }
-
-:nth-child(-2n+3) {
- a: b; }
-
-:nth-child(-2n+ 3) {
- a: b; }
-
-:nth-child( 2n + 3) {
- a: b; }
-
-foo {
- a: foo bar baz;
- b: foo, #abc, -12;
- c: 1px/2px/-3px;
- d: foo bar, baz/bang; }
-
-@page {
- prop1: val;
- prop2: val; }
-
-@page flap {
- prop1: val;
- prop2: val; }
-
-@page :first {
- prop1: val;
- prop2: val; }
-
-@page flap:first {
- prop1: val;
- prop2: val; }
-
-.foo {
- /* Foo */
- a: b; }
-
-.foo {
- /* Foo
- * Bar */
- a: b; }
-/* Foo */
-.foo {
- a: b; }
-/* Foo
- * Bar */
-.foo {
- a: b; }
-
-.foo #bar:baz(/* bang )*/ bip) {
- /* .a #foo */
- a: b; }
-
-> E {
- a: b; }
-
-+ E {
- a: b; }
-
-~ E {
- a: b; }
-
-> > E {
- a: b; }
-
->> E {
- a: b; }
-
-E* {
- a: b; }
-
-E*.foo {
- a: b; }
-
-E*:hover {
- a: b; }
-
-E, F {
- a: b; }
-
-E F {
- a: b; }
-
-E, F G, H {
- a: b; }
-
-body {
- /*
- //comment here
- */ }
-
-E > F {
- a: b; }
-
-E ~ F {
- a: b; }
-
-E + F {
- a: b; }
-
-* {
- a: b; }
-
-E {
- a: b; }
-
-E[foo] {
- a: b; }
-
-E[foo="bar"] {
- a: b; }
-
-E[foo~="bar"] {
- a: b; }
-
-E[foo^="bar"] {
- a: b; }
-
-E[foo$="bar"] {
- a: b; }
-
-E[foo*="bar"] {
- a: b; }
-
-E[foo|="en"] {
- a: b; }
-
-E:root {
- a: b; }
-
-E:nth-child(n) {
- a: b; }
-
-E:nth-last-child(n) {
- a: b; }
-
-E:nth-of-type(n) {
- a: b; }
-
-E:nth-last-of-type(n) {
- a: b; }
-
-E:first-child {
- a: b; }
-
-E:last-child {
- a: b; }
-
-E:first-of-type {
- a: b; }
-
-E:last-of-type {
- a: b; }
-
-E:only-child {
- a: b; }
-
-E:only-of-type {
- a: b; }
-
-E:empty {
- a: b; }
-
-E:link {
- a: b; }
-
-E:visited {
- a: b; }
-
-E:active {
- a: b; }
-
-E:hover {
- a: b; }
-
-E:focus {
- a: b; }
-
-E:target {
- a: b; }
-
-E:lang(fr) {
- a: b; }
-
-E:enabled {
- a: b; }
-
-E:disabled {
- a: b; }
-
-E:checked {
- a: b; }
-
-E::first-line {
- a: b; }
-
-E::first-letter {
- a: b; }
-
-E::before {
- a: b; }
-
-E::after {
- a: b; }
-
-E.warning {
- a: b; }
-
-E#myid {
- a: b; }
-
-E:not(s) {
- a: b; }
-
-E F {
- a: b; }
-
-E > F {
- a: b; }
-
-E + F {
- a: b; }
-
-E ~ F {
- a: b; }
-
-@supports (a: b) and (c: d) or (not (d: e)) and ((not (f: g)) or (not ((h: i) and (j: k)))) {
- .foo {
- a: b; } }
-
-@-prefix-supports (a: b) and (c: d) or (not (d: e)) and ((not (f: g)) or (not ((h: i) and (j: k)))) {
- .foo {
- a: b; } }
-
-foo {
- foo: bar;
- #baz: bang;
- #bip: bop; }
-
-foo {
- a: -2;
- b: -2.3em;
- c: -50%;
- d: -foo(bar baz); }
-
-foo {
- a: -0.5em;
- b: 0.5em;
- c: -foo(12px);
- d: +foo(12px); }
-
-foo {
- -moz-foo-bar: blat;
- -o-flat-blang: wibble; }
-
-foo {
- a: foo();
- b: bar baz-bang() bip; }
diff --git a/lib/scssphp/tests/outputs/selectors.css b/lib/scssphp/tests/outputs/selectors.css
deleted file mode 100755
index 0950f32..0000000
--- a/lib/scssphp/tests/outputs/selectors.css
+++ /dev/null
@@ -1,341 +0,0 @@
-* {
- color: blue; }
-
-E {
- color: blue; }
-
-E:not(:link) {
- color: blue; }
-
-E:not(:link):not(:visited) {
- color: blue; }
-
-E:not(:link, :visited) {
- color: blue; }
-
-E:matches(:hover, :focus) {
- color: blue; }
-
-E.warning {
- color: blue; }
-
-E#id {
- color: blue; }
-
-E[foo] {
- color: blue; }
-
-E[foo="barbar"] {
- color: blue; }
-
-E[foo="barbar" i] {
- color: blue; }
-
-E[foo~="hello#$@%@$#^"] {
- color: blue; }
-
-E[foo^="color: green;"] {
- color: blue; }
-
-E[foo$="239023"] {
- color: blue; }
-
-E[foo*="29302"] {
- color: blue; }
-
-E[foo|="239032"] {
- color: blue; }
-
-[foo] {
- color: blue; }
-
-[foo] .helloWorld {
- color: blue; }
-
-[foo].helloWorld {
- color: blue; }
-
-[foo="barbar"] {
- color: blue; }
-
-[foo~="hello#$@%@$#^"] {
- color: blue; }
-
-[foo^="color: green;"] {
- color: blue; }
-
-[foo$="239023"] {
- color: blue; }
-
-[foo*="29302"] {
- color: blue; }
-
-[foo|="239032"] {
- color: blue; }
-
-E:dir(ltr) {
- color: blue; }
-
-E:lang(en) {
- color: blue; }
-
-E:lang(en, fr) {
- color: blue; }
-
-E:any-link {
- color: blue; }
-
-E:link {
- color: blue; }
-
-E:visited {
- color: blue; }
-
-E:local-link {
- color: blue; }
-
-E:local-link(0) {
- color: red; }
-
-E:local-link(1) {
- color: white; }
-
-E:local-link(2) {
- color: red; }
-
-E:target {
- color: blue; }
-
-E:scope {
- color: blue; }
-
-E:current {
- color: blue; }
-
-E:current(:link) {
- color: blue; }
-
-E:past {
- color: blue; }
-
-E:future {
- color: blue; }
-
-E:active {
- color: blue; }
-
-E:hover {
- color: blue; }
-
-E:focus {
- color: blue; }
-
-E:enabled {
- color: blue; }
-
-E:disabled {
- color: blue; }
-
-E:indeterminate {
- color: blue; }
-
-E:default {
- color: blue; }
-
-E:in-range {
- color: blue; }
-
-E:out-of-range {
- color: blue; }
-
-E:required {
- color: blue; }
-
-E:optional {
- color: blue; }
-
-E:read-only {
- color: blue; }
-
-E:read-write {
- color: blue; }
-
-E:root {
- color: blue; }
-
-E:empty {
- color: blue; }
-
-E:first-child {
- color: blue; }
-
-E:nth-child(odd) {
- color: blue; }
-
-E:nth-child(2n+1) {
- color: blue; }
-
-E:nth-child(5) {
- color: blue; }
-
-E:last-child {
- color: blue; }
-
-E:nth-last-child(-n+2) {
- color: blue; }
-
-E:only-child {
- color: blue; }
-
-E:first-of-type {
- color: blue; }
-
-E:nth-of-type(2n) {
- color: blue; }
-
-E:last-of-type {
- color: blue; }
-
-E:nth-last-of-type(n) {
- color: blue; }
-
-E:only-of-type {
- color: blue; }
-
-E:nth-match(odd) {
- color: blue; }
-
-E:nth-last-match(odd) {
- color: blue; }
-
-E:column(n) {
- color: blue; }
-
-E:nth-column(n) {
- color: blue; }
-
-E:nth-last-column(n) {
- color: blue; }
-
-E F {
- color: blue; }
-
-E > F {
- color: blue; }
-
-E + F {
- color: blue; }
-
-E ~ F {
- color: blue; }
-
-E /foo/ F {
- color: blue; }
-
-E! > F {
- color: blue; }
-
-[foo|att=val] {
- color: blue; }
-
-[*|att] {
- color: yellow; }
-
-[|att] {
- color: green; }
-
-[att] {
- color: green; }
-
-E::first-line {
- color: blue; }
-
-E::first-letter {
- color: blue; }
-
-E::before {
- color: blue; }
-
-E::after {
- color: blue; }
-
-E::choices {
- color: blue; }
-
-E::value {
- color: blue; }
-
-E::repeat-index {
- color: blue; }
-
-E::repeat-item {
- color: blue; }
-
-E:first {
- color: blue; }
-
-E:first-line {
- color: blue; }
-
-E:first-letter {
- color: blue; }
-
-E:before {
- color: blue; }
-
-E:after {
- color: blue; }
-
-E:checked {
- color: blue; }
-
-E:invalid {
- color: blue; }
-
-E:valid {
- color: blue; }
-
-E:left {
- color: blue; }
-
-E:right {
- color: blue; }
-
-E:any(ol) {
- color: blue; }
-
-E::selection {
- color: blue; }
-
-div {
- font: something;
- font-size: 30em; }
- div font:something {
- size: 30em; }
-
-.something.world {
- color: blue; }
- .something .mold {
- height: 200px; }
- .dog .something {
- color: blue; }
-
-.dad .simple .wolf {
- color: blue; }
- .rad.simple.bad {
- color: blue; }
-
-.something div .what.world {
- color: blue; }
-
-div.foo div {
- color: blue; }
-
-.nice-fonts .main .message div .title, .nice-fonts div .message div .title {
- font-size: 24px; }
-
-.escape\% {
- color: red; }
-
-.escape-plan\% {
- color: green; }
diff --git a/lib/scssphp/tests/outputs/values.css b/lib/scssphp/tests/outputs/values.css
deleted file mode 100755
index 7c0e2ff..0000000
--- a/lib/scssphp/tests/outputs/values.css
+++ /dev/null
@@ -1,34 +0,0 @@
-#values {
- color: #eee;
- color: #eee;
- height: 20px;
- width: 80%;
- color: "hello world";
- height: url("http://google.com");
- dads: url(http://leafo.net);
- padding: 10px 10px 10px 10px, 3px 3px 3px;
- textblock: "This is a \
-multiline block \
-#not { color: #eee;}";
- margin: 4, 3, 1;
- content: "This is a \
-multiline string.";
- border-radius: -1px -1px -1px black; }
-
-#subtraction {
- lit: 10 -11;
- lit: -1;
- lit: -1;
- lit: -1;
- var: 10 -100;
- var: -90;
- var: -90;
- var: -90; }
-
-#special {
- a: 12px expression(1 + (3 / Foo.bar("baz" + "bang") + function() {return 12;}) % 12); }
-
-#unary {
- b: 0.5em;
- c: -foo(12px);
- d: +foo(12px); }
diff --git a/lib/scssphp/tests/outputs/variables.css b/lib/scssphp/tests/outputs/variables.css
deleted file mode 100755
index 8676338..0000000
--- a/lib/scssphp/tests/outputs/variables.css
+++ /dev/null
@@ -1,24 +0,0 @@
-cool: 100px;
-div {
- height: red, two, three; }
-
-div {
- num: 1000; }
-
-div {
- num: 2000; }
-
-pre {
- color: blue; }
-
-del {
- color: red; }
- del div pre {
- color: red; }
-
-body {
- font-family: Arial;
- font-family: Helvetica Neue;
- font-family: "Helvetica Neue";
- font-family: Helvetica, Arial, sans-serif;
- font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; }
diff --git a/lib/scssphp/todo b/lib/scssphp/todo
deleted file mode 100755
index ab271c5..0000000
--- a/lib/scssphp/todo
+++ /dev/null
@@ -1,47 +0,0 @@
-
-* change all calls to reduce to not suppress division where appropriate
-* store count in elements so we can have position of compile time errors
-* failed parsing paths can add comments early
-
-* fix indentation for @content, see @content tests
-
-misc:
-
-# sequence merging:
-
-a b c d { color: red; }
-x y z w { @extend a; }
-
- a b c d, x y z w b c d { color: red; }
-
-
-a b c d { color: red; }
-x y z w { @extend b; }
-
- a b c d, a x y z w c d, x y z a w c d { color: red; }
-
-
-a b c d { color: red; }
-x y z w { @extend c; }
-
- a b c d, a b x y z w d, x y z a b w d { color: red; }
-
- x y z a b w d
-
- before: a b
- after: d
- new: x y z w
-
-
-a b c d { color: red; }
-x y z w { @extend d; }
-
- a b c d, a b c x y z w, x y z a b c w { color: red; }
-
-
-->> new[:-1] . before . new[-1] . after
-
- new.len > 1
- before not empty
-
-
From d0f32ae24120a3fe48565a5d72f662239a1e70c9 Mon Sep 17 00:00:00 2001
From: Matt
Date: Tue, 7 Jun 2016 12:38:06 -0400
Subject: [PATCH 2/2] Updated compile function to support syntax of latest
version of scssphp.
---
sass-watcher.php | 11 +++++++++--
1 file changed, 9 insertions(+), 2 deletions(-)
diff --git a/sass-watcher.php b/sass-watcher.php
index e3bc25a..51d46ff 100644
--- a/sass-watcher.php
+++ b/sass-watcher.php
@@ -43,12 +43,19 @@ public function getdata()
}
- public function compile($scss_folder, $scss_filename,$stylename,$format_style = "scss_formatter")
+ public function compile($scss_folder, $scss_filename, $stylename, $format_style = null)
{
require_once plugin_dir_path( __FILE__ ) . 'lib/scssphp/scss.inc.php';
- $scss_compiler = new scssc();
+
+ if(is_null($format_style))
+ {
+ $format_style = new Leafo\ScssPhp\Formatter\Crunched();
+ }
+
+ $scss_compiler = new Leafo\ScssPhp\Compiler();
$scss_compiler->setImportPaths($scss_folder);
$scss_compiler->setFormatter($format_style);
+
try {
$file = $scss_filename;
$content = file_get_contents($file);