Class: Cosmos::RubyEditor::RubySyntax
- Inherits:
-
Qt::SyntaxHighlighter
- Object
- Qt::SyntaxHighlighter
- Cosmos::RubyEditor::RubySyntax
- Defined in:
- lib/cosmos/gui/text/ruby_editor.rb
Overview
This works but slows down the GUI significantly when pasting a large (10k line) block of code into the editor
Constant Summary collapse
- RUBY_KEYWORDS =
Ruby keywords - www.ruby-doc.org/docs/keywords/1.9/ Also include some common methods that are typically called by themselves like puts, print, sleep
%w(BEGIN END __ENCODING__ __END__ __FILE__ __LINE__ \ alias and begin break case class def defined? do \ else elsif end ensure false for if in module \ next nil not or raise redo rescue retry return \ self super then true undef unless until when while yield \ puts print sleep)
- STYLES =
Syntax styles - refer to the ruby.properties in Scite
{ 'normal' => create_format('black'), 'ruby_keyword' => create_format('darkBlue','bold'), 'cosmos_keyword' => create_format('blue','bold'), 'operator' => create_format('red'), 'brace' => create_format('black','bold'), 'class' => create_format('blue', 'bold'), 'method' => create_format(Cosmos::getColor(0, 127, 127), 'bold'), 'string' => create_format(Cosmos::getColor(127, 0, 127)), 'symbol' => create_format(Cosmos::getColor(192,160,48)), 'comment' => create_format('green'), }
- BRACES =
Ruby braces
['\{', '\}', '\(', '\)', '\[', '\]','\|']
- RULES =
[]
- RULES_INFO =
Build a QRegExp for each pattern
[]
Class Method Summary collapse
-
.create_format(color = Cosmos::BLACK, style = '') ⇒ Object
common stand alone methods.
Instance Method Summary collapse
Class Method Details
.create_format(color = Cosmos::BLACK, style = '') ⇒ Object
common stand alone methods
43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/cosmos/gui/text/ruby_editor.rb', line 43 def self.create_format(color = Cosmos::BLACK, style='') color = Cosmos::getColor(color) brush = Cosmos::getBrush(color) format = Qt::TextCharFormat.new format.setForeground(brush) if style == 'bold' format.setFontWeight(Qt::Font::Bold) end if style == 'italic' format.setFontItalic(true) end format end |
Instance Method Details
#highlightBlock(text) ⇒ Object
118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 |
# File 'lib/cosmos/gui/text/ruby_editor.rb', line 118 def highlightBlock(text) # Do other syntax formatting RULES_INFO.each do |expression, nth, format| index = expression.indexIn(text, 0) last_index = index last_length = -1 while index >= 0 # We actually want the index of the nth match index = expression.pos(nth) # Bail if the index goes negative because it means # we won't have a valid capture break if index < 0 length = expression.cap(nth).length() break if length <= 0 # Break if we're in an endless loop break if (last_index == index and last_length == length) last_length = length last_index = index self.setFormat(index, length, format) index = expression.indexIn(text, index + length) end end end |