GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
GeezerVison is showing www.unicode.org — UAX #31: Identifier and Pattern Syntax
Unicode Standard Annex #31Identifier and Pattern Syntax
SummaryThis document describes specifications for recommended defaults for the use of Unicode in the definitions of identifiers and in pattern-based syntax. It incorporates the Identifier section of Unicode 4.0 (somewhat reorganized) and a new section on the use of Unicode in patterns. As a part of the latter, it presents recommended new properties for addition to the Unicode Character Database. It also incorporates guidelines for use of normalization with identifiers (from UAX #15).
StatusThis document has been reviewed by Unicode members and other interested parties, and has been approved for publication by the Unicode Consortium. This is a stable document and may be used as reference material or cited as a normative reference by other specifications.
Please submit corrigenda and other comments with the online reporting form [Feedback]. Related information that is useful in understanding this document is found in References. For the latest version of the Unicode Standard see [Unicode]. For a list of current Unicode Technical Reports see [Reports]. For more information about versions of the Unicode Standard, see [Versions]. Contents1 IntroductionA common task facing an implementer of the Unicode Standard is the provision of a parsing and/or lexing engine for identifiers. To assist in the standard treatment of identifiers in Unicode character-based parsers, a set of specifications is provided here as a recommended default for the definition of identifier syntax. These guidelines are no more complex than current rules in the common programming languages, except that they include more characters of different types. This document also provides guidelines for the user of normalization and case-insensitivity with identifiers, expanding on a section that was originally in UAX #15: Unicode Normalization Forms [UAX15]. These specifications provide a definition of identifiers that is guaranteed to be backward compatible with each successive release of Unicode, but also makes available any appropriate new Unicode characters. Unicode properties are also provided for stable pattern syntax: syntax that is stable over future versions of the Unicode Standard. These can either be used alone or with the identifier characters. The following types of code points are defined (the sizes of the boxes are not to scale):
The set consisting of both Identifier Start and Only-Continue characters is are known as Identifier Characters, also as Identifier Continue characters. There are certain features that developers can depend on for stability:
In successive versions of Unicode, only the following changes are allowed, from one of the above classes to another:
The Unicode Consortium has formally adopted a stability policy on identifiers. For more information, see [Stability]. Each programming language standard has its own identifier syntax; different programming languages have different conventions for the use of certain characters such as $, @, #, or _ in identifiers. To extend such a syntax to cover the full behavior of a Unicode implementation, implementers may combine those specific rules with the syntax and properties provided here. That is, each programming language can define their identifier syntax as relative to the Unicode identifier syntax, such as saying that identifiers are defined by the Unicode properties, with the addition of "$". By addition or subtraction of a small set of language specific characters, a programming language standard can easily track a growing repertoire of Unicode characters in a compatible way. Similarly, each programming language can define white space characters or syntax characters relative to the Unicode pattern white space or syntax characters, with some specified set of additions or subtractions. Systems that want to extend identifiers so as to encompass words used in natural languages may add characters identified in Section 4 Word Boundaries of [UAX29] with the property values Katakana, ALetter, and MidLetter, plus characters described in the notes at the end of that section. Note that to preserve the disjoint nature of categories illustrated in the diagram "Character Classes for Programming", any character added to one of the categories must be subtracted from the others. In some cases there are security implications that may require additional constraints on identifiers. For more information, see [UTR36]. 1.1 ConformanceThe following describes the possible ways that an implementation can claim conformance to this technical standard.
2 Default Identifier SyntaxThe formal syntax provided here captures the general intent that an identifier consists of a string of characters beginning with a letter or an ideograph, and following with any number of letters, ideographs, digits, or underscores. It provides a definition of identifiers that is guaranteed to be backward compatible with each successive release of Unicode, but also adds any appropriate new Unicode characters. D1. Default Identifier Syntax
Identifiers are defined by the following sets of character categories from the Unicode Character Database.
The innovations in the identifier syntax to cover the Unicode Standard include the following:
2.1 Combining MarksCombining marks are accounted for in identifier syntax: a composed character sequence consisting of a base character followed by any number of combining marks is valid in an identifier. Combining marks are required in the representation of many languages, and the conformance rules in Chapter 3, Conformance of [Unicode] require the interpretation of canonical-equivalent character sequences. Enclosing combining marks (such as 2.2 Layout and Format Control CharactersCertain Unicode characters are used to control joining behavior, bidirectional ordering control, and alternative formats for display. These have the General Category value of Cf. Unlike space characters or other delimiters, they do not indicate word, line, or other unit boundaries. While it is possible to ignore these characters in determining identifiers, the recommendation is to not ignore them, and not permit them in identifiers except in special cases. This is because of the possibility for confusion between two visually identical strings: see [UTR36]. Some possible exceptions are the ZWJ and ZWNJ in certain contexts, such as between certain characters in Indic words. 2.3 Specific Character AdjustmentsSpecific identifier syntaxes can be treated as tailorings of the generic syntax based on
character properties. For example, SQL identifiers allow an underscore as an identifier part, but
not as an identifier start; C identifiers allow an underscore as either an identifier part or an
identifier start. Specific languages may also want to exclude the characters that have a For programming language identifiers, normalization and case have a number of important implications. For a discussion of these issues, see Normalization and Case. 2.4 Backward CompatibilityUnicode General Category values are kept as stable as possible, but they can change across
versions of the Unicode Standard. The bulk of the characters having a given value are determined
by other properties, and the coverage expands in the future according to the assignment of those
properties. In addition, the Other_ID_Start property adds a small list of characters that
qualified as
Similarly, the Other_ID_Continue property adds a small list of characters that qualified as
The Other_ID_Start and Other_ID_Continue properties are thus designed to ensure that the Unicode identifier specification is backward compatible: Any sequence of characters that qualified as an identifier in some version of Unicode will continue to qualify as an identifier in future versions.
3 Alternative Identifier SyntaxThe disadvantage of working with the syntactic classes defined above is the storage space needed for the detailed definitions, plus the fact that with each new version of the Unicode Standard new characters are added, which an existing parser would not be able to recognize. In other words, the recommendations based on that table are not upwardly compatible. This problem can be addressed by turning the question around. Instead of defining the set of code points that are allowed, define a small, fixed set of code points that are reserved for syntactic use and allow everything else (including unassigned code points) as part of an identifier. All parsers written to this specification would behave the same way for all versions of the Unicode Standard, because the classification of code points is fixed forever. The drawback of this method is that it allows “nonsense” to be part of identifiers because the concerns of lexical classification and of human intelligibility are separated. Human intelligibility can, however, be addressed by other means, such as usage guidelines that encourage a restriction to meaningful terms for identifiers. For an example of such guidelines, see the XML 1.1 specification by the W3C [XML1.1]. By increasing the set of disallowed characters, a reasonably intuitive recommendation for identifiers can be achieved. This approach uses the full specification of identifier classes, as of a particular version of the Unicode Standard, and permanently disallows any characters not recommended in that version for inclusion in identifiers. All code points unassigned as of that version would be allowed in identifiers, so that any future additions to the standard would already be accounted for. This approach ensures both upwardly compatible identifier stability and a reasonable division of characters into those that do and do not make human sense as part of identifiers. Some additional extensions to the list of disallowed code points can be made to further constrain “unnatural” identifiers. For example, one could include unassigned code points in blocks of characters set aside for future encoding as symbols, such as mathematical operators. With or without such fine-tuning, such a compromise approach still incurs the expense of implementing large lists of code points. While they no longer change over time, it is a matter of choice whether the benefit of enforcing somewhat word-like identifiers justifies their cost. Alternatively, one can use the properties described below, and allow all sequences of characters to be identifiers that are neither pattern syntax nor pattern whitespace. This has the advantage of simplicity and small tables, but allows many more “unnatural” identifiers.
4 Pattern SyntaxThere are many circumstances where software interprets patterns that are a mixture of literal characters, whitespace, and syntax characters. Examples include regular expressions, Java collation rules, Excel or ICU number formats, and many others. These patterns have been very limited in the past, and forced to use clumsy combinations of ASCII characters for their syntax. As Unicode becomes ubiquitous, some of these will start to use non-ASCII characters for their syntax: first as more readable optional alternatives, then eventually as the standard syntax. For forward and backward compatibility, it is advantageous to have a fixed set of whitespace and syntax code points for use in patterns. This follows the recommendations that the Unicode Consortium made regarding completely stable identifiers, and the practice that is seen in XML 1.1 [XML1.1]. (In particular, the consortium committed to not allocating characters suitable for identifiers in the range 2190..2BFF, which is being used by XML 1.1.) With a fixed set of whitespace and syntax code points, a pattern language can then have a policy requiring all possible syntax characters (even ones currently unused) to be quoted if they are literals. By using this policy, it preserves the freedom to extend the syntax in the future by using those characters. Past patterns on future systems will always work; future patterns on past systems will signal an error instead of silently producing the wrong results.
As of Unicode 4.1.0, there are two Unicode character properties that can be used for for stable syntax: Pattern_White_Space and Pattern_Syntax. Particular pattern languages may, of course, override these recommendations (for example, adding or removing other characters for compatibility in ASCII). For stability, the property values are absolutely invariant; not changing with successive versions of Unicode. Of course, this does not limit the ability of the Unicode Standard to add more symbol or whitespace characters, but the syntax and whitespace characters recommended for use in patterns will not change. When generating rules or patterns, all whitespace and syntax code points that are to be literals require quoting, using whatever quoting mechanism is available. For readability, it is recommended practice to quote or escape all literal whitespace and default ignorable code points as well.
5 Normalization and Case
This section discusses issues that must be taken into account when considering normalization and case folding of identifiers in programming languages or scripting languages. Using normalization avoids many problems where apparently identical identifiers are not treated equivalently. Such problems can appear both during compilation and during linking, in particular across different programming languages. To avoid such problems, programming languages can normalize identifiers before storing or comparing them. Generally if the programming language has case-sensitive identifiers then Normalization Form C is appropriate, while if the programming language has case-insensitive identifiers then Normalization Form KC is more appropriate.
If programming languages are using NFKC to fold differences between characters, then they use the following modification of the identifier syntax from the Unicode Standard to deal with the idiosyncrasies of a small number of characters. These characters fall into three classes: NFKC Modifications
With these amendments to the identifier syntax, all identifiers are closed under all four Normalization forms. This means that for any string S,
Identifiers are also closed under case operations (with one exception), so that for any string S,
The one exception is
When source text is parsed for identifiers, the folding of distinctions (using case mapping or NFKC) must be delayed until after parsing has located the identifiers. Thus such folding of distinctions should not be applied to string literals or to comments in program source text. The UCD provides support for handling case folding with normalization: the property FC_NFKC_Closure can be used in case folding, so that a case folding of an NFKC string is itself normalized. These properties, and the files containing them, are described in the UCD documentation [UCD]. AcknowledgementsThanks to Eric Muller, Asmus Freytag, and Martin Duerst for feedback on this document. References
ModificationsThe following summarizes modifications from previous revisions of this document.
Copyright © 2000-2005 Unicode, Inc. All Rights Reserved. The Unicode Consortium makes no expressed or implied warranty of any kind, and assumes no liability for errors or omissions. No liability is assumed for incidental and consequential damages in connection with or arising out of the use of the information or programs contained or accompanying this technical report. The Unicode Terms of Use apply. Unicode and the Unicode logo are trademarks of Unicode, Inc., and are registered in some jurisdictions. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| You are visitor 01402503 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||