This page is no longer maintained — Please continue to the home page at www.scala-lang.org

Parser combinators: how to modify line numbering?

2 replies
Christian Szegedy
Joined: 2009-02-08,
User offline. Last seen 42 years 45 weeks ago.

I am writing a small parser for an intermediate language that also
allows for line-number directives like the # directives in
C/C++ (for reporting purposes).

Does anyone have an idea how to do that within the current
parser-combinator framework in scala?

What I want to achieve that the positioned(p) stores the modified
location instead of the original one. (Of course, the column
information will be bogus, anyways, but I want to have at least the
row right.)

Naftoli Gugenheim
Joined: 2008-12-17,
User offline. Last seen 42 years 45 weeks ago.
Re: Parser combinators: how to modify line numbering?
Why not record the real line numbers of the line number directives and store them in a map, and then whenever you need to display the line number look it up in the map?

On Mon, Mar 16, 2009 at 9:47 PM, Christian Szegedy <christian.szegedy@gmail.com> wrote:
I am writing a small parser for an intermediate language that also
allows for line-number directives like the #<number> directives in
C/C++ (for reporting purposes).

Does anyone have an idea how to do that within the current
parser-combinator framework in scala?

What I want to achieve that the positioned(p) stores the modified
location instead of the original one. (Of course, the column
information will be bogus, anyways, but I want to have at least the
row right.)

Christian Szegedy
Joined: 2009-02-08,
User offline. Last seen 42 years 45 weeks ago.
Re: Parser combinators: how to modify line numbering?

It's definitely a possibility, but then it would require me to count
my lines myself, I don't see any really straightforward way to do that
(I use newline character in different lexical rules). Maybe having a
lexer below the current one is the only reliable solution.

On 3/17/09, Naftoli Gugenheim wrote:
> Why not record the real line numbers of the line number directives and store
> them in a map, and then whenever you need to display the line number look it
> up in the map?
>
>
> On Mon, Mar 16, 2009 at 9:47 PM, Christian Szegedy
> wrote:
>
> > I am writing a small parser for an intermediate language that also
> > allows for line-number directives like the # directives in
> > C/C++ (for reporting purposes).
> >
> > Does anyone have an idea how to do that within the current
> > parser-combinator framework in scala?
> >
> > What I want to achieve that the positioned(p) stores the modified
> > location instead of the original one. (Of course, the column
> > information will be bogus, anyways, but I want to have at least the
> > row right.)
> >
>
>

Copyright © 2012 École Polytechnique Fédérale de Lausanne (EPFL), Lausanne, Switzerland