Created
April 5, 2014 13:21
-
-
Save masoo/9991849 to your computer and use it in GitHub Desktop.
ruby 用シンタックスハイライト
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
module Masoojer | |
require 'System' | |
require 'mscorlib' | |
require 'WindowsBase' | |
require 'PresentationCore' | |
require 'PresentationFramework' | |
require "Sgry.Azuki" | |
require "System.Drawing" | |
class RubyHighlighter < Sgry::Azuki::Highlighter::KeywordHighlighter | |
def initialize | |
AddRegex System::Text::RegularExpressions::Regex.new(System::String.new("(\\$\\W)|((\\$|\\@\\@?)(\\w+))")), Sgry::Azuki::CharClass.Variable | |
AddRegex System::Text::RegularExpressions::Regex.new(System::String.new("(\\b0[0-7_]+)|(\\b0o[0-7_]+)|(\\b0b[01_]+)|(\\b0x[0-9a-fA-F_]+)|(\\b[1-9][0-9_]*(\\.[0-9_]+)?)(e[+-][0-9]*)?|(\\b0d[1-9][0-9_])")), Sgry::Azuki::CharClass.Number | |
AddRegex System::Text::RegularExpressions::Regex.new(System::String.new(":[a-zA-Z_]\\w*[!?=]?")), Sgry::Azuki::CharClass.Keyword2 | |
AddRegex System::Text::RegularExpressions::Regex.new(System::String.new("(::)?([A-Z]\\w*(::)?)+")), Sgry::Azuki::CharClass.Keyword2 | |
AddRegex System::Text::RegularExpressions::Regex.new(System::String.new("def\\s+(self\.)?[a-zA-Z_]\\w*[!?=]?")), Sgry::Azuki::CharClass.Function | |
AddRegex System::Text::RegularExpressions::Regex.new(System::String.new("(class|module)\\s+[A-Za-z_]\\w*(::\\w+)*(\\?|\\!)?")), Sgry::Azuki::CharClass.Class | |
AddRegex System::Text::RegularExpressions::Regex.new(System::String.new("%[QqWw]?\\([^\\)]*\\)")), Sgry::Azuki::CharClass.String | |
AddRegex System::Text::RegularExpressions::Regex.new(System::String.new("%[QqWw]?\\[[^\\]]*\\]")), Sgry::Azuki::CharClass.String | |
AddRegex System::Text::RegularExpressions::Regex.new(System::String.new("%[QqWw]?\{[^\}]*\}")), Sgry::Azuki::CharClass.String | |
AddRegex System::Text::RegularExpressions::Regex.new(System::String.new("%[QqWw]?\<[^\>]*\>")), Sgry::Azuki::CharClass.String | |
AddRegex System::Text::RegularExpressions::Regex.new(System::String.new("%[QqWw]?\/[^\/]*\/")), Sgry::Azuki::CharClass.String | |
AddRegex System::Text::RegularExpressions::Regex.new(System::String.new("%[QqWw]?\%[^\%]*\%")), Sgry::Azuki::CharClass.String | |
AddRegex System::Text::RegularExpressions::Regex.new(System::String.new("%[QqWw]?\-[^\-]*\-")), Sgry::Azuki::CharClass.String | |
AddRegex System::Text::RegularExpressions::Regex.new(System::String.new("%[QqWw]?\\|[^\\|]*\\|")), Sgry::Azuki::CharClass.String | |
keywordSet = ["alias", "and", "attr_accessor", "attr_reader", "attr_writer", "begin", "BEGIN", "break", "case", "class", | |
"def", "defined", "do", "else", "elsif", "end", "END", "ensure", | |
"false", "for", "if", "in", "include", "module", "next", "nil", "not", | |
"or", "redo", "require", "rescue", "retry", "return", "self", "super", | |
"then", "true", "undef", "unless", "until", "when", "while", "yield"] | |
keywordSet.each do |word| | |
AddRegex System::Text::RegularExpressions::Regex.new(System::String.new("\\b" + word +"( |\\Z)")), Sgry::Azuki::CharClass.Keyword | |
end | |
AddEnclosure System::String.new('\''), System::String.new('\''), Sgry::Azuki::CharClass.String, System::Char.new('\\') | |
AddEnclosure System::String.new('"'), System::String.new('"'), Sgry::Azuki::CharClass.String, System::Char.new('\\') | |
AddLineHighlight "#", Sgry::Azuki::CharClass.Comment | |
#AddEnclosure System::String.new("=begin"), System::String.new("=end"), Sgry::Azuki::CharClass.Comment, true | |
end | |
end | |
def self.build_combobox(height, width, lists, target_value) | |
combobox = System::Windows::Controls::ComboBox.new() | |
combobox.Height = height | |
combobox.Width = width | |
combobox.Padding = System::Windows::Thickness.new("3") | |
combobox.ItemsSource = lists | |
combobox.DisplayMemberPath = "Item1" | |
combobox.SelectedValuePath = "Item2" | |
combobox.BorderThickness = System::Windows::Thickness.new("0") | |
unless lists.any? {|value| value.Item2 == target_value} | |
lists.add(System::Tuple[System::String, System::String].new(target_value, target_value)) | |
end | |
combobox.SelectedValue = target_value | |
combobox | |
end | |
def self.build_statusbaritem(item) | |
statusBarItem = System::Windows::Controls::Primitives::StatusBarItem.new() | |
statusBarItem.Content = item | |
statusBarItem.Padding = System::Windows::Thickness.new("0") | |
statusBarItem | |
end | |
def self.highlighter_Ruby | |
highlighters = System::Collections::Generic::List[System::Tuple[System::String, System::String]].new | |
highlighters.add(System::Tuple[System::String, System::String].new("Default","default")) | |
highlighters.add(System::Tuple[System::String, System::String].new("Ruby","ruby")) | |
highlighterCombobox = build_combobox(24, 85, highlighters, "default") | |
highlighterStatusBarItem = build_statusbaritem(highlighterCombobox) | |
encodeStatusBarItem0 = System::Windows::Controls::Primitives::StatusBarItem.new() | |
statusBarSeparator1 = System::Windows::Controls::Separator.new() | |
statusBarSeparator1.Background = System::Windows::Media::Brushes.LightGray | |
System::Windows::Controls::DockPanel.SetDock(highlighterStatusBarItem, System::Windows::Controls::Dock.Right) | |
System::Windows::Controls::DockPanel.SetDock(statusBarSeparator1, System::Windows::Controls::Dock.Right) | |
$statusBar.Items.add(highlighterStatusBarItem) | |
$statusBar.Items.add(statusBarSeparator1) | |
$statusBar.Items.add(encodeStatusBarItem0) | |
@default_colorscheme = Sgry::Azuki::ColorScheme.new($azukiControl.ColorScheme) | |
@ruby_highlighter_handler = lambda {|sender, event| | |
if File.extname($azukiControl.Document.Name) == ".rb" or highlighterCombobox.SelectedValue == "ruby" | |
$azukiControl.Document.Highlighter = Masoojer::RubyHighlighter.new | |
$azukiControl.ColorScheme.SetColor(Sgry::Azuki::CharClass.String, System::Drawing::Color.FromArgb(0x5D90CD), System::Drawing::Color.Transparent) | |
$azukiControl.ColorScheme.SetColor(Sgry::Azuki::CharClass.Comment, System::Drawing::Color.FromArgb(0x929292), System::Drawing::Color.Transparent) | |
$azukiControl.ColorScheme.SetColor(Sgry::Azuki::CharClass.Number, System::Drawing::Color.FromArgb(0x46A609), System::Drawing::Color.Transparent) | |
$azukiControl.ColorScheme.SetColor(Sgry::Azuki::CharClass.Keyword, System::Drawing::Color.FromArgb(0xC52727), System::Drawing::Color.Transparent) | |
$azukiControl.ColorScheme.SetColor(Sgry::Azuki::CharClass.Keyword2, System::Drawing::Color.FromArgb(0xAF956F), System::Drawing::Color.Transparent) | |
$azukiControl.ColorScheme.SetColor(Sgry::Azuki::CharClass.Variable, System::Drawing::Color.FromArgb(0x39946a), System::Drawing::Color.Transparent) | |
$azukiControl.ColorScheme.SetColor(Sgry::Azuki::CharClass.Function, System::Drawing::Color.FromArgb(0xF25454), System::Drawing::Color.Transparent) | |
$azukiControl.ColorScheme.SetColor(Sgry::Azuki::CharClass.Class, System::Drawing::Color.FromArgb(0xF25454), System::Drawing::Color.Transparent) | |
$azukiControl.Invalidate | |
$azukiControl.Update | |
elsif highlighterCombobox.SelectedValue == "default" | |
$azukiControl.Document.Highlighter = Sgry::Azuki::Highlighter::KeywordHighlighter.new | |
$azukiControl.ColorScheme = @default_colorscheme | |
$azukiControl.Invalidate | |
$azukiControl.Update | |
end | |
} | |
highlighterCombobox.SelectionChanged.add @ruby_highlighter_handler | |
$mainWindow.ScriptLoadingFileEvent.add @ruby_highlighter_handler | |
end | |
end | |
Masoojer::highlighter_Ruby |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment