All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.kohsuke.rngom.rngparser.parse.host.SchemaBuilderHost Maven / Gradle / Ivy

There is a newer version: 2024.11.18751.20241128T090041Z-241100
Show newest version
/*
 * Copyright (C) 2004-2011
 * 
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */
package org.kohsuke.rngom.rngparser.parse.host;

import org.kohsuke.rngom.rngparser.ast.builder.Annotations;
import org.kohsuke.rngom.rngparser.ast.builder.BuildException;
import org.kohsuke.rngom.rngparser.ast.builder.CommentList;
import org.kohsuke.rngom.rngparser.ast.builder.DataPatternBuilder;
import org.kohsuke.rngom.rngparser.ast.builder.ElementAnnotationBuilder;
import org.kohsuke.rngom.rngparser.ast.builder.Grammar;
import org.kohsuke.rngom.rngparser.ast.builder.NameClassBuilder;
import org.kohsuke.rngom.rngparser.ast.builder.SchemaBuilder;
import org.kohsuke.rngom.rngparser.ast.builder.Scope;
import org.kohsuke.rngom.rngparser.ast.om.Location;
import org.kohsuke.rngom.rngparser.ast.om.ParsedElementAnnotation;
import org.kohsuke.rngom.rngparser.ast.om.ParsedNameClass;
import org.kohsuke.rngom.rngparser.ast.om.ParsedPattern;
import org.kohsuke.rngom.rngparser.parse.Context;
import org.kohsuke.rngom.rngparser.parse.IllegalSchemaException;
import org.kohsuke.rngom.rngparser.parse.Parseable;

import java.util.List;
import java.util.ArrayList;

/**
 * 
 * @author
 *      Kohsuke Kawaguchi ([email protected])
 */
public class SchemaBuilderHost extends Base implements SchemaBuilder {
    final SchemaBuilder lhs;
    final SchemaBuilder rhs;
    
    public SchemaBuilderHost( SchemaBuilder lhs, SchemaBuilder rhs ) {
        this.lhs = lhs;
        this.rhs = rhs;
    }
    
    public ParsedPattern annotate(ParsedPattern _p, Annotations _anno)
        throws BuildException {
        
        ParsedPatternHost p = (ParsedPatternHost) _p;
        AnnotationsHost a = cast(_anno);
        
        return new ParsedPatternHost(
            lhs.annotate(p.lhs, a.lhs),
            rhs.annotate(p.lhs, a.lhs) );
    }
    
    public ParsedPattern annotateAfter(ParsedPattern _p,
        ParsedElementAnnotation _e) throws BuildException {
        
        ParsedPatternHost p = (ParsedPatternHost) _p;
        ParsedElementAnnotationHost e = (ParsedElementAnnotationHost) _e;
        return new ParsedPatternHost(
            lhs.annotateAfter(p.lhs, e.lhs),
            rhs.annotateAfter(p.rhs, e.rhs));
    }
    
    public ParsedPattern commentAfter(ParsedPattern _p, CommentList _comments)
        throws BuildException {
        
        ParsedPatternHost p = (ParsedPatternHost) _p;
        CommentListHost comments = (CommentListHost) _comments;
        
        return new ParsedPatternHost(
            lhs.commentAfter(p.lhs, comments==null?null:comments.lhs),
            rhs.commentAfter(p.rhs, comments==null?null:comments.rhs));
    }
    
    public ParsedPattern expandPattern(ParsedPattern _p) throws BuildException, IllegalSchemaException {
        ParsedPatternHost p = (ParsedPatternHost) _p;
        return new ParsedPatternHost(
            lhs.expandPattern(p.lhs),
            rhs.expandPattern(p.rhs));
    }
    
    public NameClassBuilder getNameClassBuilder() throws BuildException {
        return new NameClassBuilderHost( lhs.getNameClassBuilder(), rhs.getNameClassBuilder() );
    }
    
    public Annotations makeAnnotations(CommentList _comments, Context context) {
        CommentListHost comments = (CommentListHost) _comments;
        Annotations l = lhs.makeAnnotations((comments!=null)?comments.lhs:null, context);
        Annotations r = rhs.makeAnnotations((comments!=null)?comments.rhs:null, context);
        if(l==null || r==null)
            throw new IllegalArgumentException("annotations cannot be null");
        return new AnnotationsHost(l,r);
    }
    
    public ParsedPattern makeAttribute(ParsedNameClass _nc, ParsedPattern _p,
        Location _loc, Annotations _anno) throws BuildException {
        
        ParsedNameClassHost nc = (ParsedNameClassHost) _nc;
        ParsedPatternHost p = (ParsedPatternHost) _p;
        LocationHost loc = cast(_loc);
        AnnotationsHost anno = cast(_anno);
        
        return new ParsedPatternHost(
            lhs.makeAttribute(nc.lhs, p.lhs, loc.lhs, anno.lhs),
            rhs.makeAttribute(nc.rhs, p.rhs, loc.rhs, anno.rhs));
    }
    
    public ParsedPattern makeChoice(List patterns,
        Location _loc, Annotations _anno) throws BuildException {

        List lp = new ArrayList();
        List rp = new ArrayList();
        for( int i=0; i lp = new ArrayList();
        List rp = new ArrayList();
        for( int i=0; i lp = new ArrayList();
        List rp = new ArrayList();
        for( int i=0; i




© 2015 - 2024 Weber Informatics LLC | Privacy Policy