Class: Textpow::SyntaxNode

Inherits:
Object
  • Object
show all
Defined in:
lib/textpow/syntax.rb

Constant Summary collapse

@@syntaxes =

OPTIONS = => Oniguruma::OPTION_CAPTURE_GROUP

{}

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(hash, syntax = nil, name_space = :default) ⇒ SyntaxNode

Returns a new instance of SyntaxNode.



81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'lib/textpow/syntax.rb', line 81

def initialize hash, syntax = nil, name_space = :default
   @name_space = name_space
   @@syntaxes[@name_space] ||= {}
   @@syntaxes[@name_space][hash["scopeName"]] = self if hash["scopeName"]
   @syntax = syntax || self
   hash.each do |key, value|
      case key
      when "firstLineMatch", "foldingStartMarker", "foldingStopMarker", "match", "begin"
         begin
              value.force_encoding("ASCII-8BIT")
            instance_variable_set( "@#{key}", Regexp.new( value ) )
         rescue ArgumentError => e
            raise ParsingError, "Parsing error in #{value}: #{e.to_s}"
         end
      when "content", "fileTypes", "name", "contentName", "end", "scopeName", "keyEquivalent"
         instance_variable_set( "@#{key}", value )
      when "captures", "beginCaptures", "endCaptures"
         instance_variable_set( "@#{key}", value.sort )
      when "repository"
         parse_repository value
      when "patterns"
         create_children value
      else
         STDERR.puts "Ignoring: #{key} => #{value.gsub("\n", "\n>>")}" if $DEBUG
      end
   end
end

Instance Attribute Details

#beginObject

Returns the value of attribute begin.



50
51
52
# File 'lib/textpow/syntax.rb', line 50

def begin
  @begin
end

#beginCapturesObject

Returns the value of attribute beginCaptures.



59
60
61
# File 'lib/textpow/syntax.rb', line 59

def beginCaptures
  @beginCaptures
end

#capturesObject

Returns the value of attribute captures.



58
59
60
# File 'lib/textpow/syntax.rb', line 58

def captures
  @captures
end

#contentObject

Returns the value of attribute content.



51
52
53
# File 'lib/textpow/syntax.rb', line 51

def content
  @content
end

#contentNameObject

Returns the value of attribute contentName.



54
55
56
# File 'lib/textpow/syntax.rb', line 54

def contentName
  @contentName
end

#endObject

Returns the value of attribute end.



55
56
57
# File 'lib/textpow/syntax.rb', line 55

def end
  @end
end

#endCapturesObject

Returns the value of attribute endCaptures.



60
61
62
# File 'lib/textpow/syntax.rb', line 60

def endCaptures
  @endCaptures
end

#fileTypesObject

Returns the value of attribute fileTypes.



52
53
54
# File 'lib/textpow/syntax.rb', line 52

def fileTypes
  @fileTypes
end

#firstLineMatchObject

Returns the value of attribute firstLineMatch.



46
47
48
# File 'lib/textpow/syntax.rb', line 46

def firstLineMatch
  @firstLineMatch
end

#foldingStartMarkerObject

Returns the value of attribute foldingStartMarker.



47
48
49
# File 'lib/textpow/syntax.rb', line 47

def foldingStartMarker
  @foldingStartMarker
end

#foldingStopMarkerObject

Returns the value of attribute foldingStopMarker.



48
49
50
# File 'lib/textpow/syntax.rb', line 48

def foldingStopMarker
  @foldingStopMarker
end

#keyEquivalentObject

Returns the value of attribute keyEquivalent.



57
58
59
# File 'lib/textpow/syntax.rb', line 57

def keyEquivalent
  @keyEquivalent
end

#matchObject

Returns the value of attribute match.



49
50
51
# File 'lib/textpow/syntax.rb', line 49

def match
  @match
end

#nameObject

Returns the value of attribute name.



53
54
55
# File 'lib/textpow/syntax.rb', line 53

def name
  @name
end

#patternsObject

Returns the value of attribute patterns.



62
63
64
# File 'lib/textpow/syntax.rb', line 62

def patterns
  @patterns
end

#repositoryObject

Returns the value of attribute repository.



61
62
63
# File 'lib/textpow/syntax.rb', line 61

def repository
  @repository
end

#scopeNameObject

Returns the value of attribute scopeName.



56
57
58
# File 'lib/textpow/syntax.rb', line 56

def scopeName
  @scopeName
end

#syntaxObject

Returns the value of attribute syntax.



45
46
47
# File 'lib/textpow/syntax.rb', line 45

def syntax
  @syntax
end

Class Method Details

.load(filename, name_space = :default) ⇒ Object



64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/textpow/syntax.rb', line 64

def self.load filename, name_space = :default
   table = nil
   case filename
   when /(\.tmSyntax|\.plist)$/
      table = Plist::parse_xml( filename )
   else
      File.open( filename ) do |f|
         table = YAML.load( f )
      end
   end
   if table
      SyntaxNode.new( table, nil, name_space )
   else
      nil
   end
end

Instance Method Details

#parse(string, processor = nil) ⇒ Object



114
115
116
117
118
119
120
121
122
# File 'lib/textpow/syntax.rb', line 114

def parse( string, processor = nil )
   processor.start_parsing self.scopeName if processor
   stack = [[self, nil]]
   string.each_line do |line|
      parse_line stack, line, processor
   end
   processor.end_parsing self.scopeName if processor
   processor
end

#syntaxesObject



110
111
112
# File 'lib/textpow/syntax.rb', line 110

def syntaxes
   @@syntaxes[@name_space]
end