mirror of
https://github.com/roc-lang/roc.git
synced 2025-10-01 07:41:12 +00:00
Generate schema for checkmate
This commit is contained in:
parent
f78919cd2e
commit
358681a464
9 changed files with 1022 additions and 57 deletions
|
@ -1,9 +1,7 @@
|
|||
use roc_checkmate_schema::{Event, VariableEvent};
|
||||
use roc_types::subs as s;
|
||||
|
||||
use crate::{
|
||||
convert::AsSchema,
|
||||
schema::{Event, VariableEvent},
|
||||
};
|
||||
use crate::convert::AsSchema;
|
||||
|
||||
pub struct Collector {
|
||||
events: Event,
|
||||
|
@ -125,50 +123,3 @@ impl Collector {
|
|||
event
|
||||
}
|
||||
}
|
||||
|
||||
impl From<VariableEvent> for Event {
|
||||
fn from(event: VariableEvent) -> Event {
|
||||
Event::VariableEvent(event)
|
||||
}
|
||||
}
|
||||
|
||||
impl Event {
|
||||
fn append(&mut self, event: Event) -> usize {
|
||||
let list = self.subevents_mut().unwrap();
|
||||
let index = list.len();
|
||||
list.push(event);
|
||||
index
|
||||
}
|
||||
|
||||
fn appendable(&self) -> bool {
|
||||
self.subevents().is_some()
|
||||
}
|
||||
|
||||
fn index(&mut self, index: usize) -> &mut Event {
|
||||
&mut self.subevents_mut().unwrap()[index]
|
||||
}
|
||||
}
|
||||
|
||||
macro_rules! impl_subevents {
|
||||
($($pat:pat => $body:expr,)*) => {
|
||||
impl Event {
|
||||
fn subevents(&self) -> Option<&Vec<Event>> {
|
||||
match self {$(
|
||||
$pat => $body,
|
||||
)*}
|
||||
}
|
||||
|
||||
fn subevents_mut(&mut self) -> Option<&mut Vec<Event>> {
|
||||
match self {$(
|
||||
$pat => $body,
|
||||
)*}
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
impl_subevents! {
|
||||
Event::Top(events) => Some(events),
|
||||
Event::Unification { subevents, .. } => Some(subevents),
|
||||
Event::VariableEvent(_) => None,
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue