# Problems about parser-tools/lex

**URL:** https://racket.discourse.group/t/problems-about-parser-tools-lex/3001
**Category:** General
**Tags:** question
**Created:** [July 4, 2024, 4:34am UTC](https://racket.discourse.group/t/problems-about-parser-tools-lex/3001 "2024-07-04T04:34:32Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![qnc](https://avatars.discourse-cdn.com/v4/letter/q/e5b9ba/32.png) [@qnc](https://racket.discourse.group/u/qnc)
#### Post date: [July 4, 2024, 4:34am UTC](https://racket.discourse.group/t/problems-about-parser-tools-lex/3001/1 "2024-07-04T04:34:32Z")

</div>

I've been writing a parser for a compiler and wish to trace the generated syntax objects' source locations. The documentation told me to simply replace `lexer` with `lexer-src-pos`. Doing so does make the procedure produce `position-token`, but all the `line` and `col` fields of `position`s are set to `#f`. I've also tried an example distributed with `parser-tools` package: `calc`. The results are the same:

```scheme
<pkgs>/parser-tools-lib/parser-tools/examples/calc> (calcl (open-input-string "1"))
(position-token (token 'NUM 1) (position 1 #f #f) (position 2 #f #f))
<pkgs>/parser-tools-lib/parser-tools/examples/calc>

```

What should I do to let it count lines automatically?

---

<div class="post-metadata">

### Author: ![sorawee](https://avatars.discourse-cdn.com/v4/letter/s/ea5d25/32.png) [@sorawee](https://racket.discourse.group/u/sorawee)
#### Post date: [July 4, 2024, 4:46am UTC](https://racket.discourse.group/t/problems-about-parser-tools-lex/3001/2 "2024-07-04T04:46:21Z")

</div>

It sounds like your port doesn’t have line/column counting. Have you tried using [`port-count-lines!`](https://docs.racket-lang.org/reference/linecol.html#%28def._%28%28quote._~23~25kernel%29._port-count-lines%21%29%29) on it?

Following is from the documentation of [`lexer`](https://docs.racket-lang.org/parser-tools/Lexers.html):

> Since the lexer gets its source information from the port, use [port-count-lines!](https://docs.racket-lang.org/reference/linecol.html#%28def._%28%28quote._~23~25kernel%29._port-count-lines%21%29%29) to enable the tracking of line and column information. Otherwise, the line and column information will return #f.

---

<div class="post-metadata">

### Author: ![qnc](https://avatars.discourse-cdn.com/v4/letter/q/e5b9ba/32.png) [@qnc](https://racket.discourse.group/u/qnc)
#### Post date: [July 4, 2024, 5:02am UTC](https://racket.discourse.group/t/problems-about-parser-tools-lex/3001/3 "2024-07-04T05:02:17Z")

</div>

Yes, it was the problem. Thanks for your timely reply.
