Date: 14 Apr 04 09:11:06 GMT
From: bill@macs.hw.ac.uk (Bill James Ellis)
Subject: [Stratego] Count newlines
Message-ID: <Pine.LNX.4.44.0404141001340.28969-100000@lxbill>
References: <20040209150349.24358.qmail@web41114.mail.yahoo.com>
MIME-Version: 1.0

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 (bill@macs.hw.ac.uk) (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
stratego@cs.uu.nl
https://mail.cs.uu.nl/mailman/listinfo/stratego


