Skip to content

Commit 0a971e3

Browse files
committed
front: describe display styles programmatically
1 parent 5989020 commit 0a971e3

File tree

2 files changed

+49
-20
lines changed

2 files changed

+49
-20
lines changed

src/wasm.rs

+40
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,46 @@ impl PredicateStyleJs {
184184
self.0.to_name().unwrap().to_string()
185185
}
186186

187+
pub fn doc(&self) -> String {
188+
let mut out = String::new();
189+
match self.0 {
190+
PredicateStyle::Expression => {
191+
todo!("explain expression style")
192+
}
193+
PredicateStyle::Sequent {
194+
ty: type_of_interest,
195+
show_reference_state,
196+
..
197+
} => {
198+
let _ = write!(&mut out, "Track the type ");
199+
match type_of_interest {
200+
TypeOfInterest::UserVisible => {
201+
let _ = write!(&mut out, "that the user observes");
202+
if show_reference_state {
203+
let _ = write!(&mut out, " and whether the outermost reference in the type is real or inherited");
204+
}
205+
}
206+
TypeOfInterest::InMemory => {
207+
let _ = write!(&mut out, "of the matched place");
208+
if show_reference_state {
209+
let _ = write!(&mut out, " and the current binding mode");
210+
}
211+
}
212+
}
213+
}
214+
}
215+
out
216+
}
217+
218+
pub fn display_generic_predicate(&self) -> String {
219+
let a = &Arenas::default();
220+
TypingPredicate {
221+
pat: &Pattern::ABSTRACT,
222+
expr: Expression::ABSTRACT.borrow(a, Mutability::Shared),
223+
}
224+
.display(self.0)
225+
}
226+
187227
pub fn explain_predicate(&self) -> String {
188228
let explanation = self.0.explain_predicate();
189229
let mut out = String::new();

web/src/components/Solver.jsx

+9-20
Original file line numberDiff line numberDiff line change
@@ -50,19 +50,6 @@ function InhRef() {
5050
return <span className="inherited-ref" title="inherited reference">&</span>
5151
}
5252

53-
const availableStyles = [
54-
{
55-
name: 'Sequent',
56-
display: <>inh, _ ⊢ p: <InhRef/>T</>,
57-
doc: "Track the type that the user observes and whether the outermost reference in the type is real or inherited"
58-
},
59-
{
60-
name: 'SequentBindingMode',
61-
display: <>ref, _ ⊢ p: T</>,
62-
doc: "Track the type of the matched place and the current binding mode"
63-
},
64-
];
65-
6653
export function Help({show, setShow, style}) {
6754
return <>
6855
<Offcanvas placement="end" scroll show={show} onHide={() => setShow(false)}>
@@ -108,6 +95,8 @@ export function Help({show, setShow, style}) {
10895
</>
10996
}
11097

98+
const availableStyles = ['Sequent', 'SequentBindingMode'];
99+
111100
export function MainNavBar({compare, setCompare, style, setStyle}) {
112101
const navigate = useNavigate()
113102
const [searchParams, setSearchParams] = useSearchParams();
@@ -124,14 +113,14 @@ export function MainNavBar({compare, setCompare, style, setStyle}) {
124113
const [helpShow, setHelpShow] = useState(false);
125114

126115
const currentStyle = style;
127-
const styles = availableStyles.map(style => {
128-
return <OverlayTrigger key={style.name} placement="bottom" overlay={<Tooltip>{style.doc}</Tooltip>}>
116+
const styles = availableStyles.map(style_name => {
117+
let style = PredicateStyleJs.from_name(style_name);
118+
return <OverlayTrigger key={style_name} placement="bottom" overlay={<Tooltip>{style.doc()}</Tooltip>}>
129119
<Button
130-
active={currentStyle.to_name() == style.name}
131-
onClick={() => setStyle(PredicateStyleJs.from_name(style.name))}
132-
>
133-
{style.display}
134-
</Button>
120+
active={currentStyle.to_name() == style_name}
121+
onClick={() => setStyle(style)}
122+
dangerouslySetInnerHTML={{__html: style.display_generic_predicate()}}
123+
></Button>
135124
</OverlayTrigger>
136125
});
137126

0 commit comments

Comments
 (0)