Task

Find all    <lang>    tags without a language specified in the text of a page.

Display counts by language section:

Description

<lang>Pseudocode</lang>

=={{header|C}}==
<lang C>printf("Hello world!\n");</lang>

=={{header|Perl}}==
<lang>print "Hello world!\n"</lang>

should display something like

2 bare language tags.

1 in perl
1 in no language



Extra credit

Allow multiple files to be read.   Summarize all results by language:

5 bare language tags.

2 in c ([[Foo]], [[Bar]])
1 in perl ([[Foo]])
2 in no language ([[Baz]])



Extra extra credit

Use the   Media Wiki API   to test actual RC tasks.




import "/ioutil" for FileUtil
import "/pattern" for Pattern
import "/set" for Set
import "/sort" for Sort
import "/fmt" for Fmt
 
var p = Pattern.new("/=/={{header/|[+0/y]}}/=/=", Pattern.start)
var bareCount = 0
var bareLang = {}
for (fileName in ["example.txt", "example2.txt", "example3.txt"]) {
    var lines = FileUtil.readLines(fileName)
    var lastHeader = "No language"
    for (line in lines) {
        line = line.trimStart()
        if (line == "") continue
        var m = p.find(line)
        if (m) {
            lastHeader = m.capsText[0]
            continue
        }
        if (line.startsWith("<lang>")) {
            bareCount = bareCount + 1
            var value = bareLang[lastHeader]
            if (value) {
                value[0] = value[0] + 1
                value[1].add(fileName)
            } else {
                bareLang[lastHeader] = [1, Set.new([fileName])]
            }
        }
    }
}
System.print("%(bareCount) bare language tags:")
for (me in bareLang) {
    var lang  = me.key
    var count = me.value[0]
    var names = me.value[1].toList
    Sort.insertion(names)
    Fmt.print(" $2d in $-11s $n", count, lang, names)
}