Skip to content

Commit 0b8ba5f

Browse files
committed
tools/parse --with-spans
1 parent 4588bec commit 0b8ba5f

File tree

3 files changed

+11
-4
lines changed

3 files changed

+11
-4
lines changed

fluent-syntax/makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,5 +34,5 @@ fixtures: $(STRUCTURE_AST)
3434

3535
.PHONY: $(STRUCTURE_AST)
3636
$(STRUCTURE_AST): test/fixtures_structure/%.json: test/fixtures_structure/%.ftl
37-
@../tools/parse.js -s $< > $@
37+
@../tools/parse.js --silent --with-spans $< > $@
3838
@echo -e " $(OK) $@"

fluent/makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,5 +34,5 @@ fixtures: $(STRUCTURE_JSON)
3434

3535
.PHONY: $(STRUCTURE_JSON)
3636
$(STRUCTURE_JSON): test/fixtures_structure/%.json: ../fluent-syntax/test/fixtures_structure/%.ftl
37-
@../tools/parse.js -rs $< > $@
37+
@../tools/parse.js --runtime --silent $< > $@
3838
@echo -e " $(OK) $@"

tools/parse.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ program
1616
.usage('[options] [file]')
1717
.option('-r, --runtime', 'Use the runtime parser')
1818
.option('-s, --silent', 'Silence syntax errors')
19+
.option('--with-spans', 'Compute spans of AST nodes')
1920
.parse(process.argv);
2021

2122
if (program.args.length) {
@@ -47,12 +48,18 @@ function printRuntime(data) {
4748
}
4849

4950
function printResource(data) {
51+
const withSpans = !!program.withSpans;
5052
const source = data.toString();
51-
const res = FluentSyntax.parse(source);
53+
const res = FluentSyntax.parse(source, {withSpans});
5254
console.log(JSON.stringify(res, null, 2));
5355

5456
if (!program.silent) {
55-
res.body.map(entry => printAnnotations(source, entry));
57+
// Spans are required to pretty-print the annotations. If needed, re-parse
58+
// the source.
59+
const {body} = withSpans
60+
? res
61+
: FluentSyntax.parse(source, {withSpans: true});
62+
body.map(entry => printAnnotations(source, entry));
5663
}
5764
}
5865

0 commit comments

Comments
 (0)