1+ use crate :: systems:: System ;
12use nom:: types:: CompleteStr ;
23use tracing:: warn;
34
@@ -24,32 +25,79 @@ named!(
2425 |s: CompleteStr | !s. 0 . eq_ignore_ascii_case( "@grahamcofborg" )
2526 )
2627) ;
28+
2729named ! (
28- parse_line_impl ( CompleteStr ) -> Option < Vec < Instruction >> ,
30+ system ( CompleteStr ) -> System ,
2931 alt!(
30- do_parse!(
31- res: ws!( many1!( ws!( preceded!(
32- alt!( tag_no_case!( "@grahamcofborg" ) | tag_no_case!( "@ofborg" ) ) ,
33- alt!(
34- ws!( do_parse!(
35- tag!( "build" ) >>
32+ value!( System :: X8664Linux , tag!( "x86_64-linux" ) ) |
33+ value!( System :: Aarch64Linux , tag!( "aarch64-linux" ) ) |
34+ value!( System :: X8664Darwin , tag!( "x86_64-darwin" ) ) |
35+ value!( System :: Aarch64Darwin , tag!( "aarch64-darwin" ) )
36+ )
37+ ) ;
38+
39+ named ! (
40+ invocation_prefix( CompleteStr ) -> CompleteStr ,
41+ alt!( tag_no_case!( "@ofborg" ) | tag_no_case!( "@grahamcofborg" ) )
42+ ) ;
43+
44+ enum Command {
45+ Eval ,
46+ Build ,
47+ BuildSystem ,
48+ Test ,
49+ }
50+
51+ named ! (
52+ command_str( CompleteStr ) -> Option <Command >,
53+ alt!(
54+ value!( Some ( Command :: Eval ) , tag!( "eval" ) ) |
55+ value!( Some ( Command :: BuildSystem ) , tag!( "build_system" ) ) |
56+ value!( Some ( Command :: Build ) , tag!( "build" ) ) |
57+ value!( Some ( Command :: Test ) , tag!( "test" ) ) |
58+
59+ // TODO: Currently keeping previous behaviour of ignoring unknown commands. Maybe
60+ // it would be better to return an error so that the caller would know one of the
61+ // commands couldn't be handled?
62+ value!( None , many_till!( take!( 1 ) , invocation_prefix) )
63+ )
64+ ) ;
65+
66+ named ! (
67+ command( CompleteStr ) -> Option <Instruction >,
68+ preceded!(
69+ ws!( invocation_prefix) ,
70+ switch!( ws!( command_str) ,
71+ Some ( Command :: Build ) =>
72+ ws!( do_parse!(
3673 pkgs: ws!( many1!( map!( normal_token, |s| s. 0 . to_owned( ) ) ) ) >>
3774 ( Some ( Instruction :: Build ( Subset :: Nixpkgs , pkgs) ) )
3875 ) ) |
76+ Some ( Command :: BuildSystem ) =>
77+ ws!( do_parse!(
78+ system: ws!( system) >>
79+ pkgs: ws!( many1!( map!( normal_token, |s| s. 0 . to_owned( ) ) ) ) >>
80+ ( Some ( Instruction :: BuildOnSystem ( system, Subset :: Nixpkgs , pkgs) ) )
81+ ) ) |
82+ Some ( Command :: Test ) =>
3983 ws!( do_parse!(
40- tag!( "test" ) >>
4184 tests: ws!( many1!( map!( normal_token, |s| format!( "nixosTests.{}" , s. 0 ) ) ) ) >>
4285 ( Some ( Instruction :: Build ( Subset :: Nixpkgs , tests) ) )
4386 ) ) |
44- value!( Some ( Instruction :: Eval ) , tag!( "eval" ) ) |
45- // TODO: Currently keeping previous behaviour of ignoring unknown commands. Maybe
46- // it would be better to return an error so that the caller would know one of the
47- // commands couldn't be handled?
48- value!( None , many_till!( take!( 1 ) , tag_no_case!( "@grahamcofborg" ) ) )
49- )
50- ) ) ) ) >> eof!( )
51- >> ( Some ( res. into_iter( ) . flatten( ) . collect( ) ) )
52- ) | value!( None )
87+ Some ( Command :: Eval ) => ws!( do_parse!( ( Some ( Instruction :: Eval ) ) ) ) |
88+ None => do_parse!( ( None ) )
89+ )
90+ )
91+ ) ;
92+
93+ named ! (
94+ parse_line_impl( CompleteStr ) -> Option <Vec <Instruction >>,
95+ opt!(
96+ do_parse!(
97+ res: ws!( many1!( ws!( command) ) )
98+ >> eof!( )
99+ >> ( res. into_iter( ) . flatten( ) . collect( ) )
100+ )
53101 )
54102) ;
55103
@@ -68,6 +116,7 @@ pub fn parse_line(text: &str) -> Option<Vec<Instruction>> {
68116pub enum Instruction {
69117 Build ( Subset , Vec < String > ) ,
70118 Eval ,
119+ BuildOnSystem ( System , Subset , Vec < String > ) ,
71120}
72121
73122#[ allow( clippy:: upper_case_acronyms) ]
@@ -108,6 +157,23 @@ mod tests {
108157 assert_eq ! ( None , parse( "@grahamcofborg build" ) ) ;
109158 }
110159
160+ #[ test]
161+ fn build_system_comment ( ) {
162+ assert_eq ! (
163+ Some ( vec![ Instruction :: BuildOnSystem (
164+ System :: X8664Linux ,
165+ Subset :: Nixpkgs ,
166+ vec![ String :: from( "foo" ) ]
167+ ) , ] ) ,
168+ parse( "@ofborg build_system x86_64-linux foo" )
169+ ) ;
170+ }
171+
172+ #[ test]
173+ fn unknown_system_comment ( ) {
174+ assert_eq ! ( None , parse( "@ofborg build_system x86_64-foolinux foo" ) ) ;
175+ }
176+
111177 #[ test]
112178 fn eval_comment ( ) {
113179 assert_eq ! ( Some ( vec![ Instruction :: Eval ] ) , parse( "@grahamcofborg eval" ) ) ;
0 commit comments