mirror of
https://github.com/danog/dart-sass.git
synced 2025-01-22 05:41:14 +01:00
styleRule()
This commit is contained in:
parent
c030eb5581
commit
6eeb6a96f4
23
lib/src/ast/style_rule.dart
Normal file
23
lib/src/ast/style_rule.dart
Normal file
@ -0,0 +1,23 @@
|
||||
// Copyright 2016 Google Inc. Use of this source code is governed by an
|
||||
// MIT-style license that can be found in the LICENSE file or at
|
||||
// https://opensource.org/licenses/MIT.
|
||||
|
||||
import 'package:source_span/source_span.dart';
|
||||
|
||||
import 'expression/interpolation.dart';
|
||||
import 'node.dart';
|
||||
|
||||
class StyleRuleNode implements AstNode {
|
||||
final InterpolationExpression selector;
|
||||
|
||||
final List<AstNode> children;
|
||||
|
||||
final SourceSpan span;
|
||||
|
||||
// TODO: validate that children only contains variable, at-rule, declaration,
|
||||
// or style nodes?
|
||||
StyleRuleNode(this.selector, Iterable<AstNode> children, {this.span})
|
||||
: children = new List.unmodifiable(children);
|
||||
|
||||
String toString() => "$selector {${children.join("; ")}}";
|
||||
}
|
@ -12,6 +12,7 @@ import 'ast/expression/identifier.dart';
|
||||
import 'ast/expression/interpolation.dart';
|
||||
import 'ast/expression/list.dart';
|
||||
import 'ast/expression/string.dart';
|
||||
import 'ast/style_rule.dart';
|
||||
import 'ast/stylesheet.dart';
|
||||
import 'ast/variable_declaration.dart';
|
||||
import 'interpolation_buffer.dart';
|
||||
@ -49,10 +50,10 @@ class Parser {
|
||||
case $semicolon: break;
|
||||
|
||||
default:
|
||||
children.add(_declaration());
|
||||
children.add(_styleRule());
|
||||
break;
|
||||
}
|
||||
} while (_scanner.scan(';'));
|
||||
} while (_scanChar($semicolon));
|
||||
|
||||
_scanner.expectDone();
|
||||
return new StylesheetNode(children, span: _scanner.spanFrom(start));
|
||||
@ -93,7 +94,39 @@ class Parser {
|
||||
|
||||
AstNode _atRule() => throw new UnimplementedError();
|
||||
|
||||
AstNode _declaration() => throw new UnimplementedError();
|
||||
StyleRuleNode _styleRule() {
|
||||
var start = _scanner.state;
|
||||
var selector = _almostAnyValue();
|
||||
_expectChar($lbrace);
|
||||
|
||||
var children = <AstNode>[];
|
||||
do {
|
||||
children.addAll(_comments());
|
||||
switch (_scanner.peekChar()) {
|
||||
case $dollar:
|
||||
children.add(_variableDeclaration());
|
||||
break;
|
||||
|
||||
case $at:
|
||||
children.add(_atRule());
|
||||
break;
|
||||
|
||||
case $semicolon:
|
||||
case $rbrace:
|
||||
break;
|
||||
|
||||
default:
|
||||
children.add(_declarationOrStyleRule());
|
||||
break;
|
||||
}
|
||||
} while (_scanChar($semicolon));
|
||||
|
||||
_expectChar($rbrace);
|
||||
return new StyleRuleNode(selector, children,
|
||||
span: _scanner.spanFrom(start));
|
||||
}
|
||||
|
||||
AstNode _declarationOrStyleRule() => throw new UnimplementedError();
|
||||
|
||||
/// Consumes whitespace if available and returns any comments it contained.
|
||||
List<CommentNode> _comments() {
|
||||
|
Loading…
x
Reference in New Issue
Block a user