Skip to content

Commit 7dd10d6

Browse files
bors[bot]Henrik Tjäder
andauthored
Merge #65
65: Smaller syntax fixes r=perlindgren a=AfoHT Should not affect syntax nor functionality Co-authored-by: Henrik Tjäder <henrik@grepit.se>
2 parents 57d6f20 + 4817b13 commit 7dd10d6

File tree

4 files changed

+126
-133
lines changed

4 files changed

+126
-133
lines changed

mock/Cargo.toml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
[package]
2-
authors = ["Jorge Aparicio <jorge@japaric.io>"]
2+
authors = [
3+
"The Real-Time Interrupt-driven Concurrency developers",
4+
"Jorge Aparicio <jorge@japaric.io>",
5+
]
36
edition = "2018"
47
name = "mock"
58
publish = false

src/analyze.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ pub(crate) fn app(app: &App) -> Result<Analysis, syn::Error> {
224224
let mut send_types = SendTypes::new();
225225
let owned_by_idle = Ownership::Owned { priority: 0 };
226226
for (name, res) in app.shared_resources.iter() {
227-
// handle not owned by idle
227+
// Handle not owned by idle
228228
if ownerships
229229
.get(name)
230230
.map(|ownership| *ownership != owned_by_idle)

src/parse.rs

Lines changed: 121 additions & 129 deletions
Original file line numberDiff line numberDiff line change
@@ -76,38 +76,36 @@ fn init_args(tokens: TokenStream2) -> parse::Result<InitArgs> {
7676

7777
let content;
7878
parenthesized!(content in input);
79-
loop {
80-
if content.is_empty() {
81-
break;
82-
}
8379

84-
// #ident = ..
85-
let ident: Ident = content.parse()?;
86-
let _: Token![=] = content.parse()?;
87-
88-
let ident_s = ident.to_string();
89-
match &*ident_s {
90-
"local" => {
91-
if local_resources.is_some() {
92-
return Err(parse::Error::new(
93-
ident.span(),
94-
"argument appears more than once",
95-
));
80+
if !content.is_empty() {
81+
loop {
82+
// Parse identifier name
83+
let ident: Ident = content.parse()?;
84+
// Handle equal sign
85+
let _: Token![=] = content.parse()?;
86+
87+
match &*ident.to_string() {
88+
"local" => {
89+
if local_resources.is_some() {
90+
return Err(parse::Error::new(
91+
ident.span(),
92+
"argument appears more than once",
93+
));
94+
}
95+
96+
local_resources = Some(util::parse_local_resources(&content)?);
97+
}
98+
_ => {
99+
return Err(parse::Error::new(ident.span(), "unexpected argument"));
96100
}
97-
98-
local_resources = Some(util::parse_local_resources(&content)?);
99101
}
100102

101-
_ => {
102-
return Err(parse::Error::new(ident.span(), "unexpected argument"));
103+
if content.is_empty() {
104+
break;
103105
}
106+
// Handle comma: ,
107+
let _: Token![,] = content.parse()?;
104108
}
105-
106-
if content.is_empty() {
107-
break;
108-
}
109-
110-
let _: Token![,] = content.parse()?;
111109
}
112110

113111
if let Some(locals) = &local_resources {
@@ -139,50 +137,47 @@ fn idle_args(tokens: TokenStream2) -> parse::Result<IdleArgs> {
139137

140138
let content;
141139
parenthesized!(content in input);
142-
loop {
143-
if content.is_empty() {
144-
break;
145-
}
146-
147-
// #ident = ..
148-
let ident: Ident = content.parse()?;
149-
let _: Token![=] = content.parse()?;
150-
151-
let ident_s = ident.to_string();
152-
match &*ident_s {
153-
"shared" => {
154-
if shared_resources.is_some() {
155-
return Err(parse::Error::new(
156-
ident.span(),
157-
"argument appears more than once",
158-
));
140+
if !content.is_empty() {
141+
loop {
142+
// Parse identifier name
143+
let ident: Ident = content.parse()?;
144+
// Handle equal sign
145+
let _: Token![=] = content.parse()?;
146+
147+
match &*ident.to_string() {
148+
"shared" => {
149+
if shared_resources.is_some() {
150+
return Err(parse::Error::new(
151+
ident.span(),
152+
"argument appears more than once",
153+
));
154+
}
155+
156+
shared_resources = Some(util::parse_shared_resources(&content)?);
159157
}
160158

161-
shared_resources = Some(util::parse_shared_resources(&content)?);
162-
}
159+
"local" => {
160+
if local_resources.is_some() {
161+
return Err(parse::Error::new(
162+
ident.span(),
163+
"argument appears more than once",
164+
));
165+
}
163166

164-
"local" => {
165-
if local_resources.is_some() {
166-
return Err(parse::Error::new(
167-
ident.span(),
168-
"argument appears more than once",
169-
));
167+
local_resources = Some(util::parse_local_resources(&content)?);
170168
}
171169

172-
local_resources = Some(util::parse_local_resources(&content)?);
170+
_ => {
171+
return Err(parse::Error::new(ident.span(), "unexpected argument"));
172+
}
173173
}
174-
175-
_ => {
176-
return Err(parse::Error::new(ident.span(), "unexpected argument"));
174+
if content.is_empty() {
175+
break;
177176
}
178-
}
179177

180-
if content.is_empty() {
181-
break;
178+
// Handle comma: ,
179+
let _: Token![,] = content.parse()?;
182180
}
183-
184-
// ,
185-
let _: Token![,] = content.parse()?;
186181
}
187182

188183
Ok(IdleArgs {
@@ -216,8 +211,9 @@ fn task_args(
216211
break;
217212
}
218213

219-
// #ident = ..
214+
// Parse identifier name
220215
let ident: Ident = content.parse()?;
216+
// Handle equal sign
221217
let _: Token![=] = content.parse()?;
222218

223219
let ident_s = ident.to_string();
@@ -244,7 +240,7 @@ fn task_args(
244240
));
245241
}
246242

247-
// #ident
243+
// Parse identifier name
248244
let ident = content.parse()?;
249245

250246
binds = Some(ident);
@@ -346,7 +342,7 @@ fn task_args(
346342
break;
347343
}
348344

349-
// ,
345+
// Handle comma: ,
350346
let _: Token![,] = content.parse()?;
351347
}
352348
let priority = priority.unwrap_or(1);
@@ -380,83 +376,79 @@ fn monotonic_args(tokens: TokenStream2) -> parse::Result<MonotonicArgs> {
380376

381377
let content;
382378
parenthesized!(content in input);
383-
loop {
384-
if content.is_empty() {
385-
break;
386-
}
387-
388-
// #ident = ..
389-
let ident: Ident = content.parse()?;
390-
let _: Token![=] = content.parse()?;
391-
392-
let ident_s = ident.to_string();
393-
match &*ident_s {
394-
"binds" => {
395-
if binds.is_some() {
396-
return Err(parse::Error::new(
397-
ident.span(),
398-
"argument appears more than once",
399-
));
379+
if !content.is_empty() {
380+
loop {
381+
// Parse identifier name
382+
let ident: Ident = content.parse()?;
383+
// Handle equal sign
384+
let _: Token![=] = content.parse()?;
385+
386+
match &*ident.to_string() {
387+
"binds" => {
388+
if binds.is_some() {
389+
return Err(parse::Error::new(
390+
ident.span(),
391+
"argument appears more than once",
392+
));
393+
}
394+
// Parse identifier name
395+
let ident = content.parse()?;
396+
397+
binds = Some(ident);
400398
}
401399

402-
// #ident
403-
let ident = content.parse()?;
404-
405-
binds = Some(ident);
406-
}
407-
408-
"priority" => {
409-
if priority.is_some() {
410-
return Err(parse::Error::new(
411-
ident.span(),
412-
"argument appears more than once",
413-
));
400+
"priority" => {
401+
if priority.is_some() {
402+
return Err(parse::Error::new(
403+
ident.span(),
404+
"argument appears more than once",
405+
));
406+
}
407+
408+
// #lit
409+
let lit: LitInt = content.parse()?;
410+
411+
if !lit.suffix().is_empty() {
412+
return Err(parse::Error::new(
413+
lit.span(),
414+
"this literal must be unsuffixed",
415+
));
416+
}
417+
418+
let value = lit.base10_parse::<u8>().ok();
419+
if value.is_none() || value == Some(0) {
420+
return Err(parse::Error::new(
421+
lit.span(),
422+
"this literal must be in the range 1...255",
423+
));
424+
}
425+
426+
priority = Some(value.unwrap());
414427
}
415428

416-
// #lit
417-
let lit: LitInt = content.parse()?;
418-
419-
if !lit.suffix().is_empty() {
420-
return Err(parse::Error::new(
421-
lit.span(),
422-
"this literal must be unsuffixed",
423-
));
424-
}
429+
"default" => {
430+
if default.is_some() {
431+
return Err(parse::Error::new(
432+
ident.span(),
433+
"argument appears more than once",
434+
));
435+
}
425436

426-
let value = lit.base10_parse::<u8>().ok();
427-
if value.is_none() || value == Some(0) {
428-
return Err(parse::Error::new(
429-
lit.span(),
430-
"this literal must be in the range 1...255",
431-
));
437+
let lit: LitBool = content.parse()?;
438+
default = Some(lit.value);
432439
}
433440

434-
priority = Some(value.unwrap());
435-
}
436-
437-
"default" => {
438-
if default.is_some() {
439-
return Err(parse::Error::new(
440-
ident.span(),
441-
"argument appears more than once",
442-
));
441+
_ => {
442+
return Err(parse::Error::new(ident.span(), "unexpected argument"));
443443
}
444-
445-
let lit: LitBool = content.parse()?;
446-
default = Some(lit.value);
447444
}
448-
449-
_ => {
450-
return Err(parse::Error::new(ident.span(), "unexpected argument"));
445+
if content.is_empty() {
446+
break;
451447
}
452-
}
453448

454-
if content.is_empty() {
455-
break;
449+
// Handle comma: ,
450+
let _: Token![,] = content.parse()?;
456451
}
457-
458-
// ,
459-
let _: Token![,] = content.parse()?;
460452
}
461453
let binds = if let Some(r) = binds {
462454
r

src/parse/util.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,8 +154,6 @@ pub fn parse_local_resources(content: ParseStream<'_>) -> parse::Result<LocalRes
154154
"identifier appears more than once in list",
155155
));
156156

157-
// println!("e: {:#?}", e);
158-
159157
let (name, local) = match e {
160158
// local = [IDENT],
161159
Expr::Path(path) => {

0 commit comments

Comments
 (0)