mirror of
https://github.com/danog/dart-sass.git
synced 2024-12-04 18:47:56 +01:00
Add parser for Expression and VariableDeclaration
This commit is contained in:
parent
2e42c749a0
commit
9939b70ffb
@ -2,6 +2,8 @@
|
||||
// MIT-style license that can be found in the LICENSE file or at
|
||||
// https://opensource.org/licenses/MIT.
|
||||
|
||||
import '../../logger.dart';
|
||||
import '../../parse/scss.dart';
|
||||
import '../../visitor/interface/expression.dart';
|
||||
import 'node.dart';
|
||||
|
||||
@ -9,4 +11,12 @@ import 'node.dart';
|
||||
abstract class Expression implements SassNode {
|
||||
/// Calls the appropriate visit method on [visitor].
|
||||
T accept<T>(ExpressionVisitor<T> visitor);
|
||||
|
||||
/// Parses an expression from [contents].
|
||||
///
|
||||
/// If passed, [url] is the name of the file from which [contents] comes.
|
||||
///
|
||||
/// Throws a [SassFormatException] if parsing fails.
|
||||
factory Expression.parse(String contents, {url, Logger logger}) =>
|
||||
new ScssParser("$contents", url: url, logger: logger).parseExpression();
|
||||
}
|
||||
|
@ -4,6 +4,8 @@
|
||||
|
||||
import 'package:source_span/source_span.dart';
|
||||
|
||||
import '../../../logger.dart';
|
||||
import '../../../parse/scss.dart';
|
||||
import '../../../visitor/interface/statement.dart';
|
||||
import '../expression.dart';
|
||||
import '../statement.dart';
|
||||
@ -35,6 +37,15 @@ class VariableDeclaration implements Statement {
|
||||
: isGuarded = guarded,
|
||||
isGlobal = global;
|
||||
|
||||
/// Parses a variable declaration from [contents].
|
||||
///
|
||||
/// If passed, [url] is the name of the file from which [contents] comes.
|
||||
///
|
||||
/// Throws a [SassFormatException] if parsing fails.
|
||||
factory VariableDeclaration.parse(String contents, {url, Logger logger}) =>
|
||||
new ScssParser(contents, url: url, logger: logger)
|
||||
.parseVariableDeclaration();
|
||||
|
||||
T accept<T>(StatementVisitor<T> visitor) =>
|
||||
visitor.visitVariableDeclaration(this);
|
||||
|
||||
|
@ -80,6 +80,22 @@ abstract class StylesheetParser extends Parser {
|
||||
});
|
||||
}
|
||||
|
||||
Expression parseExpression() {
|
||||
return wrapSpanFormatException(() {
|
||||
var expression = _expression();
|
||||
scanner.expectDone();
|
||||
return expression;
|
||||
});
|
||||
}
|
||||
|
||||
VariableDeclaration parseVariableDeclaration() {
|
||||
return wrapSpanFormatException(() {
|
||||
var declaration = variableDeclaration();
|
||||
scanner.expectDone();
|
||||
return declaration;
|
||||
});
|
||||
}
|
||||
|
||||
/// Parses a function signature of the format allowed by Node Sass's functions
|
||||
/// option and returns its name and declaration.
|
||||
///
|
||||
|
Loading…
Reference in New Issue
Block a user