Class: SublimeDSL::TextMate::Grammar
- Inherits:
-
Object
- Object
- SublimeDSL::TextMate::Grammar
- Includes:
- CustomBaseName
- Defined in:
- lib/sublime_dsl/textmate/grammar.rb,
lib/sublime_dsl/textmate/grammar/dsl_reader.rb,
lib/sublime_dsl/textmate/grammar/dsl_writer.rb,
lib/sublime_dsl/textmate/grammar/plist_reader.rb,
lib/sublime_dsl/textmate/grammar/plist_writer.rb
Overview
A language grammar.
Defined Under Namespace
Classes: BeginEndRule, DSLReader, DSLWriter, Fragment, Include, Match, MatchRule, NoMatchRule, PListReader, PListWriter, Rule, RuleBuilder
Instance Attribute Summary collapse
-
#bundle_uuid ⇒ Object
Returns the value of attribute bundle_uuid.
-
#comment ⇒ Object
Returns the value of attribute comment.
-
#file_types ⇒ Object
Returns the value of attribute file_types.
-
#first_line_match ⇒ Object
Returns the value of attribute first_line_match.
-
#folding_start_marker ⇒ Object
Returns the value of attribute folding_start_marker.
-
#folding_stop_marker ⇒ Object
Returns the value of attribute folding_stop_marker.
-
#fragments ⇒ Object
Returns the value of attribute fragments.
-
#key_equivalent ⇒ Object
TextMate only.
-
#name ⇒ Object
(also: #to_s)
Returns the value of attribute name.
-
#patterns ⇒ Object
content.
-
#scope ⇒ Object
Returns the value of attribute scope.
-
#uuid ⇒ Object
Returns the value of attribute uuid.
Class Method Summary collapse
-
.import(file) ⇒ Object
Create from a PList file.
Instance Method Summary collapse
- #complete! ⇒ Object
- #export(dir) ⇒ Object
-
#initialize(name, scope) ⇒ Grammar
constructor
A new instance of Grammar.
- #resolve_includes(parent) ⇒ Object
- #write(dir) ⇒ Object
Methods included from CustomBaseName
#basename, #basename=, #custom_basename, #dsl_file_arg
Constructor Details
#initialize(name, scope) ⇒ Grammar
Returns a new instance of Grammar.
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/sublime_dsl/textmate/grammar.rb', line 40 def initialize(name, scope) @name = name @scope = scope @file_types = nil @first_line_match = nil @folding_start = nil @folding_stop = nil @key_equivalent = nil @uuid = nil @patterns = [] @fragments = [] end |
Instance Attribute Details
#bundle_uuid ⇒ Object
Returns the value of attribute bundle_uuid.
34 35 36 |
# File 'lib/sublime_dsl/textmate/grammar.rb', line 34 def bundle_uuid @bundle_uuid end |
#comment ⇒ Object
Returns the value of attribute comment.
26 27 28 |
# File 'lib/sublime_dsl/textmate/grammar.rb', line 26 def comment @comment end |
#file_types ⇒ Object
Returns the value of attribute file_types.
25 26 27 |
# File 'lib/sublime_dsl/textmate/grammar.rb', line 25 def file_types @file_types end |
#first_line_match ⇒ Object
Returns the value of attribute first_line_match.
27 28 29 |
# File 'lib/sublime_dsl/textmate/grammar.rb', line 27 def first_line_match @first_line_match end |
#folding_start_marker ⇒ Object
Returns the value of attribute folding_start_marker.
28 29 30 |
# File 'lib/sublime_dsl/textmate/grammar.rb', line 28 def folding_start_marker @folding_start_marker end |
#folding_stop_marker ⇒ Object
Returns the value of attribute folding_stop_marker.
29 30 31 |
# File 'lib/sublime_dsl/textmate/grammar.rb', line 29 def folding_stop_marker @folding_stop_marker end |
#fragments ⇒ Object
Returns the value of attribute fragments.
38 39 40 |
# File 'lib/sublime_dsl/textmate/grammar.rb', line 38 def fragments @fragments end |
#key_equivalent ⇒ Object
TextMate only
32 33 34 |
# File 'lib/sublime_dsl/textmate/grammar.rb', line 32 def key_equivalent @key_equivalent end |
#name ⇒ Object Also known as: to_s
Returns the value of attribute name.
23 24 25 |
# File 'lib/sublime_dsl/textmate/grammar.rb', line 23 def name @name end |
#patterns ⇒ Object
content
37 38 39 |
# File 'lib/sublime_dsl/textmate/grammar.rb', line 37 def patterns @patterns end |
#scope ⇒ Object
Returns the value of attribute scope.
24 25 26 |
# File 'lib/sublime_dsl/textmate/grammar.rb', line 24 def scope @scope end |
#uuid ⇒ Object
Returns the value of attribute uuid.
33 34 35 |
# File 'lib/sublime_dsl/textmate/grammar.rb', line 33 def uuid @uuid end |
Class Method Details
.import(file) ⇒ Object
Create from a PList file.
17 18 19 |
# File 'lib/sublime_dsl/textmate/grammar.rb', line 17 def self.import(file) PListReader.new(file).grammar end |
Instance Method Details
#complete! ⇒ Object
60 61 62 63 64 |
# File 'lib/sublime_dsl/textmate/grammar.rb', line 60 def complete! @repos = fragments.keyed_by(&:name) resolve_includes self fragments.each { |f| resolve_includes f } end |
#export(dir) ⇒ Object
90 91 92 93 |
# File 'lib/sublime_dsl/textmate/grammar.rb', line 90 def export(dir) file = "#{dir}/#{basename}.tmLanguage" PListWriter.new(self).export(file) end |
#resolve_includes(parent) ⇒ Object
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/sublime_dsl/textmate/grammar.rb', line 66 def resolve_includes(parent) parent.patterns.each do |o| if o.respond_to? :patterns resolve_includes o elsif o.is_a?(Include) && o.fragment_name.start_with?('#') name = o.fragment_name[1..-1] o.fragment = @repos[name] if o.fragment o.fragment.used = true else warn "grammar #{self.name}: no such fragment: #{o.fragment_name.inspect}" end end end end |
#write(dir) ⇒ Object
82 83 84 85 86 87 88 |
# File 'lib/sublime_dsl/textmate/grammar.rb', line 82 def write(dir) file = "#{dir}/#{basename}.tmLanguage.rb" File.open(file, 'wb:utf-8') do |f| f.puts '# encoding: utf-8' f.puts "\n" << DSLWriter.new(self).dsl end end |