1
1
#![ recursion_limit = "128" ]
2
2
3
3
use log:: { debug, error, info} ;
4
+ use svd2rust:: util:: { Case , IdentFormat } ;
4
5
5
6
use std:: io:: Write ;
6
7
use std:: process;
7
8
use std:: { fs:: File , path:: Path } ;
8
9
9
- use anyhow:: { Context , Result } ;
10
+ use anyhow:: { anyhow , Context , Result } ;
10
11
use clap:: { Arg , ArgAction , Command } ;
11
12
12
13
use svd2rust:: {
@@ -18,6 +19,8 @@ use svd2rust::{
18
19
fn parse_configs ( app : Command ) -> Result < Config > {
19
20
use irx_config:: parsers:: { cmd, toml} ;
20
21
use irx_config:: ConfigBuilder ;
22
+ let ident_formats = app. clone ( ) . get_matches ( ) ;
23
+ dbg ! ( & ident_formats) ;
21
24
let irxconfig = ConfigBuilder :: default ( )
22
25
. append_parser ( cmd:: ParserBuilder :: new ( app) . exit_on_error ( true ) . build ( ) ?)
23
26
. append_parser (
@@ -29,7 +32,81 @@ fn parse_configs(app: Command) -> Result<Config> {
29
32
)
30
33
. load ( ) ?;
31
34
32
- irxconfig. get ( ) . map_err ( Into :: into)
35
+ let mut config: Config = irxconfig. get ( ) ?;
36
+ if let Some ( ident_formats) = ident_formats. get_many :: < String > ( "ident_format" ) {
37
+ for f in ident_formats {
38
+ let mut f = f. split ( ":" ) ;
39
+ dbg ! ( f. clone( ) . count( ) ) ;
40
+ if let ( Some ( n) , Some ( p) , Some ( c) , Some ( s) ) = ( f. next ( ) , f. next ( ) , f. next ( ) , f. next ( ) ) {
41
+ let fmts = & mut config. ident_formats ;
42
+ let case = match c {
43
+ "" => None ,
44
+ "p" | "pascal" | "type" => Some ( Case :: Pascal ) ,
45
+ "s" | "snake" | "lower" => Some ( Case :: Snake ) ,
46
+ "c" | "constant" | "upper" => Some ( Case :: Constant ) ,
47
+ _ => return Err ( anyhow ! ( "Unknown case" ) ) ,
48
+ } ;
49
+ let id_f = IdentFormat {
50
+ case,
51
+ prefix : p. into ( ) ,
52
+ suffix : s. into ( ) ,
53
+ } ;
54
+ dbg ! ( & id_f) ;
55
+ match n {
56
+ "field_reader" => {
57
+ fmts. field_reader = id_f;
58
+ }
59
+ "enum_name" => {
60
+ fmts. enum_name = id_f;
61
+ }
62
+ "enum_write_name" => {
63
+ fmts. enum_write_name = id_f;
64
+ }
65
+ "enum_value" => {
66
+ fmts. enum_value = id_f;
67
+ }
68
+ "interrupt" => {
69
+ fmts. interrupt = id_f;
70
+ }
71
+ "cluster" => {
72
+ fmts. cluster = id_f;
73
+ }
74
+ "cluster_accessor" => {
75
+ fmts. cluster_accessor = id_f;
76
+ }
77
+ //"cluster_mod" => {
78
+ // fmts.cluster_mod = id_f;
79
+ //},
80
+ "register" => {
81
+ fmts. register = id_f;
82
+ }
83
+ "register_spec" => {
84
+ fmts. register_spec = id_f;
85
+ }
86
+ "register_accessor" => {
87
+ fmts. register_accessor = id_f;
88
+ }
89
+ //"register_mod" => {
90
+ // fmts.register_mod = id_f;
91
+ //},
92
+ "peripheral" => {
93
+ fmts. peripheral = id_f;
94
+ }
95
+ "peripheral_sigleton" => {
96
+ fmts. peripheral_sigleton = id_f;
97
+ }
98
+ //"peripheral_mod" => {
99
+ // fmts.peripheral_mod = id_f;
100
+ //},
101
+ "peripheral_feature" => {
102
+ fmts. peripheral_feature = id_f;
103
+ }
104
+ _ => { }
105
+ }
106
+ }
107
+ }
108
+ }
109
+ Ok ( config)
33
110
}
34
111
35
112
fn run ( ) -> Result < ( ) > {
@@ -119,6 +196,14 @@ fn run() -> Result<()> {
119
196
. action ( ArgAction :: SetTrue )
120
197
. help ( "Use independent cfg feature flags for each peripheral" ) ,
121
198
)
199
+ . arg (
200
+ Arg :: new ( "ident_format" )
201
+ . long ( "ident-format" )
202
+ . short ( 'f' )
203
+ . alias ( "ident_format" )
204
+ . action ( ArgAction :: Append )
205
+ . help ( "Specify prefix, case and suffix for identifier type" ) ,
206
+ )
122
207
. arg (
123
208
Arg :: new ( "max_cluster_size" )
124
209
. long ( "max-cluster-size" )
0 commit comments