Top Description Fields Constructors Methods
org.h2.bnf

public Class Bnf

extends Object
Class Inheritance
Imports
java.io.ByteArrayInputStream, .IOException, .InputStreamReader, .Reader, java.nio.charset.StandardCharsets, java.sql.ResultSet, .SQLException, java.util.ArrayList, .HashMap, .StringTokenizer, org.h2.bnf.context.DbContextRule, org.h2.command.dml.Help, org.h2.tools.Csv, org.h2.util.StringUtils, .Utils

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

Field Summary

Modifier and TypeField and Description
private String
private String
private char
private int
private Rule
private final HashMap<String, RuleHead>
ruleMap

The rule map.

private ArrayList<RuleHead>
private String
private String[]

Constructor Summary

AccessConstructor and Description
public
Bnf()

Method Summary

Modifier and TypeMethod and Description
public void
addAlias(String
for example "procedure"
name
,
String
for example "@func@"
replacement
)

Add an alias for a rule.

private void
addFixedRule(String name, int fixedType)

private RuleHead
addRule(String topic, String section, Rule rule)

public static Bnf

Returns:

a new instance
getInstance
(Reader
if not specified, the help.csv is used
csv
)

Create an instance using the grammar specified in the CSV file.

public HashMap<String, String>

Returns:

the map of possible token types / tokens
getNextTokenList
(String
the start of the statement
query
)

Get the list of tokens that can follow.

public RuleHead

Returns:

the rule head, or null
getRuleHead
(String
the title
title
)

Get the rule head for the given title.

public static String

Returns:

the rule map key
getRuleMapKey
(String
the token
token
)

Convert convert ruleLink to rule_link.

public ArrayList<RuleHead>

Returns:

the list of statements
getStatements
()

Get the list of possible statements.

public static StringTokenizer

Returns:

the tokenizer
getTokenizer
(String
the syntax
s
)

Get the tokenizer for the given syntax.

public void
linkStatements()

Cross-link all statements with each other.

private void
parse(Reader reader)

private RuleExtension
parseExtension(boolean compatibility)

private Rule
private Rule
private Rule
private Rule
private void
read()

public static boolean

Returns:

if the statement is not empty and starts with a whitespace
startWithSpace
(String
the statement
s
)

Check whether the statement starts with a whitespace.

private String[]
public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

public void
updateTopic(String
the topic
topic
,
DbContextRule
the database context rule
rule
)

Update a topic with a context specific rule.

public void
visit(BnfVisitor
the visitor
visitor
,
String
the syntax to parse
s
)

Parse the syntax and let the rule call the visitor.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

currentTokenback to summary
private String currentToken
currentTopicback to summary
private String currentTopic
firstCharback to summary
private char firstChar
indexback to summary
private int index
lastRepeatback to summary
private Rule lastRepeat
ruleMapback to summary
private final HashMap<String, RuleHead> ruleMap

The rule map. The key is lowercase, and all spaces are replaces with underscore.

statementsback to summary
private ArrayList<RuleHead> statements
syntaxback to summary
private String syntax
tokensback to summary
private String[] tokens

Constructor Detail

Bnfback to summary
public Bnf()

Method Detail

addAliasback to summary
public void addAlias(String name, String replacement)

Add an alias for a rule.

Parameters
name:String

for example "procedure"

replacement:String

for example "@func@"

addFixedRuleback to summary
private void addFixedRule(String name, int fixedType)
addRuleback to summary
private RuleHead addRule(String topic, String section, Rule rule)
getInstanceback to summary
public static Bnf getInstance(Reader csv) throws SQLException, IOException

Create an instance using the grammar specified in the CSV file.

Parameters
csv:Reader

if not specified, the help.csv is used

Returns:Bnf

a new instance

Exceptions
SQLException:
on failure
IOException:
on failure
getNextTokenListback to summary
public HashMap<String, String> 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:String

the start of the statement

Returns:HashMap<String, String>

the map of possible token types / tokens

getRuleHeadback to summary
public RuleHead getRuleHead(String title)

Get the rule head for the given title.

Parameters
title:String

the title

Returns:RuleHead

the rule head, or null

getRuleMapKeyback to summary
public static String getRuleMapKey(String token)

Convert convert ruleLink to rule_link.

Parameters
token:String

the token

Returns:String

the rule map key

getStatementsback to summary
public ArrayList<RuleHead> getStatements()

Get the list of possible statements.

Returns:ArrayList<RuleHead>

the list of statements

getTokenizerback to summary
public static StringTokenizer getTokenizer(String s)

Get the tokenizer for the given syntax.

Parameters
s:String

the syntax

Returns:StringTokenizer

the tokenizer

linkStatementsback to summary
public void linkStatements()

Cross-link all statements with each other. This method is called after updating the topics.

parseback to summary
private void parse(Reader reader) throws SQLException, IOException
parseExtensionback to summary
private RuleExtension parseExtension(boolean compatibility)
parseListback to summary
private Rule parseList()
parseOrback to summary
private Rule parseOr()
parseRuleback to summary
private Rule parseRule()
parseTokenback to summary
private Rule parseToken()
readback to summary
private void read()
startWithSpaceback to summary
public static boolean startWithSpace(String s)

Check whether the statement starts with a whitespace.

Parameters
s:String

the statement

Returns:boolean

if the statement is not empty and starts with a whitespace

tokenizeback to summary
private String[] tokenize()
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object. Satisfying this method's contract implies a non-null result must be returned.

Returns:String

a string representation of the object

Annotations
@Override
updateTopicback to summary
public void updateTopic(String topic, DbContextRule rule)

Update a topic with a context specific rule. This is used for autocomplete support.

Parameters
topic:String

the topic

rule:DbContextRule

the database context rule

visitback to summary
public void visit(BnfVisitor visitor, String s)

Parse the syntax and let the rule call the visitor.

Parameters
visitor:BnfVisitor

the visitor

s:String

the syntax to parse