Add Tree Sitter Tests for Annotations (And General Test Updates)
Update Tests Signed-off-by: Will Hawkins <hawkinsw@obs.cr>
This commit is contained in:
@@ -114,5 +114,5 @@ import P4Lang
|
|||||||
#RequireErrorResult<(EvaluatableStatement, LexicalScopes)>(
|
#RequireErrorResult<(EvaluatableStatement, LexicalScopes)>(
|
||||||
Error(withMessage: "{2, 154}: Did not find assignment statement"),
|
Error(withMessage: "{2, 154}: Did not find assignment statement"),
|
||||||
ParserAssignmentStatement.Compile(
|
ParserAssignmentStatement.Compile(
|
||||||
node: result.rootNode!, inTree: result, withScopes: LexicalScopes())))
|
node: result.rootNode!, withTypesInScope: LexicalScopes())))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -56,7 +56,7 @@ export default grammar({
|
|||||||
annotations: $ => repeat1($.annotation),
|
annotations: $ => repeat1($.annotation),
|
||||||
|
|
||||||
//annotation: $ => choice(seq('@', "[a-z]+"), seq('@', "[a-z]+", '(', $.annotationBody, ')'), seq('@', "[a-z]+", '[', $.structuredAnnotationBody, ']')),
|
//annotation: $ => choice(seq('@', "[a-z]+"), seq('@', "[a-z]+", '(', $.annotationBody, ')'), seq('@', "[a-z]+", '[', $.structuredAnnotationBody, ']')),
|
||||||
annotation: $ => choice(seq('@', "[a-z]+")),// seq('@', "[a-z]+", '(', /* empty for now*/ ')'), seq('@', "[a-z]+", '[', /* empty for now */ ']')),
|
annotation: $ => choice($.annotation_literal), // seq('@', "[a-z]+", '(', /* empty for now*/ ')'), seq('@', "[a-z]+", '[', /* empty for now */ ']')),
|
||||||
|
|
||||||
|
|
||||||
// Instantiation
|
// Instantiation
|
||||||
@@ -146,7 +146,7 @@ export default grammar({
|
|||||||
type_identifier: $ => /[a-z]+/,
|
type_identifier: $ => /[a-z]+/,
|
||||||
string_literal: $ => /".*"/,
|
string_literal: $ => /".*"/,
|
||||||
integer: $ => /[0-9]+/,
|
integer: $ => /[0-9]+/,
|
||||||
|
annotation_literal: $ => /@[a-z_]+/,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -0,0 +1,101 @@
|
|||||||
|
=========================
|
||||||
|
Simple Annotated Declaration
|
||||||
|
=========================
|
||||||
|
@testing parser simple() {
|
||||||
|
state start {
|
||||||
|
bool l;
|
||||||
|
transition accept;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
---
|
||||||
|
(p4program
|
||||||
|
(declaration
|
||||||
|
(parserDeclaration
|
||||||
|
(parserType
|
||||||
|
(annotations
|
||||||
|
(annotation
|
||||||
|
(annotation_literal)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
(parser)
|
||||||
|
(identifier)
|
||||||
|
)
|
||||||
|
(parserStates
|
||||||
|
(parserState
|
||||||
|
(state)
|
||||||
|
(identifier)
|
||||||
|
(parserStatements
|
||||||
|
(parserStatement
|
||||||
|
(variableDeclaration
|
||||||
|
(typeRef
|
||||||
|
(baseType
|
||||||
|
(bool)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
(identifier)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
(parserTransitionStatement
|
||||||
|
(transition)
|
||||||
|
(transitionSelectionExpression
|
||||||
|
(identifier)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
=========================
|
||||||
|
Simple Annotated State
|
||||||
|
=========================
|
||||||
|
parser simple() {
|
||||||
|
@testing state start {
|
||||||
|
bool l;
|
||||||
|
transition accept;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
---
|
||||||
|
(p4program
|
||||||
|
(declaration
|
||||||
|
(parserDeclaration
|
||||||
|
(parserType
|
||||||
|
(parser)
|
||||||
|
(identifier)
|
||||||
|
)
|
||||||
|
(parserStates
|
||||||
|
(parserState
|
||||||
|
(annotations
|
||||||
|
(annotation
|
||||||
|
(annotation_literal)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
(state)
|
||||||
|
(identifier)
|
||||||
|
(parserStatements
|
||||||
|
(parserStatement
|
||||||
|
(variableDeclaration
|
||||||
|
(typeRef
|
||||||
|
(baseType
|
||||||
|
(bool)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
(identifier)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
(parserTransitionStatement
|
||||||
|
(transition)
|
||||||
|
(transitionSelectionExpression
|
||||||
|
(identifier)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
Reference in New Issue
Block a user