net.sf.latexdraw.parsers
Class CodeParser

java.lang.Object
  extended by net.sf.latexdraw.parsers.CodeParser
All Implemented Interfaces:
Parser
Direct Known Subclasses:
AbstractCSSParser, AbstractSVGParser

public abstract class CodeParser
extends java.lang.Object
implements Parser

Defines an abstract parser that parses code.

This file is part of LaTeXDraw.
Copyright (c) 2005-2012 Arnaud BLOUIN

LaTeXDraw is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

LaTeXDraw is distributed without any warranty; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

11/21/08

Version:
3.0
Author:
Arnaud BLOUIN

Nested Class Summary
private static class CodeParser.Code
          Defines a core level of the code parser that can be share with others code parser.
 
Field Summary
protected  CodeParser.Code codeCore
          The core level of the parser that contains the code to parse,...
static int EOC
          The token for the end of the code.
 
Constructor Summary
CodeParser(java.lang.String code)
          Creates and initialises the code parser.
 
Method Summary
 int getChar()
           
 int getCharAt(int pos)
          The character at the given position.
 java.lang.String getCode()
           
 CodeParser.Code getCodeCore()
           
 int getLinePosition()
           
 int getPosition()
           
 void incLinePosition()
          Increments the line position.
 void initialise()
          Reinitialises the parser.
abstract  boolean isComment()
           
 boolean isEOC()
           
 boolean isEOL()
           
abstract  boolean isWSP()
           
 int nextChar()
          Reads the next char and returns it.
 void setCode(java.lang.String code)
           
 void setCodeCore(CodeParser.Code codeCore)
           
 void setLinePosition(int linePosition)
           
 void setPosition(int position)
           
abstract  java.lang.String skipComment()
          Skips the comment.
abstract  void skipWSP()
          Skips the useless characters.
 void skipWSPComments()
          Skips both comments and ignorable characters.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface net.sf.latexdraw.parsers.Parser
parse
 

Field Detail

EOC

public static final int EOC
The token for the end of the code.

See Also:
Constant Field Values

codeCore

protected CodeParser.Code codeCore
The core level of the parser that contains the code to parse,...
It can be shared with others code parsers.

Constructor Detail

CodeParser

public CodeParser(java.lang.String code)
Creates and initialises the code parser.

Parameters:
code - The code to parse.
Throws:
java.lang.IllegalArgumentException - If the given code is null.
Method Detail

initialise

public void initialise()
Reinitialises the parser.

Since:
2.0.2

getCode

public java.lang.String getCode()
Returns:
the code.
Since:
2.0.2

setCode

public void setCode(java.lang.String code)
Parameters:
code - the code to set. It re-initialises the parser.
Since:
2.0.2

nextChar

public int nextChar()
Reads the next char and returns it.

Returns:
the next read character or EOC if the end of the path is reached.
Since:
2.0.2

getCharAt

public int getCharAt(int pos)
The character at the given position.

Parameters:
pos - The position of the wanted character.
Returns:
The character or EOC.
Since:
2.0.3

getChar

public int getChar()
Returns:
the current character or EOC if the end of the path is reached.
Since:
2.0.2

isEOC

public boolean isEOC()
Returns:
True if the end of the code is reached.
Since:
2.0.2

getPosition

public int getPosition()
Returns:
the position.
Since:
2.0.2

getLinePosition

public int getLinePosition()
Returns:
the line position.
Since:
2.0.2

skipComment

public abstract java.lang.String skipComment()
Skips the comment.

Returns:
The read comment.
Since:
2.0.2

skipWSP

public abstract void skipWSP()
Skips the useless characters.

Since:
2.0.2

skipWSPComments

public void skipWSPComments()
Skips both comments and ignorable characters.

Since:
2.0.2

isComment

public abstract boolean isComment()
Returns:
True if the current position points to a comment token.
Since:
2.0.3

isWSP

public abstract boolean isWSP()
Returns:
True if the current character is a whitespace/ignorable character.
Since:
2.0.2

isEOL

public boolean isEOL()
Returns:
True if the current character is EOL. For the EOL CR+LF, the next character (LF) is read.
Since:
2.0.2

setPosition

public void setPosition(int position)
Parameters:
position - the position to set.
Since:
2.0.2

incLinePosition

public void incLinePosition()
Increments the line position.


setLinePosition

public void setLinePosition(int linePosition)
Parameters:
linePosition - the line position to set. Must be greater than 0.
Since:
2.0.2

getCodeCore

public CodeParser.Code getCodeCore()
Returns:
the code core.
Since:
2.0.2

setCodeCore

public void setCodeCore(CodeParser.Code codeCore)
Parameters:
codeCore - the code core to set.
Since:
2.0.2