src/compiler/expression_contracts.panack
Green: covered; red: known zero; amber: unavailable. Blank lines are outside the executable-start-line denominator.
1 // Literal decoding and scalar arithmetic rules shared by the legacy and bound 2 // frontends. Nominal type identity belongs to the module passes. 3 4 pub record InterpolatedString { 5 parts: [Str], 6 variables: [Str], 7 invalid: Option[Nat] 8 } 9 10 // The lexer has already found the string boundary. Unknown escapes retain their 11 // escaped character, matching the existing literal contract. 12 pub pure decoded_escape(escape: Str): Str { 13 mut decoded: Str = escape 14 15 if escape == "n" { 16 decoded = "\n" 17 } 18 if escape == "r" { 19 decoded = "\r" 20 } 21 if escape == "t" { 22 decoded = "\t" 23 } 24 if escape == "b" { 25 decoded = "\b" 26 } 27 if escape == "f" { 28 decoded = "\f" 29 } 30 decoded 31 } 32 33 pub pure decode_string_literal(text: Str): Str { 34 mut output: Str = "" 35 mut cursor: Nat = 1 36 37 while cursor + 1 < text.len() { 38 character: Str = text[cursor] 39 if character == "\\" && cursor + 2 < text.len() { 40 escape: Str = text[cursor + 1] 41 output = output + decoded_escape(escape) 42 cursor = cursor + 2 43 } else { 44 output = output + character 45 cursor = cursor + 1 46 } 47 } 48 49 output 50 } 51 52 pub pure interpolation_name_start(character: Str): Bool { 53 character.is_letter() || character == "_" 54 } 55 56 pub pure interpolation_name_part(character: Str): Bool { 57 interpolation_name_start(character) || character.is_digit() 58 } 59 60 pub pure split_interpolated_string(text: Str): InterpolatedString { 61 mut parts: [Str] = [] 62 mut variables: [Str] = [] 63 mut part_start: Nat = 0 64 mut cursor: Nat = 0 65 66 mut invalid: Option[Nat] = None() 67 while cursor + 1 < text.len() { 68 if text[cursor] == "$" && text[cursor + 1] == "{" { 69 mut end: Nat = cursor + 2 70 valid_start = end < text.len() && interpolation_name_start(text[end]) 71 while end < text.len() && interpolation_name_part(text[end]) { 72 end = end + 1 73 } 74 if valid_start && end < text.len() && text[end] == "}" { 75 parts = parts.append(text.slice(part_start, cursor)) 76 variables = variables.append(text.slice(cursor + 2, end)) 77 cursor = end + 1 78 part_start = cursor 79 } else { 80 // A bare opening sequence is also used when building source text. 81 while end < text.len() && text[end] != "}" { end = end + 1 } 82 if end < text.len() && invalid == None() { invalid = Some(cursor) } 83 cursor = end 84 } 85 } else { 86 cursor = cursor + 1 87 } 88 } 89 if variables.len() == 0 { 90 InterpolatedString([], [], invalid) 91 } else { 92 parts = parts.append(text.slice(part_start, text.len())) 93 InterpolatedString(parts, variables, invalid) 94 } 95 } 96 97 pub pure scalar_numeric(name: Str): Bool { 98 name == "Nat" || name == "Int" || name == "Dec" || name == "Rat" 99 } 100 101 pub pure scalar_compatible_numeric(left: Str, right: Str): Bool { 102 scalar_numeric(left) && 103 scalar_numeric(right) && 104 !((left == "Dec" || 105 right == "Dec") && 106 left != right) 107 } 108 109 pub pure scalar_arithmetic_result(operator: Str, left: Str, right: Str): Str { 110 if left == "Dec" { 111 "Dec" 112 } else { 113 if operator == "/" || left == "Rat" || right == "Rat" { 114 "Rat" 115 } else { 116 if left == "Int" || right == "Int" { 117 "Int" 118 } else { 119 "Nat" 120 } 121 } 122 } 123 } 124
Functions
[
{
"id": "declaration/1",
"name": "decoded_escape",
"line": 12,
"state": "covered",
"entries": "1364"
},
{
"id": "declaration/2",
"name": "decode_string_literal",
"line": 33,
"state": "covered",
"entries": "24418"
},
{
"id": "declaration/3",
"name": "interpolation_name_start",
"line": 52,
"state": "covered",
"entries": "19180"
},
{
"id": "declaration/4",
"name": "interpolation_name_part",
"line": 56,
"state": "covered",
"entries": "17201"
},
{
"id": "declaration/5",
"name": "split_interpolated_string",
"line": 60,
"state": "covered",
"entries": "24146"
},
{
"id": "declaration/6",
"name": "scalar_numeric",
"line": 97,
"state": "covered",
"entries": "18022"
},
{
"id": "declaration/7",
"name": "scalar_compatible_numeric",
"line": 101,
"state": "covered",
"entries": "6481"
},
{
"id": "declaration/8",
"name": "scalar_arithmetic_result",
"line": 109,
"state": "covered",
"entries": "6474"
}
]Source branch outcomes
[
{
"id": "declaration/1/statement/1/value/decision/true",
"outcome": "true",
"line": 15,
"state": "covered",
"hits": "961"
},
{
"id": "declaration/1/statement/1/value/decision/false",
"outcome": "false",
"line": 15,
"state": "covered",
"hits": "403"
},
{
"id": "declaration/1/statement/2/value/decision/true",
"outcome": "true",
"line": 18,
"state": "covered",
"hits": "16"
},
{
"id": "declaration/1/statement/2/value/decision/false",
"outcome": "false",
"line": 18,
"state": "covered",
"hits": "1348"
},
{
"id": "declaration/1/statement/3/value/decision/true",
"outcome": "true",
"line": 21,
"state": "covered",
"hits": "97"
},
{
"id": "declaration/1/statement/3/value/decision/false",
"outcome": "false",
"line": 21,
"state": "covered",
"hits": "1267"
},
{
"id": "declaration/1/statement/4/value/decision/true",
"outcome": "true",
"line": 24,
"state": "covered",
"hits": "7"
},
{
"id": "declaration/1/statement/4/value/decision/false",
"outcome": "false",
"line": 24,
"state": "covered",
"hits": "1357"
},
{
"id": "declaration/1/statement/5/value/decision/true",
"outcome": "true",
"line": 27,
"state": "covered",
"hits": "7"
},
{
"id": "declaration/1/statement/5/value/decision/false",
"outcome": "false",
"line": 27,
"state": "covered",
"hits": "1357"
},
{
"id": "declaration/2/statement/2/decision/body",
"outcome": "body",
"line": 37,
"state": "covered",
"hits": "350056"
},
{
"id": "declaration/2/statement/2/decision/exit",
"outcome": "exit",
"line": 37,
"state": "covered",
"hits": "24418"
},
{
"id": "declaration/2/statement/2/body/tail/decision/true",
"outcome": "true",
"line": 39,
"state": "covered",
"hits": "1364"
},
{
"id": "declaration/2/statement/2/body/tail/decision/false",
"outcome": "false",
"line": 39,
"state": "covered",
"hits": "348692"
},
{
"id": "declaration/2/statement/2/body/tail/condition/decision/evaluate-right",
"outcome": "evaluate-right",
"line": 39,
"state": "covered",
"hits": "1364"
},
{
"id": "declaration/2/statement/2/body/tail/condition/decision/skip-right",
"outcome": "skip-right",
"line": 39,
"state": "covered",
"hits": "348692"
},
{
"id": "declaration/3/tail/decision/evaluate-right",
"outcome": "evaluate-right",
"line": 53,
"state": "covered",
"hits": "2660"
},
{
"id": "declaration/3/tail/decision/skip-right",
"outcome": "skip-right",
"line": 53,
"state": "covered",
"hits": "16520"
},
{
"id": "declaration/4/tail/decision/evaluate-right",
"outcome": "evaluate-right",
"line": 57,
"state": "covered",
"hits": "1979"
},
{
"id": "declaration/4/tail/decision/skip-right",
"outcome": "skip-right",
"line": 57,
"state": "covered",
"hits": "15222"
},
{
"id": "declaration/5/statement/5/decision/body",
"outcome": "body",
"line": 67,
"state": "covered",
"hits": "307683"
},
{
"id": "declaration/5/statement/5/decision/exit",
"outcome": "exit",
"line": 67,
"state": "covered",
"hits": "24146"
},
{
"id": "declaration/5/statement/5/body/tail/decision/true",
"outcome": "true",
"line": 68,
"state": "covered",
"hits": "1982"
},
{
"id": "declaration/5/statement/5/body/tail/decision/false",
"outcome": "false",
"line": 68,
"state": "covered",
"hits": "305701"
},
{
"id": "declaration/5/statement/5/body/tail/condition/decision/evaluate-right",
"outcome": "evaluate-right",
"line": 68,
"state": "covered",
"hits": "2624"
},
{
"id": "declaration/5/statement/5/body/tail/condition/decision/skip-right",
"outcome": "skip-right",
"line": 68,
"state": "covered",
"hits": "305059"
},
{
"id": "declaration/5/statement/5/body/tail/true/statement/1/value/decision/evaluate-right",
"outcome": "evaluate-right",
"line": 70,
"state": "covered",
"hits": "1979"
},
{
"id": "declaration/5/statement/5/body/tail/true/statement/1/value/decision/skip-right",
"outcome": "skip-right",
"line": 70,
"state": "covered",
"hits": "3"
},
{
"id": "declaration/5/statement/5/body/tail/true/statement/2/decision/body",
"outcome": "body",
"line": 71,
"state": "covered",
"hits": "15222"
},
{
"id": "declaration/5/statement/5/body/tail/true/statement/2/decision/exit",
"outcome": "exit",
"line": 71,
"state": "covered",
"hits": "1982"
},
{
"id": "declaration/5/statement/5/body/tail/true/statement/2/condition/decision/evaluate-right",
"outcome": "evaluate-right",
"line": 71,
"state": "covered",
"hits": "17201"
},
{
"id": "declaration/5/statement/5/body/tail/true/statement/2/condition/decision/skip-right",
"outcome": "skip-right",
"line": 71,
"state": "covered",
"hits": "3"
},
{
"id": "declaration/5/statement/5/body/tail/true/tail/decision/true",
"outcome": "true",
"line": 74,
"state": "covered",
"hits": "1979"
},
{
"id": "declaration/5/statement/5/body/tail/true/tail/decision/false",
"outcome": "false",
"line": 74,
"state": "covered",
"hits": "3"
},
{
"id": "declaration/5/statement/5/body/tail/true/tail/condition/decision/evaluate-right",
"outcome": "evaluate-right",
"line": 74,
"state": "covered",
"hits": "1979"
},
{
"id": "declaration/5/statement/5/body/tail/true/tail/condition/decision/skip-right",
"outcome": "skip-right",
"line": 74,
"state": "covered",
"hits": "3"
},
{
"id": "declaration/5/statement/5/body/tail/true/tail/condition/left/decision/evaluate-right",
"outcome": "evaluate-right",
"line": 74,
"state": "covered",
"hits": "1979"
},
{
"id": "declaration/5/statement/5/body/tail/true/tail/condition/left/decision/skip-right",
"outcome": "skip-right",
"line": 74,
"state": "covered",
"hits": "3"
},
{
"id": "declaration/5/statement/5/body/tail/true/tail/false/statement/0/decision/body",
"outcome": "body",
"line": 81,
"state": "zero",
"hits": "0"
},
{
"id": "declaration/5/statement/5/body/tail/true/tail/false/statement/0/decision/exit",
"outcome": "exit",
"line": 81,
"state": "covered",
"hits": "3"
},
{
"id": "declaration/5/statement/5/body/tail/true/tail/false/statement/0/condition/decision/evaluate-right",
"outcome": "evaluate-right",
"line": 81,
"state": "zero",
"hits": "0"
},
{
"id": "declaration/5/statement/5/body/tail/true/tail/false/statement/0/condition/decision/skip-right",
"outcome": "skip-right",
"line": 81,
"state": "covered",
"hits": "3"
},
{
"id": "declaration/5/statement/5/body/tail/true/tail/false/statement/1/value/decision/true",
"outcome": "true",
"line": 82,
"state": "zero",
"hits": "0"
},
{
"id": "declaration/5/statement/5/body/tail/true/tail/false/statement/1/value/decision/false",
"outcome": "false",
"line": 82,
"state": "covered",
"hits": "3"
},
{
"id": "declaration/5/statement/5/body/tail/true/tail/false/statement/1/value/condition/decision/evaluate-right",
"outcome": "evaluate-right",
"line": 82,
"state": "zero",
"hits": "0"
},
{
"id": "declaration/5/statement/5/body/tail/true/tail/false/statement/1/value/condition/decision/skip-right",
"outcome": "skip-right",
"line": 82,
"state": "covered",
"hits": "3"
},
{
"id": "declaration/5/tail/decision/true",
"outcome": "true",
"line": 89,
"state": "covered",
"hits": "22893"
},
{
"id": "declaration/5/tail/decision/false",
"outcome": "false",
"line": 89,
"state": "covered",
"hits": "1253"
},
{
"id": "declaration/6/tail/decision/evaluate-right",
"outcome": "evaluate-right",
"line": 98,
"state": "covered",
"hits": "575"
},
{
"id": "declaration/6/tail/decision/skip-right",
"outcome": "skip-right",
"line": 98,
"state": "covered",
"hits": "17447"
},
{
"id": "declaration/6/tail/left/decision/evaluate-right",
"outcome": "evaluate-right",
"line": 98,
"state": "covered",
"hits": "617"
},
{
"id": "declaration/6/tail/left/decision/skip-right",
"outcome": "skip-right",
"line": 98,
"state": "covered",
"hits": "17405"
},
{
"id": "declaration/6/tail/left/left/decision/evaluate-right",
"outcome": "evaluate-right",
"line": 98,
"state": "covered",
"hits": "2815"
},
{
"id": "declaration/6/tail/left/left/decision/skip-right",
"outcome": "skip-right",
"line": 98,
"state": "covered",
"hits": "15207"
},
{
"id": "declaration/7/tail/decision/evaluate-right",
"outcome": "evaluate-right",
"line": 102,
"state": "covered",
"hits": "6463"
},
{
"id": "declaration/7/tail/decision/skip-right",
"outcome": "skip-right",
"line": 102,
"state": "covered",
"hits": "18"
},
{
"id": "declaration/7/tail/left/decision/evaluate-right",
"outcome": "evaluate-right",
"line": 102,
"state": "covered",
"hits": "6465"
},
{
"id": "declaration/7/tail/left/decision/skip-right",
"outcome": "skip-right",
"line": 102,
"state": "covered",
"hits": "16"
},
{
"id": "declaration/7/tail/right/operand/decision/evaluate-right",
"outcome": "evaluate-right",
"line": 104,
"state": "covered",
"hits": "12"
},
{
"id": "declaration/7/tail/right/operand/decision/skip-right",
"outcome": "skip-right",
"line": 104,
"state": "covered",
"hits": "6451"
},
{
"id": "declaration/7/tail/right/operand/left/decision/evaluate-right",
"outcome": "evaluate-right",
"line": 104,
"state": "covered",
"hits": "6457"
},
{
"id": "declaration/7/tail/right/operand/left/decision/skip-right",
"outcome": "skip-right",
"line": 104,
"state": "covered",
"hits": "6"
},
{
"id": "declaration/8/tail/decision/true",
"outcome": "true",
"line": 110,
"state": "covered",
"hits": "5"
},
{
"id": "declaration/8/tail/decision/false",
"outcome": "false",
"line": 110,
"state": "covered",
"hits": "6469"
},
{
"id": "declaration/8/tail/false/tail/decision/true",
"outcome": "true",
"line": 113,
"state": "covered",
"hits": "594"
},
{
"id": "declaration/8/tail/false/tail/decision/false",
"outcome": "false",
"line": 113,
"state": "covered",
"hits": "5875"
},
{
"id": "declaration/8/tail/false/tail/condition/decision/evaluate-right",
"outcome": "evaluate-right",
"line": 113,
"state": "covered",
"hits": "5876"
},
{
"id": "declaration/8/tail/false/tail/condition/decision/skip-right",
"outcome": "skip-right",
"line": 113,
"state": "covered",
"hits": "593"
},
{
"id": "declaration/8/tail/false/tail/condition/left/decision/evaluate-right",
"outcome": "evaluate-right",
"line": 113,
"state": "covered",
"hits": "5881"
},
{
"id": "declaration/8/tail/false/tail/condition/left/decision/skip-right",
"outcome": "skip-right",
"line": 113,
"state": "covered",
"hits": "588"
},
{
"id": "declaration/8/tail/false/tail/false/tail/decision/true",
"outcome": "true",
"line": 116,
"state": "covered",
"hits": "708"
},
{
"id": "declaration/8/tail/false/tail/false/tail/decision/false",
"outcome": "false",
"line": 116,
"state": "covered",
"hits": "5167"
},
{
"id": "declaration/8/tail/false/tail/false/tail/condition/decision/evaluate-right",
"outcome": "evaluate-right",
"line": 116,
"state": "covered",
"hits": "5173"
},
{
"id": "declaration/8/tail/false/tail/false/tail/condition/decision/skip-right",
"outcome": "skip-right",
"line": 116,
"state": "covered",
"hits": "702"
}
]Reviewed declaration exclusions
[
{
"id": "declaration/0",
"reason": "record-declaration",
"line": 4
}
]