org.h2.bnf
Class Bnf

java.lang.Object
  extended by org.h2.bnf.Bnf

public class Bnf
extends java.lang.Object

This class can read a file that is similar to BNF (Backus-Naur form). It is made specially to support SQL grammar.


Method Summary
static Bnf getInstance(java.io.Reader csv)
          Create an instance using the grammar specified in the CSV file.
 java.util.HashMap<java.lang.String,java.lang.String> getNextTokenList(java.lang.String query)
          Get the list of tokens that can follow.
 java.util.Random getRandom()
           
 java.util.ArrayList<RuleHead> getStatements()
          Get the list of possible statements.
 java.lang.String getSyntaxHtml(java.lang.String bnf)
          Get the HTML documentation for a given syntax.
 void linkStatements()
          Cross-link all statements with each other.
 void updateTopic(java.lang.String topic, DbContextRule rule)
          Update a topic with a context specific rule.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getInstance

public static Bnf getInstance(java.io.Reader csv)
                       throws java.sql.SQLException,
                              java.io.IOException
Create an instance using the grammar specified in the CSV file.

Parameters:
csv - if not specified, the help.csv is used
Returns:
a new instance
Throws:
java.sql.SQLException
java.io.IOException

getRandom

public java.util.Random getRandom()

getSyntaxHtml

public java.lang.String getSyntaxHtml(java.lang.String bnf)
Get the HTML documentation for a given syntax.

Parameters:
bnf - the BNF syntax
Returns:
the HTML formatted text

getNextTokenList

public java.util.HashMap<java.lang.String,java.lang.String> getNextTokenList(java.lang.String query)
Get the list of tokens that can follow. This is the main autocomplete method. The returned map for the query 'S' may look like this:
 key: 1#SELECT, value: ELECT
 key: 1#SET, value: ET
 

Parameters:
query - the start of the statement
Returns:
the map of possible token types / tokens

linkStatements

public void linkStatements()
Cross-link all statements with each other. This method is called after updating the topics.


updateTopic

public void updateTopic(java.lang.String topic,
                        DbContextRule rule)
Update a topic with a context specific rule. This is used for autocomplete support.

Parameters:
topic - the topic
rule - the database context rule

getStatements

public java.util.ArrayList<RuleHead> getStatements()
Get the list of possible statements.

Returns:
the list of statements