use ::std::str::FromStr; use crate::ast::{span, Span}; use crate::ast::evolution::*; use crate::ast::object::*; use crate::ast::term::*; grammar; match { // Turn newlines into a token (they are skipped by default) r"(\r\n|\n|\r)(\s|\r|\n)*" => END, } else { // Match string literals and escaped tokens r#"null"# => NULL, r#"("[^"]*"|([^"]*\\")*)"# => STR, r#"`[a-zA-Z_][a-zA-Z0-9_]*`"# => ESC_IDEN, } else { // Ignore comments (only full-line for now) r#"\s*#[^\r\n]*(\r\n|\n|\r)(\s|\r|\n)*"# => { }, } else { // Ignore any other whitespace (except newlines above) r"\s+" => { }, } else { _ } pub evolution: EvolutionAst = { END? "apivolve" END )*> // TODO @mark: is bump still used? )?> )*> END? => EvolutionAst::new(v.to_owned(), vb, ds, es), }; dependency: Dependency = { "depends on" "dynamic" END => Dependency::dynamic(Path::new(p)), // "depends on" "hash" END => Dependency::fixed(p, hash), "depends on" "hash" END => Dependency::fixed(Path::new(p), hash), }; bump: (Span, VersionBump) = { "bump" "patch" END => (span(l, r), VersionBump::Patch), "bump" "minor" END => (span(l, r), VersionBump::Minor), "bump" "major" END => (span(l, r), VersionBump::Major), }; block: Block = { "add" "object" "{" END "description" END )*> "}" => Block::Obj(ObjectEvolution::new(name, ObjectOp::Add(ObjectAdd::with_desc((span(l, r), desc), fields)))), "add" "object" "{" END )*> "}" => Block::Obj(ObjectEvolution::new(name, ObjectOp::Add(ObjectAdd::minimal(fields)))), "change" "object" "{" END "description" END )*> "}" => Block::Obj(ObjectEvolution::new(name, ObjectOp::Change(ObjectChange::with_desc((span(l, r), desc), fields)))), "change" "object" "{" END )*> "}" => Block::Obj(ObjectEvolution::new(name, ObjectOp::Change(ObjectChange::minimal(fields)))), }; object_field: FieldEvolution = { "add" END? => FieldEvolution::new(name, FieldOp::Add(props)), "change" END? => FieldEvolution::new(name, FieldOp::Change(props)), "delete" END => FieldEvolution::new(name, FieldOp::Delete()), } object_field_prop: FieldProperty = { "name" END? => FieldProperty::Name(n), "type" END? => FieldProperty::Type(n), "description" END? => FieldProperty::Description(d.to_owned(), span(l, r)), "default" END? => FieldProperty::Default(Expression::Val(v)), } identifier: Iden = { => Iden::new(n.to_owned(), l, r), => Iden::new_backticked(n.to_owned(), l, r), }; value: Value = { => Value::str(v, span(l, r)), => Value::int(v, span(l, r)), => Value::real(v, span(l, r)), => Value::None(span(l, r)), }