Language Composition Bestiary - oils-for-unix/oils 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
Shell:
-
shinsh:eval 'echo hi' -
shinawk:system('ls | wc -l') -
shinmake- every single line in the actions in
shinmake!!!.ONESHELLchanges the semantics a bit. -
$(shell find /)-- capturing it in a variable rather than an action.
- every single line in the actions in
-
shin Python/C, etc:os.system()
Make:
-
makeinmake:$(eval $(mycode))
Other:
- X in
sh. Shell is special, because more binaries have something like-epython -cperl -eawk '{print $1}'sed -e
- python in python:
eval('1+2'),exec 'print "hi"'
-
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.
- 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')