hazelgrove / tylr

a tiny tile-based editor
https://tylr.fun
MIT License
284 stars 3 forks source link

kw expansion doesn't work if trying to Insert compound expression all at once #41

Open disconcision opened 2 weeks ago

disconcision commented 2 weeks ago

Trying to parse whole expressions from strings. simple infix sequences and parens seem to work, but nothing else.

If I try to do Edit.perform(Insert("let x "), Zipper.empty) I get "let >< x" (infix grout), and if I try Edit.perform(Insert("let x ="), Zipper.empty) it crashes with:

--- Stack.link/failed neq assert ---
14:53:46.395 +fs_fake.js:333 t = >_|_<
14:53:46.397 +fs_fake.js:333 sw = [(Tile
    (Pat,
     { rctx =
       [(T 'case') (NT Exp) (T '|') • (T '=>') (NT Exp) ((T '|') (NT Pat)
         (T '=>') (NT Exp))*];
14:53:46.397 +fs_fake.js:333        prec = 1; sort = Exp }))]
14:53:46.398 +fs_fake.js:333 c = {cursor: , obligs: [1] -> (Grout (Pat, (Conv, Conv)))
 , dirty: [0; 0] ->  
 [0; 2] ->  
 [2] ->  
14:53:46.399 +fs_fake.js:333  , degrouted: false | {{} "_" {}} <> {}}
14:53:46.399 +fs_fake.js:333 stack = { slope = []; bound = ROOT }

14:53:46.400 +fs_fake.js:333   (Failure "expected neq swing")

not totally sure this is actually supported... should i be dividing into tokens and feed it in iteratively?

dm0n3y commented 2 weeks ago

hmm that's unexpected. let's see if we can work around it for now. try calling Labeler.label on the string to get a list(Token.Unmolded.t), each of which will have a .text field to get the individual lexeme text to pass with the Insert action.

disconcision commented 2 weeks ago

It works! with some caveats. still can't parse expressions with nested expanding kw forms due to #42, eg:

parse("let f = fun z -> 9 in f(9)")

results in

Screenshot 2024-11-04 at 4 38 30 PM

i tried working around this by having multiple spaces in the parse string but it doesn't work

dm0n3y commented 2 weeks ago

cool. looking at #42 now.