.. $Id: index.txt a2119c07028f 2008-10-27 mtnyogi $
.. 
.. Copyright © 2007-2008 Bruce Frederiksen
.. 
.. 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.

restindex
    crumb: KRB Syntax
    page-description:
        Syntax of the *Knowledge Rule Base* (KRB) files, which is where you
        write your rules.
    /description
    section-pages: , fc_rule, bc_rule, pattern, compound_premise, python_premise
    format: rest
    encoding: utf8
    output-encoding: utf8
    include: yes
    initialheaderlevel: 2
/restindex

uservalues
    filedate: $Id: index.txt a2119c07028f 2008-10-27 mtnyogi $
/uservalues

===================
KRB Syntax
===================

This section describes the syntax for defining rules_ in KRB files.


Keywords
==================

=========  ===========  =========
as         foreach      taking 
assert     in           True 
bc_extras  None         use 
check      plan_extras  when 
extending  python       with 
False      step         without 
fc_extras                       
=========  ===========  =========



Syntax of the Entire KRB File
===================================

::

    file ::= [NL]

             ['extending' IDENTIFIER ['without' {IDENTIFIER,}] NL]

             [{fc_rule}
              ['fc_extras' NL INDENT
                 {<python_statement> NL}
               DEINDENT]]

             [{bc_rule}
              ['bc_extras' NL INDENT
                 {<python_statement> NL}
               DEINDENT]
              ['plan_extras' NL INDENT
                 {<python_statement> NL}
               DEINDENT]]

The KRB file has three optional parts.  It must contain at least one rule_
(either forward-chaining_ or backward-chaining_).

The filename (minus the .krb extension) is the name of the `rule base`_.
This must be a legal Python identifier.

Extending clause
-----------------

The optional ``extending`` clause, if used, is the first line of the file.
This defines the parent `rule base`_ that this `rule base`_ inherits_ from.
It may also specify a list of backward-chaining_ goal names to be excluded
from this inheritance.

Forward-Chaining Section
--------------------------

If the krb file contains any forward-chaining_ rules, a Python source file
will be created named <rb_name>_fc.py, where <rb_name> is the `rule base`_
name.

The syntax of a forward-chaining rule (fc_rule_) is defined here__.

The ``fc_extras`` may only be used if there are forward-chaining rules.
This allows you to add other Python code (for example, ``import`` statements)
to the generated Python source file.

.. __: fc_rule_

Backward-Chaining Section
--------------------------

If the krb file contains any backward-chaining_ rules, a Python source file
will be created named <rb_name>_bc.py, where <rb_name> is the `rule base`_
name.

The syntax of a backward-chaining rule (bc_rule_) is defined here__.

The ``bc_extras`` can only be used if there are backward-chaining rules.
This allows you to add other Python code (for example, ``import`` statements)
to the generated Python source file.

In addition, if any of the backward-chaining rules have plan_ code (a
`with clause`_ or any subgoals in the `when clause`_ with a plan_spec_),
a Python source file will be created named <rb_name>_plans.py,
where <rb_name> is the `rule base` name.

You use the ``plan_extras`` to include arbitrary Python code in this plans
file.

.. __: bc_rule_


