uk.me.nxg.unity
Class UnitParser

java.lang.Object
  extended by uk.me.nxg.unity.UnitParser

public class UnitParser
extends Object

A parser for unit strings. The parser will parse a single string.

There are a number of different parsers available, enumerated in Syntax.

See the uk.me.nxg.unity package documentation for fuller discussion of the grammars.


Nested Class Summary
static class UnitParser.Lexeme
          A single lexeme.
 
Constructor Summary
UnitParser(Syntax syntax, String unitString)
          Create a new unit parser.
 
Method Summary
 UnitParser.Lexeme getLexeme()
          Return successive lexemes from the input.
 UnitExpr getParsed()
          Retrieve the parsed result
static boolean isKnownParser(String parser)
          Indicates whether the argument is the name of a known parser.
static void main(String[] args)
          The library main program, for exploring the library's functionality.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

UnitParser

public UnitParser(Syntax syntax,
                  String unitString)
           throws UnitParserException
Create a new unit parser. The possible parser syntaxes are available from Syntax.values(), or can alternatively be specified using the values enumerated in Syntax.

Parameters:
syntax - one of the known syntaxes
unitString - the string to be parsed
Throws:
UnitParserException - if no parser can be created (typically because the required syntax is unknown)
Method Detail

getParsed

public UnitExpr getParsed()
                   throws UnitParserException
Retrieve the parsed result

Throws:
UnitParserException - if the parse fails

isKnownParser

public static boolean isKnownParser(String parser)
Indicates whether the argument is the name of a known parser.

Parameters:
parser - the string name of a parser (eg "fits")
Returns:
true if the parser corresponds to the name of one of the elements of Syntax

getLexeme

public UnitParser.Lexeme getLexeme()
Return successive lexemes from the input. Primarily for debugging.

Returns:
a Lexeme object, or null when the lexemes are exhausted

main

public static void main(String[] args)
The library main program, for exploring the library's functionality.

Usage:

 UnitParser [-isyntax] [-osyntax] [-v] unit-expression
 

Parse and redisplay the string expression given as argument. The -i and -o flags specify the input and output syntaxes.

 UnitParser -S
 

List the set of available syntaxes