(78 lines)
1 #!/usr/bin/env nomsu -V7.0.02 ###3 This file contains some definitions of text escape sequences, including ANSI console4 color codes.6 use "core/metaprogramming"7 use "core/operators"8 use "core/control_flow"10 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~12 test:13 assume "\[1, 2, 3]" == "[1, 2, 3]"14 assume "foo = \(1 + 2)!" == "foo = 3!"15 assume ("16 one17 two18 ") == ("19 one20 two21 ")22 assume "nogap" == "nogap"23 assume (["x", "y"], joined with ",") == "x,y"24 assume (["x", "y"], joined) == "xy"25 assume ("BAR", byte 2) == 6526 assume ("BAR", bytes 1 to 2) == [66, 65]27 assume ("asdf", capitalized) == "Asdf"28 assume ("asdf", uppercase) == "ASDF"29 assume ("asdf", with "s" -> "X") == "aXdf"30 assume31 ("32 one33 two35 "), lines36 ..== ["one", "two", ""]37 ($spec γ¨γ― $body) parses as ($spec means $body)39 test:40 $γγγ«γ‘γ― = "γγγ«γ‘γ―"41 ($ γ¨θ¨γ) γ¨γ― "\($)δΈη"42 assume ($γγγ«γ‘γ― γ¨θ¨γ) == "γγγ«γ‘γ―δΈη"44 ($expr for $match in $text matching $patt) compiles to:45 define mangler46 return Lua ("47 (function()48 local \(mangle "comprehension") = a_List{}49 for \($match as lua expr) in (\($text as lua expr)):gmatch(\($patt as lua expr)) do50 \(mangle "comprehension")[#\(mangle "comprehension")+1] = \($expr as lua)51 end52 return \(mangle "comprehension")53 end)()54 ")56 test:57 assume "\n" == (newline)59 test:60 assume (0xDEADBEEF as hex) == "0xDEADBEEF"62 external:63 ($num as hex) means:64 if ($num < 0):65 return ("-0x%X", formatted with -$num)66 ..else:67 return ("0x%X", formatted with $num)69 ### Text literals70 $escapes = {71 .nl = "\n", .newline = "\n", .tab = "\t", .bell = "\a", .cr = "\r"72 ."carriage return" = "\r", .backspace = "\b", ."form feed" = "\f"73 .formfeed = "\f", ."vertical tab" = "\v"74 }76 for ($name = $str) in $escapes:77 with [$lua = (Lua (quote $str))]:78 $(COMPILE RULES).$name = ->$lua