Skip to content

Instantly share code, notes, and snippets.

@ingydotnet
Last active December 27, 2015 23:29
Show Gist options
  • Select an option

  • Save ingydotnet/7406691 to your computer and use it in GitHub Desktop.

Select an option

Save ingydotnet/7406691 to your computer and use it in GitHub Desktop.
TestML, JSON/AST, Quisp
# This is a real TestML code snippet from:
# https://github.com/ingydotnet/testml-tml/blob/master/arguments.tml
Plan = 3
*what.combine(*who) == *greeting
*what.combine('and', *else) == *greeting
*what.combine('and', *else.uppercase) == *upper_greeting
# This is a conceptual lossless CompileUnit/AST, in JSON. It's a array of expressions.
# An expression is an array of function name followed by arguments. Lispy.
[
["Assign", "Plan", 3],
["BlockLoop",
["Array", "what", "who", "greeting"],
["EQ",
["combine",
["Point", "what"],
["Point", "who"]
],
["Point", "greeting"],
]
],
["BlockLoop",
["Array", "what", "else", "greeting"],
["EQ",
["combine",
["Point", "what"],
"and",
["Point", "else"]
],
["Point", "greeting"]
],
],
["BlockLoop",
["Array", "what", "else", "upper_greeting"],
["EQ",
["combine",
["Point", "what"],
"and",
["uppercase", ["Point", "else"]]
],
["Point", "upper_greeting"]
]
]
]
# This is a conceptual input format that is fairly trivial to parse. (As simple as
# JSON + some added post parse mapping rules. I got to this from the JSON by just
# removing quotes and sometimes moving the function name from the start position
# to the middle.
# - [] was replaced with ()
# - [Array…] was replaced with […]
# - Quotes can go away just like in Bash. Only words containing space or special chars,
# need quotes.
# - Assign → =
# - BlockLoop → **
# - [Point name] → *name
# - EQ → ==
# Other than that it's a perfect transformation. Not as quite as elegant as canonical
# testml syntax, but also very close to the compilation unit. This would make it easy
# to write a tiny compiler/runtime for TestML::Tiny.
(Plan = 3)
(** [what who greeting] ((*what &combine *who) == *greeting))
(** [what else greeting] ((combine *what and *else) == *greeting))
(** [what else upper_greeting] ((combine *what and (uppercase *else)) == *upper_greeting))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment