micro/testspecs.toml

80 lines
3.1 KiB
TOML

# Meta rules are separate rules with priority over all other rules.
# They can be compared to preprocessor directives, but are more powerful.
# Pattern matching in preprocessor style, is running at highest priority before anything else.
[meta.replacements]
comments = ["^--.*", ""]
# Interpolation with a shell, replaces the meta pattern by the interpolation result.
# Passing arguments is supported through groups and #<parameter number> in the shell command.
[meta.interpolation]
with = ["^#with ([\\w./]+)", "cat $1"]
date = ["#date_now", "date"]
user = ["#user", "user"]
test = ["#test", "cat ./mathlib.mlc"]
# Describes tokens to be replaced by identifiers and then later swapped back in after the tokenizer.
# All special tokens are treated as constants
[meta.token]
string_constant = "\".*?\""
char_constant = "'.'"
# Every key below is used as type in an enumerate to sort the tokens
# -> Replacement in order
# -> Every amount of other symbols is saved as some kind of value
# -> Those are using the default type "identifier"
[token]
separator = [" ", ",", "\n"]
operands = [":=", "->", "<=", ">=", "<", ">", "!", "+", "-", "/", "*", "(", ")", "[", "]", "{", "}", "=", "?", ":"]
terminator = [";"]
[semantics]
keywords = ["if", "then", "else", "end"]
[constants]
number = "(?:0b[01]+|0x[0-9a-fA-F]+|0[0-7]+|[1-9][0-9]*)"
character = "'.'"
logic = "(true|false)"
[types]
Number = "number"
Character = "character"
Type = ""
Array = "{character * number}"
Logic = "logic"
# List of rules
# Rules can be found in traces
# use better names than rule_1, rule_2, ...
# The compiler will run through all rules trying to match exactly one.
# Uses the following generic types:
# - OPERAND
# - IDENTIFIER
# - KEYWORD
# - TERMINATOR
# - OTHER (Use this type for ambiguous parts. Same as lazy .+ in regular expressions)
# Definition of custom types are possible, by creation of a rule with the same name.
# IMPORTANT: Rules are always top priority and can overwrite other types.
# Named placeholders: The character # is reserved for named placeholders. They are only valid inside a rule.
[syntax]
definition = "IDENTIFIER#1 -> IDENTIFIER#2 := OTHER#3 TERMINATOR"
definition_with_parameter = "IDENTIFIER#1 : parameter#2 -> IDENTIFIER#3 := OTHER#4 TERMINATOR"
recursion = "#basename OTHER := OTHER #basename OTHER TERMINATOR"
replace_predef = [ "IDENTIFIER#1 -> OTHER := OTHER#2 TERMINATOR OTHER IDENTIFIER#1", "#1 -> OTHER := #2 TERMINATOR OTHER (#2)" ]
replace_postdef = [ "IDENTIFIER#1 OTHER TERMINATOR IDENTIFIER#1 -> OTHER := OTHER#2 TERMINATOR", "#2 OTHER TERMINATOR #1 -> OTHER := #2 TERMINATOR" ]
unfold_parameter = [ ": OTHER IDENTIFIER#1 ( IDENTIFIER#2 OTHER#3 ) OTHER ->", ": OTHER #1 #2 #1 ( #3 ) OTHER ->" ]
unfold_parameter_remove_brackets = [ ": OTHER IDENTIFIER ( ) OTHER ->", ": OTHER OTHER ->" ]
parameter = ": OTHER ->"
# The following sections are used to build different output formats
# [interpreter] refers to the builtin interpreter using a minimal subset of C syntax
# The name of each section is only used to specify the actual output.
[clang]
definition = "#2 #1 () {return (#3);}"
Logic = "int"
Number = "long int"
Character = "char"
Type = "struct"
[interpreter]