src/Pure/Isar/completion.scala
changeset 53322 a4cd032172e0
parent 53318 ec4511548304
child 53324 c12a3edcd8e4
equal deleted inserted replaced
53321:53c314f1e8bf 53322:a4cd032172e0
    37     override val whiteSpace = "".r
    37     override val whiteSpace = "".r
    38 
    38 
    39     def reverse_symbol: Parser[String] = """>[A-Za-z0-9_']+\^?<\\""".r
    39     def reverse_symbol: Parser[String] = """>[A-Za-z0-9_']+\^?<\\""".r
    40     def reverse_symb: Parser[String] = """[A-Za-z0-9_']{2,}\^?<\\""".r
    40     def reverse_symb: Parser[String] = """[A-Za-z0-9_']{2,}\^?<\\""".r
    41     def escape: Parser[String] = """[a-zA-Z0-9_']+\\""".r
    41     def escape: Parser[String] = """[a-zA-Z0-9_']+\\""".r
    42     def word: Parser[String] = """[a-zA-Z0-9_']{3,}""".r
    42     def word: Parser[String] = word_regex
       
    43     def word3: Parser[String] = """[a-zA-Z0-9_']{3,}""".r
    43 
    44 
    44     def read(in: CharSequence): Option[String] =
    45     def read(explicit: Boolean, in: CharSequence): Option[String] =
    45     {
    46     {
       
    47       val parse_word = if (explicit) word else word3
    46       val reverse_in = new Library.Reverse(in)
    48       val reverse_in = new Library.Reverse(in)
    47       parse((reverse_symbol | reverse_symb | escape | word) ^^ (_.reverse), reverse_in) match {
    49       parse((reverse_symbol | reverse_symb | escape | parse_word) ^^ (_.reverse), reverse_in) match {
    48         case Success(result, _) => Some(result)
    50         case Success(result, _) => Some(result)
    49         case _ => None
    51         case _ => None
    50       }
    52       }
    51     }
    53     }
    52   }
    54   }
    88   }
    90   }
    89 
    91 
    90 
    92 
    91   /* complete */
    93   /* complete */
    92 
    94 
    93   def complete(decode: Boolean, line: CharSequence): Option[(String, List[Completion.Item])] =
    95   def complete(decode: Boolean, explicit: Boolean, line: CharSequence)
       
    96     : Option[(String, List[Completion.Item])] =
    94   {
    97   {
    95     val raw_result =
    98     val raw_result =
    96       abbrevs_lex.parse(abbrevs_lex.keyword, new Library.Reverse(line)) match {
    99       abbrevs_lex.parse(abbrevs_lex.keyword, new Library.Reverse(line)) match {
    97         case abbrevs_lex.Success(reverse_a, _) =>
   100         case abbrevs_lex.Success(reverse_a, _) =>
    98           val abbrevs = abbrevs_map.get_list(reverse_a)
   101           val abbrevs = abbrevs_map.get_list(reverse_a)
    99           abbrevs match {
   102           abbrevs match {
   100             case Nil => None
   103             case Nil => None
   101             case (a, _) :: _ => Some((a, abbrevs.map(_._2)))
   104             case (a, _) :: _ => Some((a, abbrevs.map(_._2)))
   102           }
   105           }
   103         case _ =>
   106         case _ =>
   104           Completion.Parse.read(line) match {
   107           Completion.Parse.read(explicit, line) match {
   105             case Some(word) =>
   108             case Some(word) =>
   106               words_lex.completions(word).map(words_map.get_list(_)).flatten match {
   109               words_lex.completions(word).map(words_map.get_list(_)).flatten match {
   107                 case Nil => None
   110                 case Nil => None
   108                 case cs => Some(word, cs.sorted)
   111                 case cs => Some(word, cs.sorted)
   109               }
   112               }