2.16.1.9 Unicode Prolog source
The ISO standard specifies the Prolog syntax in ASCII characters. As SWI-Prolog supports Unicode in source files we must extend the syntax. This section describes the implication for the source files, while writing international source files is described in section 3.1.3.
The SWI-Prolog Unicode character classification is based on version 6.0.0 of the Unicode standard. Please note that char_type/2 and friends, intended to be used with all text except Prolog source code, is based on the C library locale-based classification routines.
- Quoted atoms and strings
Any character of any script can be used in quoted atoms and strings. The escape sequences\uXXXX
and\UXXXXXXXX
(see section 2.16.1.3) were introduced to specify Unicode code points in ASCII files. - Atoms and Variables
We handle them in one item as they are closely related. The Unicode standard defines a syntax for identifiers in computer languages.30http://www.unicode.org/reports/tr31/ In this syntax identifiers start withID_Start
followed by a sequence ofID_Continue
codes. Such sequences are handled as a single token in SWI-Prolog. The token is a variable iff it starts with an uppercase character or an underscore (_
). Otherwise it is an atom. Note that many languages do not have the notion of character case. In such languages variables must be written as_name
. - White space
All characters marked as separators (Z*) in the Unicode tables are handled as layout characters. - Control and unassigned characters
Control and unassigned (C*) characters produce a syntax error if encountered outside quoted atoms/strings and outside comments. - Other characters
The first 128 characters follow the ISO Prolog standard. Unicode symbol and punctuation characters (general category S* and P*) act as glueing symbol characters (i.e., just like
: an unquoted sequence of symbol characters are combined into an atom).==
Other characters (this is mainly
No
: a numeric character of other type) are currently handled as‘solo'.