Source

yoob.js / eg / scanner.html

Full commit
<!DOCTYPE html>
<head>
  <meta charset="utf-8">
  <title>yoob.Scanner Demo</title>
  <script src="../src/yoob/scanner.js"></script>
</head>
<body>

<h1>yoob.Scanner Demo</h1>

<textarea id="input">The* [900beast] of7   "whee  galee"</textarea>

<button id="scan">Scan</button>

</body>
<script>
  var input = document.getElementById('input');

  document.getElementById('scan').onclick = function(e) {
    var s = new yoob.Scanner();
    s.init([
      ['bracket',         "^(\\(|\\)|\\[|\\])"],
      ['integer literal', "^(\\d+)"],
      ['identifier',      "^([a-zA-Z]\\w*)"],
      ['string literal',  "^\"(.*?)\""]
    ]);
    s.reset(input.value);
    while (s.token !== null) {
      alert("'" + s.token + "', type: " + s.type);
      s.scan();
    }
  };
</script>