1 | /* |
2 | * Copyright 2004-2014 H2 Group. Multiple-Licensed under the MPL 2.0, |
3 | * and the EPL 1.0 (http://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 loop in a BNF object. |
12 | */ |
13 | public class RuleRepeat implements Rule { |
14 | |
15 | private final Rule rule; |
16 | private final boolean comma; |
17 | |
18 | public RuleRepeat(Rule rule, boolean comma) { |
19 | this.rule = rule; |
20 | this.comma = comma; |
21 | } |
22 | |
23 | @Override |
24 | public void accept(BnfVisitor visitor) { |
25 | visitor.visitRuleRepeat(comma, rule); |
26 | } |
27 | |
28 | @Override |
29 | public void setLinks(HashMap<String, RuleHead> ruleMap) { |
30 | // not required, because it's already linked |
31 | } |
32 | |
33 | @Override |
34 | public boolean autoComplete(Sentence sentence) { |
35 | sentence.stopIfRequired(); |
36 | while (rule.autoComplete(sentence)) { |
37 | // nothing to do |
38 | } |
39 | return true; |
40 | } |
41 | |
42 | } |