Conlang v0.0.5: Pratternization
cl-token: - Minimize data redundancy by consolidating TokenKind::Literal; TokenData::{String, Identifier} - Rename Op to Punct cl-ast: - Remove ExprKind::{Member, Call} in favor of making them 'binary' operators - Consolidate boxes (TODO: consolidate more boxes) - Remove repetition vecs in favor of boxes (this may come with performance tradeoffs!) cl-lexer: - Reflect changes from cl-token cl-interpret, cl-repl/src/examples: - Reflect changes from cl-ast cl-parser: - Switch to Pratt parsing for expressions - TODO: Code cleanup - TODO: Use total ordering for Precedence instead of binding powers (that's what the binding powers are there for anyway) - Switch functional parsers to take Punct instead of TokenKind - It's not like we need a `for`-separated list - Remove `binary` macro. No longer needed with precedence climbing. - Repurpose `operator` macro to produce both the operator and the respective Precedence - Remove several of the smaller parser functions, since they've been consolidated into the larger `exprkind`
This commit is contained in:
parent
2c36ccc0cf
commit
fc3cbbf450
@ -13,7 +13,7 @@ resolver = "2"
|
||||
|
||||
[workspace.package]
|
||||
repository = "https://git.soft.fish/j/Conlang"
|
||||
version = "0.0.4"
|
||||
version = "0.0.5"
|
||||
authors = ["John Breaux <j@soft.fish>"]
|
||||
edition = "2021"
|
||||
license = "MIT"
|
||||
|
@ -5,7 +5,10 @@ mod display {
|
||||
//! Implements [Display] for [AST](super::super) Types
|
||||
use super::*;
|
||||
pub use delimiters::*;
|
||||
use std::fmt::{Display, Write};
|
||||
use std::{
|
||||
borrow::Borrow,
|
||||
fmt::{Display, Write},
|
||||
};
|
||||
mod delimiters {
|
||||
#![allow(dead_code)]
|
||||
#[derive(Clone, Copy, Debug)]
|
||||
@ -307,13 +310,16 @@ mod display {
|
||||
|
||||
impl Display for Expr {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
match &self.kind {
|
||||
self.kind.fmt(f)
|
||||
}
|
||||
}
|
||||
impl Display for ExprKind {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
match self {
|
||||
ExprKind::Assign(v) => v.fmt(f),
|
||||
ExprKind::Binary(v) => v.fmt(f),
|
||||
ExprKind::Unary(v) => v.fmt(f),
|
||||
ExprKind::Index(v) => v.fmt(f),
|
||||
ExprKind::Call(v) => v.fmt(f),
|
||||
ExprKind::Member(v) => v.fmt(f),
|
||||
ExprKind::Path(v) => v.fmt(f),
|
||||
ExprKind::Literal(v) => v.fmt(f),
|
||||
ExprKind::Array(v) => v.fmt(f),
|
||||
@ -334,8 +340,8 @@ mod display {
|
||||
}
|
||||
impl Display for Assign {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
let Self { head, op, tail } = self;
|
||||
write!(f, "{head} {op} {tail}")
|
||||
let Self { kind, parts } = self;
|
||||
write!(f, "{} {kind} {}", parts.0, parts.1)
|
||||
}
|
||||
}
|
||||
impl Display for AssignKind {
|
||||
@ -358,12 +364,13 @@ mod display {
|
||||
}
|
||||
impl Display for Binary {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
let Self { head, tail } = self;
|
||||
write!(f, "{head}")?;
|
||||
for (kind, expr) in tail {
|
||||
write!(f, " {kind} {expr}")?;
|
||||
let Self { kind, parts } = self;
|
||||
let (head, tail) = parts.borrow();
|
||||
match kind {
|
||||
BinaryKind::Dot => write!(f, "{head}{kind}{tail}"),
|
||||
BinaryKind::Call => write!(f, "{head}{tail}"),
|
||||
_ => write!(f, "{head} {kind} {tail}"),
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
impl Display for BinaryKind {
|
||||
@ -391,17 +398,15 @@ mod display {
|
||||
BinaryKind::Div => "/",
|
||||
BinaryKind::Rem => "%",
|
||||
BinaryKind::Dot => ".",
|
||||
BinaryKind::Call => "()",
|
||||
}
|
||||
.fmt(f)
|
||||
}
|
||||
}
|
||||
impl Display for Unary {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
let Self { ops: kinds, tail } = self;
|
||||
for kind in kinds {
|
||||
kind.fmt(f)?
|
||||
}
|
||||
tail.fmt(f)
|
||||
let Self { kind, tail } = self;
|
||||
write!(f, "{kind}{tail}")
|
||||
}
|
||||
}
|
||||
impl Display for UnaryKind {
|
||||
@ -416,29 +421,11 @@ mod display {
|
||||
.fmt(f)
|
||||
}
|
||||
}
|
||||
impl Display for Call {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
let Self { callee, args } = self;
|
||||
callee.fmt(f)?;
|
||||
for args in args {
|
||||
args.fmt(f)?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
impl Display for Tuple {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
delimit(separate(&self.exprs, ", "), INLINE_PARENS)(f)
|
||||
}
|
||||
}
|
||||
impl Display for Member {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
let Self { head: parent, tail: children } = self;
|
||||
write!(f, "{parent}.")?;
|
||||
separate(children, ".")(f)?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
impl Display for Index {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
let Self { head, indices } = self;
|
||||
@ -449,11 +436,6 @@ mod display {
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
impl Display for Indices {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
delimit(separate(&self.exprs, ", "), INLINE_SQUARE)(f)
|
||||
}
|
||||
}
|
||||
impl Display for Path {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
let Self { absolute, parts } = self;
|
||||
@ -624,8 +606,6 @@ mod convert {
|
||||
Assign => ExprKind::Assign,
|
||||
Binary => ExprKind::Binary,
|
||||
Unary => ExprKind::Unary,
|
||||
Call => ExprKind::Call,
|
||||
Member => ExprKind::Member,
|
||||
Index => ExprKind::Index,
|
||||
Path => ExprKind::Path,
|
||||
Literal => ExprKind::Literal,
|
||||
@ -646,18 +626,7 @@ mod convert {
|
||||
bool => Literal::Bool,
|
||||
char => Literal::Char,
|
||||
u128 => Literal::Int,
|
||||
&str => Literal::String,
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Tuple> for Indices {
|
||||
fn from(value: Tuple) -> Self {
|
||||
Self { exprs: value.exprs }
|
||||
}
|
||||
}
|
||||
impl From<Indices> for Tuple {
|
||||
fn from(value: Indices) -> Self {
|
||||
Self { exprs: value.exprs }
|
||||
String => Literal::String,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -324,10 +324,6 @@ pub enum ExprKind {
|
||||
Binary(Binary),
|
||||
/// A [Unary] expression: [`UnaryKind`]\* [`Expr`]
|
||||
Unary(Unary),
|
||||
/// A [Member] access expression: [`Expr`] (`.` [`Expr`])+
|
||||
Member(Member),
|
||||
/// A [Call] expression, with arguments: a(foo, bar)
|
||||
Call(Call),
|
||||
/// An Array [Index] expression: a[10, 20, 30]
|
||||
Index(Index),
|
||||
/// A [path expression](Path): `::`? [PathPart] (`::` [PathPart])*
|
||||
@ -366,9 +362,8 @@ pub enum ExprKind {
|
||||
/// An [Assign]ment expression: [`Expr`] ([`AssignKind`] [`Expr`])\+
|
||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
pub struct Assign {
|
||||
pub head: Box<Expr>,
|
||||
pub op: AssignKind,
|
||||
pub tail: Box<Expr>,
|
||||
pub kind: AssignKind,
|
||||
pub parts: Box<(ExprKind, ExprKind)>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||
@ -390,8 +385,8 @@ pub enum AssignKind {
|
||||
/// A [Binary] expression: [`Expr`] ([`BinaryKind`] [`Expr`])\+
|
||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
pub struct Binary {
|
||||
pub head: Box<Expr>,
|
||||
pub tail: Vec<(BinaryKind, Expr)>,
|
||||
pub kind: BinaryKind,
|
||||
pub parts: Box<(ExprKind, ExprKind)>,
|
||||
}
|
||||
|
||||
/// A [Binary] operator
|
||||
@ -419,17 +414,18 @@ pub enum BinaryKind {
|
||||
Div,
|
||||
Rem,
|
||||
Dot,
|
||||
Call,
|
||||
}
|
||||
|
||||
/// A [Unary] expression: [`UnaryKind`]\* [`Expr`]
|
||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
pub struct Unary {
|
||||
pub ops: Vec<UnaryKind>,
|
||||
pub tail: Box<Expr>,
|
||||
pub kind: UnaryKind,
|
||||
pub tail: Box<ExprKind>,
|
||||
}
|
||||
|
||||
/// A [Unary] operator
|
||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||
pub enum UnaryKind {
|
||||
Deref,
|
||||
Neg,
|
||||
@ -439,32 +435,11 @@ pub enum UnaryKind {
|
||||
/// Unused
|
||||
Tilde,
|
||||
}
|
||||
|
||||
/// A [Member] access expression: [`Expr`] (`.` [`Expr`])+
|
||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
pub struct Member {
|
||||
pub head: Box<Expr>,
|
||||
pub tail: Vec<Expr>,
|
||||
}
|
||||
|
||||
/// A [Call] expression, with arguments: a(foo, bar)
|
||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
pub struct Call {
|
||||
pub callee: Box<Expr>,
|
||||
pub args: Vec<Tuple>,
|
||||
}
|
||||
|
||||
/// A repeated [Index] expression: a[10, 20, 30][40, 50, 60]
|
||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
pub struct Index {
|
||||
pub head: Box<Expr>,
|
||||
pub indices: Vec<Indices>,
|
||||
}
|
||||
|
||||
/// A single [Index] expression: a[10, 20, 30]
|
||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
pub struct Indices {
|
||||
pub exprs: Vec<Expr>,
|
||||
pub head: Box<ExprKind>,
|
||||
pub indices: Vec<Expr>,
|
||||
}
|
||||
|
||||
/// A [Literal]: 0x42, 1e123, 2.4, "Hello"
|
||||
@ -486,8 +461,8 @@ pub struct Array {
|
||||
/// `[` [Expr] `;` [Literal] `]`
|
||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
pub struct ArrayRep {
|
||||
pub value: Box<Expr>,
|
||||
pub repeat: Box<Expr>,
|
||||
pub value: Box<ExprKind>,
|
||||
pub repeat: Box<ExprKind>,
|
||||
}
|
||||
|
||||
/// An address-of expression: `&` `mut`? [`Expr`]
|
||||
@ -495,7 +470,7 @@ pub struct ArrayRep {
|
||||
pub struct AddrOf {
|
||||
pub count: usize,
|
||||
pub mutable: Mutability,
|
||||
pub expr: Box<Expr>,
|
||||
pub expr: Box<ExprKind>,
|
||||
}
|
||||
|
||||
/// A [Block] expression: `{` [`Stmt`]\* [`Expr`]? `}`
|
||||
@ -507,7 +482,7 @@ pub struct Block {
|
||||
/// A [Grouping](Group) expression `(` [`Expr`] `)`
|
||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
pub struct Group {
|
||||
pub expr: Box<Expr>,
|
||||
pub expr: Box<ExprKind>,
|
||||
}
|
||||
|
||||
/// A [Tuple] expression: `(` [`Expr`] (`,` [`Expr`])+ `)`
|
||||
|
@ -5,6 +5,8 @@
|
||||
//! meaningless to get a pointer to one, and would be undefined behavior to dereference a pointer to
|
||||
//! one in any situation.
|
||||
|
||||
use std::borrow::Borrow;
|
||||
|
||||
use super::*;
|
||||
use cl_ast::*;
|
||||
/// A work-in-progress tree walk interpreter for Conlang
|
||||
@ -107,14 +109,18 @@ impl Interpret for Let {
|
||||
}
|
||||
}
|
||||
impl Interpret for Expr {
|
||||
#[inline]
|
||||
fn interpret(&self, env: &mut Environment) -> IResult<ConValue> {
|
||||
let Self { extents: _, kind } = self;
|
||||
match kind {
|
||||
kind.interpret(env)
|
||||
}
|
||||
}
|
||||
impl Interpret for ExprKind {
|
||||
fn interpret(&self, env: &mut Environment) -> IResult<ConValue> {
|
||||
match self {
|
||||
ExprKind::Assign(v) => v.interpret(env),
|
||||
ExprKind::Binary(v) => v.interpret(env),
|
||||
ExprKind::Unary(v) => v.interpret(env),
|
||||
ExprKind::Member(v) => v.interpret(env),
|
||||
ExprKind::Call(v) => v.interpret(env),
|
||||
ExprKind::Index(v) => v.interpret(env),
|
||||
ExprKind::Path(v) => v.interpret(env),
|
||||
ExprKind::Literal(v) => v.interpret(env),
|
||||
@ -136,9 +142,10 @@ impl Interpret for Expr {
|
||||
}
|
||||
impl Interpret for Assign {
|
||||
fn interpret(&self, env: &mut Environment) -> IResult<ConValue> {
|
||||
let Assign { head, op, tail } = self;
|
||||
let Assign { kind: op, parts } = self;
|
||||
let (head, tail) = parts.borrow();
|
||||
// Resolve the head pattern
|
||||
let head = match &head.kind {
|
||||
let head = match &head {
|
||||
ExprKind::Path(Path { parts, .. }) if parts.len() == 1 => {
|
||||
match parts.last().expect("parts should not be empty") {
|
||||
PathPart::SuperKw => Err(Error::NotAssignable)?,
|
||||
@ -146,8 +153,6 @@ impl Interpret for Assign {
|
||||
PathPart::Ident(Identifier(s)) => s,
|
||||
}
|
||||
}
|
||||
ExprKind::Member(_) => todo!("Member access assignment"),
|
||||
ExprKind::Call(_) => todo!("Assignment to the result of a function call?"),
|
||||
ExprKind::Index(_) => todo!("Assignment to an index operation"),
|
||||
ExprKind::Path(_) => todo!("Path expression resolution (IMPORTANT)"),
|
||||
ExprKind::Empty | ExprKind::Group(_) | ExprKind::Tuple(_) => {
|
||||
@ -193,106 +198,87 @@ impl Interpret for Assign {
|
||||
}
|
||||
impl Interpret for Binary {
|
||||
fn interpret(&self, env: &mut Environment) -> IResult<ConValue> {
|
||||
let Binary { head, tail } = self;
|
||||
let mut head = head.interpret(env)?;
|
||||
let Binary { kind, parts } = self;
|
||||
let (head, tail) = parts.borrow();
|
||||
|
||||
let head = head.interpret(env)?;
|
||||
|
||||
// Short-circuiting ops
|
||||
for (op, tail) in tail {
|
||||
match op {
|
||||
BinaryKind::LogAnd => {
|
||||
if head.truthy()? {
|
||||
head = tail.interpret(env)?;
|
||||
continue;
|
||||
}
|
||||
return Ok(head); // Short circuiting
|
||||
}
|
||||
BinaryKind::LogOr => {
|
||||
if !head.truthy()? {
|
||||
head = tail.interpret(env)?;
|
||||
continue;
|
||||
}
|
||||
return Ok(head); // Short circuiting
|
||||
}
|
||||
BinaryKind::LogXor => {
|
||||
head = ConValue::Bool(head.truthy()? ^ tail.interpret(env)?.truthy()?);
|
||||
continue;
|
||||
}
|
||||
_ => {}
|
||||
match kind {
|
||||
BinaryKind::LogAnd => {
|
||||
return if head.truthy()? {
|
||||
tail.interpret(env)
|
||||
} else {
|
||||
Ok(head)
|
||||
}; // Short circuiting
|
||||
}
|
||||
let tail = tail.interpret(env)?;
|
||||
head = match op {
|
||||
BinaryKind::Mul => env.call("mul", &[head, tail]),
|
||||
BinaryKind::Div => env.call("div", &[head, tail]),
|
||||
BinaryKind::Rem => env.call("rem", &[head, tail]),
|
||||
BinaryKind::Add => env.call("add", &[head, tail]),
|
||||
BinaryKind::Sub => env.call("sub", &[head, tail]),
|
||||
BinaryKind::Shl => env.call("shl", &[head, tail]),
|
||||
BinaryKind::Shr => env.call("shr", &[head, tail]),
|
||||
BinaryKind::BitAnd => env.call("and", &[head, tail]),
|
||||
BinaryKind::BitOr => env.call("or", &[head, tail]),
|
||||
BinaryKind::BitXor => env.call("xor", &[head, tail]),
|
||||
BinaryKind::RangeExc => env.call("range_exc", &[head, tail]),
|
||||
BinaryKind::RangeInc => env.call("range_inc", &[head, tail]),
|
||||
BinaryKind::Lt => env.call("lt", &[head, tail]),
|
||||
BinaryKind::LtEq => env.call("lt_eq", &[head, tail]),
|
||||
BinaryKind::Equal => env.call("eq", &[head, tail]),
|
||||
BinaryKind::NotEq => env.call("neq", &[head, tail]),
|
||||
BinaryKind::GtEq => env.call("gt_eq", &[head, tail]),
|
||||
BinaryKind::Gt => env.call("gt", &[head, tail]),
|
||||
BinaryKind::Dot => todo!("search within a type's namespace!"),
|
||||
_ => Ok(head),
|
||||
}?;
|
||||
BinaryKind::LogOr => {
|
||||
return if !head.truthy()? {
|
||||
tail.interpret(env)
|
||||
} else {
|
||||
Ok(head)
|
||||
}; // Short circuiting
|
||||
}
|
||||
BinaryKind::LogXor => {
|
||||
return Ok(ConValue::Bool(
|
||||
head.truthy()? ^ tail.interpret(env)?.truthy()?,
|
||||
));
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
let tail = tail.interpret(env)?;
|
||||
match kind {
|
||||
BinaryKind::Mul => env.call("mul", &[head, tail]),
|
||||
BinaryKind::Div => env.call("div", &[head, tail]),
|
||||
BinaryKind::Rem => env.call("rem", &[head, tail]),
|
||||
BinaryKind::Add => env.call("add", &[head, tail]),
|
||||
BinaryKind::Sub => env.call("sub", &[head, tail]),
|
||||
BinaryKind::Shl => env.call("shl", &[head, tail]),
|
||||
BinaryKind::Shr => env.call("shr", &[head, tail]),
|
||||
BinaryKind::BitAnd => env.call("and", &[head, tail]),
|
||||
BinaryKind::BitOr => env.call("or", &[head, tail]),
|
||||
BinaryKind::BitXor => env.call("xor", &[head, tail]),
|
||||
BinaryKind::RangeExc => env.call("range_exc", &[head, tail]),
|
||||
BinaryKind::RangeInc => env.call("range_inc", &[head, tail]),
|
||||
BinaryKind::Lt => env.call("lt", &[head, tail]),
|
||||
BinaryKind::LtEq => env.call("lt_eq", &[head, tail]),
|
||||
BinaryKind::Equal => env.call("eq", &[head, tail]),
|
||||
BinaryKind::NotEq => env.call("neq", &[head, tail]),
|
||||
BinaryKind::GtEq => env.call("gt_eq", &[head, tail]),
|
||||
BinaryKind::Gt => env.call("gt", &[head, tail]),
|
||||
BinaryKind::Dot => todo!("search within a type's namespace!"),
|
||||
BinaryKind::Call => match tail {
|
||||
ConValue::Empty => head.call(env, &[]),
|
||||
ConValue::Tuple(args) => head.call(env, &args),
|
||||
_ => Err(Error::TypeError),
|
||||
},
|
||||
_ => Ok(head),
|
||||
}
|
||||
Ok(head)
|
||||
}
|
||||
}
|
||||
|
||||
impl Interpret for Unary {
|
||||
fn interpret(&self, env: &mut Environment) -> IResult<ConValue> {
|
||||
let Unary { tail, ops } = self;
|
||||
let mut operand = tail.interpret(env)?;
|
||||
|
||||
for op in ops.iter().rev() {
|
||||
operand = match op {
|
||||
UnaryKind::Deref => env.call("deref", &[operand])?,
|
||||
UnaryKind::Neg => env.call("neg", &[operand])?,
|
||||
UnaryKind::Not => env.call("not", &[operand])?,
|
||||
UnaryKind::At => {
|
||||
println!("{operand}");
|
||||
operand
|
||||
}
|
||||
UnaryKind::Tilde => unimplemented!("Tilde operator"),
|
||||
};
|
||||
let Unary { kind, tail } = self;
|
||||
let operand = tail.interpret(env)?;
|
||||
match kind {
|
||||
UnaryKind::Deref => env.call("deref", &[operand]),
|
||||
UnaryKind::Neg => env.call("neg", &[operand]),
|
||||
UnaryKind::Not => env.call("not", &[operand]),
|
||||
UnaryKind::At => {
|
||||
println!("{operand}");
|
||||
Ok(operand)
|
||||
}
|
||||
UnaryKind::Tilde => unimplemented!("Tilde operator"),
|
||||
}
|
||||
Ok(operand)
|
||||
}
|
||||
}
|
||||
impl Interpret for Member {
|
||||
fn interpret(&self, env: &mut Environment) -> IResult<ConValue> {
|
||||
todo!("Interpret member accesses in {env}")
|
||||
}
|
||||
}
|
||||
impl Interpret for Call {
|
||||
fn interpret(&self, env: &mut Environment) -> IResult<ConValue> {
|
||||
let Self { callee, args } = self;
|
||||
// evaluate the callee
|
||||
let mut callee = callee.interpret(env)?;
|
||||
for args in args {
|
||||
let ConValue::Tuple(args) = args.interpret(env)? else {
|
||||
Err(Error::TypeError)?
|
||||
};
|
||||
callee = callee.call(env, &args)?;
|
||||
}
|
||||
Ok(callee)
|
||||
}
|
||||
}
|
||||
impl Interpret for Index {
|
||||
fn interpret(&self, env: &mut Environment) -> IResult<ConValue> {
|
||||
let Self { head, indices } = self;
|
||||
let mut head = head.interpret(env)?;
|
||||
for indices in indices {
|
||||
let Indices { exprs } = indices;
|
||||
for index in exprs {
|
||||
head = head.index(&index.interpret(env)?)?;
|
||||
}
|
||||
for index in indices {
|
||||
head = head.index(&index.interpret(env)?)?;
|
||||
}
|
||||
Ok(head)
|
||||
}
|
||||
|
@ -2,7 +2,7 @@
|
||||
#![warn(clippy::all)]
|
||||
#![feature(decl_macro)]
|
||||
use cl_structures::span::Loc;
|
||||
use cl_token::{token_type::Op, TokenKind as Kind, *};
|
||||
use cl_token::{TokenKind as Kind, *};
|
||||
use std::{
|
||||
iter::Peekable,
|
||||
str::{Chars, FromStr},
|
||||
@ -97,33 +97,33 @@ impl<'t> Lexer<'t> {
|
||||
/// Scans through the text, searching for the next [Token]
|
||||
pub fn scan(&mut self) -> LResult<Token> {
|
||||
match self.skip_whitespace().peek()? {
|
||||
'{' => self.consume()?.produce_op(Op::LCurly),
|
||||
'}' => self.consume()?.produce_op(Op::RCurly),
|
||||
'[' => self.consume()?.produce_op(Op::LBrack),
|
||||
']' => self.consume()?.produce_op(Op::RBrack),
|
||||
'(' => self.consume()?.produce_op(Op::LParen),
|
||||
')' => self.consume()?.produce_op(Op::RParen),
|
||||
'{' => self.consume()?.produce_op(Punct::LCurly),
|
||||
'}' => self.consume()?.produce_op(Punct::RCurly),
|
||||
'[' => self.consume()?.produce_op(Punct::LBrack),
|
||||
']' => self.consume()?.produce_op(Punct::RBrack),
|
||||
'(' => self.consume()?.produce_op(Punct::LParen),
|
||||
')' => self.consume()?.produce_op(Punct::RParen),
|
||||
'&' => self.consume()?.amp(),
|
||||
'@' => self.consume()?.produce_op(Op::At),
|
||||
'\\' => self.consume()?.produce_op(Op::Backslash),
|
||||
'@' => self.consume()?.produce_op(Punct::At),
|
||||
'\\' => self.consume()?.produce_op(Punct::Backslash),
|
||||
'!' => self.consume()?.bang(),
|
||||
'|' => self.consume()?.bar(),
|
||||
':' => self.consume()?.colon(),
|
||||
',' => self.consume()?.produce_op(Op::Comma),
|
||||
',' => self.consume()?.produce_op(Punct::Comma),
|
||||
'.' => self.consume()?.dot(),
|
||||
'=' => self.consume()?.equal(),
|
||||
'`' => self.consume()?.produce_op(Op::Grave),
|
||||
'`' => self.consume()?.produce_op(Punct::Grave),
|
||||
'>' => self.consume()?.greater(),
|
||||
'#' => self.consume()?.hash(),
|
||||
'<' => self.consume()?.less(),
|
||||
'-' => self.consume()?.minus(),
|
||||
'+' => self.consume()?.plus(),
|
||||
'?' => self.consume()?.produce_op(Op::Question),
|
||||
'?' => self.consume()?.produce_op(Punct::Question),
|
||||
'%' => self.consume()?.rem(),
|
||||
';' => self.consume()?.produce_op(Op::Semi),
|
||||
';' => self.consume()?.produce_op(Punct::Semi),
|
||||
'/' => self.consume()?.slash(),
|
||||
'*' => self.consume()?.star(),
|
||||
'~' => self.consume()?.produce_op(Op::Tilde),
|
||||
'~' => self.consume()?.produce_op(Punct::Tilde),
|
||||
'^' => self.consume()?.xor(),
|
||||
'0' => self.consume()?.int_with_base(),
|
||||
'1'..='9' => self.digits::<10>(),
|
||||
@ -163,8 +163,8 @@ impl<'t> Lexer<'t> {
|
||||
self.start = self.current;
|
||||
Ok(Token::new(kind, data, loc.0, loc.1))
|
||||
}
|
||||
fn produce_op(&mut self, kind: Op) -> LResult<Token> {
|
||||
self.produce(TokenKind::Op(kind), ())
|
||||
fn produce_op(&mut self, kind: Punct) -> LResult<Token> {
|
||||
self.produce(TokenKind::Punct(kind), ())
|
||||
}
|
||||
fn skip_whitespace(&mut self) -> &mut Self {
|
||||
while let Ok(c) = self.peek() {
|
||||
@ -195,120 +195,120 @@ impl<'t> Lexer<'t> {
|
||||
impl<'t> Lexer<'t> {
|
||||
fn amp(&mut self) -> LResult<Token> {
|
||||
match self.peek() {
|
||||
Ok('&') => self.consume()?.produce_op(Op::AmpAmp),
|
||||
Ok('=') => self.consume()?.produce_op(Op::AmpEq),
|
||||
_ => self.produce_op(Op::Amp),
|
||||
Ok('&') => self.consume()?.produce_op(Punct::AmpAmp),
|
||||
Ok('=') => self.consume()?.produce_op(Punct::AmpEq),
|
||||
_ => self.produce_op(Punct::Amp),
|
||||
}
|
||||
}
|
||||
fn bang(&mut self) -> LResult<Token> {
|
||||
match self.peek() {
|
||||
Ok('!') => self.consume()?.produce_op(Op::BangBang),
|
||||
Ok('=') => self.consume()?.produce_op(Op::BangEq),
|
||||
_ => self.produce_op(Op::Bang),
|
||||
Ok('!') => self.consume()?.produce_op(Punct::BangBang),
|
||||
Ok('=') => self.consume()?.produce_op(Punct::BangEq),
|
||||
_ => self.produce_op(Punct::Bang),
|
||||
}
|
||||
}
|
||||
fn bar(&mut self) -> LResult<Token> {
|
||||
match self.peek() {
|
||||
Ok('|') => self.consume()?.produce_op(Op::BarBar),
|
||||
Ok('=') => self.consume()?.produce_op(Op::BarEq),
|
||||
_ => self.produce_op(Op::Bar),
|
||||
Ok('|') => self.consume()?.produce_op(Punct::BarBar),
|
||||
Ok('=') => self.consume()?.produce_op(Punct::BarEq),
|
||||
_ => self.produce_op(Punct::Bar),
|
||||
}
|
||||
}
|
||||
fn colon(&mut self) -> LResult<Token> {
|
||||
match self.peek() {
|
||||
Ok(':') => self.consume()?.produce_op(Op::ColonColon),
|
||||
_ => self.produce_op(Op::Colon),
|
||||
Ok(':') => self.consume()?.produce_op(Punct::ColonColon),
|
||||
_ => self.produce_op(Punct::Colon),
|
||||
}
|
||||
}
|
||||
fn dot(&mut self) -> LResult<Token> {
|
||||
match self.peek() {
|
||||
Ok('.') => {
|
||||
if let Ok('=') = self.consume()?.peek() {
|
||||
self.consume()?.produce_op(Op::DotDotEq)
|
||||
self.consume()?.produce_op(Punct::DotDotEq)
|
||||
} else {
|
||||
self.produce_op(Op::DotDot)
|
||||
self.produce_op(Punct::DotDot)
|
||||
}
|
||||
}
|
||||
_ => self.produce_op(Op::Dot),
|
||||
_ => self.produce_op(Punct::Dot),
|
||||
}
|
||||
}
|
||||
fn equal(&mut self) -> LResult<Token> {
|
||||
match self.peek() {
|
||||
Ok('=') => self.consume()?.produce_op(Op::EqEq),
|
||||
Ok('>') => self.consume()?.produce_op(Op::FatArrow),
|
||||
_ => self.produce_op(Op::Eq),
|
||||
Ok('=') => self.consume()?.produce_op(Punct::EqEq),
|
||||
Ok('>') => self.consume()?.produce_op(Punct::FatArrow),
|
||||
_ => self.produce_op(Punct::Eq),
|
||||
}
|
||||
}
|
||||
fn greater(&mut self) -> LResult<Token> {
|
||||
match self.peek() {
|
||||
Ok('=') => self.consume()?.produce_op(Op::GtEq),
|
||||
Ok('=') => self.consume()?.produce_op(Punct::GtEq),
|
||||
Ok('>') => {
|
||||
if let Ok('=') = self.consume()?.peek() {
|
||||
self.consume()?.produce_op(Op::GtGtEq)
|
||||
self.consume()?.produce_op(Punct::GtGtEq)
|
||||
} else {
|
||||
self.produce_op(Op::GtGt)
|
||||
self.produce_op(Punct::GtGt)
|
||||
}
|
||||
}
|
||||
_ => self.produce_op(Op::Gt),
|
||||
_ => self.produce_op(Punct::Gt),
|
||||
}
|
||||
}
|
||||
fn hash(&mut self) -> LResult<Token> {
|
||||
match self.peek() {
|
||||
Ok('!') => self.consume()?.produce_op(Op::HashBang),
|
||||
_ => self.produce_op(Op::Hash),
|
||||
Ok('!') => self.consume()?.produce_op(Punct::HashBang),
|
||||
_ => self.produce_op(Punct::Hash),
|
||||
}
|
||||
}
|
||||
fn less(&mut self) -> LResult<Token> {
|
||||
match self.peek() {
|
||||
Ok('=') => self.consume()?.produce_op(Op::LtEq),
|
||||
Ok('=') => self.consume()?.produce_op(Punct::LtEq),
|
||||
Ok('<') => {
|
||||
if let Ok('=') = self.consume()?.peek() {
|
||||
self.consume()?.produce_op(Op::LtLtEq)
|
||||
self.consume()?.produce_op(Punct::LtLtEq)
|
||||
} else {
|
||||
self.produce_op(Op::LtLt)
|
||||
self.produce_op(Punct::LtLt)
|
||||
}
|
||||
}
|
||||
_ => self.produce_op(Op::Lt),
|
||||
_ => self.produce_op(Punct::Lt),
|
||||
}
|
||||
}
|
||||
fn minus(&mut self) -> LResult<Token> {
|
||||
match self.peek() {
|
||||
Ok('=') => self.consume()?.produce_op(Op::MinusEq),
|
||||
Ok('>') => self.consume()?.produce_op(Op::Arrow),
|
||||
_ => self.produce_op(Op::Minus),
|
||||
Ok('=') => self.consume()?.produce_op(Punct::MinusEq),
|
||||
Ok('>') => self.consume()?.produce_op(Punct::Arrow),
|
||||
_ => self.produce_op(Punct::Minus),
|
||||
}
|
||||
}
|
||||
fn plus(&mut self) -> LResult<Token> {
|
||||
match self.peek() {
|
||||
Ok('=') => self.consume()?.produce_op(Op::PlusEq),
|
||||
_ => self.produce_op(Op::Plus),
|
||||
Ok('=') => self.consume()?.produce_op(Punct::PlusEq),
|
||||
_ => self.produce_op(Punct::Plus),
|
||||
}
|
||||
}
|
||||
fn rem(&mut self) -> LResult<Token> {
|
||||
match self.peek() {
|
||||
Ok('=') => self.consume()?.produce_op(Op::RemEq),
|
||||
_ => self.produce_op(Op::Rem),
|
||||
Ok('=') => self.consume()?.produce_op(Punct::RemEq),
|
||||
_ => self.produce_op(Punct::Rem),
|
||||
}
|
||||
}
|
||||
fn slash(&mut self) -> LResult<Token> {
|
||||
match self.peek() {
|
||||
Ok('=') => self.consume()?.produce_op(Op::SlashEq),
|
||||
Ok('=') => self.consume()?.produce_op(Punct::SlashEq),
|
||||
Ok('/') => self.consume()?.line_comment(),
|
||||
Ok('*') => self.consume()?.block_comment(),
|
||||
_ => self.produce_op(Op::Slash),
|
||||
_ => self.produce_op(Punct::Slash),
|
||||
}
|
||||
}
|
||||
fn star(&mut self) -> LResult<Token> {
|
||||
match self.peek() {
|
||||
Ok('=') => self.consume()?.produce_op(Op::StarEq),
|
||||
_ => self.produce_op(Op::Star),
|
||||
Ok('=') => self.consume()?.produce_op(Punct::StarEq),
|
||||
_ => self.produce_op(Punct::Star),
|
||||
}
|
||||
}
|
||||
fn xor(&mut self) -> LResult<Token> {
|
||||
match self.peek() {
|
||||
Ok('=') => self.consume()?.produce_op(Op::XorEq),
|
||||
Ok('^') => self.consume()?.produce_op(Op::XorXor),
|
||||
_ => self.produce_op(Op::Xor),
|
||||
Ok('=') => self.consume()?.produce_op(Punct::XorEq),
|
||||
Ok('^') => self.consume()?.produce_op(Punct::XorXor),
|
||||
_ => self.produce_op(Punct::Xor),
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -339,7 +339,7 @@ impl<'t> Lexer<'t> {
|
||||
if let Ok(keyword) = Kind::from_str(&out) {
|
||||
self.produce(keyword, ())
|
||||
} else {
|
||||
self.produce(Kind::Identifier, TokenData::Identifier(out.into()))
|
||||
self.produce(Kind::Identifier, TokenData::String(out))
|
||||
}
|
||||
}
|
||||
fn xid_start(&mut self) -> LResult<char> {
|
||||
@ -370,7 +370,7 @@ impl<'t> Lexer<'t> {
|
||||
Ok('o') => self.consume()?.digits::<8>(),
|
||||
Ok('b') => self.consume()?.digits::<2>(),
|
||||
Ok('0'..='9') => self.digits::<10>(),
|
||||
_ => self.produce(Kind::Integer, 0),
|
||||
_ => self.produce(Kind::Literal, 0),
|
||||
}
|
||||
}
|
||||
fn digits<const B: u32>(&mut self) -> LResult<Token> {
|
||||
@ -378,7 +378,7 @@ impl<'t> Lexer<'t> {
|
||||
while let Ok(true) = self.peek().as_ref().map(char::is_ascii_alphanumeric) {
|
||||
value = value * B as u128 + self.digit::<B>()? as u128;
|
||||
}
|
||||
self.produce(Kind::Integer, value)
|
||||
self.produce(Kind::Literal, value)
|
||||
}
|
||||
fn digit<const B: u32>(&mut self) -> LResult<u32> {
|
||||
let digit = self.peek()?;
|
||||
@ -399,12 +399,12 @@ impl<'t> Lexer<'t> {
|
||||
{
|
||||
value.push(self.unescape()?)
|
||||
}
|
||||
self.consume()?.produce(Kind::String, value)
|
||||
self.consume()?.produce(Kind::Literal, value)
|
||||
}
|
||||
fn character(&mut self) -> LResult<Token> {
|
||||
let out = self.unescape()?;
|
||||
match self.peek()? {
|
||||
'\'' => self.consume()?.produce(Kind::Character, out),
|
||||
'\'' => self.consume()?.produce(Kind::Literal, out),
|
||||
_ => Err(Error::unmatched_delimiters('\'', self.line(), self.col())),
|
||||
}
|
||||
}
|
||||
|
@ -35,7 +35,7 @@ macro td ($($id:expr),*) {
|
||||
mod ident {
|
||||
use super::*;
|
||||
macro ident ($($id:literal),*) {
|
||||
[$(TokenData::Identifier($id.into())),*]
|
||||
[$(TokenData::String($id.into())),*]
|
||||
}
|
||||
test_lexer_data_type! {
|
||||
underscore { "_ _" => ident!["_", "_"] }
|
||||
@ -109,9 +109,8 @@ mod string {
|
||||
}
|
||||
}
|
||||
mod punct {
|
||||
use cl_token::token_type::Op;
|
||||
macro op($op:ident) {
|
||||
TokenKind::Op(Op::$op)
|
||||
TokenKind::Punct(Punct::$op)
|
||||
}
|
||||
|
||||
use super::*;
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -363,8 +363,6 @@ pub mod yamlify {
|
||||
ExprKind::Assign(k) => k.yaml(y),
|
||||
ExprKind::Binary(k) => k.yaml(y),
|
||||
ExprKind::Unary(k) => k.yaml(y),
|
||||
ExprKind::Member(k) => k.yaml(y),
|
||||
ExprKind::Call(k) => k.yaml(y),
|
||||
ExprKind::Index(k) => k.yaml(y),
|
||||
ExprKind::Path(k) => k.yaml(y),
|
||||
ExprKind::Literal(k) => k.yaml(y),
|
||||
@ -386,18 +384,25 @@ pub mod yamlify {
|
||||
}
|
||||
impl Yamlify for Assign {
|
||||
fn yaml(&self, y: &mut Yamler) {
|
||||
let Self { head, op: _, tail } = self;
|
||||
y.key("Assign").pair("head", head).pair("tail", tail);
|
||||
let Self { kind, parts } = self;
|
||||
y.key("Assign")
|
||||
.pair("kind", kind)
|
||||
.pair("head", &parts.0)
|
||||
.pair("tail", &parts.1);
|
||||
}
|
||||
}
|
||||
impl Yamlify for AssignKind {
|
||||
fn yaml(&self, y: &mut Yamler) {
|
||||
y.value(self);
|
||||
}
|
||||
}
|
||||
impl Yamlify for Binary {
|
||||
fn yaml(&self, y: &mut Yamler) {
|
||||
let Self { head, tail } = self;
|
||||
let mut y = y.key("Binary");
|
||||
y.pair("head", head);
|
||||
for (op, expr) in tail {
|
||||
y.key("tail").pair("op", op).pair("expr", expr);
|
||||
}
|
||||
let Self { kind, parts } = self;
|
||||
y.key("Binary")
|
||||
.pair("kind", kind)
|
||||
.pair("head", &parts.0)
|
||||
.pair("tail", &parts.1);
|
||||
}
|
||||
}
|
||||
impl Yamlify for BinaryKind {
|
||||
@ -407,12 +412,8 @@ pub mod yamlify {
|
||||
}
|
||||
impl Yamlify for Unary {
|
||||
fn yaml(&self, y: &mut Yamler) {
|
||||
let Self { ops, tail } = self;
|
||||
let mut y = y.key("Unary");
|
||||
for op in ops {
|
||||
y.pair("op", op);
|
||||
}
|
||||
y.pair("tail", tail);
|
||||
let Self { kind, tail } = self;
|
||||
y.key("Unary").pair("kind", kind).pair("tail", tail);
|
||||
}
|
||||
}
|
||||
impl Yamlify for UnaryKind {
|
||||
@ -420,18 +421,6 @@ pub mod yamlify {
|
||||
y.value(self);
|
||||
}
|
||||
}
|
||||
impl Yamlify for Member {
|
||||
fn yaml(&self, y: &mut Yamler) {
|
||||
let Self { head, tail } = self;
|
||||
y.key("Member").pair("head", head).pair("tail", tail);
|
||||
}
|
||||
}
|
||||
impl Yamlify for Call {
|
||||
fn yaml(&self, y: &mut Yamler) {
|
||||
let Self { callee, args } = self;
|
||||
y.key("Call").pair("callee", callee).pair("args", args);
|
||||
}
|
||||
}
|
||||
impl Yamlify for Tuple {
|
||||
fn yaml(&self, y: &mut Yamler) {
|
||||
let Self { exprs } = self;
|
||||
@ -444,12 +433,6 @@ pub mod yamlify {
|
||||
y.key("Index").pair("head", head).list(indices);
|
||||
}
|
||||
}
|
||||
impl Yamlify for Indices {
|
||||
fn yaml(&self, y: &mut Yamler) {
|
||||
let Self { exprs } = self;
|
||||
y.key("Indices").list(exprs);
|
||||
}
|
||||
}
|
||||
impl Yamlify for Array {
|
||||
fn yaml(&self, y: &mut Yamler) {
|
||||
let Self { values } = self;
|
||||
@ -466,8 +449,11 @@ pub mod yamlify {
|
||||
}
|
||||
impl Yamlify for AddrOf {
|
||||
fn yaml(&self, y: &mut Yamler) {
|
||||
let Self { count: _, mutable, expr } = self;
|
||||
y.key("Addr").yaml(mutable).pair("expr", expr);
|
||||
let Self { count, mutable, expr } = self;
|
||||
y.key("AddrOf")
|
||||
.yaml(mutable)
|
||||
.pair("count", count)
|
||||
.pair("expr", expr);
|
||||
}
|
||||
}
|
||||
impl Yamlify for Group {
|
||||
|
@ -10,4 +10,4 @@ pub mod token_type;
|
||||
|
||||
pub use token::Token;
|
||||
pub use token_data::TokenData;
|
||||
pub use token_type::TokenKind;
|
||||
pub use token_type::{Punct, TokenKind};
|
||||
|
@ -4,8 +4,6 @@
|
||||
/// external to its [TokenKind](super::token_type::TokenKind)
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub enum TokenData {
|
||||
/// [Token](super::Token) contains an [identifier](str)
|
||||
Identifier(Box<str>),
|
||||
/// [Token](super::Token) contains a [String]
|
||||
String(String),
|
||||
/// [Token](super::Token) contains a [character](char)
|
||||
@ -18,7 +16,6 @@ pub enum TokenData {
|
||||
None,
|
||||
}
|
||||
from! {
|
||||
value: &str => Self::Identifier(value.into()),
|
||||
value: String => Self::String(value),
|
||||
value: u128 => Self::Integer(value),
|
||||
value: f64 => Self::Float(value),
|
||||
@ -34,7 +31,6 @@ macro from($($value:ident: $src:ty => $dst:expr),*$(,)?) {
|
||||
impl std::fmt::Display for TokenData {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
match self {
|
||||
TokenData::Identifier(v) => v.fmt(f),
|
||||
TokenData::String(v) => write!(f, "\"{v}\""),
|
||||
TokenData::Character(v) => write!(f, "'{v}'"),
|
||||
TokenData::Integer(v) => v.fmt(f),
|
||||
|
@ -4,11 +4,13 @@ use std::{fmt::Display, str::FromStr};
|
||||
/// Stores a [Token's](super::Token) lexical information
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
|
||||
pub enum TokenKind {
|
||||
// Invalid syntax
|
||||
/// Invalid sequence
|
||||
Invalid,
|
||||
// Any kind of comment
|
||||
/// Any kind of comment
|
||||
Comment,
|
||||
// A non-keyword identifier
|
||||
/// Any tokenizable literal (See [TokenData](super::TokenData))
|
||||
Literal,
|
||||
/// A non-keyword identifier
|
||||
Identifier,
|
||||
// A keyword
|
||||
Break,
|
||||
@ -36,18 +38,13 @@ pub enum TokenKind {
|
||||
True,
|
||||
Type,
|
||||
While,
|
||||
// Literals
|
||||
Integer,
|
||||
Float,
|
||||
String,
|
||||
Character,
|
||||
// Delimiters and punctuation
|
||||
Op(Op),
|
||||
/// Delimiter or punctuation
|
||||
Punct(Punct),
|
||||
}
|
||||
|
||||
/// An operator character (delimiter, punctuation)
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
|
||||
pub enum Op {
|
||||
pub enum Punct {
|
||||
LCurly, // {
|
||||
RCurly, // }
|
||||
LBrack, // [
|
||||
@ -109,6 +106,7 @@ impl Display for TokenKind {
|
||||
match self {
|
||||
TokenKind::Invalid => "invalid".fmt(f),
|
||||
TokenKind::Comment => "comment".fmt(f),
|
||||
TokenKind::Literal => "literal".fmt(f),
|
||||
TokenKind::Identifier => "identifier".fmt(f),
|
||||
|
||||
TokenKind::Break => "break".fmt(f),
|
||||
@ -137,12 +135,7 @@ impl Display for TokenKind {
|
||||
TokenKind::Type => "type".fmt(f),
|
||||
TokenKind::While => "while".fmt(f),
|
||||
|
||||
TokenKind::Integer => "integer literal".fmt(f),
|
||||
TokenKind::Float => "float literal".fmt(f),
|
||||
TokenKind::String => "string literal".fmt(f),
|
||||
TokenKind::Character => "char literal".fmt(f),
|
||||
|
||||
TokenKind::Op(op) => op.fmt(f),
|
||||
TokenKind::Punct(op) => op.fmt(f),
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -182,63 +175,63 @@ impl FromStr for TokenKind {
|
||||
}
|
||||
}
|
||||
|
||||
impl Display for Op {
|
||||
impl Display for Punct {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
match self {
|
||||
Op::LCurly => "left curly".fmt(f),
|
||||
Op::RCurly => "right curly".fmt(f),
|
||||
Op::LBrack => "left brack".fmt(f),
|
||||
Op::RBrack => "right brack".fmt(f),
|
||||
Op::LParen => "left paren".fmt(f),
|
||||
Op::RParen => "right paren".fmt(f),
|
||||
Op::Amp => "and".fmt(f),
|
||||
Op::AmpAmp => "and-and".fmt(f),
|
||||
Op::AmpEq => "and-assign".fmt(f),
|
||||
Op::Arrow => "arrow".fmt(f),
|
||||
Op::At => "at".fmt(f),
|
||||
Op::Backslash => "backslash".fmt(f),
|
||||
Op::Bang => "bang".fmt(f),
|
||||
Op::BangBang => "not-not".fmt(f),
|
||||
Op::BangEq => "not equal to".fmt(f),
|
||||
Op::Bar => "or".fmt(f),
|
||||
Op::BarBar => "or-or".fmt(f),
|
||||
Op::BarEq => "or-assign".fmt(f),
|
||||
Op::Colon => "colon".fmt(f),
|
||||
Op::ColonColon => "path separator".fmt(f),
|
||||
Op::Comma => "comma".fmt(f),
|
||||
Op::Dot => "dot".fmt(f),
|
||||
Op::DotDot => "exclusive range".fmt(f),
|
||||
Op::DotDotEq => "inclusive range".fmt(f),
|
||||
Op::Eq => "assign".fmt(f),
|
||||
Op::EqEq => "equal to".fmt(f),
|
||||
Op::FatArrow => "fat arrow".fmt(f),
|
||||
Op::Grave => "grave".fmt(f),
|
||||
Op::Gt => "greater than".fmt(f),
|
||||
Op::GtEq => "greater than or equal to".fmt(f),
|
||||
Op::GtGt => "shift right".fmt(f),
|
||||
Op::GtGtEq => "shift right-assign".fmt(f),
|
||||
Op::Hash => "hash".fmt(f),
|
||||
Op::HashBang => "shebang".fmt(f),
|
||||
Op::Lt => "less than".fmt(f),
|
||||
Op::LtEq => "less than or equal to".fmt(f),
|
||||
Op::LtLt => "shift left".fmt(f),
|
||||
Op::LtLtEq => "shift left-assign".fmt(f),
|
||||
Op::Minus => "sub".fmt(f),
|
||||
Op::MinusEq => "sub-assign".fmt(f),
|
||||
Op::Plus => "add".fmt(f),
|
||||
Op::PlusEq => "add-assign".fmt(f),
|
||||
Op::Question => "huh?".fmt(f),
|
||||
Op::Rem => "rem".fmt(f),
|
||||
Op::RemEq => "rem-assign".fmt(f),
|
||||
Op::Semi => "ignore".fmt(f),
|
||||
Op::Slash => "div".fmt(f),
|
||||
Op::SlashEq => "div-assign".fmt(f),
|
||||
Op::Star => "star".fmt(f),
|
||||
Op::StarEq => "star-assign".fmt(f),
|
||||
Op::Tilde => "tilde".fmt(f),
|
||||
Op::Xor => "xor".fmt(f),
|
||||
Op::XorEq => "xor-assign".fmt(f),
|
||||
Op::XorXor => "cat-ears".fmt(f),
|
||||
Punct::LCurly => "{".fmt(f),
|
||||
Punct::RCurly => "}".fmt(f),
|
||||
Punct::LBrack => "[".fmt(f),
|
||||
Punct::RBrack => "]".fmt(f),
|
||||
Punct::LParen => "(".fmt(f),
|
||||
Punct::RParen => ")".fmt(f),
|
||||
Punct::Amp => "&".fmt(f),
|
||||
Punct::AmpAmp => "&&".fmt(f),
|
||||
Punct::AmpEq => "&=".fmt(f),
|
||||
Punct::Arrow => "->".fmt(f),
|
||||
Punct::At => "@".fmt(f),
|
||||
Punct::Backslash => "\\".fmt(f),
|
||||
Punct::Bang => "!".fmt(f),
|
||||
Punct::BangBang => "!!".fmt(f),
|
||||
Punct::BangEq => "!=".fmt(f),
|
||||
Punct::Bar => "|".fmt(f),
|
||||
Punct::BarBar => "||".fmt(f),
|
||||
Punct::BarEq => "|=".fmt(f),
|
||||
Punct::Colon => ":".fmt(f),
|
||||
Punct::ColonColon => "::".fmt(f),
|
||||
Punct::Comma => ",".fmt(f),
|
||||
Punct::Dot => ".".fmt(f),
|
||||
Punct::DotDot => "..".fmt(f),
|
||||
Punct::DotDotEq => "..=".fmt(f),
|
||||
Punct::Eq => "=".fmt(f),
|
||||
Punct::EqEq => "==".fmt(f),
|
||||
Punct::FatArrow => "=>".fmt(f),
|
||||
Punct::Grave => "`".fmt(f),
|
||||
Punct::Gt => ">".fmt(f),
|
||||
Punct::GtEq => ">=".fmt(f),
|
||||
Punct::GtGt => ">>".fmt(f),
|
||||
Punct::GtGtEq => ">>=".fmt(f),
|
||||
Punct::Hash => "#".fmt(f),
|
||||
Punct::HashBang => "#!".fmt(f),
|
||||
Punct::Lt => "<".fmt(f),
|
||||
Punct::LtEq => "<=".fmt(f),
|
||||
Punct::LtLt => "<<".fmt(f),
|
||||
Punct::LtLtEq => "<<=".fmt(f),
|
||||
Punct::Minus => "-".fmt(f),
|
||||
Punct::MinusEq => "-=".fmt(f),
|
||||
Punct::Plus => "+".fmt(f),
|
||||
Punct::PlusEq => "+=".fmt(f),
|
||||
Punct::Question => "?".fmt(f),
|
||||
Punct::Rem => "%".fmt(f),
|
||||
Punct::RemEq => "%=".fmt(f),
|
||||
Punct::Semi => ";".fmt(f),
|
||||
Punct::Slash => "/".fmt(f),
|
||||
Punct::SlashEq => "/=".fmt(f),
|
||||
Punct::Star => "*".fmt(f),
|
||||
Punct::StarEq => "*=".fmt(f),
|
||||
Punct::Tilde => "~".fmt(f),
|
||||
Punct::Xor => "^".fmt(f),
|
||||
Punct::XorEq => "^=".fmt(f),
|
||||
Punct::XorXor => "^^".fmt(f),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user