Skip to content

Instantly share code, notes, and snippets.

@shawwn
Created May 12, 2023 04:46
Show Gist options
  • Save shawwn/373cc9065c9dbb43e4581611677fc6b1 to your computer and use it in GitHub Desktop.
Save shawwn/373cc9065c9dbb43e4581611677fc6b1 to your computer and use it in GitHub Desktop.
I was playing around with writing a lisp-to-cmake compiler. https://github.com/shawwn/pymen/tree/cmake
cmake_policy(VERSION "3.25.0")
set(reserved
ALL
"=" ON
"==" ON
"+" ON
"_" ON
"%" ON
"*" ON
"/" ON
"<" ON
">" ON
"<=" ON
">=" ON
JS
BREAK ON
CASE ON
CATCH ON
CLASS ON
CONST ON
CONTINUE ON
DEBUGGER ON
DEFAULT ON
DELETE ON
DO ON
ELSE ON
EVAL ON
FINALLY ON
FOR ON
FUNCTION ON
IF ON
IMPORT ON
IN ON
INSTANCEOF ON
LET ON
RETURN ON
SWITCH ON
THROW ON
TRY ON
TYPEOF ON
VAR ON
VOID ON
WITH ON
LUA
AND ON
END ON
IN ON
LOAD ON
REPEAT ON
WHILE ON
BREAK ON
FALSE ON
LOCAL ON
RETURN ON
DO ON
FOR ON
NIL ON
THEN ON
ELSE ON
FUNCTION ON
NOT ON
TRUE ON
ELSEIF ON
IF ON
OR ON
UNTIL ON
PY
AND ON
EXCEPT ON
LAMBDA ON
WITH ON
AS ON
FINALLY ON
NONLOCAL ON
WHILE ON
ASSERT ON
FALSE ON
NONE ON
YIELD ON
BREAK ON
FOR ON
NOT ON
CLASS ON
FROM ON
OR ON
CONTINUE ON
GLOBAL ON
PASS ON
DEF ON
IF ON
RAISE ON
DEL ON
IMPORT ON
RETURN ON
ELIF ON
IN ON
TRUE ON
ELSE ON
IS ON
TRY ON
STR ON
PRINT ON
CMAKE
SET ON
FOREACH ON
ENDFOREACH ON
WHILE ON
ENDWHILE ON
IF ON
ELSEIF ON
ELSE ON
BLOCK ON
ENDBLOCK ON
MACRO ON
ENDMACRO ON
FUNCTION ON
ENDFUNCTION ON
BREAK ON
RETURN ON
CONTINUE ON
"AND" ON
"OR" ON
"TRUE" ON
"FALSE" ON
"ON" ON
"OFF" ON
"Y" ON
"N" ON
)
message("hi")
message("${reserved}")
message("${reserved}")
if(4 GREATER 3)
message("yes")
else()
message("no")
endif()
string(LENGTH "foo" _N)
message("${_N}")
function(foo VAR)
set("${VAR}" 42)
return(PROPAGATE "${VAR}")
endfunction()
foo(X)
message("${X}")
function(len x VAR)
return(PROPAGATE string(LENGTH x VAR))
endfunction()
len("foo" _N)
message("${_N}")
set(__e "")
if(4 GREATER 3 AND 2)
set(__e "yes")
else()
set(__e "no")
endif()
message("${__e}")
#!bin/cumen
(cmake_policy VERSION "3.25.0")
(define reserved
(obj
all: (set-of
"=" "==" "+" "-" "%" "*" "/" "<" ">" "<=" ">=")
js: (set-of
"break" "case" "catch" "class" "const" "continue"
"debugger" "default" "delete" "do" "else" "eval"
"finally" "for" "function" "if" "import" "in"
"instanceof" "let" "return" "switch" "throw"
"try" "typeof" "var" "void" "with")
lua: (set-of
"and" "end" "in" "load" "repeat" "while" "break"
"false" "local" "return" "do" "for" "nil" "then"
"else" "function" "not" "true" "elseif" "if" "or"
"until")
py: (set-of
"and" "except" "lambda" "with" "as" "finally" "nonlocal"
"while" "assert" "false" "None" "yield" "break" "for" "not"
"class" "from" "or" "continue" "global" "pass" "def" "if"
"raise" "del" "import" "return" "elif" "in" "True" "else"
"is" "try"
"from" "str" "print")
cmake: (set-of
"set"
"foreach" "endforeach"
"while" "endwhile"
"if" "elseif" "else"
"block" "endblock"
"macro" "endmacro"
"function" "endfunction"
"break" "return" "continue"
"AND" "OR"
"TRUE" "FALSE" "ON" "OFF" "Y" "N")
))
(message "hi")
(message |"${reserved}"|)
(message (%id reserved))
(if (> 4 3)
(message "yes")
(message "no"))
(when-compiling
(define-macro %dollar (x)
`(%id ,x)))
(string LENGTH "foo" N)
(message $N)
(define foo (VAR)
(set $VAR 42))
(foo X)
(message $X)
(define len (x VAR)
(string LENGTH x VAR))
(len "foo" N)
(message $N)
(message (if (and (> 4 3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;ON;JS;BREAK;ON;CASE;ON;CATCH;ON;CLASS;ON;CONST;ON;CONTINUE;ON;DEBUGGER;ON;DEFAULT;ON;DELETE;ON;DO;ON;ELSE;ON;EVAL;ON;FINALLY;ON;FOR;ON;FUNCTION;ON;IF;ON;IMPORT;ON;IN;ON;INSTANCEOF;ON;LET;ON;RETURN;ON;SWITCH;ON;THROW;ON;TRY;ON;TYPEOF;ON;VAR;ON;VOID;ON;WITH;ON;LUA;AND;ON;END;ON;IN;ON;LOAD;ON;REPEAT;ON;WHILE;ON;BREAK;ON;FALSE;ON;LOCAL;ON;RETURN;ON;DO;ON;FOR;ON;NIL;ON;THEN;ON;ELSE;ON;FUNCTION;ON;NOT;ON;TRUE;ON;ELSEIF;ON;IF;ON;OR;ON;UNTIL;ON;PY;AND;ON;EXCEPT;ON;LAMBDA;ON;WITH;ON;AS;ON;FINALLY;ON;NONLOCAL;ON;WHILE;ON;ASSERT;ON;FALSE;ON;NONE;ON;YIELD;ON;BREAK;ON;FOR;ON;NOT;ON;CLASS;ON;FROM;ON;OR;ON;CONTINUE;ON;GLOBAL;ON;PASS;ON;DEF;ON;IF;ON;RAISE;ON;DEL;ON;IMPORT;ON;RETURN;ON;ELIF;ON;IN;ON;TRUE;ON;ELSE;ON;IS;ON;TRY;ON;STR;ON;PRINT;ON;CMAKE;SET;ON;FOREACH;ON;ENDFOREACH;ON;WHILE;ON;ENDWHILE;ON;IF;ON;ELSEIF;ON;ELSE;ON;BLOCK;ON;ENDBLOCK;ON;MACRO;ON;ENDMACRO;ON;FUNCTION;ON;ENDFUNCTION;ON;BREAK;ON;RETURN;ON;CONTINUE;ON;AND;ON;OR;ON;TRUE;ON;FALSE;ON;ON;ON;OFF;ON;Y;ON;N;ON
yes
3
42
3
yes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment