diff options
author | Som Snytt <som.snytt@gmail.com> | 2014-12-24 17:59:49 -0800 |
---|---|---|
committer | Som Snytt <som.snytt@gmail.com> | 2015-02-15 20:57:13 -0800 |
commit | b4e3becbf348bad95f48da5a94f4ddb4272b2891 (patch) | |
tree | fc07c885ef9e58078df738942be88c0bef337b4a /src | |
parent | fe7867f8a7f309fe16b454fe977bd2f1870d59c2 (diff) | |
download | scala-b4e3becbf348bad95f48da5a94f4ddb4272b2891.tar.gz scala-b4e3becbf348bad95f48da5a94f4ddb4272b2891.tar.bz2 scala-b4e3becbf348bad95f48da5a94f4ddb4272b2891.zip |
[backport] SI-9060 Backpatch fifth-edition names
Because the compiler and library share some code in this
version, compiler must exclude xml tags that look like
Scala operators, such as `<:`.
This is an upstream port of:
scala-xml/commit/968f7bd94e934c781c19e25847ab09ac98cfbaf6
Diffstat (limited to 'src')
-rw-r--r-- | src/compiler/scala/tools/nsc/ast/parser/Scanners.scala | 4 | ||||
-rw-r--r-- | src/library/scala/xml/parsing/TokenTests.scala | 56 |
2 files changed, 22 insertions, 38 deletions
diff --git a/src/compiler/scala/tools/nsc/ast/parser/Scanners.scala b/src/compiler/scala/tools/nsc/ast/parser/Scanners.scala index 8d295a28d0..3ee7941995 100644 --- a/src/compiler/scala/tools/nsc/ast/parser/Scanners.scala +++ b/src/compiler/scala/tools/nsc/ast/parser/Scanners.scala @@ -367,7 +367,9 @@ trait Scanners extends ScannersCommon { val last = if (charOffset >= 2) buf(charOffset - 2) else ' ' nextChar() last match { - case ' ' | '\t' | '\n' | '{' | '(' | '>' if isNameStart(ch) || ch == '!' || ch == '?' => + // exclude valid xml names that happen to be Scala operator chars + case ' ' | '\t' | '\n' | '{' | '(' | '>' if (isNameStart(ch) && ch != ':' && !isSpecial(ch)) + || ch == '!' || ch == '?' => token = XMLSTART case _ => // Console.println("found '<', but last is '"+in.last+"'"); // DEBUG diff --git a/src/library/scala/xml/parsing/TokenTests.scala b/src/library/scala/xml/parsing/TokenTests.scala index c9cafaeea1..ce7accbd98 100644 --- a/src/library/scala/xml/parsing/TokenTests.scala +++ b/src/library/scala/xml/parsing/TokenTests.scala @@ -30,43 +30,25 @@ trait TokenTests { def isAlpha(c: Char) = (c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') def isAlphaDigit(c: Char) = isAlpha(c) || (c >= '0' && c <= '9') - /** {{{ - * NameChar ::= Letter | Digit | '.' | '-' | '_' | ':' - * | CombiningChar | Extender - * }}} - * See [4] and Appendix B of XML 1.0 specification. - */ - def isNameChar(ch: Char) = { - import java.lang.Character._ - // The constants represent groups Mc, Me, Mn, Lm, and Nd. - - isNameStart(ch) || (getType(ch).toByte match { - case COMBINING_SPACING_MARK | - ENCLOSING_MARK | NON_SPACING_MARK | - MODIFIER_LETTER | DECIMAL_DIGIT_NUMBER => true - case _ => ".-:" contains ch - }) - } - - /** {{{ - * NameStart ::= ( Letter | '_' ) - * }}} - * where Letter means in one of the Unicode general - * categories `{ Ll, Lu, Lo, Lt, Nl }`. - * - * We do not allow a name to start with `:`. - * See [3] and Appendix B of XML 1.0 specification - */ - def isNameStart(ch: Char) = { - import java.lang.Character._ - - getType(ch).toByte match { - case LOWERCASE_LETTER | - UPPERCASE_LETTER | OTHER_LETTER | - TITLECASE_LETTER | LETTER_NUMBER => true - case _ => ch == '_' - } - } + def isNameChar(c: Char): Boolean = ( + isNameStart(c) || + (c >= '0' && c <= '9') || + c == '-' || + c == '.' || + c == 0xB7 || + (c >= 0x300 && c <= 0x36F) || + (c >= 0x203F && c <= 0x2040) + ) + def isNameStart(c: Char): Boolean = ( + if (c < 0x00C0) isAlpha(c) || c == ':' || c == '_' + else if (c < 0x0300) c != 0xD7 && c != 0xF7 + else if (c < 0x2000) c >= 0x370 && c != 0x37E + else if (c < 0x3001) c == 0x200C || c == 0x200D || (0x2070 to 0x218F contains c) || + (0x2C00 to 0x2FEF contains c) + else if (c < 0xD800) true + else if (c < 0x10000) (0xF900 to 0xFDCF contains c) || (0xFDF0 to 0xFFFD contains c) + else false // codepoint < 0xF0000 + ) /** {{{ * Name ::= ( Letter | '_' ) (NameChar)* |