Class: Textpow::SyntaxNode
- Inherits:
-
Object
- Object
- Textpow::SyntaxNode
- Defined in:
- lib/textpow/syntax.rb
Constant Summary collapse
- @@syntaxes =
OPTIONS = => Oniguruma::OPTION_CAPTURE_GROUP
{}
Instance Attribute Summary collapse
-
#begin ⇒ Object
Returns the value of attribute begin.
-
#beginCaptures ⇒ Object
Returns the value of attribute beginCaptures.
-
#captures ⇒ Object
Returns the value of attribute captures.
-
#content ⇒ Object
Returns the value of attribute content.
-
#contentName ⇒ Object
Returns the value of attribute contentName.
-
#end ⇒ Object
Returns the value of attribute end.
-
#endCaptures ⇒ Object
Returns the value of attribute endCaptures.
-
#fileTypes ⇒ Object
Returns the value of attribute fileTypes.
-
#firstLineMatch ⇒ Object
Returns the value of attribute firstLineMatch.
-
#foldingStartMarker ⇒ Object
Returns the value of attribute foldingStartMarker.
-
#foldingStopMarker ⇒ Object
Returns the value of attribute foldingStopMarker.
-
#keyEquivalent ⇒ Object
Returns the value of attribute keyEquivalent.
-
#match ⇒ Object
Returns the value of attribute match.
-
#name ⇒ Object
Returns the value of attribute name.
-
#patterns ⇒ Object
Returns the value of attribute patterns.
-
#repository ⇒ Object
Returns the value of attribute repository.
-
#scopeName ⇒ Object
Returns the value of attribute scopeName.
-
#syntax ⇒ Object
Returns the value of attribute syntax.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(hash, syntax = nil, name_space = :default) ⇒ SyntaxNode
constructor
A new instance of SyntaxNode.
- #parse(string, processor = nil) ⇒ Object
- #syntaxes ⇒ Object
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
#begin ⇒ Object
Returns the value of attribute begin.
50 51 52 |
# File 'lib/textpow/syntax.rb', line 50 def begin @begin end |
#beginCaptures ⇒ Object
Returns the value of attribute beginCaptures.
59 60 61 |
# File 'lib/textpow/syntax.rb', line 59 def beginCaptures @beginCaptures end |
#captures ⇒ Object
Returns the value of attribute captures.
58 59 60 |
# File 'lib/textpow/syntax.rb', line 58 def captures @captures end |
#content ⇒ Object
Returns the value of attribute content.
51 52 53 |
# File 'lib/textpow/syntax.rb', line 51 def content @content end |
#contentName ⇒ Object
Returns the value of attribute contentName.
54 55 56 |
# File 'lib/textpow/syntax.rb', line 54 def contentName @contentName end |
#end ⇒ Object
Returns the value of attribute end.
55 56 57 |
# File 'lib/textpow/syntax.rb', line 55 def end @end end |
#endCaptures ⇒ Object
Returns the value of attribute endCaptures.
60 61 62 |
# File 'lib/textpow/syntax.rb', line 60 def endCaptures @endCaptures end |
#fileTypes ⇒ Object
Returns the value of attribute fileTypes.
52 53 54 |
# File 'lib/textpow/syntax.rb', line 52 def fileTypes @fileTypes end |
#firstLineMatch ⇒ Object
Returns the value of attribute firstLineMatch.
46 47 48 |
# File 'lib/textpow/syntax.rb', line 46 def firstLineMatch @firstLineMatch end |
#foldingStartMarker ⇒ Object
Returns the value of attribute foldingStartMarker.
47 48 49 |
# File 'lib/textpow/syntax.rb', line 47 def foldingStartMarker @foldingStartMarker end |
#foldingStopMarker ⇒ Object
Returns the value of attribute foldingStopMarker.
48 49 50 |
# File 'lib/textpow/syntax.rb', line 48 def foldingStopMarker @foldingStopMarker end |
#keyEquivalent ⇒ Object
Returns the value of attribute keyEquivalent.
57 58 59 |
# File 'lib/textpow/syntax.rb', line 57 def keyEquivalent @keyEquivalent end |
#match ⇒ Object
Returns the value of attribute match.
49 50 51 |
# File 'lib/textpow/syntax.rb', line 49 def match @match end |
#name ⇒ Object
Returns the value of attribute name.
53 54 55 |
# File 'lib/textpow/syntax.rb', line 53 def name @name end |
#patterns ⇒ Object
Returns the value of attribute patterns.
62 63 64 |
# File 'lib/textpow/syntax.rb', line 62 def patterns @patterns end |
#repository ⇒ Object
Returns the value of attribute repository.
61 62 63 |
# File 'lib/textpow/syntax.rb', line 61 def repository @repository end |
#scopeName ⇒ Object
Returns the value of attribute scopeName.
56 57 58 |
# File 'lib/textpow/syntax.rb', line 56 def scopeName @scopeName end |
#syntax ⇒ Object
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 |
#syntaxes ⇒ Object
110 111 112 |
# File 'lib/textpow/syntax.rb', line 110 def syntaxes @@syntaxes[@name_space] end |