mirror of
https://github.com/Noratrieb/uwucc.git
synced 2026-01-14 16:45:07 +01:00
use dbg-pls for parser snapshot tests
This commit is contained in:
parent
31575cbdfb
commit
e7597dab07
7 changed files with 246 additions and 333 deletions
|
|
@ -1,3 +1,4 @@
|
|||
use dbg_pls::{DebugPls, Formatter};
|
||||
use peekmore::PeekMoreIterator;
|
||||
|
||||
use crate::{
|
||||
|
|
@ -19,22 +20,28 @@ pub struct ParserError {
|
|||
}
|
||||
|
||||
impl ParserError {
|
||||
#[track_caller]
|
||||
fn new(span: Span, message: String) -> Self {
|
||||
Self { span, message }
|
||||
}
|
||||
|
||||
#[track_caller]
|
||||
fn eof() -> Self {
|
||||
Self::new(Span::default(), "unexpected end of file".to_string())
|
||||
}
|
||||
|
||||
#[track_caller]
|
||||
fn unsupported(span: Span, token: &Tok<'_>) -> Self {
|
||||
Self::new(span, format!("`{token}` is not supported"))
|
||||
}
|
||||
}
|
||||
|
||||
impl DebugPls for ParserError {
|
||||
fn fmt(&self, f: Formatter<'_>) {
|
||||
f.debug_struct("ParserError")
|
||||
.field("span", &self.span)
|
||||
.field("message", &self.message)
|
||||
.finish();
|
||||
}
|
||||
}
|
||||
|
||||
type Result<T, E = ParserError> = std::result::Result<T, E>;
|
||||
|
||||
struct Parser<'src, I>
|
||||
|
|
|
|||
|
|
@ -1,44 +1,33 @@
|
|||
---
|
||||
source: parser/src/parser/tests.rs
|
||||
expression: parsed
|
||||
expression: parsed_pretty
|
||||
---
|
||||
Ok(
|
||||
[
|
||||
Ok([
|
||||
(
|
||||
FunctionDef(
|
||||
FunctionDef {
|
||||
declaration: Normal(
|
||||
NormalDecl {
|
||||
FunctionDef(FunctionDef {
|
||||
declaration: Normal(NormalDecl {
|
||||
decl_spec: DeclSpec {
|
||||
ty: Int,
|
||||
attrs: (empty),
|
||||
attrs: "(empty)",
|
||||
},
|
||||
init_declarators: [
|
||||
(
|
||||
InitDecl {
|
||||
declarator: Declarator {
|
||||
decl: WithParams {
|
||||
ident: (
|
||||
"uwu",
|
||||
5..8,
|
||||
),
|
||||
ident: ("uwu", 5..8),
|
||||
params: [
|
||||
FunctionParamDecl {
|
||||
decl_spec: (
|
||||
DeclSpec {
|
||||
ty: Long,
|
||||
attrs: (empty),
|
||||
attrs: "(empty)",
|
||||
},
|
||||
9..13,
|
||||
),
|
||||
declarator: (
|
||||
Declarator {
|
||||
decl: Ident(
|
||||
(
|
||||
"owo",
|
||||
14..17,
|
||||
),
|
||||
),
|
||||
decl: Ident(("owo", 14..17)),
|
||||
pointer: false,
|
||||
},
|
||||
14..17,
|
||||
|
|
@ -48,18 +37,13 @@ Ok(
|
|||
decl_spec: (
|
||||
DeclSpec {
|
||||
ty: Int,
|
||||
attrs: (empty),
|
||||
attrs: "(empty)",
|
||||
},
|
||||
19..22,
|
||||
),
|
||||
declarator: (
|
||||
Declarator {
|
||||
decl: Ident(
|
||||
(
|
||||
"qwq",
|
||||
23..26,
|
||||
),
|
||||
),
|
||||
decl: Ident(("qwq", 23..26)),
|
||||
pointer: false,
|
||||
},
|
||||
23..26,
|
||||
|
|
@ -74,12 +58,9 @@ Ok(
|
|||
5..8,
|
||||
),
|
||||
],
|
||||
},
|
||||
),
|
||||
}),
|
||||
body: [],
|
||||
},
|
||||
),
|
||||
}),
|
||||
1..30,
|
||||
),
|
||||
],
|
||||
)
|
||||
])
|
||||
|
|
|
|||
|
|
@ -1,27 +1,21 @@
|
|||
---
|
||||
source: parser/src/parser/tests.rs
|
||||
expression: parsed
|
||||
expression: parsed_pretty
|
||||
---
|
||||
Ok(
|
||||
[
|
||||
Ok([
|
||||
(
|
||||
FunctionDef(
|
||||
FunctionDef {
|
||||
declaration: Normal(
|
||||
NormalDecl {
|
||||
FunctionDef(FunctionDef {
|
||||
declaration: Normal(NormalDecl {
|
||||
decl_spec: DeclSpec {
|
||||
ty: Int,
|
||||
attrs: EXTERN | THREAD_LOCAL,
|
||||
attrs: "EXTERN | THREAD_LOCAL",
|
||||
},
|
||||
init_declarators: [
|
||||
(
|
||||
InitDecl {
|
||||
declarator: Declarator {
|
||||
decl: WithParams {
|
||||
ident: (
|
||||
"uwu",
|
||||
35..38,
|
||||
),
|
||||
ident: ("uwu", 35..38),
|
||||
params: [],
|
||||
},
|
||||
pointer: false,
|
||||
|
|
@ -31,12 +25,9 @@ Ok(
|
|||
35..38,
|
||||
),
|
||||
],
|
||||
},
|
||||
),
|
||||
}),
|
||||
body: [],
|
||||
},
|
||||
),
|
||||
}),
|
||||
1..43,
|
||||
),
|
||||
],
|
||||
)
|
||||
])
|
||||
|
|
|
|||
|
|
@ -1,27 +1,21 @@
|
|||
---
|
||||
source: parser/src/parser/tests.rs
|
||||
expression: parsed
|
||||
expression: parsed_pretty
|
||||
---
|
||||
Ok(
|
||||
[
|
||||
Ok([
|
||||
(
|
||||
FunctionDef(
|
||||
FunctionDef {
|
||||
declaration: Normal(
|
||||
NormalDecl {
|
||||
FunctionDef(FunctionDef {
|
||||
declaration: Normal(NormalDecl {
|
||||
decl_spec: DeclSpec {
|
||||
ty: Void,
|
||||
attrs: (empty),
|
||||
attrs: "(empty)",
|
||||
},
|
||||
init_declarators: [
|
||||
(
|
||||
InitDecl {
|
||||
declarator: Declarator {
|
||||
decl: WithParams {
|
||||
ident: (
|
||||
"uwu",
|
||||
6..9,
|
||||
),
|
||||
ident: ("uwu", 6..9),
|
||||
params: [],
|
||||
},
|
||||
pointer: false,
|
||||
|
|
@ -31,12 +25,9 @@ Ok(
|
|||
6..9,
|
||||
),
|
||||
],
|
||||
},
|
||||
),
|
||||
}),
|
||||
body: [],
|
||||
},
|
||||
),
|
||||
}),
|
||||
1..14,
|
||||
),
|
||||
],
|
||||
)
|
||||
])
|
||||
|
|
|
|||
|
|
@ -1,27 +1,20 @@
|
|||
---
|
||||
source: parser/src/parser/tests.rs
|
||||
expression: parsed
|
||||
expression: parsed_pretty
|
||||
---
|
||||
Ok(
|
||||
[
|
||||
Ok([
|
||||
(
|
||||
Decl(
|
||||
Normal(
|
||||
NormalDecl {
|
||||
Normal(NormalDecl {
|
||||
decl_spec: DeclSpec {
|
||||
ty: Int,
|
||||
attrs: (empty),
|
||||
attrs: "(empty)",
|
||||
},
|
||||
init_declarators: [
|
||||
(
|
||||
InitDecl {
|
||||
declarator: Declarator {
|
||||
decl: Ident(
|
||||
(
|
||||
"test",
|
||||
5..9,
|
||||
),
|
||||
),
|
||||
decl: Ident(("test", 5..9)),
|
||||
pointer: false,
|
||||
},
|
||||
init: None,
|
||||
|
|
@ -29,29 +22,22 @@ Ok(
|
|||
5..9,
|
||||
),
|
||||
],
|
||||
},
|
||||
),
|
||||
}),
|
||||
),
|
||||
1..9,
|
||||
),
|
||||
(
|
||||
Decl(
|
||||
Normal(
|
||||
NormalDecl {
|
||||
Normal(NormalDecl {
|
||||
decl_spec: DeclSpec {
|
||||
ty: Double,
|
||||
attrs: THREAD_LOCAL,
|
||||
attrs: "THREAD_LOCAL",
|
||||
},
|
||||
init_declarators: [
|
||||
(
|
||||
InitDecl {
|
||||
declarator: Declarator {
|
||||
decl: Ident(
|
||||
(
|
||||
"uwu",
|
||||
32..35,
|
||||
),
|
||||
),
|
||||
decl: Ident(("uwu", 32..35)),
|
||||
pointer: false,
|
||||
},
|
||||
init: None,
|
||||
|
|
@ -61,12 +47,7 @@ Ok(
|
|||
(
|
||||
InitDecl {
|
||||
declarator: Declarator {
|
||||
decl: Ident(
|
||||
(
|
||||
"owo",
|
||||
37..40,
|
||||
),
|
||||
),
|
||||
decl: Ident(("owo", 37..40)),
|
||||
pointer: false,
|
||||
},
|
||||
init: None,
|
||||
|
|
@ -74,28 +55,23 @@ Ok(
|
|||
37..40,
|
||||
),
|
||||
],
|
||||
},
|
||||
),
|
||||
}),
|
||||
),
|
||||
11..40,
|
||||
),
|
||||
(
|
||||
Decl(
|
||||
Normal(
|
||||
NormalDecl {
|
||||
Normal(NormalDecl {
|
||||
decl_spec: DeclSpec {
|
||||
ty: Int,
|
||||
attrs: (empty),
|
||||
attrs: "(empty)",
|
||||
},
|
||||
init_declarators: [
|
||||
(
|
||||
InitDecl {
|
||||
declarator: Declarator {
|
||||
decl: WithParams {
|
||||
ident: (
|
||||
"function",
|
||||
68..76,
|
||||
),
|
||||
ident: ("function", 68..76),
|
||||
params: [],
|
||||
},
|
||||
pointer: false,
|
||||
|
|
@ -105,10 +81,8 @@ Ok(
|
|||
68..76,
|
||||
),
|
||||
],
|
||||
},
|
||||
),
|
||||
}),
|
||||
),
|
||||
64..76,
|
||||
),
|
||||
],
|
||||
)
|
||||
])
|
||||
|
|
|
|||
|
|
@ -1,63 +1,36 @@
|
|||
---
|
||||
source: parser/src/parser/tests.rs
|
||||
expression: parsed
|
||||
expression: parsed_pretty
|
||||
---
|
||||
Ok(
|
||||
[
|
||||
Ok([
|
||||
(
|
||||
Decl(
|
||||
Normal(
|
||||
NormalDecl {
|
||||
Normal(NormalDecl {
|
||||
decl_spec: DeclSpec {
|
||||
ty: Int,
|
||||
attrs: (empty),
|
||||
attrs: "(empty)",
|
||||
},
|
||||
init_declarators: [
|
||||
(
|
||||
InitDecl {
|
||||
declarator: Declarator {
|
||||
decl: Ident(
|
||||
(
|
||||
"x",
|
||||
5..6,
|
||||
),
|
||||
),
|
||||
decl: Ident(("x", 5..6)),
|
||||
pointer: false,
|
||||
},
|
||||
init: Some(
|
||||
(
|
||||
Binary(
|
||||
ExprBinary {
|
||||
lhs: (
|
||||
Atom(
|
||||
Int(
|
||||
1,
|
||||
),
|
||||
),
|
||||
9..10,
|
||||
),
|
||||
rhs: (
|
||||
Atom(
|
||||
Int(
|
||||
1,
|
||||
),
|
||||
),
|
||||
13..14,
|
||||
),
|
||||
init: Some((
|
||||
Binary(ExprBinary {
|
||||
lhs: (Atom(Int(1)), 9..10),
|
||||
rhs: (Atom(Int(1)), 13..14),
|
||||
op: Add,
|
||||
},
|
||||
),
|
||||
}),
|
||||
9..14,
|
||||
),
|
||||
),
|
||||
)),
|
||||
},
|
||||
5..6,
|
||||
),
|
||||
],
|
||||
},
|
||||
),
|
||||
}),
|
||||
),
|
||||
1..6,
|
||||
),
|
||||
],
|
||||
)
|
||||
])
|
||||
|
|
|
|||
|
|
@ -9,20 +9,16 @@ fn lex_and_pre(src: &str) -> impl Iterator<Item = (Tok<'_>, Span)> + '_ {
|
|||
}
|
||||
|
||||
fn the_current_root_parse_thing<'src>(src: impl Iterator<Item = (Tok<'src>, Span)>) -> impl Debug {
|
||||
use peekmore::PeekMore;
|
||||
|
||||
let mut parser = Parser {
|
||||
lex: src.peekmore(),
|
||||
};
|
||||
|
||||
parser.external_declarations()
|
||||
super::parse_declarations(src)
|
||||
}
|
||||
|
||||
macro_rules! parse_test {
|
||||
($src:expr) => {
|
||||
let lexer = lex_and_pre($src);
|
||||
let parsed = the_current_root_parse_thing(lexer);
|
||||
insta::assert_debug_snapshot!(parsed);
|
||||
let parsed = super::parse_declarations(lexer);
|
||||
let parsed_pretty = dbg_pls::pretty(&parsed);
|
||||
|
||||
insta::assert_debug_snapshot!(parsed_pretty);
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue