1- use std:: fs:: File ;
2- use std:: io:: LineWriter ;
3- use std:: path:: Path ;
4-
51mod dbscheme;
2+ mod language;
63mod node_types;
4+
5+ use language:: Language ;
76use node_types:: { FieldInfo , NodeInfo } ;
7+ use std:: fs:: File ;
8+ use std:: io:: LineWriter ;
9+ use std:: path:: PathBuf ;
810
9- fn read_node_types ( ) -> Option < Vec < NodeInfo > > {
10- let json_data = match std:: fs:: read_to_string ( Path :: new ( "tree-sitter-ruby/src/node-types.json" ) )
11- {
11+ fn read_node_types ( language : & Language ) -> Option < Vec < NodeInfo > > {
12+ let json_data = match std:: fs:: read_to_string ( & language. node_types_path ) {
1213 Ok ( s) => s,
1314 Err ( _) => return None ,
1415 } ;
@@ -214,19 +215,17 @@ fn convert_nodes(nodes: &[NodeInfo]) -> Vec<dbscheme::Entry> {
214215 entries
215216}
216217
217- fn write_dbscheme ( entries : & [ dbscheme:: Entry ] ) -> std:: io:: Result < ( ) > {
218- // TODO: figure out proper output path and/or take it from the command line.
219- let path = Path :: new ( "ruby.dbscheme" ) ;
218+ fn write_dbscheme ( language : & Language , entries : & [ dbscheme:: Entry ] ) -> std:: io:: Result < ( ) > {
220219 println ! (
221220 "Writing to '{}'" ,
222- match path . to_str( ) {
221+ match language . dbscheme_path . to_str( ) {
223222 None => "<undisplayable>" ,
224223 Some ( p) => p,
225224 }
226225 ) ;
227- let file = File :: create ( path ) ?;
226+ let file = File :: create ( & language . dbscheme_path ) ?;
228227 let mut file = LineWriter :: new ( file) ;
229- dbscheme:: write ( & mut file, & entries)
228+ dbscheme:: write ( & language . name , & mut file, & entries)
230229}
231230
232231fn create_location_entry ( ) -> dbscheme:: Entry {
@@ -295,7 +294,14 @@ fn create_source_location_prefix_entry() -> dbscheme::Entry {
295294}
296295
297296fn main ( ) {
298- match read_node_types ( ) {
297+ // TODO: figure out proper dbscheme output path and/or take it from the
298+ // command line.
299+ let ruby = Language {
300+ name : "Ruby" . to_string ( ) ,
301+ node_types_path : PathBuf :: from ( "tree-sitter-ruby/src/node-types.json" ) ,
302+ dbscheme_path : PathBuf :: from ( "ruby.dbscheme" ) ,
303+ } ;
304+ match read_node_types ( & ruby) {
299305 None => {
300306 println ! ( "Failed to read node types" ) ;
301307 std:: process:: exit ( 1 ) ;
@@ -304,7 +310,7 @@ fn main() {
304310 let mut dbscheme_entries = convert_nodes ( & nodes) ;
305311 dbscheme_entries. push ( create_location_entry ( ) ) ;
306312 dbscheme_entries. push ( create_source_location_prefix_entry ( ) ) ;
307- match write_dbscheme ( & dbscheme_entries) {
313+ match write_dbscheme ( & ruby , & dbscheme_entries) {
308314 Err ( e) => {
309315 println ! ( "Failed to write dbscheme: {}" , e) ;
310316 std:: process:: exit ( 2 ) ;
0 commit comments