View Javadoc

1   /**
2    * Copyright (c) 2008-2012, http://www.snakeyaml.org
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *     http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.yaml.snakeyaml.parser;
17  
18  import org.yaml.snakeyaml.events.Event;
19  
20  /**
21   * This interface represents an input stream of {@link Event Events}.
22   * <p>
23   * The parser and the scanner form together the 'Parse' step in the loading
24   * process (see chapter 3.1 of the <a href="http://yaml.org/spec/1.1/">YAML
25   * Specification</a>).
26   * </p>
27   * 
28   * @see org.yaml.snakeyaml.events.Event
29   */
30  public interface Parser {
31  
32      /**
33       * Check if the next event is one of the given type.
34       * 
35       * @param choice
36       *            Event ID.
37       * @return <code>true</code> if the next event can be assigned to a variable
38       *         of the given type. Returns <code>false</code> if no more events
39       *         are available.
40       * @throws ParserException
41       *             Thrown in case of malformed input.
42       */
43      public boolean checkEvent(Event.ID choice);
44  
45      /**
46       * Return the next event, but do not delete it from the stream.
47       * 
48       * @return The event that will be returned on the next call to
49       *         {@link #getEvent}
50       * @throws ParserException
51       *             Thrown in case of malformed input.
52       */
53      public Event peekEvent();
54  
55      /**
56       * Returns the next event.
57       * <p>
58       * The event will be removed from the stream.
59       * </p>
60       * 
61       * @throws ParserException
62       *             Thrown in case of malformed input.
63       */
64      public Event getEvent();
65  }