Building Parsers with Java

sjm.examples.coffee
Class CoffeeParser

java.lang.Object
  |
  +--sjm.examples.coffee.CoffeeParser

public class CoffeeParser
extends java.lang.Object

This class provides a parser that recognizes a textual description of a type of coffee, and builds a corresponding coffee object.

The grammar this class supports is:

 
     coffee     = name ',' roast ',' country ',' price;
     name       = Word (formerName | Empty);
     formerName = '(' Word ')';
     roast      = Word (orFrench | Empty);
     orFrench   = '/' "french";
     country    = Word;
     price      = Num;
 
 


Constructor Summary
CoffeeParser()
           
 
Method Summary
 Parser coffee()
          Return a parser that will recognize the grammar:
protected  Parser country()
           
protected  Parser formerName()
           
protected  Parser name()
           
protected  Parser orFrench()
           
protected  Parser price()
           
protected  Parser roast()
           
static Parser start()
          Return the primary parser for this class -- coffee().
static Tokenizer tokenizer()
          Returns a tokenizer that allows spaces to appear inside the "words" that identify a coffee's name.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CoffeeParser

public CoffeeParser()
Method Detail

coffee

public Parser coffee()
Return a parser that will recognize the grammar:
 
     coffee  = name ',' roast ',' country ',' price;

  
This parser creates a Coffee object as an assembly's target.
Returns:
a parser that will recognize and build a Coffee from a textual description.

country

protected Parser country()

formerName

protected Parser formerName()

name

protected Parser name()

orFrench

protected Parser orFrench()

price

protected Parser price()

roast

protected Parser roast()

start

public static Parser start()
Return the primary parser for this class -- coffee().
Returns:
the primary parser for this class -- coffee()

tokenizer

public static Tokenizer tokenizer()
Returns a tokenizer that allows spaces to appear inside the "words" that identify a coffee's name.
Returns:
a tokenizer that allows spaces to appear inside the "words" that identify a coffee's name.

by Steve Metsker