src/Pure/Tools/check_keywords.scala
author wenzelm
Wed Apr 01 15:41:08 2015 +0200 (2015-04-01)
changeset 59891 9ce697050455
child 59895 a68a0fec288d
permissions -rw-r--r--
added isabelle build option -k, for fast off-line checking of theory sources;
wenzelm@59891
     1
/*  Title:      Pure/Tools/check_keywords.scala
wenzelm@59891
     2
    Author:     Makarius
wenzelm@59891
     3
wenzelm@59891
     4
Check theory sources for conflicts with proposed keywords.
wenzelm@59891
     5
*/
wenzelm@59891
     6
wenzelm@59891
     7
package isabelle
wenzelm@59891
     8
wenzelm@59891
     9
wenzelm@59891
    10
object Check_Keywords
wenzelm@59891
    11
{
wenzelm@59891
    12
  def conflicts(
wenzelm@59891
    13
    keywords: Keyword.Keywords,
wenzelm@59891
    14
    check: Set[String],
wenzelm@59891
    15
    input: CharSequence,
wenzelm@59891
    16
    start: Token.Pos): List[(Token, Position.T)] =
wenzelm@59891
    17
  {
wenzelm@59891
    18
    object Parser extends Parse.Parser
wenzelm@59891
    19
    {
wenzelm@59891
    20
      private val conflict =
wenzelm@59891
    21
        position(token("token", tok => !(tok.is_command || tok.is_keyword) && check(tok.source)))
wenzelm@59891
    22
      private val other = token("token", _ => true)
wenzelm@59891
    23
      private val item = conflict ^^ (x => Some(x)) | other ^^ (_ => None)
wenzelm@59891
    24
wenzelm@59891
    25
      val result =
wenzelm@59891
    26
        parse_all(rep(item), Token.reader(Token.explode(keywords, input), start)) match {
wenzelm@59891
    27
          case Success(res, _) => for (Some(x) <- res) yield x
wenzelm@59891
    28
          case bad => error(bad.toString)
wenzelm@59891
    29
        }
wenzelm@59891
    30
    }
wenzelm@59891
    31
    Parser.result
wenzelm@59891
    32
  }
wenzelm@59891
    33
wenzelm@59891
    34
  def conflicts(
wenzelm@59891
    35
    keywords: Keyword.Keywords, check: Set[String], path: Path): List[(Token, Position.T)] =
wenzelm@59891
    36
    conflicts(keywords, check, File.read(path), Token.Pos.file(path.expand.implode))
wenzelm@59891
    37
}