Package org.h2.bnf
Class Bnf
java.lang.Object
org.h2.bnf.Bnf
This class can read a file that is similar to BNF (Backus-Naur form).
It is made specially to support SQL grammar.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidAdd an alias for a rule.static BnfgetInstance(Reader csv) Create an instance using the grammar specified in the CSV file.getNextTokenList(String query) Get the list of tokens that can follow.getRuleHead(String title) Get the rule head for the given title.static StringgetRuleMapKey(String token) Convert convert ruleLink to rule_link.Get the list of possible statements.static StringTokenizerGet the tokenizer for the given syntax.voidCross-link all statements with each other.static booleanCheck whether the statement starts with a whitespace.toString()voidupdateTopic(String topic, DbContextRule rule) Update a topic with a context specific rule.voidvisit(BnfVisitor visitor, String s) Parse the syntax and let the rule call the visitor.
-
Constructor Details
-
Bnf
public Bnf()
-
-
Method Details
-
getInstance
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:
SQLException- on failureIOException- on failure
-
addAlias
Add an alias for a rule.- Parameters:
name- for example "procedure"replacement- for example "@func@"
-
visit
Parse the syntax and let the rule call the visitor.- Parameters:
visitor- the visitors- the syntax to parse
-
startWithSpace
Check whether the statement starts with a whitespace.- Parameters:
s- the statement- Returns:
- if the statement is not empty and starts with a whitespace
-
getRuleMapKey
Convert convert ruleLink to rule_link.- Parameters:
token- the token- Returns:
- the rule map key
-
getRuleHead
Get the rule head for the given title.- Parameters:
title- the title- Returns:
- the rule head, or null
-
toString
-
getNextTokenList
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
Update a topic with a context specific rule. This is used for autocomplete support.- Parameters:
topic- the topicrule- the database context rule
-
getStatements
Get the list of possible statements.- Returns:
- the list of statements
-
getTokenizer
Get the tokenizer for the given syntax.- Parameters:
s- the syntax- Returns:
- the tokenizer
-