Update nom to v8
This commit is contained in:
@@ -14,7 +14,7 @@ heapless = "0.8.0"
|
|||||||
|
|
||||||
[dependencies.nom]
|
[dependencies.nom]
|
||||||
default-features = false
|
default-features = false
|
||||||
version = "7.1.3"
|
version = "8.0.0"
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
default = ["std"]
|
default = ["std"]
|
||||||
|
@@ -8,70 +8,76 @@ use nom::branch::alt;
|
|||||||
use nom::bytes::complete::tag;
|
use nom::bytes::complete::tag;
|
||||||
use nom::character::complete::{digit0, digit1};
|
use nom::character::complete::{digit0, digit1};
|
||||||
use nom::combinator::{map, map_res, opt, value};
|
use nom::combinator::{map, map_res, opt, value};
|
||||||
use nom::sequence::{delimited, preceded, tuple};
|
use nom::sequence::{delimited, preceded};
|
||||||
use nom::IResult;
|
use nom::IResult;
|
||||||
|
use nom::Parser;
|
||||||
|
|
||||||
macro_rules! tag_parser {
|
macro_rules! tag_parser {
|
||||||
($sig:ident, $tag:expr, $ret:expr) => {
|
($sig:ident, $tag:expr, $ret:expr) => {
|
||||||
fn $sig(input: &str) -> IResult<&str, AnsiSequence> {
|
fn $sig(input: &str) -> IResult<&str, AnsiSequence> {
|
||||||
value($ret, tag($tag))(input)
|
value($ret, tag($tag)).parse(input)
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
fn parse_u32(input: &str) -> IResult<&str, u32> {
|
fn parse_u32(input: &str) -> IResult<&str, u32> {
|
||||||
map_res(digit1, |s: &str| s.parse::<u32>())(input)
|
map_res(digit1, |s: &str| s.parse::<u32>()).parse(input)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn parse_u8(input: &str) -> IResult<&str, u8> {
|
fn parse_u8(input: &str) -> IResult<&str, u8> {
|
||||||
map_res(digit1, |s: &str| s.parse::<u8>())(input)
|
map_res(digit1, |s: &str| s.parse::<u8>()).parse(input)
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO kind of ugly, would prefer to pass in the default so we could use it for
|
// TODO kind of ugly, would prefer to pass in the default so we could use it for
|
||||||
// all escapes with defaults (not just those that default to 1).
|
// all escapes with defaults (not just those that default to 1).
|
||||||
fn parse_def_cursor_int(input: &str) -> IResult<&str, u32> {
|
fn parse_def_cursor_int(input: &str) -> IResult<&str, u32> {
|
||||||
map(digit0, |s: &str| s.parse::<u32>().unwrap_or(1))(input)
|
map(digit0, |s: &str| s.parse::<u32>().unwrap_or(1)).parse(input)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn cursor_pos(input: &str) -> IResult<&str, AnsiSequence> {
|
fn cursor_pos(input: &str) -> IResult<&str, AnsiSequence> {
|
||||||
map(
|
map(
|
||||||
tuple((
|
(
|
||||||
tag("["),
|
tag("["),
|
||||||
parse_def_cursor_int,
|
parse_def_cursor_int,
|
||||||
opt(tag(";")),
|
opt(tag(";")),
|
||||||
parse_def_cursor_int,
|
parse_def_cursor_int,
|
||||||
alt((tag("H"), tag("f"))),
|
alt((tag("H"), tag("f"))),
|
||||||
)),
|
),
|
||||||
|(_, x, _, y, _)| AnsiSequence::CursorPos(x, y),
|
|(_, x, _, y, _)| AnsiSequence::CursorPos(x, y),
|
||||||
)(input)
|
)
|
||||||
|
.parse(input)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn escape(input: &str) -> IResult<&str, AnsiSequence> {
|
fn escape(input: &str) -> IResult<&str, AnsiSequence> {
|
||||||
value(AnsiSequence::Escape, tag("\u{1b}"))(input)
|
value(AnsiSequence::Escape, tag("\u{1b}")).parse(input)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn cursor_up(input: &str) -> IResult<&str, AnsiSequence> {
|
fn cursor_up(input: &str) -> IResult<&str, AnsiSequence> {
|
||||||
map(delimited(tag("["), parse_def_cursor_int, tag("A")), |am| {
|
map(delimited(tag("["), parse_def_cursor_int, tag("A")), |am| {
|
||||||
AnsiSequence::CursorUp(am)
|
AnsiSequence::CursorUp(am)
|
||||||
})(input)
|
})
|
||||||
|
.parse(input)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn cursor_down(input: &str) -> IResult<&str, AnsiSequence> {
|
fn cursor_down(input: &str) -> IResult<&str, AnsiSequence> {
|
||||||
map(delimited(tag("["), parse_def_cursor_int, tag("B")), |am| {
|
map(delimited(tag("["), parse_def_cursor_int, tag("B")), |am| {
|
||||||
AnsiSequence::CursorDown(am)
|
AnsiSequence::CursorDown(am)
|
||||||
})(input)
|
})
|
||||||
|
.parse(input)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn cursor_forward(input: &str) -> IResult<&str, AnsiSequence> {
|
fn cursor_forward(input: &str) -> IResult<&str, AnsiSequence> {
|
||||||
map(delimited(tag("["), parse_def_cursor_int, tag("C")), |am| {
|
map(delimited(tag("["), parse_def_cursor_int, tag("C")), |am| {
|
||||||
AnsiSequence::CursorForward(am)
|
AnsiSequence::CursorForward(am)
|
||||||
})(input)
|
})
|
||||||
|
.parse(input)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn cursor_backward(input: &str) -> IResult<&str, AnsiSequence> {
|
fn cursor_backward(input: &str) -> IResult<&str, AnsiSequence> {
|
||||||
map(delimited(tag("["), parse_def_cursor_int, tag("D")), |am| {
|
map(delimited(tag("["), parse_def_cursor_int, tag("D")), |am| {
|
||||||
AnsiSequence::CursorBackward(am)
|
AnsiSequence::CursorBackward(am)
|
||||||
})(input)
|
})
|
||||||
|
.parse(input)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn graphics_mode1(input: &str) -> IResult<&str, AnsiSequence> {
|
fn graphics_mode1(input: &str) -> IResult<&str, AnsiSequence> {
|
||||||
@@ -79,23 +85,25 @@ fn graphics_mode1(input: &str) -> IResult<&str, AnsiSequence> {
|
|||||||
let mode =
|
let mode =
|
||||||
Vec::from_slice(&[val]).expect("Vec::from_slice should allocate sufficient size");
|
Vec::from_slice(&[val]).expect("Vec::from_slice should allocate sufficient size");
|
||||||
AnsiSequence::SetGraphicsMode(mode)
|
AnsiSequence::SetGraphicsMode(mode)
|
||||||
})(input)
|
})
|
||||||
|
.parse(input)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn graphics_mode2(input: &str) -> IResult<&str, AnsiSequence> {
|
fn graphics_mode2(input: &str) -> IResult<&str, AnsiSequence> {
|
||||||
map(
|
map(
|
||||||
tuple((tag("["), parse_u8, tag(";"), parse_u8, tag("m"))),
|
(tag("["), parse_u8, tag(";"), parse_u8, tag("m")),
|
||||||
|(_, val1, _, val2, _)| {
|
|(_, val1, _, val2, _)| {
|
||||||
let mode = Vec::from_slice(&[val1, val2])
|
let mode = Vec::from_slice(&[val1, val2])
|
||||||
.expect("Vec::from_slice should allocate sufficient size");
|
.expect("Vec::from_slice should allocate sufficient size");
|
||||||
AnsiSequence::SetGraphicsMode(mode)
|
AnsiSequence::SetGraphicsMode(mode)
|
||||||
},
|
},
|
||||||
)(input)
|
)
|
||||||
|
.parse(input)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn graphics_mode3(input: &str) -> IResult<&str, AnsiSequence> {
|
fn graphics_mode3(input: &str) -> IResult<&str, AnsiSequence> {
|
||||||
map(
|
map(
|
||||||
tuple((
|
(
|
||||||
tag("["),
|
tag("["),
|
||||||
parse_u8,
|
parse_u8,
|
||||||
tag(";"),
|
tag(";"),
|
||||||
@@ -103,22 +111,23 @@ fn graphics_mode3(input: &str) -> IResult<&str, AnsiSequence> {
|
|||||||
tag(";"),
|
tag(";"),
|
||||||
parse_u8,
|
parse_u8,
|
||||||
tag("m"),
|
tag("m"),
|
||||||
)),
|
),
|
||||||
|(_, val1, _, val2, _, val3, _)| {
|
|(_, val1, _, val2, _, val3, _)| {
|
||||||
let mode = Vec::from_slice(&[val1, val2, val3])
|
let mode = Vec::from_slice(&[val1, val2, val3])
|
||||||
.expect("Vec::from_slice should allocate sufficient size");
|
.expect("Vec::from_slice should allocate sufficient size");
|
||||||
AnsiSequence::SetGraphicsMode(mode)
|
AnsiSequence::SetGraphicsMode(mode)
|
||||||
},
|
},
|
||||||
)(input)
|
)
|
||||||
|
.parse(input)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn graphics_mode4(input: &str) -> IResult<&str, AnsiSequence> {
|
fn graphics_mode4(input: &str) -> IResult<&str, AnsiSequence> {
|
||||||
value(AnsiSequence::SetGraphicsMode(Vec::new()), tag("[m"))(input)
|
value(AnsiSequence::SetGraphicsMode(Vec::new()), tag("[m")).parse(input)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn graphics_mode5(input: &str) -> IResult<&str, AnsiSequence> {
|
fn graphics_mode5(input: &str) -> IResult<&str, AnsiSequence> {
|
||||||
map(
|
map(
|
||||||
tuple((
|
(
|
||||||
tag("["),
|
tag("["),
|
||||||
parse_u8,
|
parse_u8,
|
||||||
tag(";"),
|
tag(";"),
|
||||||
@@ -130,13 +139,14 @@ fn graphics_mode5(input: &str) -> IResult<&str, AnsiSequence> {
|
|||||||
tag(";"),
|
tag(";"),
|
||||||
parse_u8,
|
parse_u8,
|
||||||
tag("m"),
|
tag("m"),
|
||||||
)),
|
),
|
||||||
|(_, val1, _, val2, _, val3, _, val4, _, val5, _)| {
|
|(_, val1, _, val2, _, val3, _, val4, _, val5, _)| {
|
||||||
let mode = Vec::from_slice(&[val1, val2, val3, val4, val5])
|
let mode = Vec::from_slice(&[val1, val2, val3, val4, val5])
|
||||||
.expect("Vec::from_slice should allocate sufficient size");
|
.expect("Vec::from_slice should allocate sufficient size");
|
||||||
AnsiSequence::SetGraphicsMode(mode)
|
AnsiSequence::SetGraphicsMode(mode)
|
||||||
},
|
},
|
||||||
)(input)
|
)
|
||||||
|
.parse(input)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn graphics_mode(input: &str) -> IResult<&str, AnsiSequence> {
|
fn graphics_mode(input: &str) -> IResult<&str, AnsiSequence> {
|
||||||
@@ -146,26 +156,30 @@ fn graphics_mode(input: &str) -> IResult<&str, AnsiSequence> {
|
|||||||
graphics_mode3,
|
graphics_mode3,
|
||||||
graphics_mode4,
|
graphics_mode4,
|
||||||
graphics_mode5,
|
graphics_mode5,
|
||||||
))(input)
|
))
|
||||||
|
.parse(input)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn set_mode(input: &str) -> IResult<&str, AnsiSequence> {
|
fn set_mode(input: &str) -> IResult<&str, AnsiSequence> {
|
||||||
map(delimited(tag("[="), parse_u8, tag("h")), |val| {
|
map(delimited(tag("[="), parse_u8, tag("h")), |val| {
|
||||||
AnsiSequence::SetMode(val)
|
AnsiSequence::SetMode(val)
|
||||||
})(input)
|
})
|
||||||
|
.parse(input)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn reset_mode(input: &str) -> IResult<&str, AnsiSequence> {
|
fn reset_mode(input: &str) -> IResult<&str, AnsiSequence> {
|
||||||
map(delimited(tag("[="), parse_u8, tag("l")), |val| {
|
map(delimited(tag("[="), parse_u8, tag("l")), |val| {
|
||||||
AnsiSequence::ResetMode(val)
|
AnsiSequence::ResetMode(val)
|
||||||
})(input)
|
})
|
||||||
|
.parse(input)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn set_top_and_bottom(input: &str) -> IResult<&str, AnsiSequence> {
|
fn set_top_and_bottom(input: &str) -> IResult<&str, AnsiSequence> {
|
||||||
map(
|
map(
|
||||||
tuple((tag("["), parse_u32, tag(";"), parse_u32, tag("r"))),
|
(tag("["), parse_u32, tag(";"), parse_u32, tag("r")),
|
||||||
|(_, x, _, y, _)| AnsiSequence::SetTopAndBottom(x, y),
|
|(_, x, _, y, _)| AnsiSequence::SetTopAndBottom(x, y),
|
||||||
)(input)
|
)
|
||||||
|
.parse(input)
|
||||||
}
|
}
|
||||||
|
|
||||||
tag_parser!(cursor_save, "[s", AnsiSequence::CursorSave);
|
tag_parser!(cursor_save, "[s", AnsiSequence::CursorSave);
|
||||||
@@ -267,9 +281,10 @@ fn combined(input: &str) -> IResult<&str, AnsiSequence> {
|
|||||||
set_g1_graph,
|
set_g1_graph,
|
||||||
set_single_shift2,
|
set_single_shift2,
|
||||||
set_single_shift3,
|
set_single_shift3,
|
||||||
))(input)
|
))
|
||||||
|
.parse(input)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn parse_escape(input: &str) -> IResult<&str, AnsiSequence> {
|
pub fn parse_escape(input: &str) -> IResult<&str, AnsiSequence> {
|
||||||
preceded(tag("\u{1b}"), combined)(input)
|
preceded(tag("\u{1b}"), combined).parse(input)
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user