Skip to content

Commit

Permalink
chore: add json source notation, fixing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
e-matteson committed Apr 27, 2024
1 parent edd2755 commit c4c695c
Show file tree
Hide file tree
Showing 3 changed files with 112 additions and 6 deletions.
112 changes: 111 additions & 1 deletion data/json_lang.ron
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ LanguageSpec(
root_construct: "Root",
),
default_display_notation: "DefaultDisplay",
default_source_notation: None,
default_source_notation: Some("DefaultSource"),
notations: [
NotationSetSpec(
name: "DefaultDisplay",
Expand Down Expand Up @@ -193,5 +193,115 @@ LanguageSpec(
),
],
),
NotationSetSpec(
name: "DefaultSource",
notations: [
("Root", Child(0)),
("Null", Literal("null")),
("True", Literal("true")),
("False", Literal("false")),
("String", Concat(Literal("\""), Concat(Text, Literal("\"")))),
// TODO: decide how to represent empty numbers in source notation
("Number", Check(IsEmptyText, Here, Concat(Literal("•"), Text), Text)),
("Array",
Count(
zero: Concat(Literal("["), Concat(FocusMark, Literal("]"))),
one: Choice(
// single line
Concat(Literal("["),
Concat(Flat(Child(0)),
Literal("]"))),
// multi line
Concat(Literal("["),
Concat(Indent(" ", None, Concat(Newline, Child(0))),
Concat(Newline,
Literal("]")))),
),
many: Choice(
// single line
Concat(Literal("["),
Concat(Fold(
first: Flat(Child(0)),
join: Concat(Left, Concat(Literal(", "), Flat(Right))),
),
Literal("]"))),
// multi line
Concat(Literal("["),
Concat(
Indent(" ", None,
Concat(
Newline,
Fold(
first: Child(0),
join: Concat(Left,
Concat(Literal(","),
Concat(Newline,
Right))),
),
)
),
Concat(Newline, Literal("]")))),
),
),
),
("Key", Concat(Literal("\""), Concat(Text, Literal("\"")))),
("ObjectPair",
Choice(
// single line
Concat(Child(0),
Concat(Literal(": "),
Child(1))),
// multi line
Concat(Child(0),
Concat(Literal(":"),
Indent(" ", None, Concat(Newline, Child(1))))),
),
),
("Object",
Count(
zero:
Concat(Literal("{"),
Concat(FocusMark,
Literal("}"))),
one: Choice(
// single line
Concat(Literal("{"),
Concat(Flat(Child(0)),
Literal("}"))),
// multi line
Concat(Literal("{"),
Concat(Indent(" ", None, Concat(Newline, Child(0))),
Concat(Newline,
Literal("}")))),
),
many: Choice(
// single line
Concat(Literal("{"),
Concat(Fold(
first: Flat(Child(0)),
join: Concat(Left, Concat(Literal(", "), Flat(Right))),
),
Literal("}"))),
// multi line
Concat(Literal("{"),
Concat(
Indent(" ", None,
Concat(
Newline,
Fold(
first: Child(0),
join: Concat(Left,
Concat(Literal(","),
Concat(Newline,
Right))),
),
)
),
Concat(Newline, Literal("}")))),
),
)
),
],
),
]
)
4 changes: 0 additions & 4 deletions tests/json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ use std::path::Path;
use synless::{parsing::JsonParser, DocName, Engine, Settings};

const JSON_PATH: &str = "data/json_lang.ron";
const JSON_NOTATION_NAME: &str = "DefaultDisplay";

#[test]
fn test_json() {
Expand All @@ -14,9 +13,6 @@ fn test_json() {
.load_language_ron(Path::new(JSON_PATH), &json_lang_ron)
.unwrap();
engine.add_parser(&language_name, JsonParser);
engine
.set_source_notation(&language_name, JSON_NOTATION_NAME)
.unwrap();

let doc_name = DocName::Auxilliary("<testing>".to_owned());
let source = "{\"primitives\": [true, false, null, 5.3, \"string!\"]}";
Expand Down
2 changes: 1 addition & 1 deletion tests/keyhint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,6 @@ fn test_keyhint_lang() {
add_entry(s, &mut cursor, "l", "right");

let output = engine.print_source(&doc_name).unwrap();
let expected = "h: left l: right";
let expected = "h left l right";
assert_eq!(output, expected);
}

0 comments on commit c4c695c

Please sign in to comment.