Interfacing Raku to Gnome GTK+

The Skimming Process

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
use v6;

unit class SkimFile;

has Str $!file-path;
has Array $.mark-texts;

#-------------------------------------------------------------------------------
submethod BUILD ( Str :$!file-path ) {
  die "File $!file-path does not exist" unless $!file-path.IO.r;
  self!search-texts;
}

#-------------------------------------------------------------------------------
method reread-file ( ) {
  self!search-texts;
}

#-------------------------------------------------------------------------------
method !search-texts ( ) {
  $!mark-texts = [];
  my $line-count = 0;
  for $!file-path.IO.slurp.lines -> $line {
    $line-count++;

    if $line ~~
          m/^ \s*
            [ '#' ||                      # Comments in several languages
              '#`{' '{'? || '#`[' '['? || # Comment block in Raku
              '=comment' ||               # Pod document in Raku
              '/*' || '//' ||             # C, C++, Javascript, Qml
              '<!--'                      # XML, html
            ]
            \s*
            $<marker>=[ TODO || DOING || DONE || PLANNING || FIXME ||
                        ARCHIVE || HACK || CHANGED || XXX || IDEA ||
                        NOTE || REVIEW ]
            \s* $<marker-text>=[<-[\n]>+]
            $/ {

      $!mark-texts.push: [ ~$<marker>, $line-count, ~$<marker-text> ];
    }
  }
}

Also this module is far from complex. When the module is BUILD, the search for markers is started by calling search-texts()[11].

A method reread-file() is added to read the file again after changes [15-17].

The search-texts() method is also simple [20]. The file is opened and a loop is started to inspect every line from the file [23]. We keep a count of the lines [24] and check for a marker word after several types of comment characters [26-39]. If a marker is found, the marker, marker text and a line number is stored in an array [41]. The array is readable for the outside world [6].