01: package org.kohsuke.rngom.parse.host;
02:
03: import org.kohsuke.rngom.ast.builder.Annotations;
04: import org.kohsuke.rngom.ast.builder.BuildException;
05: import org.kohsuke.rngom.ast.builder.CommentList;
06: import org.kohsuke.rngom.ast.builder.Div;
07: import org.kohsuke.rngom.ast.builder.GrammarSection;
08: import org.kohsuke.rngom.ast.builder.Include;
09: import org.kohsuke.rngom.ast.om.Location;
10: import org.kohsuke.rngom.ast.om.ParsedElementAnnotation;
11: import org.kohsuke.rngom.ast.om.ParsedPattern;
12:
13: /**
14: *
15: * @author
16: * Kohsuke Kawaguchi (kk@kohsuke.org)
17: */
18: public class GrammarSectionHost extends Base implements GrammarSection {
19: private final GrammarSection lhs;
20: private final GrammarSection rhs;
21:
22: GrammarSectionHost(GrammarSection lhs, GrammarSection rhs) {
23: this .lhs = lhs;
24: this .rhs = rhs;
25: if (lhs == null || rhs == null)
26: throw new IllegalArgumentException();
27: }
28:
29: public void define(String name, Combine combine,
30: ParsedPattern _pattern, Location _loc, Annotations _anno)
31: throws BuildException {
32: ParsedPatternHost pattern = (ParsedPatternHost) _pattern;
33: LocationHost loc = cast(_loc);
34: AnnotationsHost anno = cast(_anno);
35:
36: lhs.define(name, combine, pattern.lhs, loc.lhs, anno.lhs);
37: rhs.define(name, combine, pattern.rhs, loc.rhs, anno.rhs);
38: }
39:
40: public Div makeDiv() {
41: return new DivHost(lhs.makeDiv(), rhs.makeDiv());
42: }
43:
44: public Include makeInclude() {
45: Include l = lhs.makeInclude();
46: if (l == null)
47: return null;
48: return new IncludeHost(l, rhs.makeInclude());
49: }
50:
51: public void topLevelAnnotation(ParsedElementAnnotation _ea)
52: throws BuildException {
53: ParsedElementAnnotationHost ea = (ParsedElementAnnotationHost) _ea;
54: lhs.topLevelAnnotation(ea == null ? null : ea.lhs);
55: rhs.topLevelAnnotation(ea == null ? null : ea.rhs);
56: }
57:
58: public void topLevelComment(CommentList _comments)
59: throws BuildException {
60: CommentListHost comments = (CommentListHost) _comments;
61:
62: lhs.topLevelComment(comments == null ? null : comments.lhs);
63: rhs.topLevelComment(comments == null ? null : comments.rhs);
64: }
65: }
|