Skip to content

Commit

Permalink
Merge branch 'develop-parsing-error-msg' into develop. Close #96.
Browse files Browse the repository at this point in the history
**Description**

Ogma relies on an existing library for error message reporting of JSON
files.

That library, by default, provides very plain error messages and the
line and column number of the error cannot be customized or
contextualized. This causes error messages to seem to apply to a line
and column in the file, when they really apply to the line and column of
a specific requirement (which may be hard to indentify).

**Type**

- Feature: improve error reporting messages in parsing of FRET CS JSON files.

**Additional context**

None.

**Requester**

- Ivan Perez

**Method to check presence of bug**

Not applicable (new feature).

**Expected result**

An error in a requirement in a FRET CS file indicates which requirement
it applies to.

**Solution implemented**

Modify parser to produce name of requirement on parsing errors.

Adjust test vectors and examples to include vacuous values in fields
that previously had none, since the new implementation is no longer as
lazy.

**Further notes**

None.
  • Loading branch information
ivanperez-keera committed Jul 22, 2023
2 parents b855b64 + b1e29d0 commit 9bce96a
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 8 deletions.
4 changes: 4 additions & 0 deletions ogma-cli/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Revision history for ogma-cli

## [1.X.X] - 2023-07-21

* Correct test case (#96).

## [1.0.9] - 2023-05-21

* Version bump 1.0.9 (#93).
Expand Down
2 changes: 1 addition & 1 deletion ogma-cli/examples/fret.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"Requirements": [
{
"name": "behnazOne",
"CoCoSpecCode": "",
"CoCoSpecCode": "true",
"ptLTL": "((H ((((! <b><i>flight_mode</i></b>) & (Y <b><i>flight_mode</i></b>)) & (Y TRUE)) -> (Y (((O[=<b><i>10</i></b>] ((<b><i>(conflict_detected)</i></b> & ((Y (! <b><i>(conflict_detected)</i></b>)) | (<b><i>flight_mode</i></b> & ((! (Y TRUE)) | (Y (! <b><i>flight_mode</i></b>)))))) & (! <b><i>(( replanning_mode ))</i></b>))) -> (O[<<b><i>10</i></b>] ((<b><i>flight_mode</i></b> & ((! (Y TRUE)) | (Y (! <b><i>flight_mode</i></b>)))) | <b><i>(( replanning_mode ))</i></b>))) S (((O[=<b><i>10</i></b>] ((<b><i>(conflict_detected)</i></b> & ((Y (! <b><i>(conflict_detected)</i></b>)) | (<b><i>flight_mode</i></b> & ((! (Y TRUE)) | (Y (! <b><i>flight_mode</i></b>)))))) & (! <b><i>(( replanning_mode ))</i></b>))) -> (O[<<b><i>10</i></b>] ((<b><i>flight_mode</i></b> & ((! (Y TRUE)) | (Y (! <b><i>flight_mode</i></b>)))) | <b><i>(( replanning_mode ))</i></b>))) & (<b><i>flight_mode</i></b> & ((! (Y TRUE)) | (Y (! <b><i>flight_mode</i></b>))))))))) & (((! ((! <b><i>flight_mode</i></b>) & (Y <b><i>flight_mode</i></b>))) S ((! ((! <b><i>flight_mode</i></b>) & (Y <b><i>flight_mode</i></b>))) & (<b><i>flight_mode</i></b> & ((! (Y TRUE)) | (Y (! <b><i>flight_mode</i></b>)))))) -> (((O[=<b><i>10</i></b>] ((<b><i>(conflict_detected)</i></b> & ((Y (! <b><i>(conflict_detected)</i></b>)) | (<b><i>flight_mode</i></b> & ((! (Y TRUE)) | (Y (! <b><i>flight_mode</i></b>)))))) & (! <b><i>(( replanning_mode ))</i></b>))) -> (O[<<b><i>10</i></b>] ((<b><i>flight_mode</i></b> & ((! (Y TRUE)) | (Y (! <b><i>flight_mode</i></b>)))) | <b><i>(( replanning_mode ))</i></b>))) S (((O[=<b><i>10</i></b>] ((<b><i>(conflict_detected)</i></b> & ((Y (! <b><i>(conflict_detected)</i></b>)) | (<b><i>flight_mode</i></b> & ((! (Y TRUE)) | (Y (! <b><i>flight_mode</i></b>)))))) & (! <b><i>(( replanning_mode ))</i></b>))) -> (O[<<b><i>10</i></b>] ((<b><i>flight_mode</i></b> & ((! (Y TRUE)) | (Y (! <b><i>flight_mode</i></b>)))) | <b><i>(( replanning_mode ))</i></b>))) & (<b><i>flight_mode</i></b> & ((! (Y TRUE)) | (Y (! <b><i>flight_mode</i></b>))))))))",
"fretish": "Meaning not specified"
}
Expand Down
4 changes: 4 additions & 0 deletions ogma-core/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Revision history for ogma-core

## [1.X.X] - 2023-07-21

* Correct test case (#96).

## [1.0.9] - 2023-05-21

* Version bump 1.0.9 (#93).
Expand Down
2 changes: 1 addition & 1 deletion ogma-core/tests/fret_good.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"Requirements": [
{
"name": "behnazOne",
"CoCoSpecCode": "",
"CoCoSpecCode": "true",
"ptLTL": "((H ((((! <b><i>flight_mode</i></b>) & (Y <b><i>flight_mode</i></b>)) & (Y TRUE)) -> (Y (((O[=<b><i>10</i></b>] ((<b><i>(conflict_detected)</i></b> & ((Y (! <b><i>(conflict_detected)</i></b>)) | (<b><i>flight_mode</i></b> & ((! (Y TRUE)) | (Y (! <b><i>flight_mode</i></b>)))))) & (! <b><i>(( replanning_mode ))</i></b>))) -> (O[<<b><i>10</i></b>] ((<b><i>flight_mode</i></b> & ((! (Y TRUE)) | (Y (! <b><i>flight_mode</i></b>)))) | <b><i>(( replanning_mode ))</i></b>))) S (((O[=<b><i>10</i></b>] ((<b><i>(conflict_detected)</i></b> & ((Y (! <b><i>(conflict_detected)</i></b>)) | (<b><i>flight_mode</i></b> & ((! (Y TRUE)) | (Y (! <b><i>flight_mode</i></b>)))))) & (! <b><i>(( replanning_mode ))</i></b>))) -> (O[<<b><i>10</i></b>] ((<b><i>flight_mode</i></b> & ((! (Y TRUE)) | (Y (! <b><i>flight_mode</i></b>)))) | <b><i>(( replanning_mode ))</i></b>))) & (<b><i>flight_mode</i></b> & ((! (Y TRUE)) | (Y (! <b><i>flight_mode</i></b>))))))))) & (((! ((! <b><i>flight_mode</i></b>) & (Y <b><i>flight_mode</i></b>))) S ((! ((! <b><i>flight_mode</i></b>) & (Y <b><i>flight_mode</i></b>))) & (<b><i>flight_mode</i></b> & ((! (Y TRUE)) | (Y (! <b><i>flight_mode</i></b>)))))) -> (((O[=<b><i>10</i></b>] ((<b><i>(conflict_detected)</i></b> & ((Y (! <b><i>(conflict_detected)</i></b>)) | (<b><i>flight_mode</i></b> & ((! (Y TRUE)) | (Y (! <b><i>flight_mode</i></b>)))))) & (! <b><i>(( replanning_mode ))</i></b>))) -> (O[<<b><i>10</i></b>] ((<b><i>flight_mode</i></b> & ((! (Y TRUE)) | (Y (! <b><i>flight_mode</i></b>)))) | <b><i>(( replanning_mode ))</i></b>))) S (((O[=<b><i>10</i></b>] ((<b><i>(conflict_detected)</i></b> & ((Y (! <b><i>(conflict_detected)</i></b>)) | (<b><i>flight_mode</i></b> & ((! (Y TRUE)) | (Y (! <b><i>flight_mode</i></b>)))))) & (! <b><i>(( replanning_mode ))</i></b>))) -> (O[<<b><i>10</i></b>] ((<b><i>flight_mode</i></b> & ((! (Y TRUE)) | (Y (! <b><i>flight_mode</i></b>)))) | <b><i>(( replanning_mode ))</i></b>))) & (<b><i>flight_mode</i></b> & ((! (Y TRUE)) | (Y (! <b><i>flight_mode</i></b>))))))))",
"fretish": "Meaning not specified"
}
Expand Down
4 changes: 4 additions & 0 deletions ogma-language-fret-cs/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Revision history for ogma-language-fret-cs

## [1.X.X] - 2023-07-21

* Improve parsing error messages (#96).

## [1.0.9] - 2023-05-21

* Version bump 1.0.9 (#93).
Expand Down
39 changes: 34 additions & 5 deletions ogma-language-fret-cs/src/Language/FRETComponentSpec/AST.hs
Original file line number Diff line number Diff line change
Expand Up @@ -128,11 +128,40 @@ data FRETRequirement = FRETRequirement
deriving (Show)

instance FromJSON FRETRequirement where
parseJSON (Object v) = FRETRequirement
<$> v .: "name"
<*> (fmap (CoCoSpec.pBoolSpec . CoCoSpec.myLexer) <$> v .: "CoCoSpecCode")
<*> (fmap (SMV.pBoolSpec . SMV.myLexer) <$> v .: "ptLTL")
<*> (v .: "fretish")
parseJSON (Object v) = do
n <- v .: "name"

coco <- fmap (CoCoSpec.pBoolSpec . CoCoSpec.myLexer)
<$> v .: "CoCoSpecCode"
coco' <-
case coco of
Nothing -> fail $ noField "CoCoSpecCode" n
Just (Left s) -> fail $ noParse "CoCoSpecCode" n s
Just (Right _) -> return coco

ptltl <- fmap (SMV.pBoolSpec . SMV.myLexer) <$> v .: "ptLTL"
ptltl' <-
case ptltl of
Nothing -> fail $ noField "ptLTL" n
Just (Left s) -> fail $ noParse "ptLTL" n s
Just (Right _) -> return ptltl

fretish <- v .: "fretish"

return $ FRETRequirement n coco' ptltl' fretish

where

noField field req = concat
[ "error: requirement ", show req , " does not have a ", field
, " field"
]

noParse field req err = concat
[ "error: parsing of ", field, " field of requirement ", show req
, " failed with ", err
]


parseJSON invalid =
prependFailure "parsing FRET Requirement failed, "
Expand Down
2 changes: 1 addition & 1 deletion ogma-language-fret-cs/tests/fret_good.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"Requirements": [
{
"name": "behnazOne",
"CoCoSpecCode": "",
"CoCoSpecCode": "true",
"ptLTL": "((H ((((! <b><i>flight_mode</i></b>) & (Y <b><i>flight_mode</i></b>)) & (Y TRUE)) -> (Y (((O[=<b><i>10</i></b>] ((<b><i>(conflict_detected)</i></b> & ((Y (! <b><i>(conflict_detected)</i></b>)) | (<b><i>flight_mode</i></b> & ((! (Y TRUE)) | (Y (! <b><i>flight_mode</i></b>)))))) & (! <b><i>(( replanning_mode ))</i></b>))) -> (O[<<b><i>10</i></b>] ((<b><i>flight_mode</i></b> & ((! (Y TRUE)) | (Y (! <b><i>flight_mode</i></b>)))) | <b><i>(( replanning_mode ))</i></b>))) S (((O[=<b><i>10</i></b>] ((<b><i>(conflict_detected)</i></b> & ((Y (! <b><i>(conflict_detected)</i></b>)) | (<b><i>flight_mode</i></b> & ((! (Y TRUE)) | (Y (! <b><i>flight_mode</i></b>)))))) & (! <b><i>(( replanning_mode ))</i></b>))) -> (O[<<b><i>10</i></b>] ((<b><i>flight_mode</i></b> & ((! (Y TRUE)) | (Y (! <b><i>flight_mode</i></b>)))) | <b><i>(( replanning_mode ))</i></b>))) & (<b><i>flight_mode</i></b> & ((! (Y TRUE)) | (Y (! <b><i>flight_mode</i></b>))))))))) & (((! ((! <b><i>flight_mode</i></b>) & (Y <b><i>flight_mode</i></b>))) S ((! ((! <b><i>flight_mode</i></b>) & (Y <b><i>flight_mode</i></b>))) & (<b><i>flight_mode</i></b> & ((! (Y TRUE)) | (Y (! <b><i>flight_mode</i></b>)))))) -> (((O[=<b><i>10</i></b>] ((<b><i>(conflict_detected)</i></b> & ((Y (! <b><i>(conflict_detected)</i></b>)) | (<b><i>flight_mode</i></b> & ((! (Y TRUE)) | (Y (! <b><i>flight_mode</i></b>)))))) & (! <b><i>(( replanning_mode ))</i></b>))) -> (O[<<b><i>10</i></b>] ((<b><i>flight_mode</i></b> & ((! (Y TRUE)) | (Y (! <b><i>flight_mode</i></b>)))) | <b><i>(( replanning_mode ))</i></b>))) S (((O[=<b><i>10</i></b>] ((<b><i>(conflict_detected)</i></b> & ((Y (! <b><i>(conflict_detected)</i></b>)) | (<b><i>flight_mode</i></b> & ((! (Y TRUE)) | (Y (! <b><i>flight_mode</i></b>)))))) & (! <b><i>(( replanning_mode ))</i></b>))) -> (O[<<b><i>10</i></b>] ((<b><i>flight_mode</i></b> & ((! (Y TRUE)) | (Y (! <b><i>flight_mode</i></b>)))) | <b><i>(( replanning_mode ))</i></b>))) & (<b><i>flight_mode</i></b> & ((! (Y TRUE)) | (Y (! <b><i>flight_mode</i></b>))))))))",
"fretish": "Meaning not specified"
}
Expand Down

0 comments on commit 9bce96a

Please sign in to comment.