[Oberon] Re: N-O Scanner structure confusing ?

thoken at gmail.com thoken at gmail.com
Sun Feb 4 19:05:59 MET 2007


On 2 Feb 2007, Chris Glur <easlab at absamail.co.za> wrote:
> On 1 Feb 2007, Chris Glur <easlab at absamail.co.za> wrote:
> > > Lets examine how we could possibly process text after the very versatile
> > > scanner has found a searched-for token.
> > > ...
>  Thomas wrote:
> > Texts.Scan is designed for scanning command parameters.
> > It's also used as you mention for OberonErrors.Text
> > which is formatted to allow with ease Texts.Read following Texts.Scan.
> > These texts have no delimiters between tokens but canonical ones like
> > space, tab, cr
> > and arbitrary single characters are escaped by "\".
> > Some other texts need workarounds or their own scanners.
> >
> > hoping that could be of some help,
>
> It helps to confirm that I'm increasingly having difficulties to explain.

[My knowledge of both Oberon and English isn't good either, I'm sorry]
Getting some idea of the class of text structure you're about to scan
would be fine, also lines of code that don't do what you suppose
they should do.

> The Scanner is well designed for any Algol60-family-lang compiler.
> Ie. where the tokens are demarcated by white-chars.
> Apparently python has syntactic-info in the text-indentations ?
> Scanning command parameters is just a bonus.

Not sure, but I've only looked at how
- Texts.Scanner and its procedures are introduced in "Project Oberon"
- in the compiler that comes with v4-2.3 for Windows Texts.Scanner
is used: for reading error messages and not, at least not
literally, for reading Oberon code.

> Here's a simple job which I can't acheive -- directly yet.
> 1. set the caret
> 2. scan from the caret until the token "END"
> 3. reset the caret after the found token.
>
> The problem is that I don't know how to get the char-position
> where the token was found, other than by an absurd method of
> counting the <CRs> which the scanner saw and then using the
> reader to read the whole text-stretch which the scanner has
> already proccessed. Besides, the scanner has obviously used
> the reader to do the job.

I assumed a special kind of text forcing to have this re-read done, but
the problem seems to be either more basic or related to some special
conditions like other odd statements in your lines of code or specific
to the Oberon version somehow - well, all poor guessings.

In case it's more basic, have you tried something like

Texts.Scan(S);
IF (S.class = Texts.Name) & (S.s = "END") THEN
 TextFrames.SetCaret(F, Texts.Pos(S));

Some longer fraction of Version4 code, leaving out full
preconditioning related to the frame:

PROCEDURE Do*; (* Test.Do *)
VAR F: TextFrames.Frame; S: Texts.Scanner;
BEGIN
 F := Oberon.FocusViewer.dsc.next(TextFrames.Frame);
 IF F.hasCar THEN
  Texts.OpenScanner(S, F.text, F.carloc.pos); Texts.Scan(S);
  WHILE ~S.eot & ((S.class # Texts.Name) OR (S.s # "END")) DO
   Texts.Scan(S)
  END;(***)
  IF ~S.eot THEN
   TextFrames.SetCaret(F, Texts.Pos(S))
  END
 END
END Do;

In a frame viewing all lines of this procedure at once
place the caret within these lines in front of the first "END"
which is of class Texts.Name (before "(***)"), invoke the
"Test.Do" command, the caret should show up
just to the right of the semicolon that follows this "END".
Invoke the command again and the caret jumps to a position
behind the next END.

regards, Thomas


More information about the Oberon mailing list