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) * Migrated angel_websocket to 4.0.0 (2/3 tests passed)
* Updated test to 4.0.0 (1/1 test passed) * Updated test to 4.0.0 (1/1 test passed)
* Added symbol_table and migrated to 2.0.0 (16/16 tests 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 jael_preprocessor to 3.0.0 (in progress)
* Updated angel_jael to 3.0.0 (in progress) * Updated angel_jael to 3.0.0 (in progress)
* Updated pub_sub 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; return l ?? r;
default: default:
throw UnsupportedError( 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'; import 'token.dart';
class Identifier extends Expression { class Identifier extends Expression {
final Token id; late Token id;
Identifier(this.id); Identifier(this.id);
// TODO: Fix for SyntheticIdentifier
Identifier.noToken(Token? token) {
if (token != null) {
id = token;
}
}
@override @override
dynamic compute(SymbolTable? scope) { dynamic compute(SymbolTable? scope) {
switch (name) { switch (name) {
@ -27,7 +34,7 @@ class Identifier extends Expression {
} }
} }
String get name => id.span.text ?? ''; String get name => id.span.text;
@override @override
FileSpan get span => id.span; FileSpan get span => id.span;
@ -37,11 +44,11 @@ class SyntheticIdentifier extends Identifier {
@override @override
final String name; final String name;
SyntheticIdentifier(this.name, [Token? token]) : super(token!); SyntheticIdentifier(this.name, [Token? token]) : super.noToken(token);
@override @override
FileSpan get span { FileSpan get span {
return id.span; //return id.span;
//throw UnsupportedError('Cannot get the span of a SyntheticIdentifier.'); 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); Interpolation(this.doubleCurlyL, this.expression, this.doubleCurlyR);
bool get isRaw => doubleCurlyL.span.text?.endsWith('-') ?? false; bool get isRaw => doubleCurlyL.span.text.endsWith('-');
@override @override
FileSpan get span { FileSpan get span {

View file

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

View file

@ -13,11 +13,8 @@ class StringLiteral extends Literal {
static String parseValue(Token string) { static String parseValue(Token string) {
var buf = StringBuffer(); 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; var codeUnits = text.codeUnits;
for (var i = 0; i < codeUnits.length; i++) { for (var i = 0; i < codeUnits.length; i++) {

View file

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

View file

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

View file

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

View file

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