From 46ea6050b08256c30620ccea754cb3f3dadc8712 Mon Sep 17 00:00:00 2001 From: chriseth Date: Mon, 1 Feb 2021 18:29:17 +0100 Subject: [PATCH] Add errors to grammar. --- docs/grammar/Solidity.g4 | 16 +++++++++++++++- docs/grammar/SolidityLexer.g4 | 3 ++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/docs/grammar/Solidity.g4 b/docs/grammar/Solidity.g4 index 3d66df9b6..611556db2 100644 --- a/docs/grammar/Solidity.g4 +++ b/docs/grammar/Solidity.g4 @@ -19,6 +19,7 @@ sourceUnit: ( | constantVariableDeclaration | structDefinition | enumDefinition + | errorDefinition )* EOF; //@doc: inline @@ -90,6 +91,7 @@ contractBodyElement: | enumDefinition | stateVariableDeclaration | eventDefinition + | errorDefinition | usingDirective; //@doc:inline namedArgument: name=identifier Colon value=expression; @@ -289,6 +291,18 @@ eventDefinition: Anonymous? Semicolon; +/** + * Parameter of an error. + */ +errorParameter: type=typeName name=identifier?; +/** + * Definition of an error. + */ +errorDefinition: + Error name=identifier + LParen (parameters+=errorParameter (Comma parameters+=errorParameter)*)? RParen + Semicolon; + /** * Using directive to bind library functions to types. * Can occur within contracts and libraries. @@ -367,7 +381,7 @@ inlineArrayExpression: LBrack (expression ( Comma expression)* ) RBrack; /** * Besides regular non-keyword Identifiers, the 'from' keyword can also occur as identifier outside of import statements. */ -identifier: Identifier | From; +identifier: Identifier | From | Error; literal: stringLiteral | numberLiteral | booleanLiteral | hexStringLiteral | unicodeStringLiteral; booleanLiteral: True | False; diff --git a/docs/grammar/SolidityLexer.g4 b/docs/grammar/SolidityLexer.g4 index d8e89b278..560d78e6a 100644 --- a/docs/grammar/SolidityLexer.g4 +++ b/docs/grammar/SolidityLexer.g4 @@ -29,12 +29,13 @@ Do: 'do'; Else: 'else'; Emit: 'emit'; Enum: 'enum'; +Error: 'error'; // not a real keyword Event: 'event'; External: 'external'; Fallback: 'fallback'; False: 'false'; Fixed: 'fixed' | ('fixed' [1-9][0-9]* 'x' [1-9][0-9]*); -From: 'from'; +From: 'from'; // not a real keyword /** * Bytes types of fixed length. */