File tree Expand file tree Collapse file tree 3 files changed +11
-4
lines changed Expand file tree Collapse file tree 3 files changed +11
-4
lines changed Original file line number Diff line number Diff line change @@ -34,5 +34,5 @@ fixtures: $(STRUCTURE_AST)
34
34
35
35
.PHONY : $(STRUCTURE_AST )
36
36
$(STRUCTURE_AST ) : test/fixtures_structure/% .json: test/fixtures_structure/% .ftl
37
- @../tools/parse.js -s $< > $@
37
+ @../tools/parse.js --silent --with-spans $< > $@
38
38
@echo -e " $( OK) $@ "
Original file line number Diff line number Diff line change @@ -34,5 +34,5 @@ fixtures: $(STRUCTURE_JSON)
34
34
35
35
.PHONY : $(STRUCTURE_JSON )
36
36
$(STRUCTURE_JSON ) : test/fixtures_structure/% .json: ../fluent-syntax/test/fixtures_structure/% .ftl
37
- @../tools/parse.js -rs $< > $@
37
+ @../tools/parse.js --runtime --silent $< > $@
38
38
@echo -e " $( OK) $@ "
Original file line number Diff line number Diff line change @@ -16,6 +16,7 @@ program
16
16
. usage ( '[options] [file]' )
17
17
. option ( '-r, --runtime' , 'Use the runtime parser' )
18
18
. option ( '-s, --silent' , 'Silence syntax errors' )
19
+ . option ( '--with-spans' , 'Compute spans of AST nodes' )
19
20
. parse ( process . argv ) ;
20
21
21
22
if ( program . args . length ) {
@@ -47,12 +48,18 @@ function printRuntime(data) {
47
48
}
48
49
49
50
function printResource ( data ) {
51
+ const withSpans = ! ! program . withSpans ;
50
52
const source = data . toString ( ) ;
51
- const res = FluentSyntax . parse ( source ) ;
53
+ const res = FluentSyntax . parse ( source , { withSpans } ) ;
52
54
console . log ( JSON . stringify ( res , null , 2 ) ) ;
53
55
54
56
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 ) ) ;
56
63
}
57
64
}
58
65
You can’t perform that action at this time.
0 commit comments