Misuse of terminology in `parser-tools/lex`?

71 views
Skip to first unread message

Matthew Butterick

unread,
Dec 8, 2016, 1:44:56 PM12/8/16
to Racket Developers
Forgive the possibly noobish question. 

Racket's name for a precise place in a source file is called a source location [1] — sometimes abbreviated `srcloc` — and has four possible fields: line, column, position, and span.

The `parser-tools/lex` library also dabbles in source locations, but IIUC calls them "positions" rather than "locations" [2]. Moreover, what is known as the "position" field in a Racket source location is called an "offset" in `parser-tools/lex`. [also 2]

So is it fair to say that `parser-tools/lex` is using names that are inconsistent with Racket (and, in the case of "position", contradictory)?



Jens Axel Søgaard

unread,
Dec 8, 2016, 2:52:08 PM12/8/16
to Matthew Butterick, Racket Developers
The names are consistent with the position tracking for ports:

--
You received this message because you are subscribed to the Google Groups "Racket Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to racket-dev+...@googlegroups.com.
To post to this group, send email to racke...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/racket-dev/B26F0406-4DA6-42F9-83DE-9C2D4BE9C90A%40mbtype.com.
For more options, visit https://groups.google.com/d/optout.

Matthew Butterick

unread,
Dec 8, 2016, 4:21:53 PM12/8/16
to Racket Developers, m...@mbtype.com

On Thursday, December 8, 2016 at 11:52:08 AM UTC-8, Jens Axel Søgaard wrote:
The names are consistent with the position tracking for ports:

 
Now I'm more confused. This part of the docs talks about a "location" as consisting of three values: line, column, and position. See, e.g. `port-next-location`. [1]

This, to me, seems consistent with the existing Racket lingo of source locations [2], where line, column, and position are fields within a location.



Robby Findler

unread,
Dec 8, 2016, 5:02:58 PM12/8/16
to Matthew Butterick, Racket Developers
It may be that at the time the parser-tools were developed, we were
not yet using a struct for srclocs. I think today we would not do what
the parser tools are doing.

Robby

Matthew Butterick

unread,
Dec 9, 2016, 1:23:36 PM12/9/16
to Racket Developers, m...@mbtype.com
1) Would you consider a PR (from me) for `parser-tools` that updates the names to be consistent (while preserving the older ones of course)? Or is there too much water under the bridge to bother with?

2) Relatedly: is the field ordering used by the `srcloc` struct — line / column / position / span — recommended for other interfaces to follow, or considered arbitrary?

Robby Findler

unread,
Dec 9, 2016, 1:25:06 PM12/9/16
to Matthew Butterick, Racket Developers
On Fri, Dec 9, 2016 at 12:23 PM, Matthew Butterick <m...@mbtype.com> wrote:
> 1) Would you consider a PR (from me) for `parser-tools` that updates the
> names to be consistent (while preserving the older ones of course)? Or is
> there too much water under the bridge to bother with?

Sure, cleaning up stuff like that sounds quite welcome. And the parser
tools could use a lot of clean up, I believe. They are kind of strange
and klunky compared to modern racket.

> 2) Relatedly: is the field ordering used by the `srcloc` struct — line /
> column / position / span — recommended for other interfaces to follow, or
> considered arbitrary?

I would probably say "both".

Robby

Alexis King

unread,
Dec 9, 2016, 4:01:40 PM12/9/16
to Matthew Butterick, Racket Developers
> On Dec 9, 2016, at 10:23, Matthew Butterick <m...@mbtype.com> wrote:
>
> 2) Relatedly: is the field ordering used by the `srcloc` struct — line
> / column / position / span — recommended for other interfaces to
> follow, or considered arbitrary?

IMO, I would say “just use the srcloc struct” if you need srclocs, don’t
mess around with functions that accept 5 additional arguments. That’s
what I did in megaparsack, and it produces a much cleaner interface,
especially since they’re much easier to functionally update if you want
that sort of thing.

Matthew Butterick

unread,
Jan 26, 2017, 10:07:42 PM1/26/17
to Racket Developers, m...@mbtype.com


On Friday, December 9, 2016 at 10:25:06 AM UTC-8, robby wrote:

Sure, cleaning up stuff like that sounds quite welcome. And the parser 
tools could use a lot of clean up, I believe. They are kind of strange 
and klunky compared to modern racket. 

What expectation of backward compatibility is baked into `parser-tools`? How much modernization is acceptable?

IOW, suppose I've added a `lexer-srcloc` variant of `lexer-src-pos` that uses srcloc structs rather than the "strange and klunky" structures currently used by `parser-tools`. But that creates a dependency on the `srcloc` structure in modern Racket, which might annoy the MzScheme v372 community.
 
Reply all
Reply to author
Forward
0 new messages