115 Commits

Author SHA1 Message Date
Adi Roiban
e82ca278c4 Update after review. 2014-02-18 11:24:00 +02:00
Adi Roiban
032cfa1a8c Initial code for parsing from stream. 2014-02-16 15:54:00 +02:00
Sascha Peilicke
315baa2147 Whitespace after CSS filters is significant
Fixes issue 30
2014-02-02 18:54:58 +01:00
Sascha Peilicke
4d63ecfe25 Fix all PEP-8 / flake8 code issues
Drop testscope because it's empty.
2014-02-02 17:35:38 +01:00
Sascha Peilicke
bba63d9df5 Proper media queries
The lexer now identifies media queries in @media ... {} and
@import ... ; statements. For that, two new states "mediaquery" and
import" where added. The parser uses those to implement the CSS3 media
query BNF (www.w3.org/TR/css3-mediaqueries). Overall test coverage
increased.
2014-01-21 15:03:06 +01:00
Sascha Peilicke
f01a112be0 Support CSS Device Adaptation
And the Internet Explorer specific "@-ms-viewport" used by Bootstrap3.
See http://www.w3.org/TR/css-device-adapt/ and
http://msdn.microsoft.com/en-us/library/ie/hh869615%28v=vs.85%29.aspx
2013-12-20 11:15:42 +01:00
Sascha Peilicke
d7eae509f8 Deferred variables inside @media identifiers
Followup of 11895c
2013-12-18 13:52:29 +01:00
Sascha Peilicke
780dd21b22 Fix mixin guard comparison operator list
The operator list includes "=<", but not "<>", "!=" or "<=". Properly
adjust test cases and drop occurences of invalid operators. Raise a
syntax error if an unknown operator is used. See
http://lesscss.org/#-pattern-matching-and-guard-expressions
2013-12-18 13:51:45 +01:00
Sascha Peilicke
5da1fd891b Support style and identifier lists in escaped strings.
Example:

  .foo {
    transition: ~"border-color ease-in-out .15s,
                  box-shadow ease-in-out .15s";
  }
2013-12-18 10:37:16 +01:00
Sascha Peilicke
e51ea8ca0d Drop unused productions 2013-12-18 10:37:16 +01:00
Sascha Peilicke
6c316b2982 Enhanced hack for 'rect' DOM / function ambiguity
'rect' is a DOM element and occurs as a function. Currently, the parser
doesn't have a list of valid function names but uses css_dom elements
(and some others) to identify function calls.

Therefore the lexer got additional state tracking a while ago. This
turned out to wrongly work on constructs such as "button::-moz-$FOO,
input::-moz-$BAR", where 'input' was marked as 'css_ident' rather than
'css_dom'. This is fixed by resetting the 'in_property_decl' state
variable after a comma.
2013-12-18 10:37:16 +01:00
Sascha Peilicke
b9d92afa90 Promote literal ':' to token 2013-12-18 10:37:16 +01:00
Sascha Peilicke
10c88441b5 Support selector interpolation
Quote from lesscss.org: "prior to LESS 1.3.1 a (~"@{name}") type of
selector was supported. Support for this will be removed in 1.4.0.".
Meanwhile, interpolated selectors look like .@{name}.

For this, the lexer needed another state. Promote literals '{}' to
tokens to be able to drop the 'istring' state when '.foo{' occurs
(rather than '.foo {').
2013-12-18 10:37:15 +01:00
Sascha Peilicke
8f7ee0f4a4 Properly name escapes and interpolated strings
Escapes are seperate to interpolated strings.
2013-12-13 14:22:58 +01:00
Sascha Peilicke
776ae813bd Add t_tilde token for '~'
To be used inside general_sibling_selector (e.g. 'a ~ b { ... }')
instead of the literal '~'. Necessary since we had to remove the literal
from the lexer in order to tokenize ~"..." and ~'...'.
2013-12-13 14:22:58 +01:00
Sascha Peilicke
e34dde8950 CSS strings can contain variables too
Ordinary CSS strings may contain @{...}-style variables. Here are some
examples:

    content: "@{breadcrumb-separator}\00a0";
    background-image: url("@{file-2x}");
    .col(@index + 1, ~"@{list}, @{item}");
2013-12-13 14:22:58 +01:00
Sascha Peilicke
8e07f391f7 Only use css_ms_filter in fcall
The lexer catches Microsoft-specific function calls such "progid:..."
and "DX.Transform..." in the css_ms_filter token class. It should be
used only as the function for "fcall" constructs in the parser.
2013-12-11 17:58:33 +01:00
Sascha Peilicke
94f41416cd LESS strings can contain $MS CSS filters
.klass {
  filter: ~'alpha(opacity=2)';
}
2013-12-11 17:58:32 +01:00
Sascha Peilicke
059cde1f3d Proper support for variables in escaped values.
The following constructs are escapes: ~"..." and ~'...'. Inside, only
@{...} is a LESS variable, @foo is not! To express that, the lexer needs
to additional states ('lessstringquotes' and 'lessstringapostrophe') and
some parsing rules special to those states. The literal '~' had to be
promoted to token too. Now, instead as marking the complete LESS string
as 'less_string' token, the lexer properly tokenizes it's content which
in turn the parser can properly evaluate.

Includes a minor bug fix, t_less_variable() wasn't ever used because
t_css_ident already captured them. This part was removed from
t_css_ident becaus it's much easier to overwrite t_less_variable in lexer
states.
2013-12-11 17:58:32 +01:00
Sascha Peilicke
a8805615c3 Support function calls in expressions
LESS allows functions to be operators inside LESS operations and
bootstrap3 actually makes use of that.
2013-12-11 14:24:14 +01:00
Sascha Peilicke
55703e8587 Properly distinguish clip element from CSS function
And revert "Temprarily remove the "rect" SVG DOM element."

This reverts commit fcea9f0bd65807be14c0cbf56b3d21659a81856f.
The lexer now uses a variable to distinguish of being inside a CSS
property declaration or outside. If inside, don't mark token as css_dom
(e.g. 'rect'). This circumvents the ambiguity between the "rect" SVG DOM
element and the "clip()" CSS function. CSS functions only occur within
property declarations.

For that, ';' had to be promoted from a literal to an ordinar token.
2013-11-04 17:41:06 +01:00
Sascha Peilicke
11895c7e30 Support variables inside @media identifiers
This solution is somewhat hacky, the @media element really deserves a
Node subclass and it's own parsing rules. What's still missing is LESS
variables in grouped media queries like:

    @singleQuery: ~"(max-width: 500px)";
    @media screen, @singleQuery {
        set { padding: 3 3 3 3; }
    }

Fixes #18
2013-10-31 15:31:20 +01:00
Sascha Peilicke
c194aaa8b2 Don't add variables to scope twice
Since the Variable.parse method already adds to current scope,
p_variable_decl doesn't need to do that again.
2013-10-31 10:48:23 +01:00
Sascha Peilicke
5126a571d0 Support semicolons in mixin arguments
Check https://github.com/twbs/bootstrap/commit/c017e19ed236
2013-10-21 17:05:15 +02:00
Sascha Peilicke
d668b9dafe Some Python-3 compatibility fixes 2013-07-19 11:59:01 +02:00
Sascha Peilicke
c0a265e146 Fix PEP-8 issues (with autopep8 -a) 2013-07-19 11:22:12 +02:00
Patrick
0ff5b977ec fix an other utf-8 letter 2012-07-18 17:28:04 -04:00
Patrick
0660c17cd0 trying to fix python2 and utf-8 issues 2012-07-18 17:26:06 -04:00
Patrick
e669dfa82f fix issues #10 and #11 2012-07-18 16:47:38 -04:00
robotis
a562b6de5f Change error output to stderr 2012-07-07 18:03:53 +00:00
robotis
27345faba3 Process @media properly 2012-06-25 08:58:13 +00:00
robotis
31ff7676eb Allow composite identifiers through combinators 2012-06-25 08:29:50 +00:00
robotis
78e32011c7 Handle calling scope better 2012-06-04 07:27:53 +00:00
robotis
4c399c4ca9 Fix faulty fallback behaviour when nesting fallbacks 2012-06-02 11:23:22 +00:00
robotis
6e90506eeb Comments 2012-05-07 13:12:12 +00:00
robotis
f81e8b5c8e Add support for closures 2012-05-06 09:28:41 +00:00
robotis
2e36bf89c6 6 fold Speed increase by not using copy.deepcopy 2012-05-05 17:10:04 +00:00
jtm
b46f8c4ad0 Issue 4 allow nested @import 2012-04-20 14:53:50 +00:00
jtm
ca9ef1a107 Fix error on empty parse result 2012-04-20 14:42:41 +00:00
robotis
e2f52327b5 deal with KeyboardInterrupt 2012-04-17 12:26:19 +00:00
jtm
9268e2725e checkpoint 2012-04-09 09:52:46 +00:00
jtm
ccbe525bc2 checkpoint 2012-04-08 15:44:56 +00:00
jtm
64b496093c work 2012-04-08 13:17:22 +00:00
jtm
0a30f4a0e3 Calls within inner scope 2012-04-07 14:38:52 +00:00
jtm
f7a1c2ae42 Error reporting 2012-04-07 11:33:07 +00:00
jtm
dc3c585e8e Fix bug on fallback to block in mixin call 2012-04-06 20:55:34 +00:00
jtm
5f2ab7d9b1 Fixed mixin argument parsing 2012-04-06 19:23:22 +00:00
jtm
e2f925fad8 Fix kwarg list to mixin call bug 2012-04-06 15:13:10 +00:00
jtm
85c503729e tests + documentation 2012-04-06 14:53:38 +00:00
jtm
32d7b462c8 Add post processing 2012-04-06 14:23:13 +00:00