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.
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
Add an alias for a rule.private void
addFixedRule
(String name, int fixedType) private RuleHead
static Bnf
getInstance
(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 String
getRuleMapKey
(String token) Convert convert ruleLink to rule_link.Get the list of possible statements.static StringTokenizer
Get the tokenizer for the given syntax.void
Cross-link all statements with each other.private void
private RuleExtension
parseExtension
(boolean compatibility) private Rule
private Rule
parseOr()
private Rule
private Rule
private void
read()
static boolean
Check whether the statement starts with a whitespace.private String[]
tokenize()
toString()
void
updateTopic
(String topic, DbContextRule rule) Update a topic with a context specific rule.void
visit
(BnfVisitor visitor, String s) Parse the syntax and let the rule call the visitor.
-
Field Details
-
ruleMap
The rule map. The key is lowercase, and all spaces are replaces with underscore. -
syntax
-
currentToken
-
tokens
-
firstChar
private char firstChar -
index
private int index -
lastRepeat
-
statements
-
currentTopic
-
-
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@"
-
addFixedRule
-
addRule
-
parse
- Throws:
SQLException
IOException
-
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
-
parseRule
-
parseOr
-
parseList
-
parseExtension
-
parseToken
-
read
private void read() -
toString
-
tokenize
-
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
-