#!/usr/bin/env node
// hello

console.log(wow`
  hey cool ${1+2}!!!
  wow ${html`he}ya`}
  ok cool ${html`hey \`wow\`! ${1+2+`w}o\`${wsy`}!!`}
  \` neat \`
`)

;[1,2,3].map(x => x+1)

console.log(0x20 + 1.23e-5 + 0x8 + -3)
b=c-2

/\/wow/

console.log(`ok cool ${1+2}`)

a != 4
a !== 5

var tokenize = require('tokenizer-array')
var rules = {
  c: require('./rules/c.json'),
  js: require('./rules/js.json')
}
var rrules = {}

module.exports = function (src, opts) {
  if (typeof opts === 'string') opts = { lang: opts }
  if (!opts) opts = {}
  var r = rules[opts.lang]
  if (!r) return esc(src)
  var kw0 = {}, kw1 = {}, kw2 = {}
  ;(r.kw0 || []).forEach(function (key) { kw0[key] = true })
  ;(r.kw1 || []).forEach(function (key) { kw1[key] = true })
  ;(r.kw2 || []).forEach(function (key) { kw2[key] = true })
  if (!rrules[opts.lang]) {
    rrules[opts.lang] = r.rules.map(function (x) {
      return { type: x[0], regex: RegExp(x[1]) }
    })
  }
  var tokens = tokenize(src, rrules[opts.lang])
  return tokens.map(function (t) {
    var c = xclass(t.type)
    if (t.type === 'identifier') {
      if (kw0[t.source]) c += ' kw0 kw-' + xclass(t.source)
      else if (kw1[t.source]) c += ' kw1 kw-' + xclass(t.source)
      else if (kw2[t.source]) c += ' kw2 kw-' + xclass(t.source)
    }
    return '<span class="' + c + '">' + esc(t.source) + '</span>'
  }).join('')
}

function xclass (s) { return s.replace(/[\s_]+/g,'-') }
function esc (s) {
  return s.replace(/&/g,'&amp;').replace(/</g,'&lt;').replace(/>/g,'&gt;')
}

#!/bin/bash

echo hello world > /tmp/cool

ls -1 /dev/tty* | sed 's!^/dev/tty!!' | grep -E '^(USB|ACM)'

echo ls sed grep

echo "hey cool $what ${echo hey}!"

export xyz=123

echo 1234=$foo whatever$zzz \$nope \
  hmmm ${cal} ok cool \${lalala}

echo 'cooool
  'whoa"'"' $ffff
  beans >>>> 1+2'

echo "'"

echo <<eof
wow cool eof whatever <> lalala
  hey hey eeeeyy $cool hmmm \$yea
eof

ls /dev

(highlight-syntax -t light test.js; echo '<hr>'
  highlight-syntax -t light test.sh; echo '<hr>'
  highlight-syntax -t light main.c) > /tmp/light.html

(echo cool)

#include <stdio.h>
#define FOO bar

// hello

int main (int argc, char **argv) {
  size_t len = 500;
  printf("%x\n", len);
  a != b;
  return 0;
}