Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1337)

Issue 8498020: Beginning of CSS parser using frog parsering infrastructure. (Closed)

Created:
9 years, 1 month ago by terry
Modified:
9 years, 1 month ago
Reviewers:
jimhug, kasperl, nweiz
CC:
reviews_dartlang.org, nweiz
Visibility:
Public.

Description

Beginning of CSS parser using frog parsering infrastructure. Change for in memory buffers. BUG= TEST= Committed: https://code.google.com/p/dart/source/detail?r=1752

Patch Set 1 #

Total comments: 96

Patch Set 2 : Updated to use lang.dart and world. #

Patch Set 3 : Moved to Utils #

Patch Set 4 : Moved to utils, added lang.dart and world, fixed checked errors. #

Patch Set 5 : Incorporated Jim's CR #

Total comments: 29

Patch Set 6 : Added Jim's CR comments and updated tests. #

Total comments: 1

Patch Set 7 : More changes from Nathan's CR as well as more features added. #

Patch Set 8 : Removed comment out code #

Patch Set 9 : Minor cleanup. #

Total comments: 7
Unified diffs Side-by-side diffs Delta from patch set Stats (+1910 lines, -2 lines) Patch
A frog/file_system_memory.dart View 1 1 chunk +29 lines, -0 lines 0 comments Download
M frog/presubmit.py View 1 2 3 4 5 6 1 chunk +1 line, -2 lines 0 comments Download
M frog/source.dart View 1 chunk +4 lines, -0 lines 0 comments Download
A utils/css/css.dart View 1 2 3 4 5 1 chunk +62 lines, -0 lines 0 comments Download
A utils/css/cssselectorexception.dart View 1 2 3 4 5 1 chunk +23 lines, -0 lines 0 comments Download
A utils/css/cssworld.dart View 1 2 1 chunk +26 lines, -0 lines 0 comments Download
A utils/css/parser.dart View 1 2 3 4 5 6 1 chunk +394 lines, -0 lines 3 comments Download
A utils/css/test.dart View 1 2 3 4 5 6 7 8 1 chunk +107 lines, -0 lines 0 comments Download
A utils/css/tokenizer.dart View 1 2 3 4 5 6 7 1 chunk +123 lines, -0 lines 0 comments Download
A utils/css/tokenkind.dart View 1 2 3 4 5 6 1 chunk +142 lines, -0 lines 0 comments Download
A utils/css/tree.dart View 1 2 3 4 5 6 1 chunk +297 lines, -0 lines 4 comments Download
A utils/tests/css/css.status View 1 2 3 4 5 1 chunk +14 lines, -0 lines 0 comments Download
A utils/tests/css/src/ExpressionTest.dart View 1 2 3 4 5 6 1 chunk +439 lines, -0 lines 0 comments Download
A utils/tests/css/src/SelectorLiteralTest.dart View 1 2 3 4 5 6 1 chunk +241 lines, -0 lines 0 comments Download
A utils/tests/css/testcfg.py View 1 2 1 chunk +8 lines, -0 lines 0 comments Download

Messages

Total messages: 10 (0 generated)
terry
Jim here's the beginning of the CSS parser using the frog infrastructure. I'm working on ...
9 years, 1 month ago (2011-11-08 18:56:28 UTC) #1
kasperl
I really don't think this belongs in the frog/ directory. I understand that you want ...
9 years, 1 month ago (2011-11-09 07:51:18 UTC) #2
jimhug
I'm excited to see the beginnings of our very own CSS parser in dart. Having ...
9 years, 1 month ago (2011-11-09 16:04:03 UTC) #3
terry
I've moved css to $DART/utils/css added world and lang.dart (sync'ing to latest with checking found ...
9 years, 1 month ago (2011-11-09 21:56:06 UTC) #4
nweiz
http://codereview.chromium.org/8498020/diff/1/frog/css/parser_css.dart File frog/css/parser_css.dart (right): http://codereview.chromium.org/8498020/diff/1/frog/css/parser_css.dart#newcode16 frog/css/parser_css.dart:16: bool _inInitializers; Unused variable. http://codereview.chromium.org/8498020/diff/1/frog/css/parser_css.dart#newcode66 frog/css/parser_css.dart:66: return TokenKind.isIdentifier(_peekToken.kind); Why ...
9 years, 1 month ago (2011-11-10 00:04:39 UTC) #5
jimhug
This is starting to look really nice! Take your time responding to Nathan's and my ...
9 years, 1 month ago (2011-11-10 17:58:56 UTC) #6
terry
http://codereview.chromium.org/8498020/diff/1/frog/css/parser_css.dart File frog/css/parser_css.dart (right): http://codereview.chromium.org/8498020/diff/1/frog/css/parser_css.dart#newcode16 frog/css/parser_css.dart:16: bool _inInitializers; On 2011/11/10 00:04:39, nweiz wrote: > Unused ...
9 years, 1 month ago (2011-11-16 14:00:22 UTC) #7
jimhug
LGTM! And welcome back! http://codereview.chromium.org/8498020/diff/17001/utils/css/test.dart File utils/css/test.dart (right): http://codereview.chromium.org/8498020/diff/17001/utils/css/test.dart#newcode68 utils/css/test.dart:68: final String bgcolor = templateValid ...
9 years, 1 month ago (2011-11-17 16:49:27 UTC) #8
terry
http://codereview.chromium.org/8498020/diff/1/frog/css/parser_css.dart File frog/css/parser_css.dart (right): http://codereview.chromium.org/8498020/diff/1/frog/css/parser_css.dart#newcode149 frog/css/parser_css.dart:149: if (!_maybeEat(TokenKind.END_OF_FILE)) { On 2011/11/10 00:04:39, nweiz wrote: > ...
9 years, 1 month ago (2011-11-22 16:40:47 UTC) #9
nweiz
9 years, 1 month ago (2011-11-23 00:59:44 UTC) #10
http://codereview.chromium.org/8498020/diff/1/frog/css/parser_css.dart
File frog/css/parser_css.dart (right):

http://codereview.chromium.org/8498020/diff/1/frog/css/parser_css.dart#newcode66
frog/css/parser_css.dart:66: return TokenKind.isIdentifier(_peekToken.kind);
Frog's parser needs it because there are multiple tokens that count as
identifiers. That's not the case in CSS.

On 2011/11/16 14:00:22, terry wrote:
> This is mimicked after frog's parser.
> 
> On 2011/11/10 00:04:39, nweiz wrote:
> > Why can't you use _peekKind(TokenKind.IDENTIFIER)?
>

http://codereview.chromium.org/8498020/diff/1/frog/css/parser_css.dart#newcode85
frog/css/parser_css.dart:85: void _eatSemicolon() {
I don't think it'll be useful, actually... there aren't any places in CSS where
a semicolon is mandatory; it could always just be the end of a block instead.

On 2011/11/16 14:00:22, terry wrote:
> Unused now will use later.
> 
> On 2011/11/10 00:04:39, nweiz wrote:
> > Unused method.
>

http://codereview.chromium.org/8498020/diff/1/frog/css/parser_css.dart#newcod...
frog/css/parser_css.dart:190: 'Can not mix Id selector with class selector(s).
Id ' +
On 2011/11/16 14:00:22, terry wrote:
> Of course, however this is used by the validator for css literals @{...} in
that
> context this is not a valid selector.
> 
> On 2011/11/10 00:04:39, nweiz wrote:
> > This isn't actually true. "#foo.bar" is a valid selector, and can even be
> useful
> > for matching different elements across multiple pages.
> 

Why aren't we allowing arbitrary selectors in selector literals? Allowing most
selectors but banning a few is bound to be confusing for users.

http://codereview.chromium.org/8498020/diff/30018/utils/css/parser.dart
File utils/css/parser.dart (right):

http://codereview.chromium.org/8498020/diff/30018/utils/css/parser.dart#newco...
utils/css/parser.dart:109: List<SelectorGroup> preprocess() {
I don't like "preprocess" here either. This method doesn't actually do any
processing, it just parses. It would be consistent with the dart parser and the
rest of this parser to name this after the production that it parses (that is,
"selectorGroup").

http://codereview.chromium.org/8498020/diff/30018/utils/css/parser.dart#newco...
utils/css/parser.dart:185: var errorSelector;                  // signal which
selector didn't match.
Unused variable.

http://codereview.chromium.org/8498020/diff/30018/utils/css/parser.dart#newco...
utils/css/parser.dart:264: simpleSelectorSequence(bool forceCombinatorNone) {
While this technically works by treating sequences of simple selectors as though
they were separated by a special combinator, the parse tree is going to look
pretty different from how selectors are described in the spec. ".foo.bar .baz"
isn't three simple selectors separated by two combinators; it's two sequences of
simple selectors separated by one combinator. It should parse as so:

[SimpleSelectorSequence([
     SimpleSelector(.foo),
     SimpleSelector(.bar)
   ], TokenKind.COMBINATOR_NONE),
 SimpleSelectorSequence(
   [SimpleSelector.baz],
   TokenKind.COMBINATOR_DESCENDANT
 )]

http://codereview.chromium.org/8498020/diff/30018/utils/css/tree.dart
File utils/css/tree.dart (right):

http://codereview.chromium.org/8498020/diff/30018/utils/css/tree.dart#newcode29
utils/css/tree.dart:29: class SelectorGroup extends lang.Node {
As per discussion of selector hierarchy elsewhere in this CL and over email:

A "selector group" is a comma-separated list of "selectors". The class should
contain a List<Selector>.

A "selector" is a combinator-separated list of "sequences of simple selectors".
The class should contain a List<SimpleSelectorSequence>.

A "sequence of simple selectors" is a list of "simple selectors". The class
should contain a combinator and a List<SimpleSelector>.

A "simple selector" is basically what you have here, without the combinator.

http://codereview.chromium.org/8498020/diff/30018/utils/css/tree.dart#newcode77
utils/css/tree.dart:77: String get name() => isWildcard() ? '*' : _name.name;
I don't understand the need to have a "name" property for simple selectors. If
you want a string representation, use toString. Sure, most simple selectors do
have names, but it's not a necessary aspect of them.

The semantics of the name also differ from subclass to subclass. Having a
wildcard for a name only makes sense for ElementSelector, for example.

I suggest making name a property of each subclass that needs it individually.

http://codereview.chromium.org/8498020/diff/30018/utils/css/tree.dart#newcode79
utils/css/tree.dart:79: bool isWildcard() => _name is Wildcard;
If you're going to have a separate Wildcard class for _name, you might as well
just return that for the name property rather than coercing it to a string. That
was the user can use the more-modular "sel.name is Wildcard" and "sel.namespace
is Wildcard".

http://codereview.chromium.org/8498020/diff/30018/utils/css/tree.dart#newcode119
utils/css/tree.dart:119: class NamespaceSelector extends SimpleSelector {
Namespaces aren't separate simple selectors. A namespace is a property of
element selectors (and universal selectors, but it looks like you're parsing
those as element selectors). I suggest removing this class and adding a
namespace field to ElementSelector.

Powered by Google App Engine
This is Rietveld 408576698