Class: LangScan::PairMatcher

Inherits:
Data
  • Object
show all
Defined in:
ext/langscan/pairmatcher/pairmatcher/pairmatcher.c

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(before_open_max, after_open_max, before_close_max, after_close_max) ⇒ Object



110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
# File 'ext/langscan/pairmatcher/pairmatcher/pairmatcher.c', line 110

static VALUE pairmatcher_initialize(
    VALUE self,
    VALUE before_open_max,
    VALUE after_open_max,
    VALUE before_close_max,
    VALUE after_close_max)
{
  pairmatcher_t *pairmatcher;

  Data_Get_Struct(self, pairmatcher_t, pairmatcher);
  if (pairmatcher != NULL) { rb_raise(rb_eArgError, "called twice"); }

  pairmatcher = ALLOC(pairmatcher_t);
  pairmatcher->pair_defs = Qnil;
  pairmatcher->intertoken_defs = Qnil;
  pairmatcher->recent_tokens = Qnil;
  pairmatcher->pair_stack = Qnil;
  pairmatcher->closed_pairs = Qnil;
  DATA_PTR(self) = pairmatcher;

  pairmatcher->before_open_max = NUM2INT(before_open_max);
  pairmatcher->after_open_max = NUM2INT(after_open_max);
  pairmatcher->before_close_max = NUM2INT(before_close_max);
  pairmatcher->after_close_max = NUM2INT(after_close_max);
  pairmatcher->pair_defs = rb_ary_new();
  //RBASIC(pairmatcher->pair_defs)->klass = 0;
  pairmatcher->intertoken_defs = rb_ary_new();
  //RBASIC(pairmatcher->intertoken_defs)->klass = 0;
  pairmatcher->recent_tokens = rb_ary_new();
  //RBASIC(pairmatcher->recent_tokens)->klass = 0;
  pairmatcher->pair_stack = rb_ary_new();
  //RBASIC(pairmatcher->pair_stack)->klass = 0;
  pairmatcher->closed_pairs = rb_ary_new();
  //RBASIC(pairmatcher->closed_pairs)->klass = 0;
  return self;
}

Class Method Details

.fragmentsorter(block) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/langscan/_pairmatcher.rb', line 27

def PairMatcher.fragmentsorter(block)
  buf = []
  pos = 0
  lambda {|f|
    if pos == f.beg_byteno
      pos += f.text.length
      block.call(f)
      buf.sort! {|f1, f2| f1.beg_byteno <=> f2.beg_byteno }
      while !buf.empty? && buf.first.beg_byteno == pos
        f = buf.first
        pos += f.text.length
        block.call(f)
        buf.shift
      end
    else
      buf << f
    end
  }
end

Instance Method Details

#after_close_maxObject



178
179
180
181
182
183
184
# File 'ext/langscan/pairmatcher/pairmatcher/pairmatcher.c', line 178

static VALUE
pairmatcher_get_after_close_max(VALUE self)
{
  pairmatcher_t *pairmatcher;
  GetPM(self, pairmatcher);
  return INT2NUM(pairmatcher->after_close_max);
}

#after_open_maxObject



162
163
164
165
166
167
168
# File 'ext/langscan/pairmatcher/pairmatcher/pairmatcher.c', line 162

static VALUE
pairmatcher_get_after_open_max(VALUE self)
{
  pairmatcher_t *pairmatcher;
  GetPM(self, pairmatcher);
  return INT2NUM(pairmatcher->after_open_max);
}

#before_close_maxObject



170
171
172
173
174
175
176
# File 'ext/langscan/pairmatcher/pairmatcher/pairmatcher.c', line 170

static VALUE
pairmatcher_get_before_close_max(VALUE self)
{
  pairmatcher_t *pairmatcher;
  GetPM(self, pairmatcher);
  return INT2NUM(pairmatcher->before_close_max);
}

#before_open_maxObject



153
154
155
156
157
158
159
160
# File 'ext/langscan/pairmatcher/pairmatcher/pairmatcher.c', line 153

static VALUE
pairmatcher_get_before_open_max(VALUE self)
{
  pairmatcher_t *pairmatcher;
  GetPM(self, pairmatcher);
  if (pairmatcher == NULL) { rb_raise(rb_eArgError, "not initialized"); }
  return INT2NUM(pairmatcher->before_open_max);
}

#define_intertoken_fragment(type, text) ⇒ Object

rb_define_method(PairMatcher, “initialize_copy”, pairmatcher_initialize_copy, 1);



211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
# File 'ext/langscan/pairmatcher/pairmatcher/pairmatcher.c', line 211

static VALUE
pairmatcher_define_intertoken_fragment(VALUE self, VALUE type, VALUE text)
{
  pairmatcher_t *pairmatcher;
  VALUE def;
  Check_Symbol(type);
  if (text != Qnil) {
    StringValue(text);
    text = rb_str_new4(text);
  }

  def = rb_ary_new3(2, type, text);
  //RBASIC(def)->klass = 0;

  GetPM(self, pairmatcher);
  rb_ary_push(pairmatcher->intertoken_defs, def);

  return Qnil;
}

#define_pair(pair_type, open_type, open_text, close_type, close_text) ⇒ Object



186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
# File 'ext/langscan/pairmatcher/pairmatcher/pairmatcher.c', line 186

static VALUE
pairmatcher_define_pair(VALUE self, VALUE pair_type, VALUE open_type, VALUE open_text, VALUE close_type, VALUE close_text)
{
  pairmatcher_t *pairmatcher;
  VALUE def;
  Check_Symbol(open_type);
  if (open_text != Qnil) {
    StringValue(open_text);
    open_text = rb_str_new4(open_text);
  }
  Check_Symbol(close_type);
  if (close_text != Qnil) {
    StringValue(close_text);
    close_text = rb_str_new4(close_text);
  }

  def = rb_ary_new3(5, open_type, open_text, close_type, close_text, pair_type);
  //RBASIC(def)->klass = 0;

  GetPM(self, pairmatcher);
  rb_ary_push(pairmatcher->pair_defs, def);

  return Qnil;
}

#parse(tokenizer, reporter) ⇒ Object



837
838
839
840
841
842
843
844
845
# File 'ext/langscan/pairmatcher/pairmatcher/pairmatcher.c', line 837

static VALUE
pairmatcher_parse(VALUE self, VALUE tokenizer, VALUE reporter)
{
  pairmatcher_t *pairmatcher;
  GetPM(self, pairmatcher);
  parse(pairmatcher, tokenizer, reporter);

  return Qnil;
}