:orphan: .. **************************************************************************** .. CUI .. .. The Advanced Framework for Simulation, Integration, and Modeling (AFSIM) .. .. The use, dissemination or disclosure of data in this file is subject to .. limitation or restriction. See accompanying README and LICENSE for details. .. **************************************************************************** WSF Grammar Guide ----------------- The WSF grammar format, as outlined in :doc:`wsf_grammar_format` defines the syntax of WSF commands. The grammar is used in many tools and applications for parsing WSF files. Grammar files already exist for many WSF modules and can be found in .ag files in the 'grammar' subdirectories of the WSF installation 'bin' directory. It is the developer's responsibility when adding new types and commands to maintain the grammar files so that tools and applications can correctly process WSF files. Grammar File Definition ======================= The grammar file has two main features: **Rules** to parse the WSF input and **Actions** to create data representing the input file. .. contents:: :local: :depth: 3 Rules ~~~~~ Rules form the basis for the grammar. Together the rules define how to parse the input file. A single rule can either *match* or *not match* a given input. The first rule found to match is used and consumes the text. Sequences ^^^^^^^^^ The most basic rule is a sequence. Sequences are indicated by the '{' '}' symbols. Sequences define a list of sub-rules which each must be matched in succession.:: { rule0 rule1 ... } Each rule in the sequence must be matched for the sequence to *match*. Within a sequence, rules are counted starting at 0. Later, rules may be referenced using the '$0' notation. Literals ^^^^^^^^ Literals match a single specific string of characters. Literals can either be quoted strings or plain text. The parser assumes space delimited tokens. :: end_time "the end time" Rule References ^^^^^^^^^^^^^^^ Rules may be referenced after they are defined using the '' format.:: Recurrences ^^^^^^^^^^^ Recurrences are rule references that recur 0 to many or 0 to 1 times. The '\*' character is used to denote a zero to many recurrence. '+' for 1 to many. '?' for 0 to 1. :: { string_list * end_string_list | A B C D { E F G }? } When using * or +, the existence of a terminating literal plays a role. In ``stuff * end_stuff``, any number of strings will be read until ``end_stuff`` is found. But using ``stuff *`` will consume each token that matches the integer rule, and stop only after a non-integer token. When possible, a terminating literal should be provided. Built-in Rules ^^^^^^^^^^^^^^ Matches a whitespace delimited character string:: MY_PLATFORM banana's-apple Matches either a whitespace delimited string or a quoted string:: MY_PLATFORM "C:\Program Files\MyPath" Matches any string with a list of exceptions:: # Match any space delimited string except invalid_word1 and invalid_word2 (string-except invalid_word1 invalid_word2) Matches an integer:: 0 -123 Matches a real number:: -2 -2.0 -2.0e-7 (error {}) Defines a sequence which when matched triggers an error:: #This matches any string. If it is an integer, an error will be logged. { (error { }) | } (delimited ...) Defines a non-space delimited word. All rules are matched assuming whitespace delimited inputs. This provides a way to bypass this limitation. Each argument is matched without spaces. There are some limitations using this rule, most notably, every other argument must be a literal.:: # this will match latitude values like 10.5n and 60s { (delimited n) | (delimited s) } (name *name-kind*) Matches the same as , but identifies the word as the name of something. *name-kind* identifies the kind of name. The purpose of this rule is to allow user interfaces to auto-populate suggestions to fill in this field. Example usage:: icon (name icon) | category (name category) | ignore (name category) (typeref *type-prefix*) Matches the same as , but indicates that the matched word should be an existing type. *type-prefix* indicates the key prefix for the type in the `Symbol Table`_. Example:: exclusion_zone (typeref zone) | inlusion_zone (typeref zone) (nocase { ... }) Takes any sequence and makes it case insensitive.:: (nocase { true | false }) (file-reference *file-type*) Same as , but also marks the text as being the location of an input file of the specified type. (output-file-reference *file-type*) Same as , but also marks the text as being the location of an output file of the specified type. Use the rule associated with the current symbol. See `Symbol Table`_. , , Used with a recurrence (*). Matches any string, but marks the block of text as belonging to a script. The script contents is parsed in another project, this grammar simply annotates the block of text. :: # Reads a script along with its return type, name, arguments script * end_script # Reads a script with no return type, name, arguments on_exit * end_on_exit # Reads a script variables block script_variables * end_script_variables Named Rules ^^^^^^^^^^^ A new named rule is created using this syntax:: (rule *rule-name* { *rules* }) Examples:: # Define a new rule (rule my-rule { end_time