class Line_Context( val mode: String, val context: Option[Scan.Line_Context], val structure: Line_Structure) extends TokenMarker.LineContext(mode_rule_set(mode), null) { def get_context: Scan.Line_Context = context.getOrElse(Scan.Finished)
overridedef hashCode: Int = (mode, context, structure).hashCode overridedef equals(that: Any): Boolean =
that match { case other: Line_Context =>
mode == other.mode && context == other.context && structure == other.structure case _ => false
}
}
/* tokens from line (inclusive) */
privatedef try_line_tokens(
syntax: Outer_Syntax,
buffer: JEditBuffer,
line: Int
): Option[List[Token]] = { val line_context = Line_Context.before(buffer, line) for {
ctxt <- line_context.context
text <- JEdit_Lib.get_text(buffer, JEdit_Lib.line_range(buffer, line))
} yield Token.explode_line(syntax.keywords, text, ctxt)._1
}
def line_token_iterator(
syntax: Outer_Syntax,
buffer: JEditBuffer,
start_line: Int,
end_line: Int): Iterator[Text.Info[Token]] = for {
line <- Range(start_line max 0, end_line min buffer.getLineCount).iterator
tokens <- try_line_tokens(syntax, buffer, line).iterator
starts =
tokens.iterator.scanLeft(buffer.getLineStartOffset(line))(
(i, tok) => i + tok.source.length)
(i, tok) <- starts zip tokens.iterator
} yield Text.Info(Text.Range(i, i + tok.source.length), tok)
def line_token_reverse_iterator(
syntax: Outer_Syntax,
buffer: JEditBuffer,
start_line: Int,
end_line: Int): Iterator[Text.Info[Token]] = for {
line <- Range(start_line min (buffer.getLineCount - 1), end_line max -1, -1).iterator
tokens <- try_line_tokens(syntax, buffer, line).iterator
stops =
tokens.reverseIterator.scanLeft(buffer.getLineEndOffset(line) min buffer.getLength)(
(i, tok) => i - tok.source.length)
(i, tok) <- stops zip tokens.reverseIterator
} yield Text.Info(Text.Range(i - tok.source.length, i), tok)
if (JEdit_Lib.buffer_range(buffer).contains(offset)) { val start_info = { val info1 = maybe_command_start(offset)
info1 match { case Some(Text.Info(range1, tok1)) if tok1.is_command => val info2 = maybe_command_start(range1.start - 1)
info2 match { case Some(Text.Info(_, tok2)) if keywords.is_before_command(tok2) => info2 case _ => info1
} case _ => info1
}
} val (start_before_command, start, start_next) =
start_info match { case Some(Text.Info(range, tok)) =>
(keywords.is_before_command(tok), range.start, range.stop) case None => (false, 0, 0)
}
val stop_info = { val info1 = maybe_command_stop(start_next)
info1 match { case Some(Text.Info(range1, tok1)) if tok1.is_command && start_before_command =>
maybe_command_stop(range1.stop) case _ => info1
}
} val stop =
stop_info match { case Some(Text.Info(range, _)) => range.start case None => buffer.getLength
}
val text = JEdit_Lib.get_text(buffer, Text.Range(start, stop)).getOrElse("") val spans = syntax.parse_spans(text)
(spans.iterator.scanLeft(start)(_ + _.length) zip spans.iterator).
map({ case (i, span) => Text.Info(Text.Range(i, i + span.length), span) }).
find(_.range.contains(offset))
} else None
}
overridedef hashCode: Int = (mode, opt_buffer).hashCode overridedef equals(that: Any): Boolean =
that match { case other: Marker => mode == other.mode && opt_buffer == other.opt_buffer case _ => false
}
overridedef toString: String =
opt_buffer match { case None => "Marker(" + mode + ")" case Some(buffer) => "Marker(" + mode + "," + JEdit_Lib.buffer_name(buffer) + ")"
}
overridedef markTokens(
context: TokenMarker.LineContext,
handler: TokenHandler,
raw_line: Segment
): TokenMarker.LineContext = { val line = if (raw_line == null) new Segment else raw_line val line_context =
context match { case c: Line_Context => c case _ => Line_Context.init(mode) } val structure = line_context.structure
val context1 = { val opt_syntax =
opt_buffer match { case Some(buffer) => Isabelle.buffer_syntax(buffer) case None => Isabelle.mode_syntax(mode)
} val (styled_tokens, context1) =
(line_context.context, opt_syntax) match { case (Some(ctxt), _) if mode == "isabelle-ml" || mode == "sml" => val (tokens, ctxt1) = ML_Lex.tokenize_line(mode == "sml", line, ctxt) val styled_tokens =
tokens.map(tok => (JEdit_Rendering.ml_token_markup(tok), tok.source))
(styled_tokens, new Line_Context(line_context.mode, Some(ctxt1), structure))
case (Some(ctxt), Some(syntax)) if syntax.has_tokens => val (tokens, ctxt1) = Token.explode_line(syntax.keywords, line, ctxt) val structure1 = structure.update(syntax.keywords, tokens) val styled_tokens =
tokens.map(tok => (JEdit_Rendering.token_markup(syntax, tok), tok.source))
(styled_tokens, new Line_Context(line_context.mode, Some(ctxt1), structure1))
case _ => val styled_token = (JEditToken.NULL, line.subSequence(0, line.count).toString)
(List(styled_token), new Line_Context(line_context.mode, None, structure))
}
¤ 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.0.5Bemerkung:
¤
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.