| 1 |
/* |
| 2 |
* Copyright 2004-2023 H2 Group. Multiple-Licensed under the MPL 2.0, |
| 3 |
* and the EPL 1.0 (https://h2database.com/html/license.html). |
| 4 |
* Initial Developer: H2 Group |
| 5 |
*/ |
| 6 |
package org.h2.bnf; |
| 7 |
|
| 8 |
import java.util.HashMap; |
| 9 |
|
| 10 |
/** |
| 11 |
* Represents a non-standard syntax. |
| 12 |
*/ |
| 13 |
public class RuleExtension implements Rule { |
| 14 |
|
| 15 |
private final Rule rule; |
| 16 |
private final boolean compatibility; |
| 17 |
|
| 18 |
private boolean mapSet; |
| 19 |
|
| 20 |
public RuleExtension(Rule rule, boolean compatibility) { |
| 21 |
this.rule = rule; |
| 22 |
this.compatibility = compatibility; |
| 23 |
} |
| 24 |
|
| 25 |
@Override |
| 26 |
public void accept(BnfVisitor visitor) { |
| 27 |
visitor.visitRuleExtension(rule, compatibility); |
| 28 |
} |
| 29 |
|
| 30 |
@Override |
| 31 |
public void setLinks(HashMap<String, RuleHead> ruleMap) { |
| 32 |
if (!mapSet) { |
| 33 |
rule.setLinks(ruleMap); |
| 34 |
mapSet = true; |
| 35 |
} |
| 36 |
} |
| 37 |
@Override |
| 38 |
public boolean autoComplete(Sentence sentence) { |
| 39 |
sentence.stopIfRequired(); |
| 40 |
rule.autoComplete(sentence); |
| 41 |
return true; |
| 42 |
} |
| 43 |
|
| 44 |
@Override |
| 45 |
public String toString() { |
| 46 |
return (compatibility ? "@c@ " : "@h2@ ") + rule.toString(); |
| 47 |
} |
| 48 |
|
| 49 |
} |