Class DSource

Inherits from:
Object
Declared in:
DSource.h

Class Hierarchy

    Object
      |
      +---DSource

Class Description

The DSource class is used by the class DLexer and the class DTokenizer for storing the relevant info of the source for the lexer c.q. tokenizer. By storing the objects in a list, a stack of sources can be implemented.

Example:
#include <stdio.h>
#include <string.h>
#include "ofc/DSource.h"
#include "ofc/DFile.h"

int main(int argc, char *argv[])
{
  DFile   *file = [DFile new];
  DSource *srce = [DSource new];

  char     name[] = "example.xml";

  if ([file open :name :"r"])
  {
    if ([srce set :file :name])
    {
      do                               // Do for the whole file
      {
        while (![srce isLineScanned])  // Repeat during scanning of the line
        {
          int length;

          printf("Read line:%s\n", [srce line]); // Print the remaining line

          length = strlen([srce line]);

          if (length > 10)             // Example: scan only 10 chars per time
            length = 10;

          [srce scanned :length];
        }
      }
      while ([srce nextLine]);
    }
    else
      printf("Could start sourcing \"%s\".\n", name);

    [file close];
  }
  else
    printf("Could not open \"%s\":%d.\n", name, [file error]);

  [srce free];                         // Cleanup
  [file free];

  return 0;
}
Last modified:
16-Aug-2008 (DSource.h)

Instance Variables

private id <DTextReadable> _source
the reference to the source (file)
private DText *_name
the name of the source (file)
private DText *_line
the read line
private int _lineNr
the line number
private int _columnNr
the column number
private int _scanned
the scanned part of _line

Method Index


generated 06-Sep-2008 by ObjcDoc 3.0.0