Skip to content

Commit

Permalink
Fixed another 'off end of line' bug
Browse files Browse the repository at this point in the history
  • Loading branch information
danlucraft committed Apr 17, 2009
1 parent 567ef09 commit 9447e34
Show file tree
Hide file tree
Showing 6 changed files with 105 additions and 59 deletions.
65 changes: 34 additions & 31 deletions dist/gtkmateview_rb.c
Expand Up @@ -3521,6 +3521,39 @@ static VALUE rb_gtk_mate_parser_set_end_mark_safely(VALUE self, VALUE scope, VAL
return Qnil;
}

static VALUE rb_gtk_mate_parser_set_inner_end_mark_safely(VALUE self, VALUE scope, VALUE m, VALUE line_ix, VALUE length, VALUE cap) {
GtkMateParser* gtk_mate_parser = RVAL2GOBJ(self);
// Method#type_checks
if (TYPE(line_ix) != T_FIXNUM) {
VALUE rb_arg_error = rb_eval_string("ArgumentError");
rb_raise(rb_arg_error, "expected a small integer");
}
if (TYPE(length) != T_FIXNUM) {
VALUE rb_arg_error = rb_eval_string("ArgumentError");
rb_raise(rb_arg_error, "expected a small integer");
}
if (TYPE(cap) != T_FIXNUM) {
VALUE rb_arg_error = rb_eval_string("ArgumentError");
rb_raise(rb_arg_error, "expected a small integer");
}
// Method#argument_type_conversions
GtkMateScope* _c_scope;
_c_scope = _GTK_MATE_SCOPE_SELF(scope);
GtkMateMarker* _c_m;
_c_m = _GTK_MATE_MARKER_SELF(m);
int _c_line_ix;
_c_line_ix = FIX2INT(line_ix);
int _c_length;
_c_length = FIX2INT(length);
int _c_cap;
_c_cap = FIX2INT(cap);
// Method#body

gtk_mate_parser_set_inner_end_mark_safely(gtk_mate_parser, _c_scope, _c_m, _c_line_ix, _c_length, _c_cap);
// Method#return_type_conversion
return Qnil;
}

static VALUE rb_gtk_mate_parser_set_inner_start_mark_safely(VALUE self, VALUE scope, VALUE m, VALUE line_ix, VALUE length, VALUE cap) {
GtkMateParser* gtk_mate_parser = RVAL2GOBJ(self);
// Method#type_checks
Expand Down Expand Up @@ -7141,36 +7174,6 @@ static VALUE rb_onig_rx_search(VALUE self, VALUE target, VALUE start, VALUE end)

/**** PList methods *****/

static VALUE rb_plist_parse(VALUE self, VALUE filename) {
// Method#type_checks
if (TYPE(filename) != T_STRING) {
VALUE rb_arg_error = rb_eval_string("ArgumentError");
rb_raise(rb_arg_error, "expected a string");
}
// Method#argument_type_conversions
char * _c_filename;
_c_filename = g_strdup(STR2CSTR(filename));
// Method#body
GError* inner_error;
inner_error = NULL;

PListDict* _c_return;
_c_return = plist_parse(_c_filename, &inner_error);
if (inner_error != NULL) {
if (inner_error->domain == G_FILE_ERROR) {
rb_raise(rb_vala_error, "[GLib.FileError]: %s", inner_error->message);
}
}
// Method#return_type_conversion
VALUE _rb_return;
if (_c_return == NULL)
_rb_return = Qnil;
else {
_rb_return = GOBJ2RVAL(_c_return);
}
return _rb_return;
}

static VALUE rb_plist_print_plist(VALUE self, VALUE indent, VALUE node) {
// Method#type_checks
if (TYPE(indent) != T_FIXNUM) {
Expand Down Expand Up @@ -7892,7 +7895,6 @@ void Init_gtkmateview_rb() {
rbc_gtk = rb_eval_string("Gtk");
rbc_onig = rb_define_class("Onig", rb_cObject);
rbc_plist = rb_define_class("PList", rb_cObject);
rb_define_singleton_method(rbc_plist, "parse", rb_plist_parse, 1);
rb_define_singleton_method(rbc_plist, "print_plist", rb_plist_print_plist, 2);
rbc_onig_rx = G_DEF_CLASS(onig_rx_get_type(), "Rx", rbc_onig);
rb_define_method(rbc_onig_rx, "initialize", onig_rx_initialize, 0);
Expand Down Expand Up @@ -8123,6 +8125,7 @@ void Init_gtkmateview_rb() {
rb_define_method(rbc_gtk_mate_parser, "remove_tags", rb_gtk_mate_parser_remove_tags, 0);
rb_define_method(rbc_gtk_mate_parser, "reset_table_priorities", rb_gtk_mate_parser_reset_table_priorities, 0);
rb_define_method(rbc_gtk_mate_parser, "set_end_mark_safely", rb_gtk_mate_parser_set_end_mark_safely, 5);
rb_define_method(rbc_gtk_mate_parser, "set_inner_end_mark_safely", rb_gtk_mate_parser_set_inner_end_mark_safely, 5);
rb_define_method(rbc_gtk_mate_parser, "set_inner_start_mark_safely", rb_gtk_mate_parser_set_inner_start_mark_safely, 5);
rb_define_method(rbc_gtk_mate_parser, "set_start_mark_safely", rb_gtk_mate_parser_set_start_mark_safely, 5);
rb_define_method(rbc_gtk_mate_parser, "single_scope", rb_gtk_mate_parser_single_scope, 9);
Expand Down
47 changes: 34 additions & 13 deletions dist/parser.c
Expand Up @@ -372,7 +372,7 @@ static gboolean gtk_mate_parser_parse_line (GtkMateParser* self, gint line_ix) {
line = gtk_mate_buffer_get_line (self->priv->_buffer, line_ix);
length = (gint) strlen (line);
/*buffer.get_line_length(line_ix);
stdout.printf("p%d, ", line_ix);
stdout.printf("p%d, ", line_ix);
stdout.flush();*/
if (line_ix > self->parsed_upto) {
self->parsed_upto = line_ix;
Expand All @@ -385,7 +385,7 @@ static gboolean gtk_mate_parser_parse_line (GtkMateParser* self, gint line_ix) {
_tmp0 = NULL;
start_scope = (_tmp0 = gtk_mate_scope_containing_double_scope (start_scope, line_ix), (start_scope == NULL) ? NULL : (start_scope = (g_object_unref (start_scope), NULL)), _tmp0);
}
/* stdout.printf("start_scope is: %s\n", start_scope.name);*/
/*stdout.printf("start_scope is: %s\n", start_scope.name);*/
end_scope1 = gtk_mate_scope_scope_at (self->root, line_ix, G_MAXINT);
if (end_scope1 != NULL) {
GtkMateScope* _tmp1;
Expand All @@ -407,25 +407,25 @@ static gboolean gtk_mate_parser_parse_line (GtkMateParser* self, gint line_ix) {
GtkMateScope* expected_scope;
m = (GtkMateMarker*) gee_iterator_get (_m_it);
expected_scope = gtk_mate_parser_get_expected_scope (self, gtk_mate_scanner_get_current_scope (scanner), line_ix, scanner->position);
/* if (expected_scope != null)
stdout.printf("expected_scope: %s (%d, %d)\n", expected_scope.name, expected_scope.start_loc().line,
expected_scope.start_loc().line_offset);
else
stdout.printf("no expected scope\n");
stdout.printf(" scope: %s (%d, %d) (line length: %d)\n", m.pattern.name, m.from, m.match.end(0), length);*/
/*if (expected_scope != null)
stdout.printf("expected_scope: %s (%d, %d)\n", expected_scope.name, expected_scope.start_loc().line,
expected_scope.start_loc().line_offset);
else
stdout.printf("no expected scope\n");
stdout.printf(" scope: %s (%d, %d) (line length: %d)\n", m.pattern.name, m.from, m.match.end(0), length);*/
if (m->is_close_scope) {
/* stdout.printf(" (closing)\n");*/
/*stdout.printf(" (closing)\n");*/
gtk_mate_parser_close_scope (self, scanner, expected_scope, line_ix, line, length, m, all_scopes, closed_scopes, removed_scopes);
} else {
if (GTK_MATE_IS_DOUBLE_PATTERN (m->pattern)) {
/* stdout.printf(" (opening)\n");*/
/*stdout.printf(" (opening)\n");*/
gtk_mate_parser_open_scope (self, scanner, expected_scope, line_ix, line, length, m, all_scopes, closed_scopes, removed_scopes);
} else {
/* stdout.printf(" (single)\n");*/
/*stdout.printf(" (single)\n");*/
gtk_mate_parser_single_scope (self, scanner, expected_scope, line_ix, line, length, m, all_scopes, closed_scopes, removed_scopes);
}
}
/* stdout.printf("pretty:\n%s\n", root.pretty(2));*/
/*stdout.printf("pretty:\n%s\n", root.pretty(2));*/
scanner->position = onig_match_end (m->match, 0);
(m == NULL) ? NULL : (m = (g_object_unref (m), NULL));
(expected_scope == NULL) ? NULL : (expected_scope = (g_object_unref (expected_scope), NULL));
Expand Down Expand Up @@ -670,7 +670,7 @@ void gtk_mate_parser_close_scope (GtkMateParser* self, GtkMateScanner* scanner,
if (self->priv->_colourer != NULL) {
gtk_mate_colourer_uncolour_scope (self->priv->_colourer, gtk_mate_scanner_get_current_scope (scanner), FALSE);
}
gtk_mate_scope_inner_end_mark_set (gtk_mate_scanner_get_current_scope (scanner), line_ix, m->from, TRUE);
gtk_mate_parser_set_inner_end_mark_safely (self, gtk_mate_scanner_get_current_scope (scanner), m, line_ix, length, 0);
gtk_mate_parser_set_end_mark_safely (self, gtk_mate_scanner_get_current_scope (scanner), m, line_ix, length, 0);
gtk_mate_scanner_get_current_scope (scanner)->is_open = FALSE;
_tmp10 = NULL;
Expand Down Expand Up @@ -993,6 +993,27 @@ void gtk_mate_parser_set_inner_start_mark_safely (GtkMateParser* self, GtkMateSc
}


void gtk_mate_parser_set_inner_end_mark_safely (GtkMateParser* self, GtkMateScope* scope, GtkMateMarker* m, gint line_ix, gint length, gint cap) {
gint to;
gboolean _tmp0;
g_return_if_fail (self != NULL);
g_return_if_fail (scope != NULL);
g_return_if_fail (m != NULL);
to = onig_match_end (m->match, cap);
_tmp0 = FALSE;
if (to == length) {
_tmp0 = gtk_text_buffer_get_line_count ((GtkTextBuffer*) self->priv->_buffer) > (line_ix + 1);
} else {
_tmp0 = FALSE;
}
if (_tmp0) {
gtk_mate_scope_inner_end_mark_set (scope, line_ix + 1, 0, TRUE);
} else {
gtk_mate_scope_inner_end_mark_set (scope, line_ix, MIN (to, length), TRUE);
}
}


void gtk_mate_parser_set_end_mark_safely (GtkMateParser* self, GtkMateScope* scope, GtkMateMarker* m, gint line_ix, gint length, gint cap) {
gint to;
gboolean _tmp0;
Expand Down
1 change: 1 addition & 0 deletions dist/parser.h
Expand Up @@ -89,6 +89,7 @@ void gtk_mate_parser_handle_captures (GtkMateParser* self, gint line_ix, gint le
OnigRx* gtk_mate_parser_make_closing_regex (GtkMateParser* self, const char* line, GtkMateScope* scope, GtkMateMarker* m);
void gtk_mate_parser_set_start_mark_safely (GtkMateParser* self, GtkMateScope* scope, GtkMateMarker* m, gint line_ix, gint length, gint cap);
void gtk_mate_parser_set_inner_start_mark_safely (GtkMateParser* self, GtkMateScope* scope, GtkMateMarker* m, gint line_ix, gint length, gint cap);
void gtk_mate_parser_set_inner_end_mark_safely (GtkMateParser* self, GtkMateScope* scope, GtkMateMarker* m, gint line_ix, gint length, gint cap);
void gtk_mate_parser_set_end_mark_safely (GtkMateParser* self, GtkMateScope* scope, GtkMateMarker* m, gint line_ix, gint length, gint cap);
void gtk_mate_parser_collect_child_captures (GtkMateParser* self, gint line_ix, gint length, GtkMateScope* scope, GtkMateMarker* m, GeeArrayList* all_scopes, GeeArrayList* closed_scopes);
void gtk_mate_parser_reset_table_priorities (GtkMateParser* self);
Expand Down
1 change: 1 addition & 0 deletions lib/gtkmateview.vapi
Expand Up @@ -166,6 +166,7 @@ namespace Gtk {
public void remove_tags ();
public void reset_table_priorities ();
public void set_end_mark_safely (Gtk.Mate.Scope scope, Gtk.Mate.Marker m, int line_ix, int length, int cap);
public void set_inner_end_mark_safely (Gtk.Mate.Scope scope, Gtk.Mate.Marker m, int line_ix, int length, int cap);
public void set_inner_start_mark_safely (Gtk.Mate.Scope scope, Gtk.Mate.Marker m, int line_ix, int length, int cap);
public void set_start_mark_safely (Gtk.Mate.Scope scope, Gtk.Mate.Marker m, int line_ix, int length, int cap);
public void single_scope (Gtk.Mate.Scanner scanner, Gtk.Mate.Scope? expected_scope, int line_ix, string line, int length, Gtk.Mate.Marker m, Gee.ArrayList<Gtk.Mate.Scope> all_scopes, Gee.ArrayList<Gtk.Mate.Scope> closed_scopes, Gee.ArrayList<Gtk.Mate.Scope> removed_scopes);
Expand Down
34 changes: 21 additions & 13 deletions lib/parser.vala
Expand Up @@ -140,7 +140,7 @@ namespace Gtk.Mate {
private bool parse_line(int line_ix) {
string? line = buffer.get_line(line_ix);
int length = (int) line.size();//buffer.get_line_length(line_ix);
// stdout.printf("p%d, ", line_ix);
//stdout.printf("p%d, ", line_ix);
// stdout.flush();
if (line_ix > this.parsed_upto)
this.parsed_upto = line_ix;
Expand All @@ -150,7 +150,7 @@ namespace Gtk.Mate {
// stdout.printf("start_scope is: %s\n", start_scope.name);
start_scope = start_scope.containing_double_scope(line_ix);
}
// stdout.printf("start_scope is: %s\n", start_scope.name);
//stdout.printf("start_scope is: %s\n", start_scope.name);
var end_scope1 = this.root.scope_at(line_ix, int.MAX);
if (end_scope1 != null)
end_scope1 = end_scope1.containing_double_scope(line_ix);
Expand All @@ -163,28 +163,28 @@ namespace Gtk.Mate {
all_scopes.add(start_scope);
foreach (Marker m in scanner) {
var expected_scope = get_expected_scope(scanner.current_scope, line_ix, scanner.position);
// if (expected_scope != null)
// stdout.printf("expected_scope: %s (%d, %d)\n", expected_scope.name, expected_scope.start_loc().line,
// expected_scope.start_loc().line_offset);
// else
// stdout.printf("no expected scope\n");
// stdout.printf(" scope: %s (%d, %d) (line length: %d)\n", m.pattern.name, m.from, m.match.end(0), length);
// if (expected_scope != null)
// stdout.printf("expected_scope: %s (%d, %d)\n", expected_scope.name, expected_scope.start_loc().line,
// expected_scope.start_loc().line_offset);
// else
// stdout.printf("no expected scope\n");
// stdout.printf(" scope: %s (%d, %d) (line length: %d)\n", m.pattern.name, m.from, m.match.end(0), length);
if (m.is_close_scope) {
// stdout.printf(" (closing)\n");
// stdout.printf(" (closing)\n");
close_scope(scanner, expected_scope, line_ix, line, length, m,
all_scopes, closed_scopes, removed_scopes);
}
else if (m.pattern is DoublePattern) {
// stdout.printf(" (opening)\n");
// stdout.printf(" (opening)\n");
open_scope(scanner, expected_scope, line_ix, line, length, m,
all_scopes, closed_scopes, removed_scopes);
}
else {
// stdout.printf(" (single)\n");
// stdout.printf(" (single)\n");
single_scope(scanner, expected_scope, line_ix, line, length, m,
all_scopes, closed_scopes, removed_scopes);
}
// stdout.printf("pretty:\n%s\n", root.pretty(2));
// stdout.printf("pretty:\n%s\n", root.pretty(2));
scanner.position = m.match.end(0);
}
clear_line(line_ix, start_scope, all_scopes, closed_scopes, removed_scopes);
Expand Down Expand Up @@ -303,7 +303,7 @@ namespace Gtk.Mate {
if (colourer != null) {
colourer.uncolour_scope(scanner.current_scope, false);
}
scanner.current_scope.inner_end_mark_set(line_ix, m.from, true);
set_inner_end_mark_safely(scanner.current_scope, m, line_ix, length, 0);
set_end_mark_safely(scanner.current_scope, m, line_ix, length, 0);
scanner.current_scope.is_open = false;
scanner.current_scope.end_match_string = end_match_string;
Expand Down Expand Up @@ -476,6 +476,14 @@ namespace Gtk.Mate {
else
scope.inner_start_mark_set(line_ix, int.min(to, length), true);
}

public void set_inner_end_mark_safely(Scope scope, Marker m, int line_ix, int length, int cap) {
int to = m.match.end(cap);
if (to == length && this.buffer.get_line_count() > line_ix+1)
scope.inner_end_mark_set(line_ix+1, 0, true);
else
scope.inner_end_mark_set(line_ix, int.min(to, length), true);
}

public void set_end_mark_safely(Scope scope, Marker m, int line_ix, int length, int cap) {
int to = m.match.end(cap);
Expand Down
16 changes: 14 additions & 2 deletions spec/static_parsing_spec.rb
Expand Up @@ -4,6 +4,7 @@

describe Gtk::Mate::Parser, "when parsing Ruby from scratch" do
before(:each) do
Gtk::Mate.textmate_dir = File.join(File.dirname(__FILE__), %w(.. .. .. textmate))
@mb = Gtk::Mate::Buffer.new
@mb.set_grammar_by_name("Ruby")
end
Expand Down Expand Up @@ -99,7 +100,6 @@

it "creates multiple levels of scopes" do
@mb.text = "\"william \#{:joseph} adama\""
puts @mb.parser.root.pretty(0)
@mb.parser.root.pretty(0).should == (t=<<END)
+ source.ruby (0,0)-(0,26) open
+ string.quoted.double.ruby (0,0)-(0,26) closed
Expand Down Expand Up @@ -239,7 +239,6 @@ class Red < Car
C
@mb.set_grammar_by_name("C")
@mb.text = source
puts @mb.parser.root.pretty(0)
@mb.parser.root.pretty(0).should_not include("invalid.illegal")
end

Expand Down Expand Up @@ -269,6 +268,19 @@ class Red < Car
@mb.set_grammar_by_name("Ruby")
@mb.text = source
end

it "should parse this PHP without dying" do
source = <<-PHP
<?php
/**
*
*/
class ClassName extends AnotherClass
{
PHP
@mb.set_grammar_by_name("PHP")
@mb.text = source
end
end


0 comments on commit 9447e34

Please sign in to comment.