Skip to content

Commit

Permalink
fix: allow for #include header
Browse files Browse the repository at this point in the history
  • Loading branch information
kasiaMarek committed Jun 4, 2024
1 parent 06b75bb commit be9ad2e
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -188,9 +188,7 @@ class JavaToplevelMtags(
reader.nextChar()
kwOrIdent(start, builder.append(ch.toChar))
} else if (builder.isEmpty) {
throw new Exception(
s"Unexpected symbol at word pos: '$ch'. Line: '$readCurrentLine'"
)
unexpectedCharacter(ch.toChar, reader.endCharOffset)
} else {

val pos = Position.Range(input, start, reader.endCharOffset)
Expand Down Expand Up @@ -247,6 +245,12 @@ class JavaToplevelMtags(
)
(token, true)
}
case '#' =>
reader.nextChar()
kwOrIdent(reader.endCharOffset, new StringBuilder(first + 1)) match {
case Token.Word("include", _) => (Token.IncludeHeader, true)
case _ => unexpectedCharacter('#', first)
}
case _ =>
val token = kwOrIdent(reader.endCharOffset, new StringBuilder(first))
(token, true)
Expand Down Expand Up @@ -342,6 +346,11 @@ class JavaToplevelMtags(
loop(new StringBuilder().append(existing))
}

private def unexpectedCharacter(c: Char, pos: Int): Nothing =
throw new Exception(
s"Unexpected symbol '$c' at word pos: '$pos' Line: '$readCurrentLine'"
)

}

object JavaToplevelMtags {
Expand Down Expand Up @@ -380,6 +389,7 @@ object JavaToplevelMtags {
// any allowed symbol like `=` , `-` and others
case object SpecialSym extends Token
case object Literal extends Token
case object IncludeHeader extends Token

case class Word(value: String, pos: Position) extends WithPos {
override def toString: String =
Expand Down
20 changes: 20 additions & 0 deletions tests/unit/src/test/scala/tests/JavaToplevelSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -173,4 +173,24 @@ class JavaToplevelSuite extends BaseToplevelSuite {
mode = ToplevelWithInner,
)

check(
"i6390",
"""|
|<#include "/@includes/license.ftl" />
|
|package org.apache;
|
|<#include "/@includes/vv_imports.ftl" />
|
|@SuppressWarnings("unused")
|public interface BaseReader extends Positionable{
|}
|""".stripMargin,
List("""|org/
|org/apache/
|org/apache/BaseReader# -> Positionable
|""".stripMargin),
mode = ToplevelWithInner,
)

}

0 comments on commit be9ad2e

Please sign in to comment.