# no backtracking after some convincing point

**URL:** https://discuss.codemirror.net/t/no-backtracking-after-some-convincing-point/7357
**Category:** Lezer
**Created:** [November 2, 2023, 5:08am UTC](https://discuss.codemirror.net/t/no-backtracking-after-some-convincing-point/7357 "2023-11-02T05:08:39Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![st3](https://discuss.codemirror.net/user_avatar/discuss.codemirror.net/st3/32/3877_2.png) [@st3](https://discuss.codemirror.net/u/st3)
#### Post date: [November 2, 2023, 5:08am UTC](https://discuss.codemirror.net/t/no-backtracking-after-some-convincing-point/7357/1 "2023-11-02T05:08:39Z")

</div>

wonderful.  
I am just setting out to parse what I have been compiling with regexes ([here](https://github.com/stylehouse/stylehouse/blob/8cd1857d4667ab066182eb171d6d715452eee9e0/serve.pl#L553) and [here](https://github.com/stylehouse/letz/blob/27986fa02ba14b5634a33cae21e8c7ee1aed5e2a/src/lib/lang/stholite_compiler.js#L224)) until now.  
It’s a simple javascript with extra stuff, like Sunpit and io (not that io)

IOing is like xpath, it creates and interacts with structure.

Sunpit is like a heading.  
It may contain words and|or start with a number:

```auto
S 3 innards
    ...code

```

It may contain an IO expression:

```auto
S o yeses/because/blon_itn
    ...code

```

In which case I want that to be IOing, though Title can consume anything on a line because:

```auto
    nonnl { ![\n] }

```

If not given the choice (removing SunpitHead from Sunpit) it will match IOing fine.

My question is… How can it be convinced IOing is the way to go when it is up to "S o ", so I can get some kind of error inside an IOing syntax node, etc

Not sure if this is ambiguity or precedence, as the lezer guide mentions. Ignore the @dynamicPrecedence which does nothing.

Something like “(\*COMMIT)” from perldoc perlre, which “when backtracked into on failure it causes the match to fail outright”.

```auto

@tokens {
    IOness { "i" | "o" }
    Sunpitness { "S" }
    Title { nonnl+ }
    Name { (@asciiLetter | "_")+ (@asciiLetter | "_" | @digit)* }
    Number { @digit+ }
    nonnl { ![\n] }
    nl { "\n" }
    Sigil { "@" | "#" }
    space { @whitespace }
    @precedence {Number, Title, Sunpitness, IOness, SunpitHead, Name}
    @precedence {nl, space}
}

@top Program { Line* }
Line { inline nl }

inline { Comment | expression | space* }

Comment { "#" nonnl+ }

expression { Name | Number | IOing | Sunpit }

IOing[@dynamicPrecedence=10] { IOness ' ' IOpath }

IOpath { Leg ("/" Leg)* }
Leg { Sigil? Name }

Sunpit { Sunpitness " " (IOing | SunpitHead) }
SunpitHead { Number | Number Title | Title }

```

I’m not too confident in my abilities here yet.  
My new-design-for-software system [has lately been converting syntax into cytoscape](https://github.com/stylehouse/letz/blob/94b0c722c8312ef8993214a4cff10111e5c824c2/src/lib/Le.ts#L144).  
Seems like there is some serious art to make there, eg being able to follow names off into other piles of code, as you do with code discovery whenever you forget how things work etc.

Thanks for making open source software. Here’s a picture of the above.

 ![lezer choosing Title over IOing](https://discuss.codemirror.net/uploads/default/original/2X/6/6e030aac09c76ffde2e7fa499f7deee8b1bc24a0.jpeg)

---

<div class="post-metadata">

### Author: ![marijn](https://discuss.codemirror.net/user_avatar/discuss.codemirror.net/marijn/32/136_2.png) [@marijn](https://discuss.codemirror.net/u/marijn)
#### Post date: [November 2, 2023, 3:08pm UTC](https://discuss.codemirror.net/t/no-backtracking-after-some-convincing-point/7357/2 "2023-11-02T15:08:12Z")

</div>

Lezer is not a backtracking parser. I must say I don’t understand your use case well enough to say anything concrete, but if you have syntax where two things match, and you’re using GLR parsing to accept both of them, dynamic precedence is indeed how you’d disambiguate this. But since your grammar contains to `~` GLR markers or `@extend` tokens, that dynamic precedence will do nothing.
