From 15cb538d20f9bcceb2423d47125c1bbd0c6f07ee Mon Sep 17 00:00:00 2001 From: hydroper Date: Fri, 3 May 2024 09:22:13 -0300 Subject: [PATCH] Remove optional interface methods and refactor --- crates/parser/diagnostics/diagnostic_kind.rs | 2 +- .../diagnostics/diagnostics_english_resources.rs | 2 +- crates/parser/parser/parser.rs | 15 ++++++--------- crates/parser_test/Cargo.toml | 2 +- demo/Cargo.toml | 2 +- examples/asdoc/Cargo.toml | 2 +- 6 files changed, 11 insertions(+), 14 deletions(-) diff --git a/crates/parser/diagnostics/diagnostic_kind.rs b/crates/parser/diagnostics/diagnostic_kind.rs index e03cb70..6931fe4 100644 --- a/crates/parser/diagnostics/diagnostic_kind.rs +++ b/crates/parser/diagnostics/diagnostic_kind.rs @@ -35,7 +35,7 @@ pub enum DiagnosticKind { FunctionMustContainBody = 1055, FunctionMustNotContainAnnotations = 1056, NestedClassesNotAllowed = 1057, - DirectiveNotAllowedInInterface = 1058, + UnexpectedDirective = 1058, FailedParsingAsDocTag = 1059, UnrecognizedAsDocTag = 1060, UnrecognizedProxy = 1061, diff --git a/crates/parser/diagnostics/diagnostics_english_resources.rs b/crates/parser/diagnostics/diagnostics_english_resources.rs index 192a7e7..32af52a 100644 --- a/crates/parser/diagnostics/diagnostics_english_resources.rs +++ b/crates/parser/diagnostics/diagnostics_english_resources.rs @@ -39,7 +39,7 @@ lazy_static! { DiagnosticKind::FunctionMustContainBody.id() => "Function must contain body.".into(), DiagnosticKind::FunctionMustNotContainAnnotations.id() => "Function must not contain annotations.".into(), DiagnosticKind::NestedClassesNotAllowed.id() => "Nested classes are not allowed.".into(), - DiagnosticKind::DirectiveNotAllowedInInterface.id() => "Directive not allowed in interface.".into(), + DiagnosticKind::UnexpectedDirective.id() => "Unexpected directive.".into(), DiagnosticKind::FailedParsingAsDocTag.id() => "Failed parsing contents of ASDoc tag: '@{1}'.".into(), DiagnosticKind::UnrecognizedAsDocTag.id() => "Unrecognized ASDoc tag: '@{1}'.".into(), DiagnosticKind::UnrecognizedProxy.id() => "Unrecognized proxy: '{1}'.".into(), diff --git a/crates/parser/parser/parser.rs b/crates/parser/parser/parser.rs index d424750..1d82cc4 100644 --- a/crates/parser/parser/parser.rs +++ b/crates/parser/parser/parser.rs @@ -3727,14 +3727,11 @@ impl<'input> Parser<'input> { // Body verification. // - // Interface methods are skipped in the verification as they - // may omit body. - if !interface_method { - if (has_native || has_abstract) && common.body.is_some() { - self.add_syntax_error(&name.location(), DiagnosticKind::FunctionMustNotContainBody, diagarg![]); - } else if !(has_native || has_abstract) && common.body.is_none() { - self.add_syntax_error(&name.location(), DiagnosticKind::FunctionMustContainBody, diagarg![]); - } + // Note that interface methods must have a body unlike in Java. + if (has_native || has_abstract) && common.body.is_some() { + self.add_syntax_error(&name.location(), DiagnosticKind::FunctionMustNotContainBody, diagarg![]); + } else if (interface_method || !(has_native || has_abstract)) && common.body.is_none() { + self.add_syntax_error(&name.location(), DiagnosticKind::FunctionMustContainBody, diagarg![]); } // Interface methods must not contain any annotations except for meta-data. @@ -3921,7 +3918,7 @@ impl<'input> Parser<'input> { // Interface block must only contain function definitions for directive in block.directives.iter() { if !(matches!(directive.as_ref(), Directive::FunctionDefinition(_))) { - self.add_syntax_error(&directive.location(), DiagnosticKind::DirectiveNotAllowedInInterface, diagarg![]); + self.add_syntax_error(&directive.location(), DiagnosticKind::UnexpectedDirective, diagarg![]); } } diff --git a/crates/parser_test/Cargo.toml b/crates/parser_test/Cargo.toml index fc873d6..ba62f77 100644 --- a/crates/parser_test/Cargo.toml +++ b/crates/parser_test/Cargo.toml @@ -17,7 +17,7 @@ path = "main.rs" [dependencies] clap = { version = "4.4.8", features = ["derive"] } file_paths = "1.0.0" -as3_parser = { path = "../parser", version = "1.0" } +as3_parser = { path = "../parser", version = "1" } maplit = "1.0.2" serde = { version = "1.0.192", features = ["rc", "derive"] } serde_json = "1.0.108" diff --git a/demo/Cargo.toml b/demo/Cargo.toml index 4c5f005..7614571 100644 --- a/demo/Cargo.toml +++ b/demo/Cargo.toml @@ -7,7 +7,7 @@ edition = "2021" crate-type = ["cdylib"] [dependencies] -as3_parser = { path = "../crates/parser", version = "1.0" } +as3_parser = { path = "../crates/parser", version = "1" } maplit = "1.0.2" serde = { version = "1.0.192", features = ["rc", "derive"] } serde_json = "1.0.108" diff --git a/examples/asdoc/Cargo.toml b/examples/asdoc/Cargo.toml index 8472705..d7c7409 100644 --- a/examples/asdoc/Cargo.toml +++ b/examples/asdoc/Cargo.toml @@ -4,7 +4,7 @@ version = "0.1.0" edition = "2021" [dependencies] -as3_parser = { path = "../../crates/parser", version = "1.0" } +as3_parser = { path = "../../crates/parser", version = "1" } [[example]] name = "asdoc"