org.sc3d.apt.sss.v3
Class Indentation

java.lang.Object
  extended by org.sc3d.apt.sss.v3.Indentation

public class Indentation
extends java.lang.Object

Represents an indentation analysis of a Sentence.


Field Summary
 int numLines
          The number of lines in 'sentence' to which the indentation rules apply.
 Sentence sentence
          The Sentence of which this is the indentation analysis.
 
Constructor Summary
Indentation(Lex lex)
          Constructs an Indentation analysis of 'lex.sentence', and annotates 'lex.sentence' with error messages if the indentation rules are not obeyed.
 
Method Summary
 void addIndentationError(java.lang.String message, int line)
          Attaches an error message to 'sentence' about the indentation at the beginning of line 'line'.
 int getLineDepth(int line)
          Returns the nesting depth of a line.
 int getLineIndentation(int line)
          Returns the indentation of a line.
 int getLineStart(int line)
          Returns the index into 'sentence' of the first character of a line.
static void main(java.lang.String[] args)
          Takes one argument: a filename.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

sentence

public final Sentence sentence
The Sentence of which this is the indentation analysis.


numLines

public final int numLines
The number of lines in 'sentence' to which the indentation rules apply. Lines consisting entirely of white-space don't count. Lines which start inside a comment or string literal don't count.

Constructor Detail

Indentation

public Indentation(Lex lex)
Constructs an Indentation analysis of 'lex.sentence', and annotates 'lex.sentence' with error messages if the indentation rules are not obeyed.

Method Detail

getLineStart

public int getLineStart(int line)
Returns the index into 'sentence' of the first character of a line.

Parameters:
line - the line number. Lines are numbered from '0' to 'numLines-1'. This numbering differs from that used in error messages, which is chosen to match the behaviour of text editors.
Returns:
the index of the first character of the specified line.

getLineIndentation

public int getLineIndentation(int line)
Returns the indentation of a line. The indentation is represented as the horizontal position of the text cursor after printing the initial white-space characters of the line using the normal unix rules. To be specific, ' ' moves the cursor one place, '\t' moves it at least one place to the next multiple of eight, and '\r' returns the cursor to the beginning of the line.

Parameters:
line - the line number. Lines are numbered from '0' to 'numLines-1'.
Returns:
the number of spaces equivalent to the indentation.

getLineDepth

public int getLineDepth(int line)
Returns the nesting depth of a line. According to the SSS specification, the nesting depth is defined to be the number of brackets or braces that completely enclose the line, including the new-line characters before and after it, if any.

This method actually uses a different definition which coincides with the proper one when the brackets match correctly. The depth of a line is the smallest depth of any of the characters on the line. The depth of a character is the number of open brackets, open square brackets and open braces before it minus the number of close brackets, close square brackets and close braces before it.

Parameters:
line - the line number, from '0' to 'numLines-1'.
Returns:
the nesting depth.

addIndentationError

public void addIndentationError(java.lang.String message,
                                int line)
Attaches an error message to 'sentence' about the indentation at the beginning of line 'line'. Use this method only for errors about indentation.


main

public static void main(java.lang.String[] args)
                 throws java.io.IOException
Takes one argument: a filename.

Throws:
java.io.IOException