Bnf

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

Methods
static Bnf getInstance(Reader csv)
Create an instance using the grammar specified in the CSV file.
static Bnf getInstance(Reader csv) throws SQLException, 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
static String getRuleMapKey(String token)
Convert convert ruleLink to rule_link.
static String getRuleMapKey(String token)
Convert convert ruleLink to rule_link.
Parameters:
token - the token
Returns:
the rule map key
static StringTokenizer getTokenizer(String s)
Get the tokenizer for the given syntax.
static StringTokenizer getTokenizer(String s)
Get the tokenizer for the given syntax.
Parameters:
s - the syntax
Returns:
the tokenizer
static boolean startWithSpace(String s)
Check whether the statement starts with a whitespace.
static boolean startWithSpace(String s)
Check whether the statement starts with a whitespace.
Parameters:
s - the statement
Returns:
if the statement is not empty and starts with a whitespace
void addAlias(String name, String replacement)
Add an alias for a rule.
void addAlias(String name, String replacement)
Add an alias for a rule.
Parameters:
name - for example "procedure"
replacement - for example "@func@"
HashMap getNextTokenList(String query)
Get the list of tokens that can follow.
HashMap getNextTokenList(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
RuleHead getRuleHead(String title)
Get the rule head for the given title.
RuleHead getRuleHead(String title)
Get the rule head for the given title.
Parameters:
title - the title
Returns:
the rule head, or null
ArrayList getStatements()
Get the list of possible statements.
ArrayList getStatements()
Get the list of possible statements.
Returns:
the list of statements
void linkStatements()
Cross-link all statements with each other.
void linkStatements()
Cross-link all statements with each other. This method is called after updating the topics.
void updateTopic(String topic, DbContextRule rule)
Update a topic with a context specific rule.
void updateTopic(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
void visit(BnfVisitor visitor, String s)
Parse the syntax and let the rule call the visitor.
void visit(BnfVisitor visitor, String s)
Parse the syntax and let the rule call the visitor.
Parameters:
visitor - the visitor
s - the syntax to parse