Skip to content

Commit

Permalink
dcparser: Helpful panic message for deprecated common type alias
Browse files Browse the repository at this point in the history
It's common to define a type alias for the uint8 data type as 'bool'.
This is legal in Panda, but Donet provides the 'bool' data type by
default, and acts as an alias for uint8 under the hood.

This commit adds a production rule to catch this exact alias that is
common in legacy DC files, and provide a useful deprecation message to
the developer with an explanation to the parser panic.
  • Loading branch information
maxrdz committed Mar 4, 2024
1 parent 4d0ce44 commit e658a28
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
6 changes: 6 additions & 0 deletions libdonet/src/dcparser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,12 @@ parser! {

type_definition: () {
Typedef nonmethod_type_with_name => {},
// This rule handles a specific piece of illegal grammar that is legal in Panda.
// The parser will panic with a useful message describing the issue.
Typedef UInt8T BoolT => panic!("\n\"typedef uint8 bool;\" is deprecated!\n\n\
Cannot declare type alias for uint8 as 'bool', as it is a reserved identifier \
in the DC language.\nDonet introduces the 'bool' data type, which is an alias \
for uint8 under the hood.\n"),
type_definition OpenBrackets array_range CloseBrackets => {},
}

Expand Down
2 changes: 1 addition & 1 deletion test/otp.dc
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ from otp.status import StatusDatabase/UD
from otp.avatar import AvatarHandle
from otp.login import AstronLoginManager/UD

typedef uint8 bool;
//typedef uint8 bool; // 'bool' is a valid data type in Donet's DC language.

typedef uint32 DoId;

Expand Down

0 comments on commit e658a28

Please sign in to comment.