Skip to content

Commit b2e5659

Browse files
committed
initial parser signature
1 parent cc423a0 commit b2e5659

File tree

3 files changed

+26
-5
lines changed

3 files changed

+26
-5
lines changed

argus-core/src/expr/traits.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
use std::any::Any;
2+
13
use enum_dispatch::enum_dispatch;
24

35
use super::{BoolExpr, ExprRef, NumExpr};
@@ -14,6 +16,9 @@ pub trait Expr {
1416
/// If the expression doesn't contain arguments (i.e., it is a leaf expression) then
1517
/// the vector is empty.
1618
fn args(&self) -> Vec<ExprRef<'_>>;
19+
20+
/// [`std::any::Any`] trampoline for expressions
21+
fn as_any(&self) -> &dyn Any;
1722
}
1823

1924
/// Marker trait for numeric expressions

argus-parser/src/lexer.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
use std::{env, fmt, fs};
1+
use std::fmt;
22

3-
use ariadne::{sources, Color, Label, Report, ReportKind};
43
use chumsky::prelude::*;
54

65
pub type Span = SimpleSpan<usize>;
6+
pub type Output<'a> = Vec<(Token<'a>, Span)>;
7+
pub type Error<'a> = extra::Err<Rich<'a, char, Span>>;
78

89
#[derive(Clone, Debug, PartialEq, Eq)]
910
pub enum Token<'src> {
@@ -76,7 +77,7 @@ impl<'src> fmt::Display for Token<'src> {
7677
}
7778
}
7879

79-
pub fn lexer<'src>() -> impl Parser<'src, &'src str, Vec<(Token<'src>, Span)>, extra::Err<Rich<'src, char, Span>>> {
80+
pub fn lexer<'src>() -> impl Parser<'src, &'src str, Output<'src>, Error<'src>> {
8081
// A parser for numbers
8182
let digits = text::digits(10).slice();
8283

@@ -173,8 +174,6 @@ mod tests {
173174
#[test]
174175
fn simple_test() {
175176
use Token::*;
176-
type Output<'a> = Vec<(Token<'a>, Span)>;
177-
type MyErr<'a> = extra::Err<Rich<'a, char, Span>>;
178177
let cases = [
179178
("true", vec![(Bool(true), Span::new(0, 4))]),
180179
("false", vec![(Bool(false), Span::new(0, 5))]),

argus-parser/src/parser.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,18 @@
1+
use std::{env, fmt, fs};
12

3+
use ariadne::{sources, Color, Label, Report, ReportKind};
4+
use chumsky::{input::SpannedInput, prelude::*};
5+
6+
use crate::lexer::{lexer, Span, Token};
7+
8+
pub type Spanned<T> = (T, Span);
9+
10+
// The type of the input that our parser operates on. The input is the `&[(Token, Span)]` token buffer generated by the
11+
// lexer, wrapped in a `SpannedInput` which 'splits' it apart into its constituent parts, tokens and spans, for chumsky
12+
// to understand.
13+
type ParserInput<'tokens, 'src> = SpannedInput<Token<'src>, Span, &'tokens [(Token<'src>, Span)]>;
14+
15+
pub fn parser<'tokens, 'src: 'tokens>(
16+
) -> impl Parser<'tokens, ParserInput<'tokens, 'src>, Spanned<Expr<'src>>, extra::Err<Rich<'tokens, Token<'src>, Span>>>
17+
+ Clone {
18+
}

0 commit comments

Comments
 (0)