Fixed jael

This commit is contained in:
thomashii@dukefirehawk.com 2021-04-30 07:32:16 +08:00
parent ea6d566607
commit e83d56c9af
10 changed files with 26 additions and 30 deletions

View file

@ -19,7 +19,7 @@
* Migrated angel_websocket to 4.0.0 (2/3 tests passed)
* Updated test to 4.0.0 (1/1 test passed)
* Added symbol_table and migrated to 2.0.0 (16/16 tests passed)
* Migrated jael to 4.0.0 (17/20 tests passed)
* Migrated jael to 4.0.0 (20/20 tests passed)
* Updated jael_preprocessor to 3.0.0 (in progress)
* Updated angel_jael to 3.0.0 (in progress)
* Updated pub_sub to 3.0.0 (in progress)

View file

@ -38,7 +38,7 @@ class BinaryExpression extends Expression {
return l ?? r;
default:
throw UnsupportedError(
'Unsupported binary operator: "${operator.span.text ?? "<null>"}".');
'Unsupported binary operator: "${operator.span.text}".');
}
}

View file

@ -4,10 +4,17 @@ import 'expression.dart';
import 'token.dart';
class Identifier extends Expression {
final Token id;
late Token id;
Identifier(this.id);
// TODO: Fix for SyntheticIdentifier
Identifier.noToken(Token? token) {
if (token != null) {
id = token;
}
}
@override
dynamic compute(SymbolTable? scope) {
switch (name) {
@ -27,7 +34,7 @@ class Identifier extends Expression {
}
}
String get name => id.span.text ?? '';
String get name => id.span.text;
@override
FileSpan get span => id.span;
@ -37,11 +44,11 @@ class SyntheticIdentifier extends Identifier {
@override
final String name;
SyntheticIdentifier(this.name, [Token? token]) : super(token!);
SyntheticIdentifier(this.name, [Token? token]) : super.noToken(token);
@override
FileSpan get span {
return id.span;
//throw UnsupportedError('Cannot get the span of a SyntheticIdentifier.');
//return id.span;
throw UnsupportedError('Cannot get the span of a SyntheticIdentifier.');
}
}

View file

@ -9,7 +9,7 @@ class Interpolation extends ElementChild {
Interpolation(this.doubleCurlyL, this.expression, this.doubleCurlyR);
bool get isRaw => doubleCurlyL.span.text?.endsWith('-') ?? false;
bool get isRaw => doubleCurlyL.span.text.endsWith('-');
@override
FileSpan get span {

View file

@ -25,10 +25,7 @@ class NumberLiteral extends Literal {
@override
num compute(scope) {
if (number.span.text == null) {
return 0;
}
return _value ??= parse(number.span.text!);
return _value ??= parse(number.span.text);
}
}
@ -45,9 +42,6 @@ class HexLiteral extends Literal {
@override
num compute(scope) {
if (hex.span.text == null) {
return 0;
}
return _value ??= parse(hex.span.text!);
return _value ??= parse(hex.span.text);
}
}

View file

@ -13,11 +13,8 @@ class StringLiteral extends Literal {
static String parseValue(Token string) {
var buf = StringBuffer();
if (string.span.text == null) {
return buf.toString();
}
var text = string.span.text!.substring(1, string.span.text!.length - 1);
var text = string.span.text.substring(1, string.span.text.length - 1);
var codeUnits = text.codeUnits;
for (var i = 0; i < codeUnits.length; i++) {

View file

@ -72,11 +72,11 @@ class JaelFormatter {
var b = StringBuffer('{{');
if (child.isRaw) b.write('-');
b.write(' ');
b.write(child.expression.span.text?.trim());
b.write(child.expression.span.text.trim());
b.write(' }}');
s = b.toString();
} else {
s = child.span.text ?? '';
s = child.span.text;
}
if (isFirst) {
s = s.trimLeft();

View file

@ -304,9 +304,9 @@ class Renderer {
SymbolTable scope, bool html5, int index, int total) {
if (child is Text && parent.tagName.name != 'textarea') {
if (index == 0) {
buffer.write(child.span.text?.trimLeft());
buffer.write(child.span.text.trimLeft());
} else if (index == total - 1) {
buffer.write(child.span.text?.trimRight());
buffer.write(child.span.text.trimRight());
} else {
buffer.write(child.span.text);
}

View file

@ -91,7 +91,7 @@ class Parser {
}
var doctype = _current;
var html = parseIdentifier();
if (html == null || html.span.text?.toLowerCase() != 'html') {
if (html == null || html.span.text.toLowerCase() != 'html') {
errors.add(JaelError(
JaelErrorSeverity.error,
'Expected "html" in doctype declaration.',
@ -112,7 +112,7 @@ class Parser {
return Doctype(lt, doctype, html, null, null, null, _current);
}
if (public.span.text?.toLowerCase() != 'public') {
if (public.span.text.toLowerCase() != 'public') {
//errors.add(JaelError(
// JaelErrorSeverity.error,
// 'Expected "public" in doctype declaration.',

View file

@ -167,7 +167,7 @@ class _Scanner implements Scanner {
var span = _scanner.spanFrom(start, end);
if (span.text?.isNotEmpty == true) {
if (span.text.isNotEmpty == true) {
tokens.add(Token(TokenType.text, span, null));
}
}
@ -205,9 +205,7 @@ class _Scanner implements Scanner {
var token = potential.first;
tokens.add(token);
if (token.span.text != null) {
_scanner.scan(token.span.text!);
}
_scanner.scan(token.span.text);
if (token.type == TokenType.lt) {
brackets.addFirst(token);