update miette to 3.0

This commit is contained in:
Robin Appelman 2022-01-19 15:57:44 +01:00
commit 71427689e7
4 changed files with 15 additions and 26 deletions

View file

@ -1,7 +1,7 @@
[package] [package]
name = "php-literal-parser" name = "php-literal-parser"
description = "parser for php literals" description = "parser for php literals"
version = "0.2.11" version = "0.4.0"
authors = ["Robin Appelman <robin@icewind.nl>"] authors = ["Robin Appelman <robin@icewind.nl>"]
edition = "2018" edition = "2018"
license = "MIT OR Apache-2.0" license = "MIT OR Apache-2.0"
@ -13,8 +13,9 @@ logos = "0.12"
thiserror = "1" thiserror = "1"
memchr = "2" memchr = "2"
serde = "1" serde = "1"
miette = "1" miette = "3"
[dev-dependencies] [dev-dependencies]
maplit = "1" maplit = "1"
serde_derive = "1" serde_derive = "1"
miette = { version = "3", features = ["fancy"] }

View file

@ -1,4 +1,4 @@
use miette::DiagnosticResult; use miette::Result;
use php_literal_parser::from_str; use php_literal_parser::from_str;
use serde_derive::Deserialize; use serde_derive::Deserialize;
@ -8,7 +8,7 @@ struct Target {
bars: Vec<u8>, bars: Vec<u8>,
} }
fn main() -> DiagnosticResult<()> { fn main() -> Result<()> {
let target = from_str(r#"["foo" => true, "bars" => [1, 2, 3, 4]]"#)?; let target = from_str(r#"["foo" => true, "bars" => [1, 2, 3, 4]]"#)?;
assert_eq!( assert_eq!(

View file

@ -1,7 +1,7 @@
use miette::DiagnosticResult; use miette::Result;
use php_literal_parser::{from_str, Value}; use php_literal_parser::{from_str, Value};
fn main() -> DiagnosticResult<()> { fn main() -> Result<()> {
let source = r###" let source = r###"
array ( array (
"double" => "quote", "double" => "quote",

View file

@ -47,10 +47,9 @@ impl serde::de::Error for ParseError {
#[derive(Debug, Clone, Diagnostic)] #[derive(Debug, Clone, Diagnostic)]
#[diagnostic(code(php_literal_parser::unexpected_token))] #[diagnostic(code(php_literal_parser::unexpected_token))]
pub struct UnexpectedTokenError { pub struct UnexpectedTokenError {
#[source_code]
src: String, src: String,
#[snippet(src)] #[label("Expected {}", self.expected)]
snip: SourceSpan,
#[highlight(snip, label("Expected {}", self.expected))]
err_span: SourceSpan, err_span: SourceSpan,
pub expected: TokenList, pub expected: TokenList,
pub found: Option<Token>, pub found: Option<Token>,
@ -61,12 +60,10 @@ impl UnexpectedTokenError {
expected: &[Token], expected: &[Token],
found: Option<Token>, found: Option<Token>,
src: String, src: String,
snip: SourceSpan,
err_span: SourceSpan, err_span: SourceSpan,
) -> Self { ) -> Self {
UnexpectedTokenError { UnexpectedTokenError {
src, src,
snip,
err_span, err_span,
expected: expected.into(), expected: expected.into(),
found, found,
@ -137,10 +134,9 @@ impl Error for UnexpectedTokenError {}
#[diagnostic(code(php_literal_parser::invalid_primitive))] #[diagnostic(code(php_literal_parser::invalid_primitive))]
#[error("{kind}")] #[error("{kind}")]
pub struct PrimitiveError { pub struct PrimitiveError {
#[source_code]
src: String, src: String,
#[snippet(src)] #[label("{}", self.kind.desc())]
snip: SourceSpan,
#[highlight(snip, label("{}", self.kind.desc()))]
err_span: SourceSpan, err_span: SourceSpan,
pub kind: PrimitiveErrorKind, pub kind: PrimitiveErrorKind,
} }
@ -178,10 +174,9 @@ impl From<UnescapeError> for PrimitiveErrorKind {
#[diagnostic(code(php_literal_parser::invalid_array_key))] #[diagnostic(code(php_literal_parser::invalid_array_key))]
#[error("Invalid array key")] #[error("Invalid array key")]
pub struct ArrayKeyError { pub struct ArrayKeyError {
#[source_code]
src: String, src: String,
#[snippet(src)] #[label("{}", self.kind)]
snip: SourceSpan,
#[highlight(snip, label("{}", self.kind))]
err_span: SourceSpan, err_span: SourceSpan,
kind: ArrayKeyErrorKind, kind: ArrayKeyErrorKind,
} }
@ -209,7 +204,6 @@ impl ArrayKeyError {
pub fn new(kind: ArrayKeyErrorKind, source: &str, err_span: Span) -> Self { pub fn new(kind: ArrayKeyErrorKind, source: &str, err_span: Span) -> Self {
ArrayKeyError { ArrayKeyError {
src: source.into(), src: source.into(),
snip: map_span(&(0..source.len())),
err_span: map_span(&err_span), err_span: map_span(&err_span),
kind, kind,
} }
@ -220,10 +214,9 @@ impl ArrayKeyError {
#[diagnostic(code(php_literal_parser::trailing))] #[diagnostic(code(php_literal_parser::trailing))]
#[error("Trailing characters after parsing")] #[error("Trailing characters after parsing")]
pub struct TrailingError { pub struct TrailingError {
#[source_code]
src: String, src: String,
#[snippet(src)] #[label("end of parsed value")]
snip: SourceSpan,
#[highlight(snip, label("end of parsed value"))]
err_span: SourceSpan, err_span: SourceSpan,
} }
@ -231,7 +224,6 @@ impl TrailingError {
pub fn new(source: &str, err_span: Span) -> Self { pub fn new(source: &str, err_span: Span) -> Self {
TrailingError { TrailingError {
src: source.into(), src: source.into(),
snip: map_span(&(0..source.len())),
err_span: map_span(&err_span), err_span: map_span(&err_span),
} }
} }
@ -256,7 +248,6 @@ impl<'source> ExpectToken<'source> for Option<SpannedToken<'source>> {
expected, expected,
None, None,
source.into(), source.into(),
map_span(&(0..source.len())),
map_span(&(source.len()..source.len())), map_span(&(source.len()..source.len())),
) )
.into() .into()
@ -276,7 +267,6 @@ impl<'a, 'source> ExpectToken<'source> for Option<&'a SpannedToken<'source>> {
expected, expected,
None, None,
source.into(), source.into(),
map_span(&(0..source.len())),
map_span(&(source.len()..source.len())), map_span(&(source.len()..source.len())),
) )
.into() .into()
@ -298,7 +288,6 @@ impl<'source> ExpectToken<'source> for SpannedToken<'source> {
expected, expected,
Some(self.token), Some(self.token),
source.into(), source.into(),
map_span(&(0..source.len())),
map_span(&self.span), map_span(&self.span),
) )
.into()) .into())
@ -322,7 +311,6 @@ impl<T, E: Into<PrimitiveErrorKind>> ResultExt<T> for Result<T, E> {
self.map_err(|error| { self.map_err(|error| {
PrimitiveError { PrimitiveError {
src: source.into(), src: source.into(),
snip: map_span(&(0..source.len())),
err_span: map_span(&span), err_span: map_span(&span),
kind: error.into(), kind: error.into(),
} }