command_parser: unnest the grammar definition
This commit is contained in:
parent
3fd1b2265d
commit
f2dcb8b08d
@ -84,8 +84,8 @@ impl Command {
|
|||||||
$block
|
$block
|
||||||
}
|
}
|
||||||
)*
|
)*
|
||||||
Token::End => Err(Error::UnexpectedEnd),
|
Token::End => return Err(Error::UnexpectedEnd),
|
||||||
_ => Err(Error::UnexpectedToken(lexer.token))
|
_ => return Err(Error::UnexpectedToken(lexer.token))
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@ -94,7 +94,7 @@ impl Command {
|
|||||||
($result: expr) => {
|
($result: expr) => {
|
||||||
match lexer.token {
|
match lexer.token {
|
||||||
Token::End => Ok($result),
|
Token::End => Ok($result),
|
||||||
_ => Err(Error::UnexpectedToken(lexer.token)),
|
_ => return Err(Error::UnexpectedToken(lexer.token)),
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@ -111,42 +111,31 @@ impl Command {
|
|||||||
],
|
],
|
||||||
End => Ok(Command::Report(ReportMode::Once)),
|
End => Ok(Command::Report(ReportMode::Once)),
|
||||||
],
|
],
|
||||||
Channel => choice![
|
Channel => {
|
||||||
Number => {
|
let channel = choice![
|
||||||
let channel = CHANNEL_IDS.iter()
|
Number => {
|
||||||
.position(|id| *id == lexer.slice());
|
CHANNEL_IDS.iter()
|
||||||
match channel {
|
.position(|id| *id == lexer.slice())
|
||||||
Some(channel) => {
|
.ok_or(Error::NoSuchChannel)
|
||||||
choice![
|
},
|
||||||
Enable => Ok(Command::Channel(
|
]? as u8;
|
||||||
channel as u8,
|
choice![
|
||||||
ChannelCommand::Enable
|
Enable =>
|
||||||
)),
|
Ok(Command::Channel(channel, ChannelCommand::Enable)),
|
||||||
Disable => Ok(Command::Channel(
|
Disable =>
|
||||||
channel as u8,
|
Ok(Command::Channel(channel, ChannelCommand::Enable)),
|
||||||
ChannelCommand::Enable
|
Setup => {
|
||||||
)),
|
let setup = choice![
|
||||||
Setup => choice![
|
Number => {
|
||||||
Number => {
|
SETUP_IDS.iter()
|
||||||
let setup = SETUP_IDS.iter()
|
.position(|id| *id == lexer.slice())
|
||||||
.position(|id| *id == lexer.slice());
|
.ok_or(Error::NoSuchSetup)
|
||||||
match setup {
|
},
|
||||||
Some(setup) =>
|
]? as u8;
|
||||||
end!(Command::Channel(
|
end!(Command::Channel(channel, ChannelCommand::Setup(setup)))
|
||||||
channel as u8,
|
},
|
||||||
ChannelCommand::Setup(setup as u8)
|
]
|
||||||
)),
|
},
|
||||||
None =>
|
|
||||||
Err(Error::NoSuchSetup)
|
|
||||||
}
|
|
||||||
},
|
|
||||||
],
|
|
||||||
]
|
|
||||||
}
|
|
||||||
None => Err(Error::NoSuchChannel)
|
|
||||||
}
|
|
||||||
},
|
|
||||||
],
|
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user