feat: some new features

- tuples `#(Int, Int)`
- `trace` and `trace("text")`
This commit is contained in:
rvcas
2022-11-28 22:24:15 -05:00
committed by Lucas
parent 6066e3176c
commit 0823b78bf8
17 changed files with 335 additions and 223 deletions

View File

@@ -1,4 +1,4 @@
use std::{collections::HashSet, fmt};
use std::collections::HashSet;
use miette::Diagnostic;
@@ -72,7 +72,7 @@ pub enum ErrorKind {
#[error("unexpected end")]
UnexpectedEnd,
#[error("unexpected {0}")]
#[diagnostic(help("try removing it"))]
#[diagnostic(help("{}", .0.help().unwrap_or_else(|| Box::new(""))))]
Unexpected(Pattern),
#[error("unclosed {start}")]
Unclosed {
@@ -87,12 +87,22 @@ pub enum ErrorKind {
#[derive(Debug, PartialEq, Eq, Hash, Diagnostic, thiserror::Error)]
pub enum Pattern {
#[error("{0:?}")]
Char(char),
#[error("{0}")]
#[diagnostic(help("try removing it"))]
Token(Token),
#[error("literal")]
Literal,
#[error("type name")]
TypeIdent,
#[error("indentifier")]
TermIdent,
#[error("end of input")]
End,
#[error("pattern")]
#[diagnostic(help("list spread in match can only have a discard or var"))]
Match,
}
impl From<char> for Pattern {
@@ -105,16 +115,3 @@ impl From<Token> for Pattern {
Self::Token(tok)
}
}
impl fmt::Display for Pattern {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
Pattern::Token(token) => write!(f, "{}", token),
Pattern::Char(c) => write!(f, "{:?}", c),
Pattern::Literal => write!(f, "literal"),
Pattern::TypeIdent => write!(f, "type name"),
Pattern::TermIdent => write!(f, "identifier"),
Pattern::End => write!(f, "end of input"),
}
}
}

View File

@@ -31,6 +31,7 @@ pub fn lexer() -> impl Parser<char, Vec<(Token, Span)>, Error = ParseError> {
just('|').to(Token::Vbar),
just("&&").to(Token::AmperAmper),
just("\n\n").to(Token::EmptyLine),
just('#').to(Token::Hash),
));
let grouping = choice((
@@ -74,7 +75,7 @@ pub fn lexer() -> impl Parser<char, Vec<(Token, Span)>, Error = ParseError> {
"pub" => Token::Pub,
"use" => Token::Use,
"todo" => Token::Todo,
"try" => Token::Try,
"trace" => Token::Trace,
"type" => Token::Type,
"when" => Token::When,
_ => {

View File

@@ -69,7 +69,7 @@ pub enum Token {
Pub,
Use,
Todo,
Try,
Trace,
Type,
When,
}
@@ -143,7 +143,7 @@ impl fmt::Display for Token {
Token::Opaque => "opaque",
Token::Pub => "pub",
Token::Todo => "todo",
Token::Try => "try",
Token::Trace => "try",
Token::Type => "type",
};
write!(f, "\"{}\"", s)