275 Commits

Author SHA1 Message Date
robotis
cb291c5e80 Fix for issue 31. hsl(a) processing on floats. 2014-02-18 12:00:07 +00:00
Adi Roiban
e82ca278c4 Update after review. 2014-02-18 11:24:00 +02:00
Adi Roiban
5a763750d4 Add support for py3. 2014-02-16 17:48:07 +02:00
Adi Roiban
032cfa1a8c Initial code for parsing from stream. 2014-02-16 15:54:00 +02:00
Sascha Peilicke
7f6c314c71 Bump version to 0.10.1 2014-02-02 18:55:23 +01:00
Sascha Peilicke
315baa2147 Whitespace after CSS filters is significant
Fixes issue 30
2014-02-02 18:54:58 +01:00
Sascha Peilicke
da1b0d2b9d Bump version to 0.10
Moved to lesscpy.__version__ and use it in setup.py. Also, don't put the
whole license text into the 'license' tag but rather the short form
'MIT'. The license file is part of the source distribution already and
was added to package_data (so that it ends up somewhere when 'setup.py
install' is invoked).
2014-02-02 18:30:28 +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
a556030931 Move tests to root dir
In essence, tests are not an importable submodule anymore but an
independent piece of code that won't be installed in a user's
site-packages directory.
2014-02-02 13:28:58 +01:00
Sascha Peilicke
ed91f7dac6 Adjust bootstrap3 test CSS to lesscpy
We still have subtle differences that are semantically equivalent:

  - #fff vs. #ffffff
  - 0.0 vs .0
  - 0 vs 0%
  - property sort order (and identation for -moz-$BLA)

There are still some other issues to fix, disable the bootstrap3 test
therefore to let the testsuite pass.
2014-01-24 14:05:18 +01:00
Sascha Peilicke
277d8c3957 Fix '&' multiplication
Let'S do it by example:

  .ident_a, .ident_b {
    & + & + & { color: red; }
  }

We have to generate all permutations of the parent identifier list and
the amount of ampersand child identifiers. In the above case, the
exploded identifier list has ident_count**ampersand_count entries (8).

As a bonus, we get the same identifier sort order as lessc does.

Conflicts:
	lesscpy/plib/identifier.py
2014-01-24 14:01:10 +01:00
Sascha Peilicke
54b1e696c6 Add missing whitespace for & 2014-01-24 13:58:11 +01:00
Sascha Peilicke
e70c16c570 Fix url("..") whitespace formatting regex.
Missed some cases.
2014-01-24 13:58:11 +01:00
Sascha Peilicke
68bbfc3161 Always break lines after commas in identifiers
Upstream lessc does it and we want to align.
2014-01-24 13:58:11 +01:00
Sascha Peilicke
6f4a3efd3c Support & nesting and (double-)nested media queries
Example:

  .visible {
    &.visible-sm {
      @media screen { color: blue; }
    }
  }

Not the most beautiful code on the planet but does the trick.
2014-01-23 14:10:17 +01:00
Sascha Peilicke
3b74578cc9 Implement nested media queries
Including double-nested queries which are used (not only) by bootstrap3.
Triple-nested (or more) media queries are currently not supported. Added
several tests.

See http://www.lesscss.org/#-nested-media-queries
2014-01-22 11:27:46 +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
1c2240dfd7 Accept resolution types as css_number
dpi, dpcm and dppx, check http://www.w3.org/TR/css3-values/#resolution
2014-01-21 15:03:06 +01:00
Sascha Peilicke
c0510a4d11 Skip empty @media blocks 2014-01-21 15:03:06 +01:00
Sascha Peilicke
74bee8c411 Output rgba(x,y,z,0) exactly as lessc
Currently a hack.
2014-01-21 15:03:06 +01:00
Sascha Peilicke
7a041ce2a9 Apply bootstrap3 theme CSS formatting
The previous test case was generated by lessc (upstream). Meanwhile,
lesscpy also parses it but generates slightly different (though
functionally equivalent) output. Therefore adjust the desired output so
that this test finally passes.
2014-01-21 15:03:06 +01:00
Sascha Peilicke
93bdaac50f Use greyscale rather than grayscale.
The latter doesn't exist (anymore).
2014-01-21 15:03:06 +01:00
Sascha Peilicke
27f10f25d3 Allow float degrees / percentages in color functions 2014-01-21 15:03:06 +01:00
Sascha Peilicke
6ecdef7f35 Support expressions in @media attributes 2014-01-21 15:03:05 +01:00
Sascha Peilicke
106c9972d4 Add argb() function
Used by bootstrap3. Quote from the lesscss.org documentation:

Creates a hex representation of a color in #AARRGGBB format (NOT
Android development.
2014-01-21 15:03:05 +01:00
Sascha Peilicke
b2e13d0470 Proper rgba() function alpha output
The alpha value can either be a number in the range 0-1 or a percentage
(0-100%). Alpha values greater than 1 are simply dropped. Compare with
the rgba() function definition at http://lesscss.org/#reference.
2013-12-20 11:15:42 +01:00
Sascha Peilicke
b82a93e5ab Change color 'BLUE' to 'blue'
Upstream lessc only knows lowercase color names, we should stick to
that.
2013-12-20 11:15:42 +01:00
Sascha Peilicke
3a31d25c07 Clamp rgb(R, G, B, A) to rgb(R, G, B)
This is what upstream lessc does.
2013-12-20 11:15:42 +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
840f3265a3 Don't evaluate expression in 'font: 0/0 a;'
This is the ugliest (but valid) CSS statement since sliced bread and
Bootstrap3 makes use of it in the escaped form: 'font: ~"0/0" a;'. Add
test-cases for both variants and special treatment in Expression.parse.

Oh my...
2013-12-20 11:15:42 +01:00
Sascha Peilicke
585364b016 Not recurse forever if missing mixin declarations
Bail out after recursing 64 times into Deferred.parse and raise syntax
error for missing declaration to provide a meaningful error message.
Otherwise the code loops until the interpreter stack end (max
recursion depth).
2013-12-20 11:15:35 +01:00
Sascha Peilicke
dc4196cf6d Fix block fills generation with only variables.
If the parsed block contents contains only LESS variable definitions,
the block should not be renderend. Previously this was implemented by
not returning self from Variable.parse() (contrary to it's docstring and
other plib classes). The real fix is to just check for the above
condition and return self again.
2013-12-20 11:14:03 +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
0a2b0690d1 Ignore missing whitespace in escaped strings
Function argument lists are missing whitespaces after each comma with
the currenct escaped strings code. However, the minified version had
commas before which wasn't any better.

Likely an easy fix somewhere but shouldn't block now.
2013-12-18 10:37:16 +01:00
Sascha Peilicke
1305cfdb83 Simplifiy ~"-Some::weird(#thing)" test
I don't think it makes sense to test for that just now. The function
call parsing should be significantly enhanced before.

Changed to ~"-Some(#thing)" instead.
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
2cfa2bfc09 Add new HTML5 'main' and 'template' tags 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
bdf6a5e840 Bring back support for @@name variables 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
c844c7b34c Support swapping "@{...}" type variables
These only occur in interpolated strings (~'...' or ~"...").
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