Qore Programming Language Reference Manual  0.9.3.2
Parse Directives

Qore supports the use of parse directives in order to set parsing options, load modules, control warnings, and include other files.

Parse directives that set parsing options can be used any time parse options have not been locked on a Program object. They are used most often when it's not possible or desirable to set the parse options in the qore command line.

The following are the recommended parse directives for Qore programming (note that Qore is moving toward establishing %new-style as the default syntax; all examples given in the Qore documentation are given assuming %new-style):

Parse Directives

Directive Description
%allow-bare-refs Prohibits the use of the "$" character in variable names, method calls, and object member references. This makes Qore scripts appear superficially more like C++ or Java programs.

This parse option is set by default with %new-style.

Name resolution is made in the following order when this option is set: local variables, class constants and static class vars (when parsing in class code), global variables, and (non-class) constants.

Note that implicit arguments are still referenced with the "$" character even when this parse option is set; see also %require-dollar

Since Qore 0.8.1
%allow-debugger Allows debugging actions that could be insecure such as reading the thread local variable stack

Since Qore 0.8.13
%allow-injection Allows code and dependency injections into the given Program object
%allow-weak-references Allows the use of the weak assignment operator (:=)

Since Qore 0.8.13
%append-include-path Appends the given directories to qore's include path; also performs environment variable substitution
%append-module-path Appends the given directories to qore's module path; also performs environment variable substitution

Since Qore 0.8.6
%assume-global Resets the default Qore behavior of assuming global variable scope when variables are first referenced if no my or our is present; use after %assume-local to reset the default parsing behavior.

This parse option is also set with %old-style

Since Qore 0.8.4
%assume-local Assume local variable scope when variables are first referenced if no my or our is present. When used with %allow-bare-refs, local variables without my must be declared with a data type restriction (can be any).

This parse option is set by default with %new-style; see also %assume-global

Since Qore 0.8.1
%broken-int-assignments Use old pre-0.8.12 broken int and softint runtime handling where type errors were ignored at runtime
%broken-list-parsing Use old pre-0.8.12 broken list parsing where certain lists without parentheses would be rewritten to make top-level statements like list l = 1, 2, 3; valid
%broken-logic-precedence Use old pre-0.8.12 precedence of logical and bitwise operators
%broken-loop-statement Accept break and continue outside of loops as with pre-0.8.13
%broken-operators Accept spaces in multi-character operators as with pre-0.8.12
%broken-references Do not enforce reference and *reference type restrictions as with pre-0.8.13
%broken-sprintf Use pre-0.9 sprintf format handling where no argument is handled differently than NOTHING
%correct-int-assignments revert the effect of the %broken-int-assignments parse option
%correct-list-parsing revert the effect of the %broken-list-parsing parse option
%correct-logic-precedence revert the effect of the %broken-logic-precedence parse option
%correct-loop-statement revert the effect of the %broken-loop-statement parse option
%correct-operators revert the effect of the %broken-operators parse option
%correct-references revert the effect of the %broken-references parse option
%correct-sprintf revert the effect of the %broken-sprintf parse option
%define Creates and optionally sets a value for a parse define

Since Qore 0.8.3
%disable-all-warnings Turns off all warnings
%disable-warning warning-code Disables the named warning until %enable-warning is encountered with the same code or %enable-all-warnings is encountered
%else Allows for parsing an alternate block when used with the %ifdef or %ifndef parse directives (for conditional parsing based on parse defines)

Since Qore 0.8.3
%enable-all-warnings Turns on all warnings
%enable-warning warning-code Enables the named warning
%endif Closes a conditionally-parsed block started by the %ifdef or %ifndef parse directives

Since Qore 0.8.3
%endtry Closes a %try-module or %try-reexport-module block

Since Qore 0.8.6
%exec-class class_name Instantiates the named class as the application class; also turns on %no-top-level. If the program is read from stdin or from the command line, an argument must be given specifying the class name. Any top level statements before this directive are silently ignored
%ifdef Opens a conditionally-parsed block; if the given parse define is defined, then the block after the %ifdef is parsed until either an %else or an %endif

Since Qore 0.8.3
%ifndef Opens a conditionally-parsed block; if the given parse define is not defined, then the block after the %ifdef is parsed until either an %else or an %endif

Since Qore 0.8.3
%include file_name Starts parsing file_name immediately. Parsing resumes with the current input after file_name has been completely parsed
%lockdown Made up of %no-external-access, %no-threads, and %no-io; equivalent to parse option Qore::PO_LOCKDOWN and the –lockdown command line option
%lock-options Prohibits further changes to parse options (equivalent to the --lock-options command line option)
%lock-warnings Prohibits further changes to the warning mask (equivalent to the --lock-warnings command line option)
%loose-args reverts the effect of the %strict-args parse options
%new-style Sets both %allow-bare-refs and %assume-local. These two options together make programming in Qore superficially more like programming in C++ or Java programs; use this if you dislike programming with the "$" sign, for example; see also %old-style

Since Qore 0.8.1
%old-style Resets default Qore parsing behavior by setting %require-dollar and %assume-global; this option is the opposite of %new-style

Since Qore 0.8.4
%no-debugging Forbids debugging of the current Program object

Since Qore 0.8.13
%no-class-defs Disallows class definitions; equivalent to Qore::PO_NO_CLASS_DEFS and the --no-class-defs command line option
%no-child-restrictions Allows child program objects to have parse option restrictions that are not a strict subset of the parents'; equivalent to parse option Qore::PO_NO_CHILD_PO_RESTRICTIONS and the --no-child-restrictions command line option
%no-constant-defs Disallows constant definitions; equivalent to parse option Qore::PO_NO_CONSTANT_DEFS and the --no-constant-defs command line option
%no-database Disallows access to database functionality (for example the Datasource class; equivalent to parse option Qore::PO_NO_DATABASE and the --no-database command line option
%no-external-access made up of %no-process-control, %no-network, %no-filesystem, %no-database, %no-external-info, and %no-modules; equivalent to parse option Qore::PO_NO_EXTERNAL_ACCESS and the --no-external-access command line option
%no-external-info Disallows any access to functionality that provides external information (see %no-external-info for a list of features not available with this parse option); equivalent to parse option Qore::PO_NO_EXTERNAL_INFO and the --no-external-info command line option
%no-external-process Disallows any access to external processes (see %no-external-process for a list of features not available with this parse option); equivalent to parse option Qore::PO_NO_EXTERNAL_PROCESS and the --no-external-process command line option
%no-filesystem Disallows access to the local filesystem; equivalent to parse option Qore::PO_NO_FILESYSTEM and the --no-filesystem command line option
%no-global-vars Disallows the use of global variables; equivalent to parse option Qore::PO_NO_GLOBAL_VARS and the --no-global-vars command line option
%no-gui Disallows functionality that draws graphics to the display; equivalent to parse option Qore::PO_NO_GUI and the -pno-gui command line option
%no-io Made up of %no-gui | %no-terminal-io | %no-filesystem | %no-network | %no-database; equivalent to parse option Qore::PO_NO_IO and the –no-io command line option
%no-locale-control Disallows access to functionality that changes locale information (see no-locale-control for a list of features not available with this parse option); equivalent to parse option Qore::PO_NO_LOCALE_CONTROL and the --no-locale-control command line option
%no-modules Disallows loading modules with the %requires, %try-module, and %try-reexport-module parse directive or at runtime with load_module(); equivalent to Qore::PO_NO_MODULES and the -pno-modules command line option

Since Qore 0.8.4
%no-namespace-defs Disallows new namespace definitions; equivalent to Qore::PO_NO_NAMESPACE_DEFS and the --no-namespace-defs command line option
%no-network Disallows access to the network; equivalent to parse option Qore::PO_NO_NETWORK and the --no-network command line option
%no-new Disallows use of the new operator; equivalent to parse option Qore::PO_NO_NEW and the --no-new command line option
%no-process-control Disallows access to functions that would affect the current process (see %no-process-control for a list of features not available with this parse option); equivalent to parse option Qore::PO_NO_PROCESS_CONTROL and the --no-process-control command line option
%no-reflection Disallows access to the reflection API provided by the reflection module; equivalent to parse option Qore::PO_NO_REFLECTION

Since Qore 0.9
%no-subroutine-defs Disallows subroutine (function) definitions; equivalent to parse option Qore::PO_NO_SUBROUTINE_DEFS and the --no-subroutine-defs command line option
%no-terminal-io Disallows access to terminal I/O (see %no-terminal-io for a list of features not available with this parse option); equivalent to parse option Qore::PO_NO_TERMINAL_IO and the -pno-terminal-io command line option
%no-thread-classes Disallows access to thread classes (see %no-thread-classes for a list of features not available with this parse option); equivalent to parse option Qore::PO_NO_THREAD_CLASSES and the --no-thread-classes command line option
%no-thread-control Disallows access to thread control operations (see %no-thread-control for a list of features not available with this parse option); equivalent to parse option Qore::PO_NO_THREAD_CONTROL and the --no-thread-control command line option
%no-thread-info Disallows any access to functionality that provides threading information (see %no-thread-info for a list of features not available with this parse option); equivalent to parse option Qore::PO_NO_THREAD_INFO and the --no-thread-info command line option
%no-threads Disallows access to all thread control operations and thread classes (equivalent to --no-thread-control and --no-thread-classes together); equivalent to parse option Qore::PO_NO_THREADS and the --no-threads command line option
%no-top-level Disallows any further top level code; equivalent to parse option Qore::PO_NO_TOP_LEVEL_STATEMENTS and the --no-top-level command line option
%no-transient Removes the Transient Members keyword for backwards-compatibility; equivalent to parse option Qore::PO_NO_TRANSIENT
%no-uncontrolled-apis Disallows access to uncontrolled APIs such as external language bindings or direct generic system call APIs that could bypass Qore's sandboxing controls
%perl-bool-eval Set to mimic perl's boolean evaluation; this is the default with qore >= 0.8.6; prior to this version, by default qore used strict mathematic boolean evaluation, where any value converted to 0 is False and otherwise it's is True.

As of Qore 0.8.6+, this parse option is only needed if %strict-bool-eval is set.

When this option is set, boolean evaluation follows the same rules as <value>::val(); see also %strict-bool-eval

Since Qore 0.8.6
%push-parse-options Stores parse options so that they will be restored when the current file is done parsing; use in include files to ensure parse options are set appropriately for the file being parsed
%require-dollar Resets the default Qore behavior where the use of the "$" character in variable names, method calls, and object member references is required; use after %allow-bare-refs to reset the default parsing behavior

Since Qore 0.8.4
%require-our Requires global variables to be declared with our prior to use (like perl's use strict vars pragma); equivalent to parse option Qore::PO_REQUIRE_OUR and the --require-our command line option
%require-prototypes Requires type declarations for all function and method parameters and return types. Variables and object members do not need to have type declarations; equivalent to parse option Qore::PO_REQUIRE_PROTOTYPES and the --require-prototypes command line option

Since Qore 0.8.0
%require-types Requires type declarations for all function and method parameters, return types, variables, and object members; equivalent to parse option Qore::PO_REQUIRE_TYPES and the --require-types command line option; also implies %strict-args

Since Qore 0.8.0
%requires[(reexport)] feature [<|<=|=|>=|> version] If the named feature is not already present in Qore, then the QORE_MODULE_DIR environment variable is used to provide a list of directories to seach for a module with the same name (feature[-api-x.y].qmod for binary modules or feature.qm for user modules). If the module is not found, then the qore default module directory is checked.

This directive must be used to load modules providing parse support (i.e. modules providing classes, constants, functions, etc that are resolved at parse time).

If version information is provided, then it is compared with the module's version information, and if it does not match a parse exception is raised.

See also Qore::load_module() for a function providing run-time module loading and %try-module and %try-reexport-module for a similar parse directive that allows module loading errors to be handled at runtime
%set-time-zone Sets the time zone for the current program from a UTC offset (with format "+/-[00[:00[:00]]"; ":" characters are optional) or a time zone region name (ex: "Europe/Prague")

Since Qore 0.8.3
%strict-args Prohibits access to builtin functions and methods flagged with RUNTIME_NOOP and also causes errors to be raised if excess arguments are given to functions that do not access excess arguments and if a non-list lvalue is passed to the Push Operator (push), Pop Operator (pop), or Shift Operator (shift)

Since Qore 0.8.0
%strict-bool-eval Sets qore's default strict mathematic boolean evaluation mode, where any value converted to 0 is False and otherwise it's is True; this was how qore behaved by default prior to v0.8.6.

Equivalent to parse option Qore::PO_STRICT_BOOLEAN_EVAL and the -pstrict-bool-eval command line option.

See also %perl-bool-eval

Since Qore 0.8.6
%strong-encapsulation Disallows out-of-line class and namespace declarations.

Since Qore 0.8.13
%try-module [(var_decl)] feature [<|<=|=|>=|> version] If the named feature is not already present in Qore, then the QORE_MODULE_DIR environment variable is used to provide a list of directories to seach for a module with the same name (feature[-api-x.y].qmod for binary modules or feature.qm for user modules). If the module is not found, then the qore default module directory is checked.

If an error occurs loading the module, then the variable declared after %try-module is instantiated with the exception information, and the code up to the %endtry parse declaration is parsed into the program, allowing for the qore script/program to handle module loading errors at parse time for modules that must be loaded at parse time.

If version information is provided, then it is compared with the module's version information, and if it does not match a parse exception is raised that is handled like any other load error.

See also Qore::load_module() for a function providing run-time module loading and %requires for a similar declaration that does not allow for parse-time module loading error handling.

Since Qore 0.8.6
%try-reexport-module [(var_decl)] feature [<|<=|=|>=|> version] The same as %try-module except that if used in a user module, the module is reexported to the importing code<br>
Since Qore 0.8.13

%allow-bare-refs

Parse Directive:
%allow-bare-refs
Command Line:
–allow-bare-refs, -B
Parse Option Constant:
Qore::PO_ALLOW_BARE_REFS
Description:
Prohibits the use of the "$" character in variable names, method calls, and object member references. This makes Qore scripts appear superficially more like C++ or Java programs. This parse option is set by default with %new-style and is the opposite of %require-dollar.

Name resolution is made in the following order when this option is set:
Note
  • when using this option (or %new-style) the lack of $ characters in variable names makes it necessary to declare local variables before using them
  • ref implicit_arguments "implicit arguments" are still referenced with the "$" character even when this parse option is set.
Since
Qore 0.8.1
See also
%require-dollar

%allow-debugger

Parse Directive:
%allow-debugger
Command Line:
n/a
Parse Option Constant:
Qore::PO_ALLOW_DEBUGGER
Description:
Allows access to functionality that can be used to debug other Program containers. Mainly related to classes:
Since
Qore 0.8.13

%allow-injection

Parse Directive:
%allow-injection
Command Line:
-pallow-injection
Parse Option Constant:
Qore::PO_ALLOW_INJECTION
Description:
Allows for code and dependency injections in the given Program object.
See also
Since
Qore 0.8.12

%allow-weak-references

Parse Directive:
%allow-weak-references
Command Line:
-pallow-weak-references
Parse Option Constant:
Qore::PO_ALLOW_WEAK_REFERENCES
Description:
Allows the use of the weak assignment operator (:=).
See also
Since
Qore 0.8.13

%append-include-path

Parse Directive:
%append-include-path dir1[:dir2...]
Command Line:
n/a
Parse Option Constant:
n/a
Description:
Appends the given directories to qore's include path; also performs environment variable substitution. Only directories that exist and are readable are added to the include path.
See also
%append-module-path

%append-module-path

Parse Directive:
%append-module-path dir1[:dir2...]
Command Line:
n/a
Parse Option Constant:
n/a
Description:
Appends the given directories to qore's module path; also performs environment variable substitution. Only directories that exist and are readable are added to the module path.
Since
Qore 0.8.6
See also
%append-include-path

%assume-global

Parse Directive:
%assume-global
Command Line:
n/a
Parse Option Constant:
n/a
Description:
Resets the default Qore behavior of assuming global variable scope when variables are first referenced if no my or our is present; use after %assume-local to reset the default parsing behavior. This parse option is also set with %old-style
Since
Qore 0.8.4
See also
%assume-local

%assume-local

Parse Directive:
%assume-local
Command Line:
--assume-local
Parse Option Constant:
Qore::PO_ASSUME_LOCAL
Description:
Assume local variable scope when variables are first referenced if no my or our is present. When used with %allow-bare-refs, local variables without my must be declared with a data type restriction (can be any). This parse option is set by default with %new-style and is the opposite of %assume-global
Since
Qore 0.8.1
See also
%assume-global

%broken-int-assignments

Parse Directive:
%broken-int-assignments
Command Line:
-pbroken-int-assignments
Parse Option Constant:
Qore::PO_BROKEN_INT_ASSIGNMENTS
Description:
Use old pre-0.8.12 broken int and softint runtime handling where type errors were ignored at runtime.
See also
%correct-int-assignments
Since
Qore 0.8.12

%broken-list-parsing

Parse Directive:
%broken-list-parsing
Command Line:
-pbroken-list-parsing
Parse Option Constant:
Qore::PO_BROKEN_LIST_PARSING
Description:
Use old pre-0.8.12 broken list parsing where certain lists without parentheses would be rewritten to make top-level statements like list l = 1, 2, 3; valid.
See also
%correct-list-parsing
Since
Qore 0.8.12

%broken-logic-precedence

Parse Directive:
%broken-logic-precedence
Command Line:
-pbroken-logic-precedence
Parse Option Constant:
Qore::PO_BROKEN_LOGIC_PRECEDENCE
Description:
Use old pre-0.8.12 precedence where the && had the same precedence as || and all three bitwise operators ( &, |, ^) shared the same precedence.

An example of impact of %broken-logic-precedence directive:

See also
%correct-logic-precedence
Since
Qore 0.8.12

%broken-loop-statement

Parse Directive:
%broken-loop-statement
Command Line:
--broken-loop-statement
Parse Option Constant:
Qore::PO_BROKEN_LOOP_STATEMENT
Description:
Use old pre-0.8.13 handling of break/continue: continue statements in a switch behave like a break statement, both break and continue behave like return when used outside of a loop.
Since
Qore 0.8.13

%broken-operators

Parse Directive:
%broken-operators
Command Line:
-pbroken-operators
Parse Option Constant:
Qore::PO_BROKEN_OPERATORS
Description:
Accept spaces in the following multi-character operators for backwards compatibility with Qore before 0.8.12: For example, when this parse directive is not set, the following is a bug:
int i = 1;
i+ =4;
When this parse directive is set; the above code is accepted.
See also
%correct-operators
Since
Qore 0.8.12

%broken-references

Parse Directive:
%broken-references
Command Line:
--pbroken-references
Parse Option Constant:
Qore::PO_BROKEN_REFERENCES
Description:
Do not enforce reference and *reference type restrictions as with pre-0.8.13; when this option is in effect, the reference and *reference type restrictions are ignored and have no type restrictions.
Since
Qore 0.8.3

%broken-sprintf

Parse Directive:
%broken-sprintf
Command Line:
--pbroken-sprintf
Parse Option Constant:
Qore::PO_BROKEN_SPRINTF
Description:
Use pre-0.9 sprintf format handling where no argument is handled differently than NOTHING
See also
%correct-sprintf
Since
Qore 0.9

%correct-int-assignments

Parse Directive:
n/a
Command Line:
n/a
Parse Option Constant:
n/a
Description:
Reverts the effect of the %broken-int-assignments parse option.
See also
%broken-int-assignments
Since
Qore 0.8.12.10

%correct-list-parsing

Parse Directive:
n/a
Command Line:
n/a
Parse Option Constant:
n/a
Description:
Reverts the effect of the %broken-list-parsing parse option.
See also
%broken-list-parsing
Since
Qore 0.8.12.10

%correct-logic-precedence

Parse Directive:
n/a
Command Line:
n/a
Parse Option Constant:
n/a
Description:
Reverts the effect of the %broken-logic-precedence parse option.
See also
%broken-logic-precedence
Since
Qore 0.8.12.10

%correct-loop-statement

Parse Directive:
%correct-loop-statement
Command Line:
n/a
Parse Option Constant:
n/a
Description:
Reverts the effect of the %broken-loop-statement parse option.
See also
%broken-loop-statement
Since
Qore 0.8.13

%correct-operators

Parse Directive:
%correct-operators
Command Line:
n/a
Parse Option Constant:
n/a
Description:
Reverts the effect of the %broken-operators parse option.
See also
%broken-operators
Since
Qore 0.8.12.10

%correct-references

Parse Directive:
%correct-references
Command Line:
n/a
Parse Option Constant:
n/a
Description:
Reverts the effect of the %broken-references parse option.
See also
%broken-references
Since
Qore 0.8.13

%correct-sprintf

Parse Directive:
%correct-sprintf
Command Line:
n/a
Parse Option Constant:
n/a
Description:
Reverts the effect of the %broken-sprintf parse option.
See also
%broken-sprintf
Since
Qore 0.9

%define

Parse Directive:
%define
Command Line:
--define, -D
Parse Option Constant:
n/a
Description:
Creates and optionally sets a value for a parse define
Since
Qore 0.8.3

%disable-all-warnings

Parse Directive:
%disable-all-warnings
Command Line:
n/a, warnings are disabled by default
Parse Option Constant:
n/a
Description:
Disables all warnings while parsing. See Warnings for more information.

%disable-warning

Parse Directive:
%disable-warning
Command Line:
n/a, warnings are disabled by default
Parse Option Constant:
n/a
Description:
Disables the named warning while parsing. See Warnings for more information.

%else

Parse Directive:
%else
Command Line:
n/a
Parse Option Constant:
n/a
Description:
Allows for parsing an alternate block when used with the %ifdef or %ifndef parse directives (for conditional parsing based on parse defines)
Since
Qore 0.8.3

%enable-all-warnings

Parse Directive:
%enable-all-warnings
Command Line:
--enable-all-warnings, -W
Parse Option Constant:
n/a
Description
Enables all warnings while parsing. See Warnings for more information.

%enable-warning

Parse Directive:
%enable-warning
Command Line:
--enable-warning, -w
Parse Option Constant:
n/a
Description:
Enables the named warning while parsing. See Warnings for more information.

%endif

Parse Directive:
%endif
Command Line:
n/a
Parse Option Constant:
n/a
Description:
Closes a conditionally-parsed block started by the %ifdef or %ifndef parse directives (for conditional parsing based on parse defines)
Since
Qore 0.8.3

%endtry

Parse Directive:
%endtry
Command Line:
n/a
Parse Option Constant:
n/a
Description:
Closes a %try-module or %try-reexport-module block
Since
Qore 0.8.6

%exec-class

Parse Directive:
%exec-class
Command Line:
--exec-class, -x
Parse Option Constant:
n/a
Description:
Executes the named class as the application class and turns on %no-top-level as well. Any top level statements before this directive are silently ignored.
See also
Qore::set_return_value()

%ifdef

Parse Directive:
%ifdef
Command Line:
n/a
Parse Option Constant:
n/a
Description:
Opens a conditionally-parsed block; if the given parse define is defined, then the block after the %ifdef is parsed until either an %else or an %endif
Since
Qore 0.8.3

%ifndef

Parse Directive:
%ifndef
Command Line:
n/a
Parse Option Constant:
n/a
Description:
Opens a conditionally-parsed block; if the given parse define is not defined, then the block after the %ifndef is parsed until either an %else or an %endif
Since
Qore 0.8.3

%include

Parse Directive:
%include
Command Line:
n/a
Parse Option Constant:
n/a
Description:
Includes a file to be parsed. If the path is not absolute (i.e. starting with ""/"), then files are searched first in the directory of the currently-executing script (if known), then in each path in the environment variable QORE_INCLUDE_DIR.
If the first character of the include target is '$', then environment variable substitution is performed on the leading environment variable
Since
Qore 0.8.9 added environment variable substitution

%lockdown

Parse Directive:
%lockdown
Command Line:
--lockdown
Parse Option Constant:
Qore::PO_LOCKDOWN
Description:
The most restrictive parse restriction, making any external access, threading, i/o, etc illegal. Made up of %no-external-access, %no-threads, and %no-io

%lock-options

Parse Directive:
%lock-options
Command Line:
--lock-options, -K
Parse Option Constant:
n/a
Description:
Prohibits further changes to parse options.

%lock-warnings

Parse Directive:
%lock-warnings
Command Line:
--lock-warnings, -A
Parse Option Constant:
Qore::PO_LOCK_WARNINGS
Description:
Prohibits further changes to the warning mask.

%loose-args

Parse Directive:
n/a
Command Line:
n/a
Parse Option Constant:
n/a
Description:
Reverts the effect of the %strict-args parse option.
See also
%loose-args

%new-style

Parse Directive:
%new-style
Command Line:
--new-style, -n
Parse Option Constant:
Qore::PO_NEW_STYLE
Description:
Sets both %allow-bare-refs and %assume-local. These two options together make programming in Qore superficially more like programming in C++ or Java programs; use this if you dislike programming with the "$" sign, for example.
See also
%old-style
Note
  • Qore is moving toward establishing %new-style as the default syntax; all examples given in the Qore documentation are given assuming %new-style.
  • when using this option (or %allow-bare-refs) the lack of $ characters in variable names makes it necessary to declare local variables before using them
Since
Qore 0.8.1

%old-style

Parse Directive:
%old-style
Command Line:
n/a
Parse Option Constant:
n/a
Description:
Resets default Qore parsing behavior by setting %require-dollar and %assume-global; this option has the opposite effect of %new-style
See also
%new-style
Since
Qore 0.8.4

%no-debugging

Parse Directive:
%no-debugging
Command Line:
n/a
Parse Option Constant:
Qore::PO_NO_DEBUGGING
Description:
Forbids debugging of the current Program object; when this parse option is set, debuggers cannot attach to the Program object.
Since
Qore 0.8.13

%no-child-restrictions

Parse Directive:
%no-child-restrictions
Command Line:
--no-child-restrictions, -I
Parse Option Constant:
Qore::PO_NO_CHILD_PO_RESTRICTIONS
Description:
Allows child program objects to have parse option restrictions that are not a strict subset of the parents'.

%no-class-defs

Parse Directive:
%no-class-defs
Command Line:
--no-class-defs
Parse Option Constant:
Qore::PO_NO_CLASS_DEFS
Description:
Disallows new class definitions. Any use of the reserved word class will result in a parse exception.

%no-constant-defs

Parse Directive:
%no-constant-defs
Command Line:
--no-constant-defs
Parse Option Constant:
Qore::PO_NO_CONSTANT_DEFS
Description:
Disallows new constant definitions. Any use of the reserved word const will result in a parse exception.

%no-database

Parse Directive:
%no-database
Command Line:
--no-database
Parse Option Constant:
Qore::PO_NO_DATABASE
Description:
Disallows access to database functionality. Currently this means that access to the following classes is restricted:

%no-external-access

Parse Directive:
%no-external-access
Command Line:
--no-external-access
Parse Option Constant:
Qore::PO_NO_EXTERNAL_ACCESS
Description:
This option is made up of %no-process-control, %no-network, %no-filesystem, %no-database, %no-external-info, %no-modules, and %no-uncontrolled-apis
See also
%lockdown

%no-external-info

Parse Directive:
%no-external-info
Command Line:
--no-external-info
Parse Option Constant:
Qore::PO_NO_EXTERNAL_INFO
Description:
Disallows any access to functionality that provides external information. The following features are unavailable with this option:

%no-external-process

Parse Directive:
%no-external-process
Command Line:
--no-external-process, -E
Parse Option Constant:
Qore::PO_NO_EXTERNAL_PROCESS
Description:
Disallows any access to external processes. The following features are unavailable with this option:

%no-filesystem

Parse Directive:
%no-filesystem
Command Line:
--no-filesystem, -F
Parse Option Constant:
Qore::PO_NO_FILESYSTEM
Description:
Disallows any access to the external filesystem. The following features are unavailable with this option:

%no-global-vars

Parse Directive:
%no-global-vars
Command Line:
--no-global-vars, -G
Parse Option Constant:
Qore::PO_NO_GLOBAL_VARS
Description:
Disallows the use of global variables.

%no-gui

Parse Directive:
%no-gui
Command Line:
--no-gui, –set-parse-option=no-gui, -pno-gui
Parse Option Constant:
Qore::PO_NO_GUI
Description:
Disallows the use of functionality that draws graphics to the display (this functionality is not implemented in the qore library; only implemented in modules).

%no-io

Parse Directive:
%no-io
Command Line:
--no-io, –set-parse-option=no-io, -pno-io
Parse Option Constant:
Qore::PO_NO_IO
Description:
Made up of %no-gui | %no-terminal-io | %no-filesystem | %no-network | %no-database | %no-uncontrolled-apis

%no-locale-control

Parse Directive:
%no-locale-control
Command Line:
--no-locale-control, -P
Parse Option Constant:
Qore::PO_NO_LOCALE_CONTROL
Description:
Disallows access to functions that would affect the locale settings of the current program. The following features are unavailable with this option:

%no-modules

Parse Directive:
%no-modules
Command Line:
-pno-modules
Parse Option Constant:
Qore::PO_NO_MODULES
Description:
Disallows loading modules with the %requires, %try-module, or %try-reexport-module directives or at runtime with load_module()
Since
Qore 0.8.4

%no-namespace-defs

Parse Directive:
%no-namespace-defs
Command Line:
--no-namespace-defs, -M
Parse Option Constant:
Qore::PO_NO_NAMESPACE_DEFS
Description:
Disallows new namespace definitions.

%no-network

Parse Directive:
%no-network
Command Line:
--no-network, -Y
Parse Option Constant:
Qore::PO_NO_NETWORK
Description:
Disallows any access to the network. The following features are unavailable with this option:

%no-new

Parse Directive:
%no-new
Command Line:
--no-new, -N
Parse Option Constant:
Qore::PO_NO_NEW
Description:
Disallows use of the new operator.

%no-process-control

Parse Directive:
%no-process-control
Command Line:
--no-process-control, -P
Parse Option Constant:
Qore::PO_NO_PROCESS_CONTROL
Description:
Disallows access to functions that would affect the current process. The following features are unavailable with this option:

%no-reflection

Parse Directive:
%no-reflection
Command Line:
--pno-reflection
Parse Option Constant:
Qore::PO_NO_REFLECTION
Description:
Disallows access to the reflection API provided by the reflection module.
Since
Qore 0.9

%no-subroutine-defs

Parse Directive:
%no-subroutine-defs
Command Line:
--no-subroutine-defs, -S
Parse Option Constant:
Qore::PO_NO_SUBROUTINE_DEFS
Description:
Disallows subroutine (function) definitions.

%no-terminal-io

Parse Directive:
%no-terminal-io
Command Line:
--no-terminal-io,--set-parse-option=no-terminal-io, -pno-terminal-io
Parse Option Constant:
Qore::PO_NO_TERMINAL_IO
Description:
Disallows access to terminal input and output. The following features are unavailable with this option:

%no-thread-classes

Parse Directive:
%no-thread-classes
Command Line:
--no-thread-classes
Parse Option Constant:
Qore::PO_NO_THREAD_CLASSES
Description:
Disallows access to thread classes. The following features are unavailable with this option:

%no-thread-control

Parse Directive:
%no-thread-control
Command Line:
--no-thread-control, -R
Parse Option Constant:
Qore::PO_NO_THREAD_CONTROL
Description:
Disallows access to thread control operations. The following features are unavailable with this option:

%no-thread-info

Parse Directive:
%no-thread-info
Command Line:
--no-thread-info
Parse Option Constant:
Qore::PO_NO_THREAD_INFO
Description:
Disallows access to functionality that provides information about threading. The following features are unavailable with this option:

%no-threads

Parse Directive:
%no-threads
Command Line:
--no-threads, -T
Parse Option Constant:
Qore::PO_NO_THREADS
Description:
Disallows access to all thread control operations and thread classes (equivalent to %no-thread-control and %no-thread-classes together).

%no-top-level

Parse Directive:
%no-top-level
Command Line:
--no-top-level, -L
Parse Option Constant:
Qore::PO_NO_TOP_LEVEL_STATEMENTS
Description:
Disallows top level code from this point on, any top level statements before this directive are still allowed and become part of the Program context.

%no-transient

Parse Directive:
%no-transient
Command Line:
--pno-transient
Parse Option Constant:
Qore::PO_NO_TRANSIENT
Description:
Removes the Transient Members keyword for backwards-compatibility.
Since
Qore 0.9

%no-uncontrolled-apis

Parse Directive:
no-uncontrolled-apis
Command Line:
-p=no-uncontrolled-apis
Parse Option Constant:
Qore::PO_NO_UNCONTROLLED_APIS
Description:
Disallows access to uncontrolled APIs such as external language bindings or direct generic system call APIs that could bypass Qore's sandboxing controls.

%perl-bool-eval

Parse Directive:
%perl-bool-eval
Command Line:
n/a
Parse Option Constant:
n/a
Description:
Set to mimic perl's (and Python's) boolean evaluation; this is now the default (as of qore version 0.8.6); prior to this version, by default qore used strict mathematic boolean evaluation, where any value converted to 0 is False and otherwise it's is True.

As of Qore 0.8.6+, %perl-bool-eval is the default behavior and therefore only needs to be set if %strict-bool-eval was set first.

When this option is set, boolean evaluation follows the same rules as <value>::val(); for example:
string str = "hello";
if (str)
printf("string is: %y\n", str);

With this option set (the default), the above prints out:
string is: "hello"
When it's not set (i.e. %strict-bool-eval is set), nothing is printed out as the string expression evaluates to False due to qore's old strict mathematical boolean evaluation.

Basically with this option set, qore's boolean evaluation becomes like perl's and Python's, whereas any expression that has the following values is False: NOTHING, string "0" and empty strings, integer, float, and number 0 (zero), absolute date 1970-01-01Z (ie the start of the epoch with an offset of 0), relative date PT0H (ie any relative date with a 0 duration), NULL, empty binary objects, empty hashes, and empty lists. All other values are True.
Note
also affects the boolean(any) function
See also
%strict-bool-eval
Since
Qore 0.8.6

%push-parse-options

Parse Directive:
%push-parse-options
Command Line:
n/a
Parse Option Constant:
n/a
Description:
Stores parse options so that they will be restored when the current file is done parsing; use in include files to ensure parse options are set appropriately for the file being parsed.

For example:
%push-parse-options
%new-style

%require-dollar

Parse Directive:
%require-dollar
Command Line:
n/a
Parse Option Constant:
n/a
Description:
Resets the default Qore behavior where the use of the "$" character in variable names, method calls, and object member references is required; use after %allow-bare-refs to reset the default parsing behavior
Since
Qore 0.8.4

%require-our

Parse Directive:
%require-our
Command Line:
--require-our, -O
Parse Option Constant:
Qore::PO_REQUIRE_OUR
Description:
Requires global variables to be declared with our prior to use (recommended to use for all larger scripts/programs).

%require-prototypes

Parse Directive:
%require-prototypes
Command Line:
--require-prototypes
Parse Option Constant:
Qore::PO_REQUIRE_PROTOTYPES
Description:
Requires type declarations for all function and method parameters and return types. Variables and object members do not need to have type declarations with this option.
See also
%require-types, which is a superset of this option.

%require-types

Parse Directive:
%require-types
Command Line:
--require-types
Parse Option Constant:
Qore::PO_REQUIRE_TYPES
Description:
Requires type declarations for all function and method parameters, return types, variables, and object members. Additionally causes CALL-WITH-TYPE-ERRORS exceptions to be thrown if a function, method, or code call is made with excess arguments not handled by the target. In case calls are made to user code over a Program barrier, the parse options of the target code determine if this exception is raised;
See also
%require-prototypes, which is a subset of this option.

%requires

Parse Directive:
%requires[(reexport)] feature [<|<=|=|>=|> version]
Command Line:
--load, -l
Parse Option Constant:
n/a
Description:
Loads a Qore module immediately. The parse directive can be used to load a module during parsing, and the command line version can be used to load a module before parsing. If the optional (reexport) option is used in a user module, then any modules loaded with this form of the %requires parse directive will also be imported into the importing Program.

From Qore 0.7.1, you can specify a comparison operator (one of <, <=, =, >=, or >) and version information after the module name as well. Version numbers are compared via integer comparisons of each element, where elements are separated by a ".". If one of the versions does not have as many elements as another, the missing elements are assumed to be "0" (i.e. version "1.0" compared with version "1.0.1" will be extended to "1.0.0").

For example:
%requires oracle >= 1.0.1

This will load the oracle module if it is at least version 1.0.1.

For example:
%requires(reexport) Mime

If this form is used in a user module, all public definitions from the Mime module would also be loaded into any Program that requires the user module.

Note that there is one special feature name: "qore". This pseudo-feature can be used to check the minimum Qore version; if this feature is requested with version information, then the Qore library's version information is used for the version number comparison.
See also
%try-module and %try-reexport-module for similar parse directives that allows module loading errors to be caught and handled at parse-time

%set-time-zone

Parse Directive:
%set-time-zone
Command Line:
--time-zone, -z
Parse Option Constant:
none; this is set by calling Qore::TimeZone::setRegion() or Qore::TimeZone::setUTCOffset()
Description:
Sets the time zone for the current program from a UTC offset (with format "+/-00[:00[:00]]"; ":"" characters are optional) or a time zone region name (ex: \c "Europe/Prague").

%strict-args

Parse Directive:
%strict-args
Command Line:
--strict-args
Parse Option Constant:
Qore::PO_STRICT_ARGS
Description:
Prohibits access to builtin functions and methods flagged with RUNTIME_NOOP and also causes errors to be raised if excess arguments are given to functions that do not access excess arguments and if a non-list lvalue is passed to the Push Operator (push), Pop Operator (pop), or Shift Operator (shift). Additionally, If a function, method, or code call is made with excess arguments not handled by the target, a CALL-WITH-TYPE-ERRORS exception is thrown. In case calls are made to user code over a Program barrier, the parse options of the target code determine if this exception is raised;
See also
%loose-args

%strict-bool-eval

Parse Directive:
%strict-bool-eval
Command Line:
-pstrict-bool-eval
Parse Option Constant:
Qore::PO_STRICT_BOOLEAN_EVAL
Description:
When set, this option enables qore's default strict mathematic boolean evaluation, where any value converted to 0 is False and otherwise it's is True.

This option takes effect at runtime.

For example:
string str = "hello";
if (str)
printf("string is: %y\n", str);

If %strict-bool-eval is set, then Qore's boolean evaluation will evaluate "hello" in a strict mathematical sense and convert it to 0, which is False, so nothing would be printed out, but when %perl-bool-eval is enabled, this will be True (following the rules for <string>::val()).

Qore's strict mathematical boolean evaluation was the default prior to Qore 0.8.6, however it was considered non-intuitive and a design bug, and therefore the default behavior of the language was changed to a more intuitive form of boolean evaluation as documented in %perl-bool-eval.
Note
also affects the boolean(any) function
See also
perl-bool-eval
Since
Qore 0.8.6

%strong-encapsulation

Parse Directive:
%strong-encapsulation
Command Line:
-pstrong-encapsulation
Parse Option Constant:
Qore::PO_STRONG_ENCAPSULATION
Description:
Disallows out-of-line namespace and class declarations which break encapsulation by allowing changes to existing namespaces and classes by external code.
Since
Qore 0.8.13

%try-module

Parse Directive:
%try-module [(var_decl)] feature [<|<=|=|>=|> version]
Command Line:
n/a
Parse Option Constant:
n/a
Description:
Loads a Qore module immediately; if an error occurs loading the module, then the variable declared in parentheses after %try-module is instantiated with the exception information, and the code up to the %endtry parse declaration is parsed into the program, allowing for the qore script/program to handle module loading errors at parse time for modules that must be loaded at parse time.

A comparison operator (one of <, <=, =, >=, or >) and version information can be optionally given after the module name as well. Version numbers are compared via integer comparisons of each element, where elements are separated by a ".". If one of the versions does not have as many elements as another, the missing elements are assumed to be "0" (i.e. version "1.0" compared with version "1.0.1" will be extended to "1.0.0"). Version errors are handled in the same was as any other module loading error.

For example:
%new-style
%try-module (ex) some_module > 2.0
%define DontHaveSomeModule
printf("error loading module %y: %s: %s\n", ex.arg, ex.err, ex.desc);
exit(1);
%endtry
%ifndef DontHaveSomeModule
some_module_api();
%endif

This will load the "some_module" module if it is at least version 2.0, and print an error message and exit gracefully if it cannot be loaded. Note that in order for the Qore script to be executable and exit gracefully in case the given module cannot be loaded, a parse define must be set in the %try-module block and any code that accesses definitions provided by that module must be wrapped in %ifndef blocks as in the above example.

The variable declaration in parentheses is optional; use the variant without the exception variable in code where parse option PO_NO_TOP_LEVEL_STATEMENTS is set, for example. In this case, for example, other parse options can be set before the %endtry directive.

Here is an example without a variable declaration in parentheses:
%new-style
%try-module some_module > 2.0
%define DontHaveSomeModule
%endtry

Note
  • There is one special feature name: "qore". This pseudo-feature can be used to check the minimum Qore version; if this feature is requested with version information, then the Qore library's version information is used for the version number comparison.
  • No type can be given with the %try-module variable declaration; the value assigned to the variable will be a hash.
See also
%requires for a similar parse directive where errors are handled with the default parse exception handler
Since
Qore 0.8.6; the variant without the variable declaration was introduced in Qore 0.8.6.1

%try-reexport-module

Parse Directive:
%try-reexport-module [(var_decl)] feature [<|<=|=|>=|> version]
Command Line:
n/a
Parse Option Constant:
n/a
Description:
Loads a Qore module immediately; if an error occurs loading the module, then the variable declared in parentheses after %try-module is instantiated with the exception information, and the code up to the %endtry parse declaration is parsed into the program, allowing for the qore script/program to handle module loading errors at parse time for modules that must be loaded at parse time.

A comparison operator (one of <, <=, =, >=, or >) and version information can be optionally given after the module name as well. Version numbers are compared via integer comparisons of each element, where elements are separated by a ".". If one of the versions does not have as many elements as another, the missing elements are assumed to be "0" (i.e. version "1.0" compared with version "1.0.1" will be extended to "1.0.0"). Version errors are handled in the same was as any other module loading error.

If the module is successfully loaded in a user module, then the module is also reexported to any code that requires the importing module.

For example:
%new-style
%try-reexport-module (ex) some_module > 2.0
%define DontHaveSomeModule
printf("error loading module %y: %s: %s\n", ex.arg, ex.err, ex.desc);
exit(1);
%endtry
%ifndef DontHaveSomeModule
some_module_api();
%endif

This will load the "some_module" module if it is at least version 2.0, and print an error message and exit gracefully if it cannot be loaded. Note that in order for the Qore script to be executable and exit gracefully in case the given module cannot be loaded, a parse define must be set in the %try-module block and any code that accesses definitions provided by that module must be wrapped in %ifndef blocks as in the above example.

The variable declaration in parentheses is optional; use the variant without the exception variable in code where parse option PO_NO_TOP_LEVEL_STATEMENTS is set, for example. In this case, for example, other parse options can be set before the %endtry directive.

Here is an example without a variable declaration in parentheses:
%new-style
%try-reexport-module some_module > 2.0
%define DontHaveSomeModule
%endtry

Note
  • There is one special feature name: "qore". This pseudo-feature can be used to check the minimum Qore version; if this feature is requested with version information, then the Qore library's version information is used for the version number comparison.
  • No type can be given with the %try-module variable declaration; the value assigned to the variable will be a hash.
See also
  • %try-module
  • %requires for a similar parse directive where errors are handled with the default parse exception handler
Since
Qore 0.8.13