Skip to content

Commit

Permalink
Remove optional interface methods and refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
hydroper committed May 3, 2024
1 parent 69b4919 commit 15cb538
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 14 deletions.
2 changes: 1 addition & 1 deletion crates/parser/diagnostics/diagnostic_kind.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ pub enum DiagnosticKind {
FunctionMustContainBody = 1055,
FunctionMustNotContainAnnotations = 1056,
NestedClassesNotAllowed = 1057,
DirectiveNotAllowedInInterface = 1058,
UnexpectedDirective = 1058,
FailedParsingAsDocTag = 1059,
UnrecognizedAsDocTag = 1060,
UnrecognizedProxy = 1061,
Expand Down
2 changes: 1 addition & 1 deletion crates/parser/diagnostics/diagnostics_english_resources.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
15 changes: 6 additions & 9 deletions crates/parser/parser/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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![]);
}
}

Expand Down
2 changes: 1 addition & 1 deletion crates/parser_test/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
2 changes: 1 addition & 1 deletion demo/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion examples/asdoc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 15cb538

Please sign in to comment.