INCLAN: syntax: Difference between revisions

From CYANA Wiki
Jump to navigation Jump to search
 
(9 intermediate revisions by the same user not shown)
Line 1: Line 1:
== Synopsis ==
== Synopsis ==


syntax {''format''}
'''syntax''' ''format''


== Description ==
== Description ==


The statement "syntax" analyzes the command line parameters of the  
Analyzes the command line parameters of the current macro. This statement can only be called within a macro. Command line parameters that match with one of the ''format'' specifications are removed from the list of command line parameters and assigned to a new local variable.
current macro. This statement can only be called within a macro.
Command line parameters that match with one of the ''format'' specifi-
cations are removed from the list of command line parameters and  
assigned to a new local variable.


Possible ''format'' items are:
The possible ''format'' items are:


;''name''=[=]''type''[=''default'']: named parameter with the given ''name'', ''type'', and, optionally, ''default'' value
;''name''=[=]''type''[=''default'']: Declares a named parameter with the given ''name'', ''type'' and, optionally, ''default'' value. If the ''default'' value is absent, the parameter is required, and an error will occur if the parameter is not specified in the macro call. A local variable with the given ''name'' is created, and either the value specified by the user, or, in its absence, the ''default'' value is assigned to it. The value must be compatible with the given ''type'' (see below). In a macro call, a named parameter can either be specified anywhere in the parameter list in the form “''name'' '''=''' ''value''” or as a positional parameter of the form “''value''” at the same position in the parameter list as the corresponding ''format'' in the '''syntax''' statement. Only parameters that appear before “'''*'''” or “'''**'''” (see below) can be specified as positional parameters without giving their ''name''. A ''name'' may contain an asterisk “*” to indicate how much it can be abbreviated. By default, all unambiguous abbreviations are allowed. If a ''name'' starts with an asterisk, then the corresponding parameter is a positional parameter that cannot be given in the form “''name'' '''=''' ''value''”. The optional second “'''='''” sign after the ''name'' indicates that a parameter that matches ''name'' but does not contain an “'''='''” sign is not recognized, otherwise (with only one “'''='''” sign after ''name''), an error occurs in this situation.


;''name''{|''name''}: literal option with the ''name'', or one out of a mutually exclusive list of names
;''name'':Declares a literal option with the ''name''. A local variable with the given ''name'' is created. If the option ''name'' is present in the macro call this variable is set to 1 (i.e. the logical value “true”), otherwise it is set to 0 (“false”).


;**: allows for additional parameters that do not match with one of the ''formats''
;''name''<sub>'''1'''</sub>|''name''<sub>'''2'''</sub> . . .:Declares a set of mutually exclusive literal options with the names ''name''<sub>1</sub>, ''name''<sub>2</sub>, etc. Local variables with the given ''names'' are created. If one of the option names is present in the macro call, the corresponding variable is set to 1 (i.e. the logical value “true”). The other variables are set to 0.


;&#42;: same as "**" except that additional parameters must not contain an "=" sign
;'''**''':Allows for additional parameters that do not match with one of the ''formats''.


A ''format'' must not contain blanks. A ''name'' may contain a "*" to
;'''*''':Has the same meaning as “'''**'''” except that additional parameters must not contain an '''='''” sign.
indicate how much it can be abbreviated. By default, all unambiguous
abbreviations are allowed. The optional second "=" sign after a ''name''
indicates that a parameter that matches ''name'' but doesn'''t contain an
"=" sign is not recognized, otherwise (with one "=" sign after ''name'',
an error occurs in this situation). Parameters that appear before "*" or
"**" can be specified as positional parameters without giving their
''name''; parameters following "*" or "**" must always be given with their
name.


''Formats'' must not contain blanks.<br>
A ''type'' can be one of the following:
A ''type'' can be one of the following:


;&#42;: anything
;<nowiki>*</nowiki>:Any character string.
;[''limit''[=]]@i[[=]''limit'']: integer expression in given range
 
;[''limit''[=]]@r[[=]''limit'']: real expression in given range
;'''@i''':Integer expression.
;''name''{|''name''}: list of mutually exclusive literals
 
;@f''extension'': a filename that will be extended with the given ''extension'', if necessary (extension can also be $''name'' to denote the value of a preceding parameter)
;'''@r''':Real expression.
 
;[''l''<[=]]@i[<[=]''u'']:Integer expression with the given lower and/or upper bounds.
 
;[''l''<[=]]@r[<[=]''u'']:Real expression in with the given lower and/or upper bounds.
 
;@ii:Integer range. The lower and upper bounds are available as ''name'''''(1)''' and ''name'''''(2)''', respectively. A range is given in the form ''l..u'' or ''l-u'', where l and u denote the upper and the lower bound of the range. Either the lower bound or the upper bound can be omitted (“''..u''” or “''l..''”).
 
;@rr:Real range, defined in the way as an integer range.
 
;''name''<sub>'''1'''</sub>|''name''<sub>'''2'''</sub>. . .:List of mutually exclusive literals.
 
;@f.''extension'':Filename that will be extended with the given ''extension'', if necessary (''extension'' can also be '''$'''''name'' to denote the value of the preceding parameter ''name'').
 
== Examples ==
 
command read_file
  syntax format=asc|bin file=@f.$format weight=@r=1.0
  ...
end
 
<nowiki>#</nowiki> The command read_file has three parameters.<br>
<nowiki>#</nowiki> The first parameter (format) is required and<br>
<nowiki>#</nowiki> can either be asc or bin, the second parameter<br>
<nowiki>#</nowiki> (file) is also required and is a filename that<br>
<nowiki>#</nowiki> will be given the extension .asc or .bin,<br>
<nowiki>#</nowiki> depending on the chosen format, and the third<br>
<nowiki>#</nowiki> parameter (weight) is an optional real number<br>
<nowiki>#</nowiki> with default value 1.0.<br>
 
read_file asc test
 
<nowiki>#</nowiki> Positional parameters and default value for<br>
<nowiki>#</nowiki> weight. Equivalent to setting format=asc,<br>
<nowiki>#</nowiki> file=test.asc and weight=1.0.<br>
read_file file=test format=asc weight=2.0
 
<nowiki>#</nowiki> Named parameters in any order.

Latest revision as of 15:30, 17 August 2009

Synopsis

syntax format

Description

Analyzes the command line parameters of the current macro. This statement can only be called within a macro. Command line parameters that match with one of the format specifications are removed from the list of command line parameters and assigned to a new local variable.

The possible format items are:

name=[=]type[=default]
Declares a named parameter with the given name, type and, optionally, default value. If the default value is absent, the parameter is required, and an error will occur if the parameter is not specified in the macro call. A local variable with the given name is created, and either the value specified by the user, or, in its absence, the default value is assigned to it. The value must be compatible with the given type (see below). In a macro call, a named parameter can either be specified anywhere in the parameter list in the form “name = value” or as a positional parameter of the form “value” at the same position in the parameter list as the corresponding format in the syntax statement. Only parameters that appear before “*” or “**” (see below) can be specified as positional parameters without giving their name. A name may contain an asterisk “*” to indicate how much it can be abbreviated. By default, all unambiguous abbreviations are allowed. If a name starts with an asterisk, then the corresponding parameter is a positional parameter that cannot be given in the form “name = value”. The optional second “=” sign after the name indicates that a parameter that matches name but does not contain an “=” sign is not recognized, otherwise (with only one “=” sign after name), an error occurs in this situation.
name
Declares a literal option with the name. A local variable with the given name is created. If the option name is present in the macro call this variable is set to 1 (i.e. the logical value “true”), otherwise it is set to 0 (“false”).
name1|name2 . . .
Declares a set of mutually exclusive literal options with the names name1, name2, etc. Local variables with the given names are created. If one of the option names is present in the macro call, the corresponding variable is set to 1 (i.e. the logical value “true”). The other variables are set to 0.
**
Allows for additional parameters that do not match with one of the formats.
*
Has the same meaning as “**” except that additional parameters must not contain an “=” sign.

Formats must not contain blanks.
A type can be one of the following:

*
Any character string.
@i
Integer expression.
@r
Real expression.
[l<[=]]@i[<[=]u]
Integer expression with the given lower and/or upper bounds.
[l<[=]]@r[<[=]u]
Real expression in with the given lower and/or upper bounds.
@ii
Integer range. The lower and upper bounds are available as name(1) and name(2), respectively. A range is given in the form l..u or l-u, where l and u denote the upper and the lower bound of the range. Either the lower bound or the upper bound can be omitted (“..u” or “l..”).
@rr
Real range, defined in the way as an integer range.
name1|name2. . .
List of mutually exclusive literals.
@f.extension
Filename that will be extended with the given extension, if necessary (extension can also be $name to denote the value of the preceding parameter name).

Examples

command read_file
  syntax format=asc|bin file=@f.$format weight=@r=1.0	
  ...
end

# The command read_file has three parameters.
# The first parameter (format) is required and
# can either be asc or bin, the second parameter
# (file) is also required and is a filename that
# will be given the extension .asc or .bin,
# depending on the chosen format, and the third
# parameter (weight) is an optional real number
# with default value 1.0.

read_file asc test

# Positional parameters and default value for
# weight. Equivalent to setting format=asc,
# file=test.asc and weight=1.0.

read_file file=test format=asc weight=2.0

# Named parameters in any order.