use crate::leaf::*;
use newer_type::implement;
use syan::parse::{Parse, Unparse};
pub use crate::cst::Header;
#[derive(Parse, Unparse, Debug, Clone, PartialEq)]
pub enum HeaderV1 {
UsePackage {
use_kw: KwUse,
package_kw: KwPackage,
open_kw: Option<KwOpen>,
path: ast::ModChainV1,
},
UseOf {
use_kw: KwUse,
open_kw: Option<KwOpen>,
path: ast::ModChainV1,
of_kw: KwOf,
relpath: LiteralTok,
},
Use {
use_kw: KwUse,
open_kw: Option<KwOpen>,
path: ast::ModChainV1,
},
Legacy(Header),
}
impl HeaderV1 {
pub fn display_name(&self) -> String {
match self {
Self::UsePackage { path, .. } => format!("use package {}", path.render()),
Self::UseOf { path, relpath, .. } => {
format!("use {} of `{}`", path.render(), relpath.body)
}
Self::Use { path, .. } => format!("use {}", path.render()),
Self::Legacy(Header::Require(t)) => format!("@require: {}", t.content),
Self::Legacy(Header::Import(t)) => format!("@import: {}", t.content),
Self::Legacy(Header::Stage(_)) => "@stage:".to_string(),
}
}
}
impl ast::ModChainV1 {
pub fn render(&self) -> String {
match self {
Self::Long(t) => {
let mut parts = t.mods.clone();
parts.push(t.name.clone());
parts.join(".")
}
Self::Single(t) => t.name.clone(),
}
}
pub fn head_name(&self) -> String {
match self {
Self::Long(t) => t.mods.first().cloned().unwrap_or_else(|| t.name.clone()),
Self::Single(t) => t.name.clone(),
}
}
}
pub use crate::cst::BindName;
#[derive(Parse, Unparse, Debug, Clone, PartialEq)]
pub enum FileV1 {
Document {
headers: Vec<HeaderV1>,
body: ast::Expr,
eoi: EoiTok,
},
Library {
headers: Vec<HeaderV1>,
module_kw: KwModule,
name: CtorTok,
sig_annot: Option<SigAnnotV1>,
eq: DefEqTok,
struct_kw: KwStruct,
binds: Vec<Bind>,
end_kw: KwEnd,
eoi: EoiTok,
},
}
#[derive(Parse, Unparse, Debug, Clone, PartialEq)]
pub struct SigAnnotV1 {
pub coerce: CoerceTok,
pub sig_: SigExprErasedV1,
}
pub use ast::{AscribedInnerV1, OptParamEntryV1, OptParamsV1, Param, ParamBody};
#[derive(Parse, Unparse, Debug, Clone, PartialEq)]
pub enum Bind {
Value {
kw: KwVal,
stage: Option<BindStageV1>,
name: BindName,
params: Vec<Param>,
eq: DefEqTok,
body: ast::Expr,
},
ValueInline {
kw: KwVal,
stage: Option<BindStageV1>,
inline_kw: KwInline,
ctx: Option<VarTok>,
cmd: AnyHorzCmdTok,
params: Vec<Param>,
eq: DefEqTok,
body: ast::Expr,
},
ValueBlock {
kw: KwVal,
stage: Option<BindStageV1>,
block_kw: KwBlock,
ctx: Option<VarTok>,
cmd: AnyVertCmdTok,
params: Vec<Param>,
eq: DefEqTok,
body: ast::Expr,
},
ValueMath {
kw: KwVal,
stage: Option<BindStageV1>,
math_kw: KwMath,
ctx: VarTok,
cmd: AnyHorzCmdTok,
params: Vec<Param>,
scripts: Option<ScriptsParamV1>,
eq: DefEqTok,
body: ast::Expr,
},
ValueRec {
kw: KwVal,
stage: Option<BindStageV1>,
rec_kw: KwRec,
first: ast::RecClauseV1,
ands: Vec<ast::AndClauseV1>,
},
ValueMutable {
kw: KwVal,
stage: Option<BindStageV1>,
mutable_kw: KwMutable,
name: VarTok,
arrow: OverwriteEqTok,
value: ast::Expr,
},
Type {
kw: KwType,
first: TypeBindSingleV1,
ands: Vec<TypeAndV1>,
},
Module {
module_kw: KwModule,
name: CtorTok,
sig_annot: Option<SigAnnotV1>,
eq: DefEqTok,
body: ModExprErasedV1,
},
Signature {
kw: KwSignature,
name: CtorTok,
eq: DefEqTok,
sig_: SigExprErasedV1,
},
Include { kw: KwInclude, body: ModExprErasedV1 },
}
#[derive(Parse, Unparse, Debug, Clone, PartialEq)]
pub struct BindStageV1 {
pub persistent: Option<KwPersistent>,
pub tilde: ExactTildeTok,
}
#[derive(Parse, Unparse, Debug, Clone, PartialEq)]
pub struct ScriptsParamV1 {
pub with_kw: KwWith,
pub sub: VarTok,
pub sup: VarTok,
}
#[derive(Parse, Unparse, Debug, Clone, PartialEq)]
pub struct TypeBindSingleV1 {
pub name: VarTok,
pub tyvars: Vec<TypeVarTok>,
pub eq: DefEqTok,
pub body: TypeBodyV1,
}
#[derive(Parse, Unparse, Debug, Clone, PartialEq)]
pub struct TypeAndV1 {
pub and_kw: KwAnd,
pub bind: TypeBindSingleV1,
}
#[derive(Parse, Unparse, Debug, Clone, PartialEq)]
pub struct TypeBindsV1 {
pub first: TypeBindSingleV1,
pub ands: Vec<TypeAndV1>,
}
#[derive(Parse, Unparse, Debug, Clone, PartialEq)]
pub enum TypeBodyV1 {
Variant {
leading_bar: Option<BarTok>,
first: VariantDefV1,
rest: Vec<BarVariantDefV1>,
},
Synonym(ast::TypeExpr),
}
#[derive(Parse, Unparse, Debug, Clone, PartialEq)]
pub struct VariantDefV1 {
pub ctor: CtorTok,
pub of_ty: Option<OfTypeV1>,
}
#[derive(Parse, Unparse, Debug, Clone, PartialEq)]
pub struct OfTypeV1 {
pub of_kw: KwOf,
pub ty: ast::TypeExpr,
}
#[derive(Parse, Unparse, Debug, Clone, PartialEq)]
pub struct BarVariantDefV1 {
pub bar: BarTok,
pub def: VariantDefV1,
}
#[derive(Debug, Clone, PartialEq)]
pub struct StructBindV1(pub Box<Bind>);
impl Parse<crate::token::Atom> for StructBindV1 {
type Error = syan::error::ParseError<crate::span::Span>;
fn parse_stream<S: syan::parse::ParseStream<Atom = crate::token::Atom>>(
stream: &mut S,
) -> Result<Self, Self::Error> {
let value = <Bind as Parse<_>>::parse_stream(stream)?;
Ok(StructBindV1(Box::new(value)))
}
}
impl Unparse<crate::token::Atom> for StructBindV1 {
fn unparse<S: syan::parse::unparse::Emitter<crate::token::Atom>>(
&self,
sink: &mut S,
) -> Result<(), S::Error> {
self.0.unparse(sink)
}
}
#[derive(Debug, Clone, PartialEq)]
pub struct StructDeclV1(pub Box<ast::Decl>);
impl Parse<crate::token::Atom> for StructDeclV1 {
type Error = syan::error::ParseError<crate::span::Span>;
fn parse_stream<S: syan::parse::ParseStream<Atom = crate::token::Atom>>(
stream: &mut S,
) -> Result<Self, Self::Error> {
let value = <ast::Decl as Parse<_>>::parse_stream(stream)?;
Ok(StructDeclV1(Box::new(value)))
}
}
impl Unparse<crate::token::Atom> for StructDeclV1 {
fn unparse<S: syan::parse::unparse::Emitter<crate::token::Atom>>(
&self,
sink: &mut S,
) -> Result<(), S::Error> {
self.0.unparse(sink)
}
}
macro_rules! erased_leaf_v1 {
($($(#[$doc:meta])* $name:ident => $target:ty;)*) => {
$(
$(#[$doc])*
#[implement(newer_type_std::ops::Deref)]
#[derive(Debug, Clone, PartialEq)]
pub struct $name(pub Box<$target>);
impl Parse<crate::token::Atom> for $name {
type Error = syan::error::ParseError<crate::span::Span>;
fn parse_stream<S: syan::parse::ParseStream<Atom = crate::token::Atom>>(
stream: &mut S,
) -> Result<Self, Self::Error> {
let value = <$target as Parse<_>>::parse_stream(stream)?;
Ok($name(Box::new(value)))
}
}
impl Unparse<crate::token::Atom> for $name {
fn unparse<S: syan::parse::unparse::Emitter<crate::token::Atom>>(
&self,
sink: &mut S,
) -> Result<(), S::Error> {
self.0.unparse(sink)
}
}
)*
};
}
erased_leaf_v1! {
ExprErasedV1 => ast::Expr;
PatErasedV1 => ast::Pattern;
PatBotErasedV1 => ast::PatBot;
TyErasedV1 => ast::TypeExpr;
MathErasedV1 => ast::MathElemCst;
ModExprErasedV1 => ast::ModExpr;
SigExprErasedV1 => ast::SigExpr;
TypeBindsErasedV1 => TypeBindsV1;
}
#[syan::parse::recurse]
pub mod ast {
use crate::leaf::*;
use syan::parse::{Parse, Unparse};
#[derive(Parse, Unparse, Debug, Clone, PartialEq)]
pub struct Param {
pub opts: Option<OptParamsV1>,
pub body: ParamBody,
}
#[derive(Parse, Unparse, Debug, Clone, PartialEq)]
pub enum ParamBody {
Pat(PatBot),
Ascribed {
paren: ParenGroup<()>,
#[group(self.paren)]
inner: AscribedInnerV1,
},
}
#[derive(Parse, Unparse, Debug, Clone, PartialEq)]
pub struct AscribedInnerV1 {
pub pat: super::PatErasedV1,
pub colon: ColonTok,
pub ty: super::TyErasedV1,
}
#[derive(Parse, Unparse, Debug, Clone, PartialEq)]
pub struct OptParamsV1 {
pub q: OptionalTypeTok,
pub paren: ParenGroup<()>,
#[group(self.paren)]
pub entries: Vec<OptParamEntryV1>,
}
#[derive(Parse, Unparse, Debug, Clone, PartialEq)]
pub struct OptParamEntryV1 {
pub label: VarTok,
pub eq: DefEqTok,
pub var: VarTok,
pub comma: Option<CommaTok>,
}
#[derive(Parse, Unparse, Debug, Clone, PartialEq)]
pub enum Expr {
LetRecIn {
let_kw: KwLet,
rec_kw: KwRec,
first: RecClauseV1,
ands: Vec<AndClauseV1>,
in_kw: KwIn,
body: Box<Expr>,
},
LetMutableIn {
let_kw: KwLet,
mutable_kw: KwMutable,
name: VarTok,
arrow: OverwriteEqTok,
init: Box<Expr>,
in_kw: KwIn,
body: Box<Expr>,
},
LetIn {
kw: KwLet,
name: super::BindName,
params: Vec<Param>,
eq: DefEqTok,
value: Box<Expr>,
in_kw: KwIn,
body: Box<Expr>,
},
LetPatternIn {
kw: KwLet,
pat: super::PatErasedV1,
eq: DefEqTok,
value: Box<Expr>,
in_kw: KwIn,
body: Box<Expr>,
},
OpenIn {
let_kw: KwLet,
open_kw: KwOpen,
name: CtorTok,
in_kw: KwIn,
body: Box<Expr>,
},
If {
kw: KwIf,
cond: Box<Expr>,
then_kw: KwThen,
then_branch: Box<Expr>,
else_kw: KwElse,
else_branch: Box<Expr>,
},
Fun {
kw: KwFun,
params: Vec<Param>,
arrow: ArrowTok,
body: Box<Expr>,
},
Match {
kw: KwMatch,
scrutinee: Box<Expr>,
with_kw: KwWith,
leading_bar: Option<BarTok>,
first: MatchArm,
rest: Vec<BarArm>,
end_kw: KwEnd,
},
Overwrite {
name: VarTok,
arrow: OverwriteEqTok,
value: super::ExprErasedV1,
},
Ops(OpChain),
}
#[derive(Parse, Unparse, Debug, Clone, PartialEq)]
pub struct RecClauseV1 {
pub name: super::BindName,
pub params: Vec<Param>,
pub eq: DefEqTok,
pub value: super::ExprErasedV1,
}
#[derive(Parse, Unparse, Debug, Clone, PartialEq)]
pub struct AndClauseV1 {
pub and_kw: KwAnd,
pub clause: RecClauseV1,
}
#[derive(Parse, Unparse, Debug, Clone, PartialEq)]
pub struct MatchArm {
pub pat: super::PatErasedV1,
pub arrow: ArrowTok,
pub body: super::ExprErasedV1,
}
#[derive(Parse, Unparse, Debug, Clone, PartialEq)]
pub struct BarArm {
pub bar: BarTok,
pub arm: MatchArm,
}
#[derive(Parse, Unparse, Debug, Clone, PartialEq)]
pub struct OpChain {
pub head: AppExpr,
pub tail: Vec<OpRhs>,
}
#[derive(Parse, Unparse, Debug, Clone, PartialEq)]
pub struct OpRhs {
pub op: BinOpTok,
pub rhs: AppExpr,
}
#[derive(Parse, Unparse, Debug, Clone, PartialEq)]
pub struct AppExpr {
pub minus: Option<ExactMinusTok>,
pub stage: Option<StagePrefix>,
pub excl: Option<UnopExclamTok>,
pub head: Atomic,
pub head_accesses: Vec<AccessSeg>,
pub args: Vec<AppArg>,
}
#[derive(Parse, Unparse, Debug, Clone, PartialEq)]
pub enum StagePrefix {
Next(ExactAmpTok),
Prev(ExactTildeTok),
}
#[derive(Parse, Unparse, Debug, Clone, PartialEq)]
pub struct AccessSeg {
pub hash: AccessTok,
pub label: VarTok,
}
#[derive(Parse, Unparse, Debug, Clone, PartialEq)]
pub enum AppArg {
Bundled {
opts: OptArgsV1,
excl: Option<UnopExclamTok>,
atom: Atomic,
accesses: Vec<AccessSeg>,
},
BundledCtor { opts: OptArgsV1, ctor: CtorTok },
Atom {
stage: Option<StagePrefix>,
excl: Option<UnopExclamTok>,
atom: Atomic,
accesses: Vec<AccessSeg>,
},
Ctor(CtorTok),
}
#[derive(Parse, Unparse, Debug, Clone, PartialEq)]
pub struct OptArgsV1 {
pub q: OptionalTypeTok,
pub paren: ParenGroup<()>,
#[group(self.paren)]
pub entries: Vec<OptArgEntryV1>,
}
#[derive(Parse, Unparse, Debug, Clone, PartialEq)]
pub struct OptArgEntryV1 {
pub label: VarTok,
pub eq: DefEqTok,
pub value: super::ExprErasedV1,
pub comma: Option<CommaTok>,
}
#[derive(Parse, Unparse, Debug, Clone, PartialEq)]
pub enum Atomic {
Length(LengthTok),
Float(FloatTok),
Int(IntTok),
Literal(LiteralTok),
True(KwTrue),
False(KwFalse),
Ctor(CtorTok),
Var(VarTok),
VarWithMod(VarWithModTok),
Command { kw: CommandTok, name: AnyHorzCmdTok },
Unit { paren: UnitParen },
Paren {
paren: ParenGroup<()>,
#[group(self.paren)]
inner: Box<ParenBody>,
},
Record {
rec: RecordGroup<()>,
#[group(self.rec)]
body: RecordBody,
},
List {
list: ListGroup<()>,
#[group(self.list)]
items: Vec<ListItem>,
},
InlineText {
igrp: InlineGroup<()>,
#[group(self.igrp)]
elems: Vec<InlineElem>,
},
BlockText {
bgrp: BlockGroup<()>,
#[group(self.bgrp)]
elems: Vec<BlockElem>,
},
MathText {
mgrp: MathGroup<()>,
#[group(self.mgrp)]
elems: Vec<super::MathErasedV1>,
},
}
#[derive(Parse, Unparse, Debug, Clone, PartialEq)]
pub enum RecordBody {
Update {
base: super::ExprErasedV1,
with_kw: KwWith,
fields: Vec<RecordField>,
},
Fields(Vec<RecordField>),
}
#[derive(Parse, Unparse, Debug, Clone, PartialEq)]
pub struct ParenBody {
pub first: super::ExprErasedV1,
pub rest: Vec<CommaExpr>,
}
#[derive(Parse, Unparse, Debug, Clone, PartialEq)]
pub struct CommaExpr {
pub comma: CommaTok,
pub value: super::ExprErasedV1,
}
#[derive(Parse, Unparse, Debug, Clone, PartialEq)]
pub struct RecordField {
pub name: VarTok,
pub eq: DefEqTok,
pub value: super::ExprErasedV1,
pub comma: Option<CommaTok>,
}
#[derive(Parse, Unparse, Debug, Clone, PartialEq)]
pub struct ListItem {
pub value: super::ExprErasedV1,
pub comma: Option<CommaTok>,
}
#[derive(Parse, Unparse, Debug, Clone, PartialEq)]
pub enum InlineElem {
Char(CharTok),
CodeText(CodeTextTok),
Space(SpaceTok),
Break(BreakTok),
Embed { var: VarInHorzTok, semi: EndActiveTok },
EmbedMath {
mgrp: MathGroup<()>,
#[group(self.mgrp)]
elems: Vec<super::MathErasedV1>,
},
Cmd { name: AnyHorzCmdTok, tail: CmdTail },
ItemBullet(ItemTok),
Sep(SepTok),
}
#[derive(Parse, Unparse, Debug, Clone, PartialEq)]
pub enum BlockElem {
Embed { var: VarInVertTok, semi: EndActiveTok },
Cmd { name: AnyVertCmdTok, tail: CmdTail },
}
#[derive(Parse, Unparse, Debug, Clone, PartialEq)]
pub enum CmdTail {
Semi(EndActiveTok),
Args {
lead_opts: Option<OptArgsV1>,
args: super::ExprErasedV1,
semi: Option<EndActiveTok>,
},
}
#[derive(Parse, Unparse, Debug, Clone, PartialEq)]
pub struct Pattern {
pub head: PatCons,
pub as_clause: Option<AsClause>,
}
#[derive(Parse, Unparse, Debug, Clone, PartialEq)]
pub struct AsClause {
pub as_kw: KwAs,
pub name: VarTok,
}
#[derive(Parse, Unparse, Debug, Clone, PartialEq)]
pub struct PatCons {
pub head: PatBot,
pub tail: Vec<ConsSeg>,
}
#[derive(Parse, Unparse, Debug, Clone, PartialEq)]
pub struct ConsSeg {
pub cons: ConsTok,
pub tail: PatBot,
}
#[derive(Parse, Unparse, Debug, Clone, PartialEq)]
pub enum PatBot {
CtorApplied { ctor: CtorTok, arg: Box<PatBot> },
Ctor(CtorTok),
Int(IntTok),
True(KwTrue),
False(KwFalse),
Str(LiteralTok),
Wild(WildcardTok),
Var(VarTok),
Unit { paren: UnitParen },
Paren {
paren: ParenGroup<()>,
#[group(self.paren)]
inner: Box<PatternParenBody>,
},
List {
plist: ListGroup<()>,
#[group(self.plist)]
items: Vec<PatListItem>,
},
}
#[derive(Parse, Unparse, Debug, Clone, PartialEq)]
pub struct PatternParenBody {
pub first: super::PatErasedV1,
pub rest: Vec<CommaPattern>,
}
#[derive(Parse, Unparse, Debug, Clone, PartialEq)]
pub struct CommaPattern {
pub comma: CommaTok,
pub value: super::PatErasedV1,
}
#[derive(Parse, Unparse, Debug, Clone, PartialEq)]
pub struct PatListItem {
pub value: super::PatErasedV1,
pub comma: Option<CommaTok>,
}
#[derive(Parse, Unparse, Debug, Clone, PartialEq)]
pub enum TypeExpr {
OptRowFun {
opt_dom: TypeOptDomV1,
dom: TypeProd,
arrow: ArrowTok,
cod: Box<TypeExpr>,
},
Fun {
dom: TypeProd,
arrow: ArrowTok,
cod: Box<TypeExpr>,
},
Atom(TypeProd),
}
#[derive(Parse, Unparse, Debug, Clone, PartialEq)]
pub struct TypeOptDomV1 {
pub q: OptionalTypeTok,
pub paren: ParenGroup<()>,
#[group(self.paren)]
pub inner: TypeOptDomInnerV1,
}
#[derive(Parse, Unparse, Debug, Clone, PartialEq)]
pub struct TypeOptDomInnerV1 {
pub entries: Vec<TypeOptEntryV1>,
pub row_tail: Option<RowTailV1>,
}
#[derive(Parse, Unparse, Debug, Clone, PartialEq)]
pub struct TypeOptEntryV1 {
pub label: VarTok,
pub colon: ColonTok,
pub ty: super::TyErasedV1,
pub comma: Option<CommaTok>,
}
#[derive(Parse, Unparse, Debug, Clone, PartialEq)]
pub struct RowTailV1 {
pub bar: BarTok,
pub var: RowVarTok,
}
#[derive(Parse, Unparse, Debug, Clone, PartialEq)]
pub struct TypeProd {
pub first: TypeApp,
pub rest: Vec<StarType>,
}
#[derive(Parse, Unparse, Debug, Clone, PartialEq)]
pub struct StarType {
pub star: ExactTimesTok,
pub ty: TypeApp,
}
#[derive(Parse, Unparse, Debug, Clone, PartialEq)]
pub enum TypeApp {
InlineCmdTy {
kw: KwInline,
ilist: ListGroup<()>,
#[group(self.ilist)]
args: Vec<TypeCmdArgItemV1>,
},
BlockCmdTy {
kw: KwBlock,
blist: ListGroup<()>,
#[group(self.blist)]
args: Vec<TypeCmdArgItemV1>,
},
MathCmdTy {
kw: KwMath,
mlist: ListGroup<()>,
#[group(self.mlist)]
args: Vec<TypeCmdArgItemV1>,
},
AppliedLong {
ctor: VarWithModTok,
first: TypeAtom,
rest: Vec<TypeAtom>,
},
Applied {
ctor: VarTok,
first: TypeAtom,
rest: Vec<TypeAtom>,
},
Atom(TypeAtom),
}
#[derive(Parse, Unparse, Debug, Clone, PartialEq)]
pub struct TypeCmdArgItemV1 {
pub opts: Option<TypeCmdOptDomV1>,
pub ty: super::TyErasedV1,
pub comma: Option<CommaTok>,
}
#[derive(Parse, Unparse, Debug, Clone, PartialEq)]
pub struct TypeCmdOptDomV1 {
pub q: OptionalTypeTok,
pub paren: ParenGroup<()>,
#[group(self.paren)]
pub entries: Vec<TypeCmdOptEntryV1>,
}
#[derive(Parse, Unparse, Debug, Clone, PartialEq)]
pub struct TypeCmdOptEntryV1 {
pub label: VarTok,
pub colon: ColonTok,
pub ty: super::TyErasedV1,
pub comma: Option<CommaTok>,
}
#[derive(Parse, Unparse, Debug, Clone, PartialEq)]
pub enum TypeAtom {
Paren {
paren: ParenGroup<()>,
#[group(self.paren)]
inner: super::TyErasedV1,
},
Record {
rec: RecordGroup<()>,
#[group(self.rec)]
inner: TypeRecordInnerV1,
},
Var(TypeVarTok),
LongName(VarWithModTok),
Name(VarTok),
}
#[derive(Parse, Unparse, Debug, Clone, PartialEq)]
pub struct TypeRecordInnerV1 {
pub fields: Vec<TypeRecordFieldV1>,
pub row_tail: Option<RowTailV1>,
}
#[derive(Parse, Unparse, Debug, Clone, PartialEq)]
pub struct TypeRecordFieldV1 {
pub name: VarTok,
pub colon: ColonTok,
pub ty: super::TyErasedV1,
pub comma: Option<CommaTok>,
}
#[derive(Parse, Unparse, Debug, Clone, PartialEq)]
pub struct MathElemCst {
pub base: MathBot,
pub scripts: Vec<MathScript>,
}
#[derive(Parse, Unparse, Debug, Clone, PartialEq)]
pub enum MathBot {
Cmd { name: AnyMathCmdTok, args: Vec<MathArg> },
Chars(MathCharTok),
Embed(VarInMathTok),
Sep(SepTok),
Group {
mgrp: MathGroup<()>,
#[group(self.mgrp)]
elems: Vec<super::MathErasedV1>,
},
}
#[derive(Parse, Unparse, Debug, Clone, PartialEq)]
pub enum MathScript {
Super { hat: SuperscriptTok, group: MathGroupArg },
Sub { under: SubscriptTok, group: MathGroupArg },
Primes(PrimesTok),
}
#[derive(Parse, Unparse, Debug, Clone, PartialEq)]
pub enum MathGroupArg {
Group {
mgrp: MathGroup<()>,
#[group(self.mgrp)]
elems: Vec<super::MathErasedV1>,
},
Bot(Box<MathBot>),
}
#[derive(Parse, Unparse, Debug, Clone, PartialEq)]
pub enum MathArg {
Math {
mgrp: MathGroup<()>,
#[group(self.mgrp)]
elems: Vec<super::MathErasedV1>,
},
Inline {
igrp: InlineGroup<()>,
#[group(self.igrp)]
elems: Vec<InlineElem>,
},
Block {
bgrp: BlockGroup<()>,
#[group(self.bgrp)]
elems: Vec<BlockElem>,
},
ParenEscape {
paren: ParenGroup<()>,
#[group(self.paren)]
inner: Box<ParenBody>,
},
ListEscape {
list: ListGroup<()>,
#[group(self.list)]
items: Vec<ListItem>,
},
RecordEscape {
rec: RecordGroup<()>,
#[group(self.rec)]
body: RecordBody,
},
}
#[derive(Parse, Unparse, Debug, Clone, PartialEq)]
pub enum ModChainV1 {
Long(LongUpperTok),
Single(CtorTok),
}
#[derive(Parse, Unparse, Debug, Clone, PartialEq)]
pub enum ModExpr {
Functor {
fun_kw: KwFun,
lp: LParenTok,
param: CtorTok,
colon: ColonTok,
dom: Box<SigExpr>,
rp: RParenTok,
arrow: ArrowTok,
body: Box<ModExpr>,
},
Coerce {
name: CtorTok,
coerce: CoerceTok,
sig_: Box<SigExpr>,
},
App { func: ModChainV1, arg: ModChainV1 },
Var(ModChainV1),
Struct {
struct_kw: KwStruct,
binds: Vec<super::StructBindV1>,
end_kw: KwEnd,
},
}
#[derive(Parse, Unparse, Debug, Clone, PartialEq)]
pub enum SigExpr {
Functor {
lp: LParenTok,
param: CtorTok,
colon: ColonTok,
dom: Box<SigExpr>,
rp: RParenTok,
arrow: ArrowTok,
cod: Box<SigExpr>,
},
WithType {
base: SigBotV1,
with_kw: KwWith,
path: Option<ModChainV1>,
type_kw: KwType,
binds: super::TypeBindsErasedV1,
},
Bot(SigBotV1),
}
#[derive(Parse, Unparse, Debug, Clone, PartialEq)]
pub enum SigBotV1 {
Path(LongUpperTok),
Var(CtorTok),
Sig {
sig_kw: KwSig,
decls: Vec<super::StructDeclV1>,
end_kw: KwEnd,
},
}
#[derive(Parse, Unparse, Debug, Clone, PartialEq)]
pub enum Decl {
Val {
kw: KwVal,
stage: Option<super::BindStageV1>,
name: super::BindName,
quant: Vec<TypeVarTok>,
colon: ColonTok,
ty: TypeExpr,
},
ValHorzCmd {
kw: KwVal,
cmd: HorzCmdTok,
quant: Vec<TypeVarTok>,
colon: ColonTok,
ty: TypeExpr,
},
ValVertCmd {
kw: KwVal,
cmd: VertCmdTok,
quant: Vec<TypeVarTok>,
colon: ColonTok,
ty: TypeExpr,
},
TypeOpaque {
kw: KwType,
name: VarTok,
cons: ConsTok,
kind: KindV1,
},
Type {
kw: KwType,
binds: super::TypeBindsErasedV1,
},
Module {
kw: KwModule,
name: CtorTok,
colon: ColonTok,
sig_: Box<SigExpr>,
},
Signature {
kw: KwSignature,
name: CtorTok,
eq: DefEqTok,
sig_: Box<SigExpr>,
},
Include { kw: KwInclude, sig_: Box<SigExpr> },
}
#[derive(Parse, Unparse, Debug, Clone, PartialEq)]
pub struct KindV1 {
pub first: VarTok,
pub rest: Vec<KindArrowV1>,
}
#[derive(Parse, Unparse, Debug, Clone, PartialEq)]
pub struct KindArrowV1 {
pub arrow: ArrowTok,
pub base: VarTok,
}
}
pub fn parse_file_v1(src: &str) -> Result<FileV1, crate::cst::ParseFileError> {
let atoms = crate::lexer::lex_with_version(src, crate::version::RustyfiVersion::V0_1)
.map_err(crate::cst::ParseFileError::from_lex)?;
let mut stream = crate::stream::AtomStream::new(atoms);
match <FileV1 as Parse<_>>::parse(&mut stream) {
Ok(file) => Ok(file),
Err(e) => Err(crate::parse_error::locate(src, &stream, &e)),
}
}