157 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
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
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
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
74bee8c411 Output rgba(x,y,z,0) exactly as lessc
Currently a hack.
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
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
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
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
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
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
57f19f3bb7 Add some missing media type DOM elements
And split out HTML / CSS2 media types and CSS3 keyframe selectors from
"html4" DOM elements.
2013-11-04 15:00:32 +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
ba8ad98f52 Cleanup t_css_ident 2013-10-31 15:30:42 +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
57517bd017 Use operator module everywhere
Much cleaner than using getattr().

Fixes issue #13
2013-08-12 14:49:04 +02:00
Sascha Peilicke
e6512edb98 Add utility away_from_zero_round and use it for LESS round()
Also _ophsl should use it when running unter Py3k (instead of
convergent_round).
2013-08-08 18:26:23 +02:00
Sascha Peilicke
8da243d2b8 Use convergent_round everywhere except for round() LESS function.
The LESS function round uses away-from-zero rounding.
2013-08-08 18:25:23 +02:00
Sascha Peilicke
7a65e81fa7 Add utility function convergent_round
Mimics Python3's changed rounding behavior: "The round() function
rounding strategy and return type have changed. Exact halfway cases are
now rounded to the nearest even result instead of away from zero. (For
example, round(2.5) now returns 2 rather than 3.) round(x[, n]) now
delegates to x.__round__([n]) instead of always returning a float. It
generally returns an integer when called with a single argument and a
value of the same type as x when called with two arguments."
2013-08-08 18:25:23 +02:00
Sascha Peilicke
a80cb8942a Allow camel-case DOM elements defined in SVG-1.1
The SVG standard defines several DOM elements in camel-case (namely
textPath, altGlyph, altGlyphDef, altGlyphItem and glyphRef). Even though
most browser also accept lower-case, the lexer should take this into
account.
2013-08-08 10:58:21 +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
robotis
3b594f7217 Better support for python2.x + python3.x 2012-07-19 09:31:18 +00:00
Patrick
2b18e4f351 fix super for python2.x 2012-07-18 17:34:48 -04:00
Patrick
60628cc999 fix super for python2.x 2012-07-18 17:32:48 -04:00
Patrick
0ff5b977ec fix an other utf-8 letter 2012-07-18 17:28:04 -04:00