def quote_string(str: String): String =
Library.string_builder(hint = str.length + 10) { result =>
result += '"' for (s <- Symbol.iterator(str)) { if (s.length == 1) { val c = s(0) if (c < 32 && c != YXML.X_char && c != YXML.Y_char || c == '\\' || c == '"') {
result += '\\' if (c < 10) result += '0' if (c < 100) result += '0'
result ++= c.asInstanceOf[Int].toString
} else result += c
} else result ++= s
}
result += '"'
}
}
finalclass Outer_Syntax private( val keywords: Keyword.Keywords = Keyword.Keywords.empty, val rev_abbrevs: Thy_Header.Abbrevs = Nil, val language_context: Completion.Language_Context = Completion.Language_Context.outer, val has_tokens: Boolean = true
) { /** syntax content **/
def parse_spans(toks: List[Token]): List[Command_Span.Span] = { val result = new mutable.ListBuffer[Command_Span.Span] val content = new mutable.ListBuffer[Token] val ignored = new mutable.ListBuffer[Token]
def ship(content: List[Token]): Unit = { val kind = if (content.forall(_.is_ignored)) Command_Span.Ignored_Span elseif (content.exists(_.is_error)) Command_Span.Malformed_Span else
content.find(_.is_command) match { case None => Command_Span.Malformed_Span case Some(cmd) => val name = cmd.source val keyword_kind = keywords.kinds.get(name) val offset =
content.takeWhile(_ != cmd).foldLeft(0) { case (i, tok) => i + Symbol.length(tok.source)
} val end_offset = offset + Symbol.length(name) val range = Text.Range(offset, end_offset) + 1
Command_Span.Command_Span(keyword_kind, name, Position.Range(range))
}
result += Command_Span.Span(kind, content)
}
def flush(): Unit = { if (content.nonEmpty) { ship(content.toList); content.clear() } if (ignored.nonEmpty) { ship(ignored.toList); ignored.clear() }
}
for (tok <- toks) { if (tok.is_ignored) ignored += tok elseif (keywords.is_before_command(tok) ||
tok.is_command &&
(!content.exists(keywords.is_before_command) || content.exists(_.is_command))) {
flush(); content += tok
} else { content ++= ignored; ignored.clear(); content += tok }
}
flush()
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.