Skip to content

Commit 8c6b733

Browse files
committed
Allowing . in annotation keys
1 parent d32493c commit 8c6b733

3 files changed

Lines changed: 6 additions & 4 deletions

File tree

src/main/scala/viper/silver/parser/FastParser.scala

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -805,7 +805,7 @@ class FastParser {
805805

806806
def stringLiteral[$: P]: P[String] = P("\"" ~ CharsWhile(_ != '\"').! ~ "\"")
807807

808-
def annotation[$: P]: P[(String, Seq[String])] = P("@" ~~ ident ~ parens(stringLiteral.rep(sep = ",")))
808+
def annotation[$: P]: P[(String, Seq[String])] = P("@" ~~ annotationIdentifier ~ parens(stringLiteral.rep(sep = ",")))
809809

810810
def annotatedAtom[$: P]: P[PExp] = FP(annotation ~ atom).map{
811811
case (pos, (key, value, exp)) => PAnnotatedExp(exp, (key, value))(pos)
@@ -827,6 +827,8 @@ class FastParser {
827827

828828
def identifier[$: P]: P[Unit] = CharIn("A-Z", "a-z", "$_") ~~ CharIn("0-9", "A-Z", "a-z", "$_").repX
829829

830+
def annotationIdentifier[$: P]: P[String] = (CharIn("A-Z", "a-z", "$_") ~~ CharIn("0-9", "A-Z", "a-z", "$_.").repX).!
831+
830832
def ident[$: P]: P[String] = identifier.!.filter(a => !keywords.contains(a)).opaque("invalid identifier (could be a keyword)")
831833

832834
def idnuse[$: P]: P[PIdnUse] = FP(ident).map { case (pos, id) => PIdnUse(id)(pos) }

src/test/resources/all/annotation/annotationSuccess.vpr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ method m(x: Ref, y: Ref)
3535
requires acc(y.f)
3636
{
3737
var tmp: Int
38-
@annotatingastatement("the assignment")
38+
@annotating.a.statement("the assignment")
3939
tmp := @asd("test 123") fun02(x, @ann("this is ugly") y, true)
4040
y.f := 1
4141
assert tmp == fun02(x, y, true)

src/test/scala/AstAnnotationTests.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ class AstAnnotationTests extends AnyFunSuite {
8888
| var tmp: Int
8989
| @annotatingastatement("the assignment", "12")
9090
| @annotatingastatement("34")
91-
| @suchannotations()
91+
| @such.annotations()
9292
| tmp := @asd("test 123") fun02(x, @ann("this is ugly") y, true)
9393
| y.f := 1
9494
| assert tmp == fun02(x, y, true)
@@ -108,7 +108,7 @@ class AstAnnotationTests extends AnyFunSuite {
108108

109109
val assignment = res.methods.head.body.get.ss(1)
110110
val assignmentAnn = assignment.info.getUniqueInfo[AnnotationInfo].get
111-
assert(assignmentAnn.values == Map("annotatingastatement" -> Seq("the assignment", "12", "34"), "suchannotations" -> Seq()))
111+
assert(assignmentAnn.values == Map("annotatingastatement" -> Seq("the assignment", "12", "34"), "such.annotations" -> Seq()))
112112

113113
val rhs = assignment.asInstanceOf[LocalVarAssign].rhs
114114
val rhsAnn = rhs.info.getUniqueInfo[AnnotationInfo].get

0 commit comments

Comments
 (0)