# Unable to use parser-tools/lex::lexer with in-port

**URL:** <https://racket.discourse.group/t/unable-to-use-parser-tools-lex-lexer-with-in-port/1982>\
**Category:** Questions & Answers\
**Created:** [June 8, 2023, 1:45pm UTC](https://racket.discourse.group/t/unable-to-use-parser-tools-lex-lexer-with-in-port/1982 "2023-06-08T13:45:02Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![rscho](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/rscho/32/726_2.png) [@rscho](https://racket.discourse.group/u/rscho)\
**Post date:** [June 8, 2023, 1:45pm UTC](https://racket.discourse.group/t/unable-to-use-parser-tools-lex-lexer-with-in-port/1982/1 "2023-06-08T13:45:02Z")

</div>

Hi,

I may be missing something, but I think this fails when it should yield a list. This expression makes racket enter an infinite loop, due to an apparent conflict between `in-port` and `lexer`:

```scheme
(require parser-tools/lex)
(for/list ([t (in-port
               (lexer [#\1 'one] [(eof) 'end])
               (open-input-string "1"))])
 t)

```

What do you think?

Thanks!

---

<div class="post-metadata">

**Author:** ![samth](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/samth/32/3_2.png) [@samth](https://racket.discourse.group/u/samth)\
**Post date:** [June 8, 2023, 4:04pm UTC](https://racket.discourse.group/t/unable-to-use-parser-tools-lex-lexer-with-in-port/1982/2 "2023-06-08T16:04:16Z")

</div>

`in-port` never passes `eof` to the function. It's not obvious to me what you want to do, but `in-producer` might be what you're looking for.

---

<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:** [June 8, 2023, 4:37pm UTC](https://racket.discourse.group/t/unable-to-use-parser-tools-lex-lexer-with-in-port/1982/3 "2023-06-08T16:37:39Z")

</div>

This works for me:

```scheme
(require parser-tools/lex)
(for/list ([t (in-port
               (lexer [#\1 'one] [(eof) eof])
               (open-input-string "1"))])
  t)

```

The doc of in-port states that it stops when it encounters eof, so the solution is to produce an eof.

---

<div class="post-metadata">

**Author:** ![rscho](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/rscho/32/726_2.png) [@rscho](https://racket.discourse.group/u/rscho)\
**Post date:** [June 8, 2023, 11:42pm UTC](https://racket.discourse.group/t/unable-to-use-parser-tools-lex-lexer-with-in-port/1982/4 "2023-06-08T23:42:31Z")

</div>

Thank you for this explanation. I didn't understand the necessity to pass `eof`. I am folding over a sequence of tokens and I had trouble doing that with the `parser-tools/yacc` parser, so I cooked up something of my own.
