diff options
author | Marc Coquand <marc@mccd.space> | 2024-05-16 08:55:22 -0500 |
---|---|---|
committer | Marc Coquand <marc@mccd.space> | 2024-05-16 08:55:22 -0500 |
commit | 31c00b27094c1ed7c4a1f817c3d14d57cc19458f (patch) | |
tree | d1cf48dee18f638f3f5f9b0fa465af1474a42a34 /local | |
parent | 29c0915254eb71deab3262b44177750679790e61 (diff) | |
download | rcm-31c00b27094c1ed7c4a1f817c3d14d57cc19458f.tar.gz rcm-31c00b27094c1ed7c4a1f817c3d14d57cc19458f.tar.bz2 rcm-31c00b27094c1ed7c4a1f817c3d14d57cc19458f.zip |
Add ocaml-rapper-script
Diffstat (limited to '')
-rwxr-xr-x | local/bin/ocaml-rapper-extract-type.awk | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/local/bin/ocaml-rapper-extract-type.awk b/local/bin/ocaml-rapper-extract-type.awk new file mode 100755 index 0000000..4223570 --- /dev/null +++ b/local/bin/ocaml-rapper-extract-type.awk @@ -0,0 +1,62 @@ +BEGIN { + # Set the initial state + inside_rapper = 0 + statement_name = "" + generated_type = "" + add_bracket = 0 +} + +# Extract function name so that we can use that +# for the type name +/let [a-zA-Z0-9_]+ =/ && inside_rapper == 0 { + statement_name = $2 +} + +# If [%rapper, begin extraction +/\[%rapper/ && inside_rapper == 0 { + inside_rapper = 1 + add_bracket = 1 + printf "type " statement_name "_result = \n" +} + +inside_rapper == 1 && /@[a-z?]+{[a-z_0-9]+}/g { + from = 0 + # Remove everything before "@" and after "}" + pos = match ($0, /@[a-z?]+{[a-z_0-9]+}/, val) + while (0 < pos) { + + # Split the line based on curly braces + split(val[0], parts, /{/) + + # Extract the @type + # Remove the @ + type = substr(parts[1], 2) + + # Remove the last character of key + key = substr(parts[2], 1, length(parts[2])-1) + + # ? = optional + if (substr(type, length(type)) == "?") { + type = substr(type, 1, length(type) - 1) " option" + } + + if (add_bracket == 0){ + print " ; " key " : " type + } + + else if (add_bracket == 1) { + print " { " key " : " type + add_bracket = 0 + } + from += pos + val[0, "length"] + pos = match( substr( $0, from ), /@[a-z?]+{[a-z_0-9]+}/, val ) + } +} + +# If we see |sql], set inside_rapper to 0 +/\|sql}/ && inside_rapper == 1 { + printf " }\n" + inside_rapper = 0 + } + + |