anchor.diff:  -module('trane').
   -author('mats cronqvist').
   -export([sax/3
  -         , unit/0
  +         , unit/0,unit/1
            , wget_parse/1,wget_print/1]).
   
   -define(ok(X),$a=<X,X=<$z;$A=<X,X=<$Z;$0=<X,X=<$9;X==$_;X==$-;X==$:).
  
positive.code: dc(Str) -> string:to_lower(Str).
  
  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  %% ad-hoc unit test
  unit() ->
    validate(
      [{"<!DOCTYPE bla><P a=b c=d>",
        [{exclamation,"doctype bla"},
         {tag,"p",[{"a","b"},{"c","d"}]},
         {end_tag,"p"}]},
       {"<head><B>< p><p ></z></ b></x>",
        [{tag,"head",[]},
         {tag,"b",[]},
         {tag,"p",[]},
         {tag,"p",[]}, 
         {end_tag,"p"},
         {end_tag,"p"},
         {end_tag,"b"},
         {end_tag,"head"}]},
       {"<tag catt xatt=\"\" batt>",
        [{tag,"tag",[{"catt",""},{"xatt",""},{"batt",""}]},
         {end_tag,"tag"}]},
       {"<a>...<...</a>",
        [{tag,"a",[]},
         {text,"...&lt;..."},
         {end_tag,"a"}]},
       {"<P a=b c=d>hej<!-- tobbe --><b>svejsan</b>foo</p>grump<x x=y />",
        [{tag,"p",[{"a","b"},{"c","d"}]},
         {text,"hej"},
         {comment," tobbe "},
         {tag,"b",[]},
         {text,"svejsan"},
         {end_tag,"b"},
         {text,"foo"},
         {end_tag,"p"},
         {text,"grump"},
         {tag,"x",[{"x","y"}]},
         {end_tag,"x"}]}
      ]).
  
  validate([]) -> [];
  validate([{Str,Toks}|Vs]) -> 
  
negative.code: tokenize({text,Str,Token}) ->
    case ff(text,Str) of
      {{tag,""},EStr,{text,Txt}} -> 
        try [Token,{text,Txt}]++tokenize({{tag,""},EStr})
        catch _:_ -> tokenize({text,Txt++"&lt;"++EStr,Token})
        end;
      {{text,Str},"",eof} -> [Token,{eof,{text,Str}}]
    end;
  tokenize({TZ,Str,Token}) ->
    [{Token,{TZ,Str}}].
  
  tz(nil,"<"++Str)                        -> {{tag,""},ws(Str)};
  tz(nil,[_|Str])                         -> {nil,Str};
  