Subject: [Stratego] Count newlines
From: [email-masked] (Bill James Ellis)
Date: 14 Apr 04 09:11:06 GMT

Hi,

I want to be able to relate parts of my
parsed structure (tree) to the original
file.

I would like to count newlines (currently
just skipped as LAYOUT), and then store
the value of this counter when important
bits of the grammar are parsed.

My Layout.sdf looks like:
--------------------------------------------------
module Layout
    exports
        lexical syntax
            [\ \n] -> LAYOUT
        context-free restrictions
        LAYOUT? -/- [\ \n]
--------------------------------------------------

And my grammar looks like:
--------------------------------------------------
module Code
    imports
        Syntax
        Layout
    exports
        sorts GD-compilation-unit
        context-free syntax

...

GD-store-rep
GT-semicolon
GD-store
 ->
GD-store-rep {cons("I-store-rep1")}

GD-store
 ->
GD-store-rep {cons("I-store-rep2")}

GD-store-list
GT-arrow
GD-annotation-expression
 ->
GD-store {cons("I-store1")}

...
--------------------------------------------------

Ie. i use the cons facility to build the terms
that my Stratego code transforms.

Is there a way to count the newlines that are seen
by LAYOUT, and store this count in some global
variable G. Then, for selected parts of the grammar,
add G to the cons terms doing something like:
{cons("I-store1", G)}?

Any help appreciated,

Bill J Ellis
----------------------------------------------------------------------------
Bill J. Ellis ([email-masked]) (http://www.macs.hw.ac.uk/~bill) 
Research Associate / Phd Student             |     _\(_
School of Mathematical and Computer Sciences |     = "_)
Heriot-Watt University                       |    _/~)
Riccarton, Edinburgh, Scotland EH14 4AS      |~~~~\/""~~~~~~~~

_______________________________________________
stratego mailing list
[email-masked]
https://mail.cs.uu.nl/mailman/listinfo/stratego