Chapter 6. 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.

Table 6.1. Parse Directives

Directive

Description

%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

%enable-all-warnings

Turns on all warnings

%enable-warning warning-code

Enables the named warning.

%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.

%include file_name

Starts parsing file_name immediately. Parsing resumes with the current input after file_name has been completely parsed.

%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).

%no-class-defs

Disallows class definitions. Equivalent to 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 PO_NO_CHILD_RESTRICTIONS and the --no-child-restrictions command-line option.

%no-constant-defs

Disallows constant definitions. Equivalent to parse option 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 PO_NO_DATABASE and the --no-database 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 PO_NO_EXTERNAL_PROCESS and the --no-external-process command-line option.

%no-filesystem

Disallows access to the local filesystem. Equivalent to parse option PO_NO_FILESYSTEM and the --no-filesystem command-line option.

%no-global-vars

Disallows the use of global variables. Equivalent to parse option 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 PO_NO_GUI and the -pno-gui command-line option.

%no-namespace-defs

Disallows new namespace definitions. Equivalent to PO_NO_NAMESPACE_DEFS and the --no-namespace-defs command-line option.

%no-network

Disallows access to the network. Equivalent to parse option PO_NO_NETWORK and the --no-network command-line option.

%no-new

Disallows use of the new operator. Equivalent to parse option 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 PO_NO_PROCESS_CONTROL and the --no-process-control command-line option.

%no-subroutine-defs

Disallows subroutine (function) definitions. Equivalent to parse option 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 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 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 PO_NO_THREAD_CONTROL and the --no-thread-control 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 PO_NO_THREADS and the --no-threads command-line option.

%no-top-level

Disallows top level code. Equivalent to parse option PO_NO_TOP_LEVEL_STATEMENTS and the --no-top-level command-line option.

%require-our

Requires global variables to be declared with our prior to use (like perl's use strict vars pragma). Equivalent to parse option PO_REQUIRE_OUR and the --require-our command-line option.

%requires 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.qmod). 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 load_module() for a run-time module loading.


6.1. disable-all-warnings

Parse Directive

%disable-all-warnings

Command-Line

none, warnings are disabled by default

Parse Option Constant

n/a

Description

Disables all warnings while parsing. See Warnings for more information.

6.2. disable-warning

Parse Directive

%disable-warning

Command-Line

none, warnings are disabled by default

Parse Option Constant

n/a

Description

Disables the named warning while parsing. See Warnings for more information.

6.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.

6.4. 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.

6.5. 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.

6.6. include

Parse Directive

%include

Command-Line

n/a from the command-line

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.

6.7. lock-options

Parse Directive

%lock-options

Command-Line

--lock-options, -K

Parse Option Constant

n/a

Description

Prohibits further changes to parse options.

6.8. lock-warnings

Parse Directive

%lock-warnings

Command-Line

--lock-warnings, -A

Parse Option Constant

PO_LOCK_WARNINGS

Description

Prohibits further changes to the warning mask.

6.9. no-child-restrictions

Parse Directive

%no-child-restrictions

Command-Line

--no-child-restrictions, -I

Parse Option Constant

PO_NO_CHILD_PO_RESTRICTIONS

Description

Allows child program objects to have parse option restrictions that are not a strict subset of the parents'.

6.10. no-class-defs

Parse Directive

%no-class-defs

Command-Line

--no-class-defs

Parse Option Constant

PO_NO_CLASS_DEFS

Description

Disallows new class definitions. Any use of the reserved word class will result in a parse exception.

6.11. no-constant-defs

Parse Directive

%no-constant-defs

Command-Line

--no-constant-defs

Parse Option Constant

PO_NO_CONSTANT_DEFS

Description

Disallows new constant definitions. Any use of the reserved word const will result in a parse exception.

6.12. no-database

Parse Directive

%no-database

Command-Line

--no-database, -D

Parse Option Constant

PO_NO_DATABASE

Description

Disallows access to database functionality. Currently this means that access to the Datasource and DatasourcePool classes is restricted.

6.13. no-external-process

Parse Directive

%no-external-process

Command-Line

--no-external-process, -E

Parse Option Constant

PO_NO_EXTERNAL_PROCESS

Description

Disallows any access to external processes.

Table 6.2. Unavailable Features with no-external-process

Feature/Function

Description

backquote operator

The backquote operator (``) is not available.

system()

The system() function is not available.

kill()

The kill() function is not available.

exec()

The exec() function is not available.

backquote()

The backquote() function is not available.


6.14. no-filesystem

Parse Directive

%no-filesystem

Command-Line

--no-filesystem, -F

Parse Option Constant

PO_NO_FILESYSTEM

Description

Disallows any access to the external filesystem.

Table 6.3. Unavailable Features with no-filesystem

Feature/Function

Description

Dir class

The Dir class is not available.

File class

The File class is not available.

chdir()

The chdir() function is not available.

chmod()

The chmod() function is not available.

chown()

The chown() function is not available.

glob()

The glob() function is not available.

hlstat()

The hlstat() function is not available.

hstat()

The hstat() function is not available.

is_cdev()

The is_cdev() function is not available.

is_bdev()

The is_bdev() function is not available.

is_dev()

The is_dev() function is not available.

is_executable()

The is_executable() function is not available.

is_dir()

The is_dir() function is not available.

is_file()

The is_file() function is not available.

is_pipe()

The is_pipe() function is not available.

is_link()

The is_link() function is not available.

is_readable()

The is_readable() function is not available.

is_socket()

The is_socket() function is not available.

is_writeable()

The is_writeable() function is not available.

lstat()

The lstat() function is not available.

mkdir()

The mkdir() function is not available.

mkfifo()

The mkfifo() function is not available.

rmdir()

The rmdir() function is not available.

stat()

The stat() function is not available.

umask()

The umask() function is not available.

unlink()

The unlink() function is not available.


6.15. no-global-vars

Parse Directive

%no-global-vars

Command-Line

--no-global-vars, -G

Parse Option Constant

PO_NO_GLOBAL_VARS

Description

Disallows the use of global variables.

6.16. no-gui

Parse Directive

%no-gui

Command-Line

--no-gui, --set-parse-option=no-gui, -pno-gui

Parse Option Constant

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).

6.17. no-namespace-defs

Parse Directive

%no-namespace-defs

Command-Line

--no-namespace-defs, -M

Parse Option Constant

PO_NO_NAMESPACE_DEFS

Description

Disallows new namespace definitions.

6.18. no-network

Parse Directive

%no-network

Command-Line

--no-network, -Y

Parse Option Constant

PO_NO_NETWORK

Description

Disallows any access to the network.

Table 6.4. Unavailable Features with no-network

Feature/Function

Description

FtpClient class

The FtpClient class is not available.

HTTPClient class

The HTTPClient class is not available.

XmlRpcClient class

The XmlRpcClient class is not available.

JsonRpcClient class

The JsonRpcClient class is not available.

Socket class

The Socket class is not available.


6.19. no-new

Parse Directive

%no-new

Command-Line

--no-new, -N

Parse Option Constant

PO_NO_NEW

Description

Disallows use of the new operator.

6.20. no-process-control

Parse Directive

%no-process-control

Command-Line

--no-process-control, -P

Parse Option Constant

PO_NO_PROCESS_CONTROL

Description

Disallows access to functions that would affect the current process.

Table 6.5. Unavailable Features with no-process-control

Feature/Function

Description

abort()

The abort() function is not available.

fork()

The fork() function is not available.

exec()

The exec() function is not available.

exit()

The exit() function is not available.

remove_signal_handler()

The remove_signal_handler() function is not available.

set_signal_handler()

The set_signal_handler() function is not available.

setegid()

The setegid() function is not available.

seteuid()

The seteuid() function is not available.

setgid()

The setgid() function is not available.

setuid()

The setuid() function is not available.

sleep()

The sleep() function is not available.

usleep()

The usleep() function is not available.


6.21. no-subroutine-defs

Parse Directive

%no-subroutine-defs

Command-Line

--no-subroutine-defs, -S

Parse Option Constant

PO_NO_SUBROUTINE_DEFS

Description

Disallows subroutine (function) definitions.

6.22. 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

PO_NO_TERMINAL_IO

Description

Disallows access to terminal input and output.

Table 6.6. Unavailable Features with no-terminal-io

Feature/Function

Description

flush()

The flush() function is not available.

f_printf()

The f_printf() function is not available.

print()

The print() function is not available.

printf()

The printf() function is not available.

vprintf()

The vprintf() function is not available.

stdin

The stdin constant is not accessible.

stdout

The stdout constant is not accessible.

stderr

The stderr constant is not accessible.


6.23. no-thread-classes

Parse Directive

%no-thread-classes

Command-Line

--no-thread-classes

Parse Option Constant

PO_NO_THREAD_CLASSES

Description

Disallows access to thread classes.

Table 6.7. Unavailable Features with no-thread-classes

Feature/Function

Description

AutoGate class

The AutoGate class is not available.

AutoLock class

The AutoLock class is not available.

AutoReadLock class

The AutoReadLock class is not available.

AutoWriteLock class

The AutoWriteLock class is not available.

Condition class

The Condition class is not available.

Counter class

The Counter class is not available.

Mutex class

The Mutex class is not available.

Queue class

The Queue class is not available.

RWLock class

The RWLock class is not available.


6.24. no-thread-control

Parse Directive

%no-thread-control

Command-Line

--no-thread-control, -R

Parse Option Constant

PO_NO_THREAD_CONTROL

Description

Disallows access to thread control operations.

Table 6.8. Unavailable Features with no-thread-control

Feature/Function

Description

background operator

The background operator is not available.

thread_exit statement

The thread_exit statement is not available.

get_thread_data()

The get_thread_data() function is not available.

get_all_thread_data()

The get_all_thread_data() function is not available.

save_thread_data()

The save_thread_data() function is not available.

delete_thread_data()

The delete_thread_data() function is not available.

delete_all_thread_data()

The delete_all_thread_data() function is not available.

getAllThreadCallStacks()

The getAllThreadCallStacks() function is not available (this function is deprecated and will be removed from a future release).

throwThreadResourceExceptions()

The throwThreadResourceExceptions() function is not available.


6.25. no-threads

Parse Directive

%no-threads

Command-Line

--no-threads, -T

Parse Option Constant

PO_NO_THREADS

Description

Disallows access to all thread control operations and thread classes (equivalent to no-thread-control and no-thread-classes together).

6.26. no-top-level

Parse Directive

%no-top-level

Command-Line

--no-top-level, -L

Parse Option Constant

PO_NO_TOP_LEVEL_STATEMENTS

Description

Disallows top level code.

6.27. require-our

Parse Directive

%require-our

Command-Line

--require-our, -O

Parse Option Constant

PO_REQUIRE_OUR

Description

Requires global variables to be declared with our prior to use (recommended to use for all larger scripts/programs).

6.28. requires

Parse Directive

%requires

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.

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 exteneded 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.

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.