Language Composition Bestiary - oilshell/oil GitHub Wiki

Languages are generally composed using strings in Unix. This has well-known downsides like escaping problems leading to code injection attacks.

There are two ways that languages are composed using strings.

  • One language can accept a string in another language (eval)
  • One language can generate another: The most basic form of Metaprogramming

Eval (Runtime)

Shell:

  • sh in sh: eval 'echo hi'
  • sh in awk: system('ls | wc -l')
  • sh in make
    • every single line in the actions in sh in make !!! .ONESHELL changes the semantics a bit.
    • $(shell find /) -- capturing it in a variable rather than an action.
  • sh in Python/C, etc: os.system()

Make:

  • make in make: $(eval $(mycode))

Other:

  • X in sh. Shell is special, because more binaries have something like -e
    • python -c
    • perl -e
    • awk '{print $1}'
    • sed -e
  • python in python: eval('1+2'), exec 'print "hi"'

Code Generation (Build Time)

  • shell generating shell

  • sed generating C

  • awk generating C: TODO: Python build system had a sed example I rewrote in Awk. Shell

  • C preprocessor generating C

  • cmake generating Makefiles

  • autoconf

    • m4 generating things that generate shell, make, C headers (config.h)
    • Makefile.pre.in, config.h.in, etc.

Web

  • JS in HTML:
    • <script></script>
    • <onload="">
  • CSS in HTML:
    • <style></style>
    • <p style="">
  • HTML in JS:
    • document.innerHTML = '<p>hi</p>'
    • special extension: JSX, which is PHP-like
  • CSS in JS:
    • element.style = 'font-size: large;'
    • document.querySelectorAll('#id')
⚠️ **GitHub.com Fallback** ⚠️