001: package org.kohsuke.rngom.ast.builder;
002:
003: import org.kohsuke.rngom.ast.om.Location;
004: import org.kohsuke.rngom.ast.om.ParsedElementAnnotation;
005: import org.kohsuke.rngom.ast.om.ParsedNameClass;
006: import org.kohsuke.rngom.ast.om.ParsedPattern;
007: import org.kohsuke.rngom.parse.*;
008: import org.kohsuke.rngom.parse.IllegalSchemaException;
009: import org.kohsuke.rngom.parse.Parseable;
010:
011: import java.util.List;
012:
013: // TODO: define combine error check should be done by the parser.
014: public interface SchemaBuilder<N extends ParsedNameClass, P extends ParsedPattern, E extends ParsedElementAnnotation, L extends Location, A extends Annotations<E, L, CL>, CL extends CommentList<L>> {
015:
016: /**
017: * Returns the {@link NameClassBuilder}, which is used to build name
018: * classes for this {@link SchemaBuilder}. The
019: * {@link org.kohsuke.rngom.nc.NameClass}es that are built will then be
020: * fed into this {@link SchemaBuilder}to further build RELAX NG patterns.
021: *
022: * @return always return a non-null valid object. This method can (and
023: * probably should) always return the same object.
024: */
025: NameClassBuilder<N, E, L, A, CL> getNameClassBuilder()
026: throws BuildException;
027:
028: P makeChoice(List<P> patterns, L loc, A anno) throws BuildException;
029:
030: P makeInterleave(List<P> patterns, L loc, A anno)
031: throws BuildException;
032:
033: P makeGroup(List<P> patterns, L loc, A anno) throws BuildException;
034:
035: P makeOneOrMore(P p, L loc, A anno) throws BuildException;
036:
037: P makeZeroOrMore(P p, L loc, A anno) throws BuildException;
038:
039: P makeOptional(P p, L loc, A anno) throws BuildException;
040:
041: P makeList(P p, L loc, A anno) throws BuildException;
042:
043: P makeMixed(P p, L loc, A anno) throws BuildException;
044:
045: P makeEmpty(L loc, A anno);
046:
047: P makeNotAllowed(L loc, A anno);
048:
049: P makeText(L loc, A anno);
050:
051: P makeAttribute(N nc, P p, L loc, A anno) throws BuildException;
052:
053: P makeElement(N nc, P p, L loc, A anno) throws BuildException;
054:
055: DataPatternBuilder makeDataPatternBuilder(String datatypeLibrary,
056: String type, L loc) throws BuildException;
057:
058: P makeValue(String datatypeLibrary, String type, String value,
059: Context c, String ns, L loc, A anno) throws BuildException;
060:
061: /**
062: *
063: * @param parent
064: * The parent scope. null if there's no parent scope.
065: * For example, if the complete document looks like the following:
066: * <pre><xmp>
067: * <grammar>
068: * <start><element name="root"><empty/></element></start>
069: * </grammar>
070: * </xmp></pre>
071: * Then when the outer-most {@link Grammar} is created, it will
072: * receive the <tt>null</tt> parent.
073: */
074: Grammar<P, E, L, A, CL> makeGrammar(Scope<P, E, L, A, CL> parent);
075:
076: /**
077: * Called when annotation is found right inside a pattern
078: *
079: * such as,
080: *
081: * <pre><xmp>
082: * <element name="foo"> <!-- this becomes 'P' -->
083: * <foreign:annotation /> <!-- this becomes 'A' -->
084: * ...
085: * </element>
086: * </xmp></pre>
087: */
088: P annotate(P p, A anno) throws BuildException;
089:
090: /**
091: * Called when element annotation is found after a pattern.
092: *
093: * such as,
094: *
095: * <pre><xmp>
096: * <element name="foo">
097: * <empty /> <!-- this becomes 'P' -->
098: * <foreign:annotation /> <!-- this becomes 'E' -->
099: * </element>
100: * </xmp></pre>
101: */
102: P annotateAfter(P p, E e) throws BuildException;
103:
104: P commentAfter(P p, CL comments) throws BuildException;
105:
106: /**
107: *
108: * @param current
109: * Current grammar that we are parsing. This is what contains
110: * externalRef.
111: * @param scope
112: * The parent scope. null if there's no parent scope.
113: * See {@link #makeGrammar(Scope)} for more details about
114: * when this parameter can be null.
115: */
116: P makeExternalRef(Parseable current, String uri, String ns,
117: Scope<P, E, L, A, CL> scope, L loc, A anno)
118: throws BuildException, IllegalSchemaException;
119:
120: L makeLocation(String systemId, int lineNumber, int columnNumber);
121:
122: /**
123: * Creates {@link Annotations} object to parse annotations on patterns.
124: *
125: * @return
126: * must be non-null.
127: */
128: A makeAnnotations(CL comments, Context context);
129:
130: ElementAnnotationBuilder<P, E, L, A, CL> makeElementAnnotationBuilder(
131: String ns, String localName, String prefix, L loc,
132: CL comments, Context context);
133:
134: CL makeCommentList();
135:
136: P makeErrorPattern();
137:
138: /**
139: * If this {@link SchemaBuilder}is interested in actually parsing
140: * comments, this method returns true.
141: * <p>
142: * Returning false allows the schema parser to speed up the processing by
143: * skiping comment-related handlings.
144: */
145: boolean usesComments();
146:
147: /**
148: * Called after all the parsing is done.
149: *
150: * <p>
151: * This hook typically allows as {@link SchemaBuilder} to expand
152: * notAllowed (if it's following the simplification as in the spec.)
153: */
154: P expandPattern(P p) throws BuildException, IllegalSchemaException;
155: }
|