1pub const EBNF: &str = include_str!("../../grammar/vibe-0.1.ebnf");
4pub const GBNF: &str = include_str!("../../grammar/vibe-0.1.gbnf");
5
6pub const SOURCE_SCHEMA_JSON: &str = r#"{
7 "$schema": "https://json-schema.org/draft/2020-12/schema",
8 "title": "vibe-0.1-source",
9 "type": "object",
10 "additionalProperties": false,
11 "required": ["language", "kind", "source"],
12 "properties": {
13 "language": { "const": "vibe-0.1" },
14 "kind": { "enum": ["cell", "module"] },
15 "source": { "type": "string", "minLength": 1 },
16 "locales": {
17 "type": "array",
18 "items": { "type": "string" }
19 },
20 "using": {
21 "type": "array",
22 "items": { "type": "string" }
23 }
24 }
25}"#;
26
27pub const DIAGNOSTIC_SCHEMA_JSON: &str = r#"{
28 "$schema": "https://json-schema.org/draft/2020-12/schema",
29 "title": "vibe-0.1-diagnostic",
30 "type": "object",
31 "required": ["valid", "kind"],
32 "properties": {
33 "valid": { "type": "boolean" },
34 "kind": { "enum": ["cell", "module"] },
35 "error_code": { "type": ["string", "null"] },
36 "span": { "type": ["array", "null"], "items": { "type": "integer" }, "minItems": 2, "maxItems": 2 },
37 "message": { "type": ["string", "null"] },
38 "suggested_fix": { "type": ["string", "null"] },
39 "evidential": { "type": ["array", "null"] },
40 "shacl_violations": { "type": "array" },
41 "errors": { "type": "array" }
42 }
43}"#;
44
45#[cfg(test)]
46mod tests {
47 use super::*;
48
49 #[test]
50 fn ebnf_and_gbnf_are_0_1() {
51 assert!(EBNF.contains("Program"));
52 assert!(EBNF.contains("BindDecl"));
53 assert!(EBNF.contains("LambdaExpr"));
54 assert!(EBNF.contains("TweenExpr"));
55 assert!(EBNF.contains("Expression ::= Pipeline"));
56 assert!(EBNF.contains("PrefixedName"));
57 assert!(GBNF.contains("root"));
58 assert!(GBNF.contains("bind-decl"));
59 assert!(GBNF.contains("lambda"));
60 assert!(GBNF.contains("tween ::="));
61 assert!(GBNF.contains("expr ::= tween"));
62 assert!(!GBNF.contains("<<["));
63 assert!(SOURCE_SCHEMA_JSON.contains("vibe-0.1"));
64 assert!(DIAGNOSTIC_SCHEMA_JSON.contains("\"errors\""));
65 assert!(DIAGNOSTIC_SCHEMA_JSON.contains("evidential"));
66 }
67
68 #[test]
69 fn ebnf_file_matches_vibescript_core_section_3() {
70 let core = include_str!("../../../../docs/manuals/standards/vibescript-core.md")
71 .replace("\r\n", "\n");
72 let marker = "```ebnf\n";
73 let start = core.find(marker).expect("core.md §3 fenced ebnf") + marker.len();
74 let rest = &core[start..];
75 let end = rest.find("```").expect("closing ebnf fence");
76 let from_spec = rest[..end].trim();
77 let from_file = EBNF
78 .replace("\r\n", "\n")
79 .lines()
80 .filter(|line| !line.starts_with("(* vibe-0.1"))
81 .collect::<Vec<_>>()
82 .join("\n");
83 let from_file = from_file.trim();
84 assert_eq!(
85 from_file, from_spec,
86 "crates/vibe/grammar/vibe-0.1.ebnf must stay a copy of vibescript-core.md §3"
87 );
88 }
89}