Skip to content

Commit

Permalink
[backport] SI-6478 Fixing JavaTokenParser ident
Browse files Browse the repository at this point in the history
Backport of 2569341 from PR
#1466
  • Loading branch information
jroper authored and JamesIry committed Feb 7, 2013
1 parent 0dd02d9 commit 6052e19
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,12 @@ import scala.annotation.migration
* - `floatingPointNumber`
*/
trait JavaTokenParsers extends RegexParsers {
/** Anything starting with an ASCII alphabetic character or underscore,
* followed by zero or more repetitions of regex's `\w`.
/** Anything that is a valid Java identifier, according to
* <a href="http://docs.oracle.com/javase/specs/jls/se7/html/jls-3.html#jls-3.8">The Java Language Spec</a>.
* Generally, this means a letter, followed by zero or more letters or numbers.
*/
def ident: Parser[String] =
"""[a-zA-Z_]\w*""".r
"""\p{javaJavaIdentifierStart}\p{javaJavaIdentifierPart}*""".r
/** An integer, without sign or with a negative sign. */
def wholeNumber: Parser[String] =
"""-?\d+""".r
Expand Down
26 changes: 26 additions & 0 deletions test/files/run/parserJavaIdent.check
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
[1.7] parsed: simple
[1.8] parsed: with123
[1.6] parsed: with$
[1.10] parsed: withøßöèæ
[1.6] parsed: with_
[1.6] parsed: _with
[1.1] failure: java identifier expected

3start
^
[1.1] failure: java identifier expected

-start
^
[1.5] failure: java identifier expected

with-s
^
[1.3] failure: java identifier expected

we♥scala
^
[1.6] failure: java identifier expected

with space
^
26 changes: 26 additions & 0 deletions test/files/run/parserJavaIdent.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
object Test extends scala.util.parsing.combinator.JavaTokenParsers {

def test[A](s: String) {
val res = parseAll(ident, s) match {
case Failure(_, in) => Failure("java identifier expected", in)
case o => o
}
println(res)
}

def main(args: Array[String]) {
// Happy tests
test("simple")
test("with123")
test("with$")
test("withøßöèæ")
test("with_")
test("_with")
// Sad tests
test("3start")
test("-start")
test("with-s")
test("we♥scala")
test("with space")
}
}

2 comments on commit 6052e19

@scala-jenkins
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Job pr-rangepos-per-commit failed for 6052e19 (results):


Took 8 s.
sad kitty
to rebuild, comment "PLS REBUILD/pr-rangepos-per-commit@6052e19292c95270ac0a4bf30b6df47a257f88d4"on PR #2112

@scala-jenkins
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Job pr-checkin-per-commit failed for 6052e19 (results):


Took 13 s.
sad kitty
to rebuild, comment "PLS REBUILD/pr-checkin-per-commit@6052e19292c95270ac0a4bf30b6df47a257f88d4"on PR #2112

Please sign in to comment.