001/*
002 * Copyright (C) 2009-2011 Mathias Doenitz
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 */
016
017package org.parboiled;
018
019/**
020 * Instances of classes implementing this interface can be used directly in a rule definition to define a parser action.
021 * If the class also implements the {@link ContextAware} interface it will be used to inform the object of the
022 * current parsing {@link Context} immediately before the invocation of the {@link #run} method.
023 * Additionally, if the class implementing this interface is an inner class (anonymous or not) and its outer class(es)
024 * implement(s) {@link ContextAware} its outer class(es) will also be informed object of the current parsing {@link Context}
025 * immediately before the invocation of the actions {@link #run} method.
026 * This allows simple anonymous action class implementations directly in the parser rule definitions, even when
027 * they access context-sensitive methods defined in the BaseActions or BaseParser classes.
028 */
029public interface Action<V> {
030
031    /**
032     * Runs the parser action.
033     *
034     * @param context the current parsing context
035     * @return true if the parsing process is to proceed, false if the current rule is to fail
036     */
037    boolean run(Context<V> context);
038
039}