Repository navigation
Conversation
There was a problem hiding this comment.
Code Review
This pull request adds support for nested list elements (such as nested ...for and ...if loops) and CR/CRLF line breaks in the Craft text format. It also enhances runtime error reporting by tracking and outputting the template name and line number of the failing node, with corresponding updates to the conformance schemas, test suites, and catalog generation. Feedback on the changes suggests optimizing the _lineStarts helper in text.dart to avoid allocating an intermediate list of all runes in the file, which improves memory efficiency for large files.
| List<int> _lineStarts(String file) { | ||
| final List<int> characters = file.runes.toList(); | ||
| final List<int> starts = <int>[0]; | ||
| for (int i = 0; i < characters.length; i += 1) { | ||
| final int c = characters[i]; | ||
| if (c == 0x0A || (c == 0x0D && characters.elementAtOrNull(i + 1) != 0x0A)) { | ||
| starts.add(i + 1); | ||
| } | ||
| } | ||
| return starts; | ||
| } |
There was a problem hiding this comment.
The current implementation of _lineStarts calls file.runes.toList(), which allocates a new list containing all runes in the file. For large files, this can lead to unnecessary memory allocation and overhead.
We can optimize this by iterating over file.runes directly and tracking the previous character to detect line breaks (including CR LF, CR, and LF). This avoids allocating the intermediate list entirely.
List<int> _lineStarts(String file) {
final List<int> starts = <int>[0];
int i = 0;
int? previous;
for (final int c in file.runes) {
if (previous == 0x0A || (previous == 0x0D && c != 0x0A)) {
starts.add(i);
}
previous = c;
i += 1;
}
if (previous == 0x0A || previous == 0x0D) {
starts.add(i);
}
return starts;
}879b8bd to
1413169
Compare
1413169 to
60a23c4
Compare
60a23c4 to
791abd0
Compare
791abd0 to
a70ffe7
Compare
a70ffe7 to
c3a28d5
Compare
Fixes dogfood bugs B04, B15 and B08. - B04: CR LF and CR are line breaks (craft_text_format requirement 6, a deliberate difference from RFW 2.0.0). A CR LF counts as one line in every reported position, including the source size limit; a CR inside a string literal is rejected and a CR ends an end-of-line comment. - B15: the element of a `...for` or `...if` may itself be a `...for` or `...if` (craft_language_extensions requirement 7), so `...for x in l: ...if c: e` filters a list. It parses to a loop whose output is a loop; the runtime flattens it (craft_runtime requirement 6), catalog schema derivation places the inner loop as an element, and the limits count it one level deeper. - B08: expansion error reports name the template that holds the failing node and, for libraries parsed with a source identifier, its line and column (craft_runtime requirement 12; conformance cases check `template` and `line`). Source locations carry line and column. Clearer messages for a self-call, a widget, builder or handler where a value is required (naming the function and argument, event, switch or setter), `let` after the bindings or inside a value, and a whole builder argument. - Token start offsets after a comment are now right, so the position of a node after a comment is correct. As a consequence, a comment between the two colons of `::` (`ui:/*c*/:Card()`) is rejected: craft_libraries_and_names requirement 1 now says that nothing, not even a comment, may separate them (RFW-derived code accepted it before).
c3a28d5 to
cafd49f
Compare
Description
Fixes from dogfooding the Craft engine: we built real apps on top of the stack as a power user would. Stacked on #33.
//comment....for x in l: ...if c: e(and any nesting of...for/...if) parses and filters a list. The binary format doesn't change.::must be written as two adjacent colons; a comment between them is now rejected.Each fix starts from the dogfooding repro, turned into a conformance case or unit test that fails before the change and passes after it. The blueprints are updated (
craft_text_format,craft_language_extensions,craft_runtime,craft_libraries_and_names,craft_a2ui_integration). An independent review checked the blueprints, tests and code, including about 306,000 line-ending variants.Pre-launch Checklist
One time:
For this PR:
python3 ./scripts/fix_licenses.py --check)../scripts/fix_format.sh --check).