Skip to content
This repository was archived by the owner on Sep 1, 2020. It is now read-only.

Commit e89ac28

Browse files
committed
Merge pull request #29 from milessabin/feature/prime-identifiers
Allow primes at the end of identifiers.
2 parents 9afc167 + 6dc8a6a commit e89ac28

File tree

5 files changed

+80
-0
lines changed

5 files changed

+80
-0
lines changed

src/compiler/scala/tools/nsc/ast/parser/Scanners.scala

+11
Original file line numberDiff line numberDiff line change
@@ -637,6 +637,10 @@ trait Scanners extends ScannersCommon {
637637
putChar(ch)
638638
nextChar()
639639
getIdentOrOperatorRest()
640+
case '\'' =>
641+
putChar(ch)
642+
nextChar()
643+
getPrimeRest()
640644
case SU => // strangely enough, Character.isUnicodeIdentifierPart(SU) returns true!
641645
finishNamed()
642646
case _ =>
@@ -649,6 +653,13 @@ trait Scanners extends ScannersCommon {
649653
}
650654
}
651655

656+
private def getPrimeRest(): Unit =
657+
if (ch == '\'') {
658+
putChar(ch)
659+
nextChar()
660+
getPrimeRest()
661+
} else finishNamed()
662+
652663
private def getOperatorRest(): Unit = (ch: @switch) match {
653664
case '~' | '!' | '@' | '#' | '%' |
654665
'^' | '*' | '+' | '-' | '<' |

src/library/scala/reflect/NameTransformer.scala

+1
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ object NameTransformer {
5454
enterOp('\\', "$bslash")
5555
enterOp('?', "$qmark")
5656
enterOp('@', "$at")
57+
enterOp('\'', "$prime")
5758

5859
/** Replace operator symbols by corresponding `\$opname`.
5960
*
+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
primed-identifiers.scala:4: error: value b' is not a member of object a1
2+
a1 b'c' // parses as a1 b' c'
3+
^
4+
primed-identifiers.scala:4: error: not found: value c'
5+
a1 b'c' // parses as a1 b' c'
6+
^
7+
two errors found
+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
object a1 {
2+
def b(c: Char) = ???
3+
4+
a1 b'c' // parses as a1 b' c'
5+
}
6+
7+
object a2 {
8+
def b'(c: Int) = ???
9+
def b(c: Char) = ???
10+
11+
val c' = 23
12+
a2 b'c' // parses as a2 b' c'
13+
}
+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
object Test {
2+
val l = List("Identifiers", "with", "primes", "!")
3+
4+
val l' = l map(_.length)
5+
6+
val l'' = l zip l'
7+
8+
val l''' = l''.reverse
9+
10+
object a1 {
11+
def b(c: Char) = ???
12+
13+
a1 b 'c'
14+
}
15+
16+
object a2 {
17+
def b'(c: Int) = ???
18+
def b(c: Char) = ???
19+
20+
a2 b' 23
21+
a2 b'23
22+
23+
val i = 23
24+
a2 b'i
25+
26+
val c' = 23
27+
a2 b'c' // parses as a2 b' c'
28+
29+
a2 b 'c'
30+
}
31+
32+
case object Foo'
33+
case class Bar'(i: Int)
34+
35+
((): Any) match {
36+
case foo': String => ???
37+
case Foo' => ???
38+
case Bar'(foo') => ???
39+
}
40+
41+
val (x', y') = (13, 23)
42+
43+
for (z' <- List(x', y')) x'*2
44+
45+
type T' = Int
46+
def foo[U', F'[_]](ft: F'[T'], fu: F'[U']) = (ft, fu)
47+
}
48+

0 commit comments

Comments
 (0)