# Issue with overlapping tokens

**URL:** <https://discuss.codemirror.net/t/issue-with-overlapping-tokens/5117>\
**Category:** Lezer\
**Created:** [October 10, 2022, 4:20pm UTC](https://discuss.codemirror.net/t/issue-with-overlapping-tokens/5117 "2022-10-10T16:20:16Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![SirBogman](https://discuss.codemirror.net/letter_avatar_proxy/v4/letter/s/e9a140/32.png) [@SirBogman](https://discuss.codemirror.net/u/SirBogman)\
**Post date:** [October 10, 2022, 4:20pm UTC](https://discuss.codemirror.net/t/issue-with-overlapping-tokens/5117/1 "2022-10-10T16:20:16Z")

</div>

I am having trouble figuring out how to deal with overlapping tokens. Here is an example of the behavior I want:

```auto
# 1. Two numbers
100 99 ==> Program(Number, Number)

# 2. Two numbers, one negative
100 -99 ==> Program(Number, Number)

# 3. Verb usage of `-`, with space
100- 99 ==> Program(Number, Verb, Number)

# 4. Verb usage of `-`, without space
100-99 ==> Program(Number, Verb, Number)

```

And here is my grammar, simplified for this example:

```auto
@top Program { Number space Number | Number space? Verb space? Number }
@tokens {
  @precedence { Number, Verb }
  Verb { "-" }
  Number { "-"? @digit+ }
  space { " "+ }
}

```

The fourth test case is failing.

Without the precedence, the error is: `Overlapping tokens Number and Verb used in same context (example: "-" vs "-0")`.

How can I get it to use the surrounding context to help? If `-` directly follows a digit (no space between them), then it has to be part of a Verb and not a Number. Otherwise, it’s part of a Number.

---

<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:** [October 10, 2022, 7:01pm UTC](https://discuss.codemirror.net/t/issue-with-overlapping-tokens/5117/2 "2022-10-10T19:01:19Z")

</div>

If your language is whitespace-sensitive, you either have to explicitly include the space in the grammar (instead of using `@skip`), _or_ you have to use external tokenizers that look at surrounding text and make decisions based on that. Lezer’s built-in tokens are strictly regular, so they don’t support lookahead/lookbehind.

---

<div class="post-metadata">

**Author:** ![SirBogman](https://discuss.codemirror.net/letter_avatar_proxy/v4/letter/s/e9a140/32.png) [@SirBogman](https://discuss.codemirror.net/u/SirBogman)\
**Post date:** [October 10, 2022, 7:36pm UTC](https://discuss.codemirror.net/t/issue-with-overlapping-tokens/5117/3 "2022-10-10T19:36:00Z")

</div>

Ok, thanks. I don’t think I was using @skip in my example, unless there is some kind of default skip.

---

<div class="post-metadata">

**Author:** ![SirBogman](https://discuss.codemirror.net/letter_avatar_proxy/v4/letter/s/e9a140/32.png) [@SirBogman](https://discuss.codemirror.net/u/SirBogman)\
**Post date:** [October 10, 2022, 11:09pm UTC](https://discuss.codemirror.net/t/issue-with-overlapping-tokens/5117/4 "2022-10-10T23:09:33Z")

</div>

The external tokenizer worked will for this too. Thanks.
