001/* 002 * ModeShape (http://www.modeshape.org) 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016package org.modeshape.sequencer.ddl; 017 018import org.modeshape.common.text.ParsingException; 019import org.modeshape.sequencer.ddl.node.AstNode; 020 021/** 022 * Interface for parsing DDL files. 023 */ 024public interface DdlParser { 025 026 /** 027 * Determine this parser's score for the given DDL string. This method is called to determine how well this parser handles the 028 * supplied DDL, and is often called before the {@link #parse(String, AstNode, Object)} method. 029 * 030 * @param ddl the input string to parse; may not be null 031 * @param fileName the name of the DDL content, which may be used to improve the score; may be null if not known 032 * @param scorer the scorer that should be used to record the score; may not be null 033 * @return an object that will be passed to the {@link #parse(String, AstNode,Object)} method 034 * @throws ParsingException if there is an error parsing the supplied DDL content 035 */ 036 public Object score( String ddl, 037 String fileName, 038 DdlParserScorer scorer ) throws ParsingException; 039 040 /** 041 * Parses a DDL string, adding child {@link AstNode}s and properties to the supplied root. This method instantiates the 042 * tokenizer, calls a method to allow subclasses to register keywords and statement start phrases with the tokenizer and 043 * finally performs the tokenizing (i.e. tokens.start()) before calling the actual parse method. 044 * 045 * @param ddl the input string to parse; may not be null 046 * @param rootNode the top level {@link AstNode}; may not be null 047 * @param scoreReturnObject the object returned from {@link #score(String, String, DdlParserScorer)} for the same DDL content; 048 * may be null if the {@link #score(String, String, DdlParserScorer)} method was not called 049 * @throws ParsingException if there is an error parsing the supplied DDL content 050 */ 051 public void parse( String ddl, 052 AstNode rootNode, 053 Object scoreReturnObject ) throws ParsingException; 054 055 /** 056 * Get the identifier for this parser. 057 * 058 * @return the parser's identifier; never null 059 */ 060 public String getId(); 061 062 /** 063 * Allows parsers to post process the {@link AstNode} tree given the supplied root. Initial use-case would be to allow a 064 * second pass through the tree to resolve any table references (FK's) that were defined out of order in the DDL 065 * 066 * @param rootNode the top level {@link AstNode}; may not be null 067 */ 068 public void postProcess( AstNode rootNode ); 069 070}