mirror of https://codeberg.org/topola/topola.git
refactor(specctra-core/read): reuse String::read_dsn where possible
This commit is contained in:
parent
5e54453433
commit
50ef279286
|
|
@ -66,7 +66,7 @@ impl<R: std::io::BufRead> ReadDsn<R> for String {
|
||||||
impl<R: std::io::BufRead> ReadDsn<R> for char {
|
impl<R: std::io::BufRead> ReadDsn<R> for char {
|
||||||
fn read_dsn(tokenizer: &mut ListTokenizer<R>) -> Result<Self, ParseErrorContext> {
|
fn read_dsn(tokenizer: &mut ListTokenizer<R>) -> Result<Self, ParseErrorContext> {
|
||||||
let err = tokenizer.add_context(ParseError::Expected("a single character"));
|
let err = tokenizer.add_context(ParseError::Expected("a single character"));
|
||||||
let string = tokenizer.consume_token()?.expect_leaf()?;
|
let string = String::read_dsn(tokenizer)?;
|
||||||
let mut it = string.chars();
|
let mut it = string.chars();
|
||||||
let first = match it.next() {
|
let first = match it.next() {
|
||||||
None => return Err(err),
|
None => return Err(err),
|
||||||
|
|
@ -81,7 +81,7 @@ impl<R: std::io::BufRead> ReadDsn<R> for char {
|
||||||
|
|
||||||
impl<R: std::io::BufRead> ReadDsn<R> for bool {
|
impl<R: std::io::BufRead> ReadDsn<R> for bool {
|
||||||
fn read_dsn(tokenizer: &mut ListTokenizer<R>) -> Result<Self, ParseErrorContext> {
|
fn read_dsn(tokenizer: &mut ListTokenizer<R>) -> Result<Self, ParseErrorContext> {
|
||||||
match tokenizer.consume_token()?.expect_leaf()?.as_str() {
|
match String::read_dsn(tokenizer)?.as_str() {
|
||||||
"on" => Ok(true),
|
"on" => Ok(true),
|
||||||
"off" => Ok(false),
|
"off" => Ok(false),
|
||||||
_ => Err(tokenizer.add_context(ParseError::Expected("boolean"))),
|
_ => Err(tokenizer.add_context(ParseError::Expected("boolean"))),
|
||||||
|
|
@ -94,9 +94,7 @@ macro_rules! impl_ReadDsn_via_FromStr {
|
||||||
($(($t:ty, $name:expr));* $(;)?) => {
|
($(($t:ty, $name:expr));* $(;)?) => {
|
||||||
$( impl<R: std::io::BufRead> ReadDsn<R> for $t {
|
$( impl<R: std::io::BufRead> ReadDsn<R> for $t {
|
||||||
fn read_dsn(tokenizer: &mut ListTokenizer<R>) -> Result<Self, ParseErrorContext> {
|
fn read_dsn(tokenizer: &mut ListTokenizer<R>) -> Result<Self, ParseErrorContext> {
|
||||||
tokenizer
|
String::read_dsn(tokenizer)?
|
||||||
.consume_token()?
|
|
||||||
.expect_leaf()?
|
|
||||||
.parse()
|
.parse()
|
||||||
.map_err(|_| tokenizer.add_context(ParseError::Expected($name)))
|
.map_err(|_| tokenizer.add_context(ParseError::Expected($name)))
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue