dip.order
Class OrderParser

java.lang.Object
  extended bydip.order.OrderParser

public class OrderParser
extends java.lang.Object

Parses text to create an Order object.

NOTE: this code is rather hackish (and in no way reflective of the rest of the code base). It is not expandable, or modular. However, it is a pretty flexible parser in terms of what it will accept. As a point of history, it's the first piece of code written for jDip.

I am gradually replacing the most crusty parts with better code. For example, Coast now normalizes coasts with regular expressions, and the code is far cleaner.

In the future, I anticipate we will have some sort of command-normalization (Order.normalize) which will be implemented by Order subclasses, and some sort of pattern matching that will allow the order to be matched to the tokens. This will allow Order classes to be modfied or added without rewriting the OrderParser.

note: The parser is extremely tolerant of misspellings in single-word provinces. However, it is not at all tolerant of multiword province misspellings. This is because it cannot easily recognize multi-word provinces. A pattern based parser could, and would be more robust in this regard.

	HOLD:
	:   h 
	
	MOVE, RETREAT:
	:   m 
	: m  (to) 
	
	SUPPORT:
	:   s  
	:   s   m 
	
	CONVOY:
	:   c   m 
	
	DISBAND:	
	:   d 

	BUILD:	
	:   

	REMOVE:	
	:    
	

	Where: 

	 = "army", "a", "fleet", "f" or 
	 = Source province.
	 = Destination province.
	 = Power name or abbreviation of two or more characters.
	 = "h", "hold", "holds", "stand", "stands".
	 = "-", "->", "=>", "m", "move", "moves", "move to", "moves to".
	 = "s", "support", "supports".
	 = "c", "convoy", "convoys".
	 = "d", "disband".
	 = "b", "build"
	 = "r", "remove" 

	


Method Summary
static OrderParser getInstance()
          Gets an OrderParser instance
 Order parse(OrderFactory orderFactory, java.lang.String text, Power power, TurnState turnState, boolean locked, boolean guess)
          Parse an order to an Order object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getInstance

public static OrderParser getInstance()
Gets an OrderParser instance


parse

public Order parse(OrderFactory orderFactory,
                   java.lang.String text,
                   Power power,
                   TurnState turnState,
                   boolean locked,
                   boolean guess)
            throws OrderException
Parse an order to an Order object.

There are several options to control parsing.

	power: 	
			"default" power to assume; null if not required
	World:
			current world; needed for province/power matching

	locked:	
			if true, only orders for the specified power are legal.
			if power==null then an IAE is thrown.
	guess:
			only works if (power==null) and power is NOT locked
			guesses power based upon source province
			Position (derived from world) must be accurate; since guessing depends 
			upon knowing the current position information, and phase information.


	States:
	
	Power		Locked	Guess	Result
	=====   	======	=====	=================================================
	null		false	false	VALID: but power must always be present in text to parse!
	null		false	true	VALID: power is based on source province, whether specified or not
	null		true	false	illegal
	null		true	true	illegal

	(defined)	false	false	VALID: power must be specified, if not, assumes "Power" given
	(defined)	false	true	VALID: if power not specified, it is based on source province
	(defined)	true	false	VALID: power *always* is "Power" given
	(defined)	true	true	illegal
	

Throws:
OrderException


Copyright 2002-2004 Zachary DelProposto / jDip Development Team. All Rights Reserved.