File tree Expand file tree Collapse file tree 2 files changed +29
-2
lines changed Expand file tree Collapse file tree 2 files changed +29
-2
lines changed Original file line number Diff line number Diff line change
1
+ //! This is a simple CLI utility to take in an FTL file and output the AST.
2
+ //!
3
+ //! ## View the `Debug` representation:
4
+ //!
5
+ //! From the root directory of the `fluent-rs` repo:
6
+ //!
7
+ //! ```sh
8
+ //! cargo run --bin parser -- ./fluent-syntax/tests/fixtures/literal_expressions.ftl
9
+ //! ```
10
+ //!
11
+ //! ## View the `json` representation:
12
+ //!
13
+ //! ```sh
14
+ //! cargo run --bin parser --features json -- ./fluent-syntax/tests/fixtures/literal_expressions.ftl
15
+ //! ```
16
+
1
17
use fluent_syntax:: parser:: parse;
2
18
use std:: env;
3
19
use std:: fs:: File ;
@@ -13,7 +29,8 @@ fn read_file(path: &str) -> Result<String, io::Error> {
13
29
14
30
fn main ( ) {
15
31
let args: Vec < String > = env:: args ( ) . collect ( ) ;
16
- let source = read_file ( args. get ( 1 ) . expect ( "Pass an argument" ) ) . expect ( "Failed to fetch file" ) ;
32
+ let source = read_file ( args. get ( 1 ) . expect ( "Pass a file path as the first argument" ) )
33
+ . expect ( "Failed to fetch file" ) ;
17
34
18
35
let ( ast, errors) = match parse ( source. as_str ( ) ) {
19
36
Ok ( ast) => ( ast, None ) ,
Original file line number Diff line number Diff line change
1
+ //! Run the `update_fixtures` binary after updating any of the `benches` `.ftl` fixtures.
2
+ //! This will update the `.json` files used in reference tests.
3
+ //!
4
+ //! This file must be run from `{PROJECT_ROOT}/fluent-syntax`
5
+ //!
6
+ //! ```sh
7
+ //! cargo run --bin update_fixtures --features="json"
8
+ //! ```
1
9
use std:: fs;
2
10
use std:: io;
3
11
@@ -17,7 +25,9 @@ fn main() {
17
25
18
26
for sample in samples {
19
27
let path = format ! ( "./benches/{}.ftl" , sample) ;
20
- let source = read_file ( & path) . unwrap ( ) ;
28
+ let source = read_file ( & path) . expect (
29
+ "Could not read the benches file. Are you running this from the correct directory? It must be run from `{PROJECT_ROOT}/fluent-syntax`" ,
30
+ ) ;
21
31
let ast = parse ( source) . unwrap ( ) ;
22
32
let target_json = serde_json:: to_string_pretty ( & ast) . unwrap ( ) ;
23
33
let new_path = format ! ( "./tests/fixtures/benches/{}.json" , sample) ;
You can’t perform that action at this time.
0 commit comments