Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 16 additions & 14 deletions REFERENCE.md

Large diffs are not rendered by default.

20 changes: 10 additions & 10 deletions ergo.rego
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@ _object_step_problems(step, true) := {"object step without each_as"} if not "eac
_object_step_problems(step, true) := ({concat("", ["unknown field ", _text(k), " in naming step"]) |
some k in object.keys(step)
not k in {"each_as", "keys"}
} | {"invalid name" | not _valid_name(step.each_as)}) | {"invalid keys" | not _keys_well_formed(step)} if "each_as" in object.keys(step)
} | {"invalid alias" | not _valid_name(step.each_as)}) | {"invalid keys" | not _keys_well_formed(step)} if "each_as" in object.keys(step)

_where_problems(id) := {["identified_by", concat("", [kind, " inside where"])] | some kind in _wrapped_in_where(id)}

Expand Down Expand Up @@ -2686,19 +2686,19 @@ _input_paths(spec) := [object.get(spec, f, []) | some f in ["path", "each"]] if

_name_problems(node, names) := union({_invalid_name_problem(node), _name_given_twice_problem(node, names), _unknown_name_problem(node, names)})

_invalid_name_problem(node) := {"invalid name" |
_invalid_name_problem(node) := {"invalid alias" |
_quantified(node)
"as" in object.keys(node)
not _valid_name(node.as)
}

_name_given_twice_problem(node, names) := {"name given twice" |
_name_given_twice_problem(node, names) := {"alias given twice" |
_quantified(node)
_valid_name(node.as)
node.as in names
}

_unknown_name_problem(node, names) := {concat("", ["unknown name ", p[0]]) |
_unknown_name_problem(node, names) := {concat("", ["unknown alias ", p[0]]) |
some f in ["path", "left", "right", "each", "inputs"]
some p in _own_paths(node, f)
_named(p)
Expand Down Expand Up @@ -3622,12 +3622,12 @@ _as_text(check, given) := concat("", [" as $", check.as]) if {
not check.as in given
}

_as_text(check, given) := " as <name given twice>" if {
_as_text(check, given) := " as <alias given twice>" if {
_valid_name(check.as)
check.as in given
}

_as_text(check, _) := " as <invalid name>" if {
_as_text(check, _) := " as <invalid alias>" if {
"as" in object.keys(check)
not _valid_name(check.as)
}
Expand Down Expand Up @@ -5528,11 +5528,11 @@ _s_sentence_problems(parsed) := (((((((((((((({concat("", [node.bare_word, " is
some node in _s_nodes(parsed)
is_object(node)
"bare_word" in object.keys(node)
} | {concat("", [node.bad_name, " can't be a name"]) |
} | {concat("", [node.bad_name, " can't be an alias"]) |
some node in _s_nodes(parsed)
is_object(node)
"bad_name" in object.keys(node)
}) | {concat("", [node.as, " can't be a name"]) |
}) | {concat("", [node.as, " can't be an alias"]) |
some node in _s_nodes(parsed)
is_object(node)
_s_bad_name(object.get(node, "as", ""))
Expand Down Expand Up @@ -6239,7 +6239,7 @@ _s_elapsed_unsupported(a) := {"an elapsed time isn't supported yet except alone
object.get(a, "terms", []) != [node]
}

_s_from_paths_unsupported(a) := _s_paths_unsupported(a) | {concat("", ["unknown name ", ref.steps[0]]) |
_s_from_paths_unsupported(a) := _s_paths_unsupported(a) | {concat("", ["unknown alias ", ref.steps[0]]) |
some node in _s_nodes(a)
is_object(node)
ref := object.get(node, "named_by", {"start": ""})
Expand Down Expand Up @@ -6758,7 +6758,7 @@ _s_for_line_unsupported(lines, ftext) := _s_for_unsupported(fl, []) | _s_lines_p

_s_for_unsupported(fl, assertions) := ({u | some item in fl.items; some u in _s_item_unsupported(item)} | {u | some a in assertions; some u in _s_assertion_unsupported(a)}) | {u | some i, item in fl.items; some u in _s_names_not_given(item, {later.as | some later in array.slice(fl.items, i, count(fl.items))})}

_s_names_not_given(x, later) := {concat("", ["unknown name ", ref.steps[0]]) |
_s_names_not_given(x, later) := {concat("", ["unknown alias ", ref.steps[0]]) |
some node in _s_nodes(x)
is_object(node)
ref := object.get(node, "named_by", {"start": ""})
Expand Down
67 changes: 43 additions & 24 deletions ergo_test.rego

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion spec/cases/any_of/cases.json
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@
{"name": "checks.any_of_inside.options.a.0", "value": ["any_of can't go here"]},
{"name": "checks.empty_option", "value": ["empty option a"]},
{"name": "checks.empty_options", "value": ["empty options"]},
{"name": "checks.name_from_sibling.options.b.0", "value": ["unknown name $x"]},
{"name": "checks.name_from_sibling.options.b.0", "value": ["unknown alias $x"]},
{"name": "checks.no_options", "value": ["missing options"]},
{"name": "checks.option_object", "value": ["option a not a list"]}
]
Expand Down
18 changes: 9 additions & 9 deletions spec/cases/derived/cases.json
Original file line number Diff line number Diff line change
Expand Up @@ -6217,7 +6217,7 @@
"description": "passes when every pull request has enough reviews",
"rules": [
"sentence.for.line",
"sentence.for.name",
"sentence.for.alias",
"sentence.for.scope",
"for.walk",
"for.try",
Expand Down Expand Up @@ -6309,7 +6309,7 @@
"description": "fails as value when one pull request has too few, and lists it with the sentence that failed",
"rules": [
"sentence.for.line",
"sentence.for.name",
"sentence.for.alias",
"sentence.for.scope",
"for.walk",
"for.try",
Expand Down Expand Up @@ -6403,7 +6403,7 @@
"description": "counts an empty list as 0, which fails the pull request as value",
"rules": [
"sentence.for.line",
"sentence.for.name",
"sentence.for.alias",
"sentence.for.scope",
"for.walk",
"for.try",
Expand Down Expand Up @@ -6468,7 +6468,7 @@
"description": "fails as absent when a pull request has no reviews field",
"rules": [
"sentence.for.line",
"sentence.for.name",
"sentence.for.alias",
"sentence.for.scope",
"for.walk",
"for.try",
Expand Down Expand Up @@ -6552,7 +6552,7 @@
"description": "fails as null when the reviews are null",
"rules": [
"sentence.for.line",
"sentence.for.name",
"sentence.for.alias",
"sentence.for.scope",
"for.walk",
"for.try",
Expand Down Expand Up @@ -6620,7 +6620,7 @@
"description": "fails as unusable when the reviews are not a list",
"rules": [
"sentence.for.line",
"sentence.for.name",
"sentence.for.alias",
"sentence.for.scope",
"for.walk",
"for.try",
Expand Down Expand Up @@ -10679,7 +10679,7 @@
"sentence.derived.elapsed",
"tally.elapsed",
"sentence.for.line",
"sentence.for.name",
"sentence.for.alias",
"sentence.for.scope",
"for.walk",
"for.try",
Expand Down Expand Up @@ -10746,7 +10746,7 @@
"sentence.derived.elapsed",
"tally.elapsed",
"sentence.for.line",
"sentence.for.name",
"sentence.for.alias",
"sentence.for.scope",
"for.walk",
"for.try",
Expand Down Expand Up @@ -10826,7 +10826,7 @@
"sentence.derived.elapsed",
"tally.elapsed",
"sentence.for.line",
"sentence.for.name",
"sentence.for.alias",
"sentence.for.scope",
"for.walk",
"for.try",
Expand Down
22 changes: 11 additions & 11 deletions spec/cases/for/cases.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"for.inputs",
"for.failed_items",
"sentence.for.line",
"sentence.for.name",
"sentence.for.alias",
"sentence.phrase.is"
],
"input": {
Expand Down Expand Up @@ -2050,7 +2050,7 @@
{
"description": "reads the item's field, not the subject's field of the same name",
"rules": [
"sentence.for.name",
"sentence.for.alias",
"for.try",
"for.inputs",
"for.pass",
Expand Down Expand Up @@ -2096,7 +2096,7 @@
{
"description": "a subject whose field has that name is not read when the item lacks the field",
"rules": [
"sentence.for.name",
"sentence.for.alias",
"for.try",
"for.failed_items",
"sentence.phrase.is"
Expand Down Expand Up @@ -2564,7 +2564,7 @@
"for.pass",
"for.inputs",
"for.failed_items",
"sentence.for.name",
"sentence.for.alias",
"sentence.for.scope",
"sentence.phrase.is"
],
Expand Down Expand Up @@ -4875,7 +4875,7 @@
{
"description": "fails every row as ill_formed with no inputs, and $well_formed lists the problem",
"rules": [
"sentence.for.name",
"sentence.for.alias",
"written_wrong",
"written_wrong.row",
"sentence.written_wrong.slot"
Expand Down Expand Up @@ -4967,7 +4967,7 @@
{
"description": "fails every row as ill_formed with no inputs, and $well_formed lists the problem",
"rules": [
"sentence.for.name",
"sentence.for.alias",
"written_wrong",
"written_wrong.row",
"sentence.written_wrong.slot"
Expand Down Expand Up @@ -5010,7 +5010,7 @@
{
"name": "checks.c",
"value": [
"for: params can't be a name"
"for: params can't be an alias"
]
}
]
Expand Down Expand Up @@ -5059,7 +5059,7 @@
{
"description": "fails every row as ill_formed with no inputs, and $well_formed lists the problem",
"rules": [
"sentence.for.name",
"sentence.for.alias",
"written_wrong",
"written_wrong.row",
"sentence.written_wrong.slot"
Expand Down Expand Up @@ -5102,7 +5102,7 @@
{
"name": "checks.c",
"value": [
"for: empty can't be a name"
"for: empty can't be an alias"
]
}
]
Expand Down Expand Up @@ -5151,7 +5151,7 @@
{
"description": "fails every row as ill_formed with no inputs, and $well_formed lists the problem",
"rules": [
"sentence.for.name",
"sentence.for.alias",
"written_wrong",
"written_wrong.row",
"sentence.written_wrong.slot"
Expand Down Expand Up @@ -5194,7 +5194,7 @@
{
"name": "checks.c",
"value": [
"for: input can't be a name"
"for: input can't be an alias"
]
}
]
Expand Down
16 changes: 8 additions & 8 deletions spec/cases/lists/cases.json
Original file line number Diff line number Diff line change
Expand Up @@ -509,11 +509,11 @@
{"name": "checks.as_on_equals", "value": ["as can't go here"]},
{"name": "checks.check_not_object.check", "value": ["invalid check"]},
{"name": "checks.each_on_equals", "value": ["each can't go here"]},
{"name": "checks.invalid_name", "value": ["invalid name"]},
{"name": "checks.name_twice.check", "value": ["name given twice"]},
{"name": "checks.invalid_name", "value": ["invalid alias"]},
{"name": "checks.name_twice.check", "value": ["alias given twice"]},
{"name": "checks.no_check", "value": ["missing check"]},
{"name": "checks.too_deep.check.check", "value": ["nested too deep"]},
{"name": "checks.unknown_name.check", "value": ["unknown name $q"]}
{"name": "checks.unknown_name.check", "value": ["unknown alias $q"]}
]
},
{"requirement": "s", "subject": {"type": "thing", "id": "t1"}, "check": "as_on_equals", "passed": false, "cause": "ill_formed", "inputs": [{"name": "cs", "value": [1]}]},
Expand Down Expand Up @@ -576,8 +576,8 @@
"expressions": {
"s": {
"check_not_object": "every cs: <invalid check>",
"invalid_name": "every cs as <invalid name>: cs[] is present",
"name_twice": "every cs as $x: every b as <name given twice>: $x is present",
"invalid_name": "every cs as <invalid alias>: cs[] is present",
"name_twice": "every cs as $x: every b as <alias given twice>: $x is present",
"no_check": "every cs: <missing check>",
"too_deep": "every cs: every b: <nested too deep>",
"unknown_name": "every cs: $q.v == 1"
Expand Down Expand Up @@ -615,14 +615,14 @@
"inputs": [
{"name": "count(checks)", "value": 2},
{"name": "require", "value": "every"},
{"name": "checks.input", "value": ["invalid name"]},
{"name": "checks.params", "value": ["invalid name"]}
{"name": "checks.input", "value": ["invalid alias"]},
{"name": "checks.params", "value": ["invalid alias"]}
]
},
{"requirement": "s", "subject": {"type": "thing", "id": "t1"}, "check": "input", "passed": false, "cause": "ill_formed", "inputs": [{"name": "cs[]", "value": [1]}], "failed_items": [{"path": "item 1 of cs", "item": "item 1 of cs", "cause": "ill_formed", "value": 1}]},
{"requirement": "s", "subject": {"type": "thing", "id": "t1"}, "check": "params", "passed": false, "cause": "ill_formed", "inputs": [{"name": "cs[]", "value": [1]}], "failed_items": [{"path": "item 1 of cs", "item": "item 1 of cs", "cause": "ill_formed", "value": 1}]}
],
"expressions": {"s": {"params": "every cs as <invalid name>: cs[] is present"}}
"expressions": {"s": {"params": "every cs as <invalid alias>: cs[] is present"}}
}
]
}
Expand Down
3 changes: 2 additions & 1 deletion spec/check_grammar.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@
re.compile(p)
for p in [
r" is a word of the grammar: write \.",
r" can't be a name$",
r" can't be an alias$",
r" is given twice$",
r"^if any can't go with some$",
r"^unknown name ",
r"^unknown alias ",
r"^min above max$",
r"^number out of range: ",
r"^invalid pattern ",
Expand Down
Loading
Loading