org.quasiliteral.syntax
Class Indenter

java.lang.Object
  |
  +--org.quasiliteral.syntax.Indenter

public class Indenter
extends Object

Untamed: Keeps track of indentation info for BaseLexer's subclasses and clients.

Author:
Mark S. Miller, Terry Stanley

Field Summary
private  char[] myCloserStack
          The closers -- close bracketing characters that would close the currently unclosed open brackets
private  int[] myIndentStack
          The indentation level associated with each unclosed open bracket
private  int myNest
          How many block-levels deep am I?
private  boolean[] myNestStack
          Was this open bracket also a nesting?
private  Twine[] myOpennerStack
          The openners are Twine for reporting located errors at close time
private  int myTOS
          My top-of-stack is the same as the number of unclosed open bracketing characters.
 
Constructor Summary
Indenter()
          Enabled:
 
Method Summary
 int getCloseIndent()
          Enabled: If the character that would close the most recently open bracket (getCloser()) were typed, where should it be indented?
 char getCloser()
          Enabled: Which character would close the most recent open bracket?
 int getIndent()
          Enabled: How indented should a vanilla new line be in this context?
private  Object grow(Object array)
           
 void nest(Twine openner, char closerChar)
          Enabled: Push a nester
 void pop(char closerChar, Twine closer)
          Enabled: Process a closing bracket by popping the stacks.
 void popIf(char closerChar)
          Enabled: If the tos is closerChar, then process a closing bracket by popping the stacks.
 void push(Twine openner, char closerChar, int indent)
          Enabled: Push a non-nester
private  void push(Twine openner, char closerChar, int indent, boolean isNest)
          Internal push
 void requireEmpty(String msg)
          Enabled:
 String toString()
          Suppressed: Show closing stack
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

myNest

private int myNest
How many block-levels deep am I?

Each open-bracketing character at the end of a line introduces a new nesting level. Each nesting level counts for four spaces.


myTOS

private int myTOS
My top-of-stack is the same as the number of unclosed open bracketing characters.

The stack keeps track of unclosed open brackets, and what indent should be assigned to new lines within that bracket (should it be the most recent -- the top of stack).


myOpennerStack

private Twine[] myOpennerStack
The openners are Twine for reporting located errors at close time


myCloserStack

private char[] myCloserStack
The closers -- close bracketing characters that would close the currently unclosed open brackets

We start the stack off with an indent level of zero and a dummy closer character.


myIndentStack

private int[] myIndentStack
The indentation level associated with each unclosed open bracket


myNestStack

private boolean[] myNestStack
Was this open bracket also a nesting?

I.e., was the openner the last character on its line? If so, then its popping should also decrement myNest.

Constructor Detail

Indenter

public Indenter()
Enabled:

Method Detail

grow

private Object grow(Object array)

push

private void push(Twine openner,
                  char closerChar,
                  int indent,
                  boolean isNest)
Internal push


nest

public void nest(Twine openner,
                 char closerChar)
Enabled: Push a nester


push

public void push(Twine openner,
                 char closerChar,
                 int indent)
Enabled: Push a non-nester


pop

public void pop(char closerChar,
                Twine closer)
Enabled: Process a closing bracket by popping the stacks.

If the opening was also a nesting, this decrements the nest level.

Parameters:
closerChar - As an error check, 'closerChar' must be the closing bracket character needed to close the most recent unclosed bracket.
closer - Used by some syntax errors to report where the erronous closing text occurs.

requireEmpty

public void requireEmpty(String msg)
Enabled:


popIf

public void popIf(char closerChar)
Enabled: If the tos is closerChar, then process a closing bracket by popping the stacks.

If the opening was also a nesting, this decrements the nest level.

Parameters:
closerChar - Checks whether 'closerChar' is the closing bracket character needed to close the most recent unclosed bracket.

getIndent

public int getIndent()
Enabled: How indented should a vanilla new line be in this context?

A vanilla new line is one that doesn't begin with a close bracketing character (for these, use pop()'s return value), and one that's not continuing a previous line by virtue of a binary operator or a backslash


getCloser

public char getCloser()
Enabled: Which character would close the most recent open bracket?


getCloseIndent

public int getCloseIndent()
Enabled: If the character that would close the most recently open bracket (getCloser()) were typed, where should it be indented?


toString

public String toString()
Suppressed: Show closing stack

Overrides:
toString in class Object
Returns:
a string representation of the object.


comments?