2023-01-03 16:54:26 +00:00
|
|
|
from langkit.parsers import Cut, Grammar, List, Opt, Or, Pick
|
2020-10-20 22:17:08 +02:00
|
|
|
|
2021-09-29 14:19:20 +02:00
|
|
|
from language import rflx_ast as ast
|
2020-10-23 16:42:14 +02:00
|
|
|
from language.lexer import rflx_lexer as lexer
|
2020-10-16 19:59:50 +02:00
|
|
|
|
2020-12-24 16:12:01 +01:00
|
|
|
grammar = Grammar("main_rule")
|
2020-10-20 22:17:08 +02:00
|
|
|
|
2020-12-24 16:12:01 +01:00
|
|
|
grammar.add_rules(
|
2020-10-23 23:16:32 +02:00
|
|
|
main_rule=Opt(grammar.specification),
|
2021-06-28 15:06:01 +02:00
|
|
|
unqualified_identifier=ast.UnqualifiedID(
|
|
|
|
|
Or(
|
|
|
|
|
lexer.Package,
|
|
|
|
|
lexer.Is,
|
|
|
|
|
lexer.If,
|
|
|
|
|
lexer.End,
|
|
|
|
|
lexer.Null,
|
|
|
|
|
lexer.Type,
|
|
|
|
|
lexer.Range,
|
|
|
|
|
lexer.With,
|
|
|
|
|
lexer.Mod,
|
|
|
|
|
lexer.Message,
|
|
|
|
|
lexer.Then,
|
|
|
|
|
lexer.Sequence,
|
|
|
|
|
lexer.Of,
|
|
|
|
|
lexer.In,
|
|
|
|
|
lexer.Not,
|
|
|
|
|
lexer.New,
|
|
|
|
|
lexer.For,
|
|
|
|
|
lexer.When,
|
|
|
|
|
lexer.Where,
|
|
|
|
|
lexer.Use,
|
|
|
|
|
lexer.All,
|
|
|
|
|
lexer.Some,
|
|
|
|
|
lexer.Generic,
|
|
|
|
|
lexer.Session,
|
|
|
|
|
lexer.Begin,
|
|
|
|
|
lexer.Return,
|
|
|
|
|
lexer.Function,
|
|
|
|
|
lexer.State,
|
|
|
|
|
lexer.Transition,
|
2021-09-22 13:45:34 +02:00
|
|
|
lexer.Goto,
|
2021-06-28 15:06:01 +02:00
|
|
|
lexer.Exception,
|
|
|
|
|
lexer.Renames,
|
|
|
|
|
lexer.Channel,
|
|
|
|
|
lexer.Readable,
|
|
|
|
|
lexer.Writable,
|
|
|
|
|
lexer.Desc,
|
|
|
|
|
lexer.Append,
|
|
|
|
|
lexer.Extend,
|
|
|
|
|
lexer.Read,
|
|
|
|
|
lexer.Write,
|
|
|
|
|
lexer.Reset,
|
|
|
|
|
lexer.Checksum,
|
|
|
|
|
lexer.ValidChecksum,
|
|
|
|
|
lexer.HasData,
|
|
|
|
|
lexer.Head,
|
|
|
|
|
lexer.Opaque,
|
|
|
|
|
lexer.Present,
|
|
|
|
|
lexer.Valid,
|
|
|
|
|
lexer.And,
|
|
|
|
|
lexer.Or,
|
2022-06-08 11:26:10 +00:00
|
|
|
lexer.Case,
|
2021-06-28 15:06:01 +02:00
|
|
|
lexer.UnqualifiedIdentifier,
|
|
|
|
|
)
|
|
|
|
|
),
|
2020-10-23 23:16:32 +02:00
|
|
|
qualified_identifier=ast.ID(
|
|
|
|
|
Opt(grammar.unqualified_identifier, "::"), grammar.unqualified_identifier
|
|
|
|
|
),
|
2020-10-22 21:36:00 +02:00
|
|
|
numeric_literal=ast.NumericLiteral(lexer.Numeral),
|
2020-11-13 20:24:19 +01:00
|
|
|
variable=ast.Variable(grammar.qualified_identifier),
|
2021-05-07 17:24:01 +02:00
|
|
|
sequence_aggregate=ast.SequenceAggregate(
|
2020-10-25 01:13:18 +02:00
|
|
|
"[", List(grammar.numeric_literal, sep=",", empty_valid=True), "]"
|
|
|
|
|
),
|
2020-10-24 16:23:35 +02:00
|
|
|
string_literal=ast.StringLiteral(lexer.StringLiteral),
|
|
|
|
|
concatenation=Or(
|
|
|
|
|
ast.Concatenation(
|
|
|
|
|
grammar.concatenation,
|
|
|
|
|
"&",
|
2023-01-03 16:54:26 +00:00
|
|
|
Cut(),
|
2021-05-07 17:24:01 +02:00
|
|
|
Or(grammar.sequence_aggregate, grammar.string_literal),
|
2020-10-24 16:23:35 +02:00
|
|
|
),
|
2021-05-07 17:24:01 +02:00
|
|
|
Or(grammar.sequence_aggregate, grammar.string_literal),
|
2020-10-24 16:23:35 +02:00
|
|
|
),
|
2020-10-23 01:40:13 +02:00
|
|
|
primary=Or(
|
2020-10-24 16:23:35 +02:00
|
|
|
grammar.concatenation,
|
2020-10-23 01:40:13 +02:00
|
|
|
grammar.numeric_literal,
|
2020-10-24 23:04:45 +02:00
|
|
|
grammar.string_literal,
|
2020-11-13 20:24:19 +01:00
|
|
|
grammar.variable,
|
2020-10-23 01:40:13 +02:00
|
|
|
grammar.paren_expression,
|
|
|
|
|
),
|
2020-10-22 15:51:34 +02:00
|
|
|
paren_expression=ast.ParenExpression("(", grammar.expression, ")"),
|
2020-11-20 08:18:35 +01:00
|
|
|
suffix=Or(
|
2020-11-20 00:13:52 +01:00
|
|
|
ast.Attribute(
|
2020-11-20 08:18:35 +01:00
|
|
|
grammar.suffix,
|
2020-11-20 00:13:52 +01:00
|
|
|
"'",
|
|
|
|
|
Or(
|
|
|
|
|
# pylint: disable=no-member
|
|
|
|
|
ast.Attr.alt_first(lexer.First),
|
|
|
|
|
ast.Attr.alt_size(lexer.Size),
|
|
|
|
|
ast.Attr.alt_last(lexer.Last),
|
|
|
|
|
ast.Attr.alt_valid_checksum(lexer.ValidChecksum),
|
|
|
|
|
),
|
|
|
|
|
),
|
2020-11-07 23:11:13 +01:00
|
|
|
grammar.primary,
|
|
|
|
|
),
|
2020-11-20 08:18:35 +01:00
|
|
|
factor=Or(
|
|
|
|
|
# pylint: disable=no-member
|
2023-01-03 16:54:26 +00:00
|
|
|
ast.BinOp(grammar.primary, ast.Op.alt_pow("**"), Cut(), grammar.primary),
|
2020-11-20 08:18:35 +01:00
|
|
|
grammar.suffix,
|
|
|
|
|
),
|
2020-11-07 23:11:13 +01:00
|
|
|
term=Or(
|
|
|
|
|
ast.BinOp(
|
|
|
|
|
grammar.term,
|
|
|
|
|
Or(
|
|
|
|
|
# pylint: disable=no-member
|
|
|
|
|
ast.Op.alt_mul("*"),
|
2020-11-12 09:02:41 +01:00
|
|
|
ast.Op.alt_div("/"),
|
2020-11-07 23:11:13 +01:00
|
|
|
ast.Op.alt_mod("mod"),
|
|
|
|
|
),
|
2023-01-03 16:54:26 +00:00
|
|
|
Cut(),
|
2020-11-07 23:11:13 +01:00
|
|
|
grammar.factor,
|
|
|
|
|
),
|
|
|
|
|
grammar.factor,
|
|
|
|
|
),
|
2023-01-03 16:54:26 +00:00
|
|
|
unop_term=Or(ast.Negation("-", Cut(), grammar.term), grammar.term),
|
2020-11-07 23:11:13 +01:00
|
|
|
simple_expr=Or(
|
|
|
|
|
ast.BinOp(
|
|
|
|
|
grammar.simple_expr,
|
|
|
|
|
Or(
|
|
|
|
|
# pylint: disable=no-member
|
|
|
|
|
ast.Op.alt_add("+"),
|
|
|
|
|
ast.Op.alt_sub("-"),
|
|
|
|
|
),
|
2023-01-03 16:54:26 +00:00
|
|
|
Cut(),
|
2020-11-16 09:44:09 +01:00
|
|
|
grammar.unop_term,
|
2020-11-07 23:11:13 +01:00
|
|
|
),
|
2020-11-16 09:44:09 +01:00
|
|
|
grammar.unop_term,
|
2020-11-07 23:11:13 +01:00
|
|
|
),
|
|
|
|
|
relation=Or(
|
|
|
|
|
ast.BinOp(
|
|
|
|
|
grammar.relation,
|
|
|
|
|
Or(
|
|
|
|
|
# pylint: disable=no-member
|
|
|
|
|
ast.Op.alt_eq("="),
|
|
|
|
|
ast.Op.alt_neq("/="),
|
|
|
|
|
ast.Op.alt_le("<="),
|
|
|
|
|
ast.Op.alt_lt("<"),
|
|
|
|
|
ast.Op.alt_ge(">="),
|
|
|
|
|
ast.Op.alt_gt(">"),
|
|
|
|
|
),
|
2023-01-03 16:54:26 +00:00
|
|
|
Cut(),
|
2020-11-07 23:11:13 +01:00
|
|
|
grammar.simple_expr,
|
|
|
|
|
),
|
|
|
|
|
grammar.simple_expr,
|
|
|
|
|
),
|
2020-10-22 15:51:34 +02:00
|
|
|
expression=Or(
|
|
|
|
|
ast.BinOp(
|
|
|
|
|
grammar.expression,
|
2020-11-07 23:11:13 +01:00
|
|
|
Or(
|
|
|
|
|
# pylint: disable=no-member
|
|
|
|
|
ast.Op.alt_and("and"),
|
|
|
|
|
ast.Op.alt_or("or"),
|
|
|
|
|
),
|
2023-01-03 16:54:26 +00:00
|
|
|
Cut(),
|
2020-11-07 23:11:13 +01:00
|
|
|
grammar.relation,
|
2020-10-22 15:51:34 +02:00
|
|
|
),
|
2020-11-07 23:11:13 +01:00
|
|
|
grammar.relation,
|
2020-10-22 15:51:34 +02:00
|
|
|
),
|
2020-10-25 01:13:18 +02:00
|
|
|
quantified_expression=ast.QuantifiedExpression(
|
|
|
|
|
"for",
|
|
|
|
|
Or(
|
|
|
|
|
# pylint: disable=no-member
|
2021-01-09 15:51:26 +01:00
|
|
|
ast.Quantifier.alt_all("all"),
|
|
|
|
|
ast.Quantifier.alt_some("some"),
|
2020-10-25 01:13:18 +02:00
|
|
|
),
|
|
|
|
|
grammar.unqualified_identifier,
|
|
|
|
|
"in",
|
|
|
|
|
grammar.extended_expression,
|
|
|
|
|
"=>",
|
|
|
|
|
grammar.extended_expression,
|
|
|
|
|
),
|
|
|
|
|
comprehension=ast.Comprehension(
|
|
|
|
|
"[",
|
|
|
|
|
"for",
|
|
|
|
|
grammar.unqualified_identifier,
|
|
|
|
|
"in",
|
|
|
|
|
grammar.extended_expression,
|
2021-07-23 18:16:07 +02:00
|
|
|
Opt("if", grammar.extended_expression),
|
2020-10-25 01:13:18 +02:00
|
|
|
"=>",
|
|
|
|
|
grammar.extended_expression,
|
|
|
|
|
"]",
|
|
|
|
|
),
|
|
|
|
|
call=ast.Call(
|
2021-05-07 17:24:01 +02:00
|
|
|
grammar.unqualified_identifier,
|
|
|
|
|
"(",
|
|
|
|
|
List(grammar.extended_expression, sep=","),
|
|
|
|
|
")",
|
2020-10-25 01:13:18 +02:00
|
|
|
),
|
|
|
|
|
conversion=ast.Conversion(grammar.qualified_identifier, "(", grammar.extended_expression, ")"),
|
2021-01-09 16:09:49 +01:00
|
|
|
null_message_aggregate=ast.NullMessageAggregate("null", "message"),
|
|
|
|
|
message_aggregate_association=ast.MessageAggregateAssociation(
|
2020-10-25 01:13:18 +02:00
|
|
|
grammar.unqualified_identifier, "=>", grammar.extended_expression
|
|
|
|
|
),
|
2021-01-09 16:09:49 +01:00
|
|
|
message_aggregate_association_list=ast.MessageAggregateAssociations(
|
|
|
|
|
List(grammar.message_aggregate_association, sep=",")
|
|
|
|
|
),
|
2020-10-25 01:13:18 +02:00
|
|
|
message_aggregate=ast.MessageAggregate(
|
|
|
|
|
grammar.qualified_identifier,
|
|
|
|
|
"'",
|
|
|
|
|
"(",
|
2021-01-09 16:09:49 +01:00
|
|
|
Or(grammar.null_message_aggregate, grammar.message_aggregate_association_list),
|
2020-10-25 01:13:18 +02:00
|
|
|
")",
|
|
|
|
|
),
|
|
|
|
|
extended_primary=Or(
|
|
|
|
|
grammar.concatenation,
|
|
|
|
|
grammar.numeric_literal,
|
|
|
|
|
grammar.string_literal,
|
|
|
|
|
grammar.quantified_expression,
|
|
|
|
|
grammar.comprehension,
|
|
|
|
|
grammar.call,
|
|
|
|
|
grammar.conversion,
|
|
|
|
|
grammar.message_aggregate,
|
2020-11-13 20:24:19 +01:00
|
|
|
grammar.variable,
|
|
|
|
|
grammar.extended_paren_expression,
|
2022-06-08 11:26:10 +00:00
|
|
|
grammar.extended_case_expression,
|
2020-10-24 23:04:45 +02:00
|
|
|
),
|
2020-11-13 20:24:19 +01:00
|
|
|
extended_paren_expression=ast.ParenExpression("(", grammar.extended_expression, ")"),
|
2022-06-08 11:26:10 +00:00
|
|
|
extended_choice_list=List(Or(grammar.qualified_identifier, grammar.numeric_literal), sep="|"),
|
|
|
|
|
extended_choices=ast.Choice(
|
|
|
|
|
"when", grammar.extended_choice_list, "=>", grammar.extended_expression
|
|
|
|
|
),
|
|
|
|
|
extended_case_expression=ast.CaseExpression(
|
|
|
|
|
"(", "case", grammar.extended_expression, "is", List(grammar.extended_choices, sep=","), ")"
|
|
|
|
|
),
|
2020-11-20 08:18:35 +01:00
|
|
|
extended_suffix=Or(
|
2020-11-20 00:13:52 +01:00
|
|
|
ast.Select(
|
2020-11-20 08:18:35 +01:00
|
|
|
grammar.extended_suffix,
|
2020-11-20 00:13:52 +01:00
|
|
|
".",
|
2023-01-03 16:54:26 +00:00
|
|
|
Cut(),
|
2020-11-20 00:13:52 +01:00
|
|
|
grammar.unqualified_identifier,
|
|
|
|
|
),
|
|
|
|
|
ast.Attribute(
|
2020-11-20 08:18:35 +01:00
|
|
|
grammar.extended_suffix,
|
2020-11-14 01:00:07 +01:00
|
|
|
"'",
|
|
|
|
|
Or(
|
|
|
|
|
# pylint: disable=no-member
|
2020-11-20 00:13:52 +01:00
|
|
|
ast.Attr.alt_first(lexer.First),
|
|
|
|
|
ast.Attr.alt_size(lexer.Size),
|
|
|
|
|
ast.Attr.alt_last(lexer.Last),
|
|
|
|
|
ast.Attr.alt_valid_checksum(lexer.ValidChecksum),
|
2021-05-21 16:23:51 +02:00
|
|
|
ast.Attr.alt_has_data(lexer.HasData),
|
2020-11-20 00:13:52 +01:00
|
|
|
ast.Attr.alt_head(lexer.Head),
|
|
|
|
|
ast.Attr.alt_opaque(lexer.Opaque),
|
|
|
|
|
ast.Attr.alt_present(lexer.Present),
|
|
|
|
|
ast.Attr.alt_valid(lexer.Valid),
|
2020-11-14 01:00:07 +01:00
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
ast.Binding(
|
2020-11-20 08:18:35 +01:00
|
|
|
grammar.extended_suffix,
|
2020-11-14 01:00:07 +01:00
|
|
|
"where",
|
|
|
|
|
List(
|
|
|
|
|
ast.TermAssoc(grammar.unqualified_identifier, "=", grammar.extended_expression),
|
|
|
|
|
sep=",",
|
|
|
|
|
),
|
|
|
|
|
),
|
2020-11-13 20:24:19 +01:00
|
|
|
grammar.extended_primary,
|
|
|
|
|
),
|
2020-11-20 08:18:35 +01:00
|
|
|
extended_factor=Or(
|
|
|
|
|
ast.BinOp(
|
|
|
|
|
grammar.extended_factor,
|
|
|
|
|
Or(
|
|
|
|
|
# pylint: disable=no-member
|
|
|
|
|
ast.Op.alt_pow("**"),
|
|
|
|
|
),
|
2023-01-03 16:54:26 +00:00
|
|
|
Cut(),
|
2020-11-20 08:18:35 +01:00
|
|
|
grammar.extended_suffix,
|
|
|
|
|
),
|
|
|
|
|
grammar.extended_suffix,
|
|
|
|
|
),
|
2020-11-13 20:24:19 +01:00
|
|
|
extended_term=Or(
|
|
|
|
|
ast.BinOp(
|
|
|
|
|
grammar.extended_term,
|
|
|
|
|
Or(
|
|
|
|
|
# pylint: disable=no-member
|
|
|
|
|
ast.Op.alt_mul("*"),
|
|
|
|
|
ast.Op.alt_div("/"),
|
|
|
|
|
ast.Op.alt_mod("mod"),
|
|
|
|
|
),
|
2023-01-03 16:54:26 +00:00
|
|
|
Cut(),
|
2020-11-13 20:24:19 +01:00
|
|
|
grammar.extended_factor,
|
|
|
|
|
),
|
|
|
|
|
grammar.extended_factor,
|
|
|
|
|
),
|
2020-11-16 09:44:09 +01:00
|
|
|
extended_unop_term=Or(
|
2023-01-03 16:54:26 +00:00
|
|
|
ast.Negation("-", Cut(), grammar.extended_term),
|
2020-11-16 09:44:09 +01:00
|
|
|
grammar.extended_term,
|
|
|
|
|
),
|
2020-11-13 20:24:19 +01:00
|
|
|
extended_simple_expr=Or(
|
|
|
|
|
ast.BinOp(
|
|
|
|
|
grammar.extended_simple_expr,
|
|
|
|
|
Or(
|
|
|
|
|
# pylint: disable=no-member
|
|
|
|
|
ast.Op.alt_add("+"),
|
|
|
|
|
ast.Op.alt_sub("-"),
|
|
|
|
|
),
|
2023-01-03 16:54:26 +00:00
|
|
|
Cut(),
|
2020-11-16 09:44:09 +01:00
|
|
|
grammar.extended_unop_term,
|
2020-11-13 20:24:19 +01:00
|
|
|
),
|
2020-11-16 09:44:09 +01:00
|
|
|
grammar.extended_unop_term,
|
2020-11-13 20:24:19 +01:00
|
|
|
),
|
|
|
|
|
extended_relation=Or(
|
|
|
|
|
ast.BinOp(
|
|
|
|
|
grammar.extended_relation,
|
|
|
|
|
Or(
|
|
|
|
|
# pylint: disable=no-member
|
|
|
|
|
ast.Op.alt_eq("="),
|
|
|
|
|
ast.Op.alt_neq("/="),
|
|
|
|
|
ast.Op.alt_le("<="),
|
|
|
|
|
ast.Op.alt_lt("<"),
|
|
|
|
|
ast.Op.alt_ge(">="),
|
|
|
|
|
ast.Op.alt_gt(">"),
|
|
|
|
|
ast.Op.alt_in("in"),
|
|
|
|
|
ast.Op.alt_notin("not", "in"),
|
|
|
|
|
),
|
2023-01-03 16:54:26 +00:00
|
|
|
Cut(),
|
2020-11-13 20:24:19 +01:00
|
|
|
grammar.extended_simple_expr,
|
|
|
|
|
),
|
|
|
|
|
grammar.extended_simple_expr,
|
2020-10-24 23:04:45 +02:00
|
|
|
),
|
|
|
|
|
extended_expression=Or(
|
|
|
|
|
ast.BinOp(
|
|
|
|
|
grammar.extended_expression,
|
2020-10-25 15:15:17 +01:00
|
|
|
Or(
|
|
|
|
|
# pylint: disable=no-member
|
2020-11-13 20:24:19 +01:00
|
|
|
ast.Op.alt_and("and"),
|
|
|
|
|
ast.Op.alt_or("or"),
|
2020-10-25 15:15:17 +01:00
|
|
|
),
|
2023-01-03 16:54:26 +00:00
|
|
|
Cut(),
|
2020-11-13 20:24:19 +01:00
|
|
|
grammar.extended_relation,
|
2020-10-25 15:15:17 +01:00
|
|
|
),
|
2020-11-13 20:24:19 +01:00
|
|
|
grammar.extended_relation,
|
2020-10-24 23:04:45 +02:00
|
|
|
),
|
2020-11-20 08:37:00 +01:00
|
|
|
aspect=ast.Aspect(grammar.unqualified_identifier, Opt("=>", grammar.expression)),
|
2020-10-22 12:38:56 +02:00
|
|
|
range_type_definition=ast.RangeTypeDef(
|
|
|
|
|
"range",
|
2020-11-20 08:37:00 +01:00
|
|
|
grammar.expression,
|
2020-10-22 12:38:56 +02:00
|
|
|
"..",
|
2020-11-20 08:37:00 +01:00
|
|
|
grammar.expression,
|
2020-10-22 12:38:56 +02:00
|
|
|
"with",
|
2020-11-20 08:37:00 +01:00
|
|
|
grammar.aspect,
|
2020-10-21 23:34:47 +02:00
|
|
|
),
|
2020-11-20 08:37:00 +01:00
|
|
|
modular_type_definition=ast.ModularTypeDef("mod", grammar.expression),
|
2020-10-22 12:38:56 +02:00
|
|
|
integer_type_definition=Or(grammar.range_type_definition, grammar.modular_type_definition),
|
2020-11-20 08:37:00 +01:00
|
|
|
if_condition=Pick("if", grammar.expression),
|
|
|
|
|
extended_if_condition=Pick("if", grammar.extended_expression),
|
2020-10-22 15:51:34 +02:00
|
|
|
then=ast.Then(
|
|
|
|
|
"then",
|
2022-09-19 16:29:25 +02:00
|
|
|
grammar.unqualified_identifier,
|
2020-11-20 08:37:00 +01:00
|
|
|
Opt("with", List(grammar.aspect, sep=",")),
|
2020-10-22 15:51:34 +02:00
|
|
|
Opt(grammar.if_condition),
|
|
|
|
|
),
|
2021-10-07 17:11:56 +02:00
|
|
|
type_argument=ast.TypeArgument(grammar.unqualified_identifier, "=>", grammar.expression),
|
|
|
|
|
null_message_field=ast.NullMessageField("null", grammar.then, ";"),
|
|
|
|
|
message_field=ast.MessageField(
|
2020-10-22 15:51:34 +02:00
|
|
|
grammar.unqualified_identifier,
|
|
|
|
|
":",
|
|
|
|
|
grammar.qualified_identifier,
|
2021-10-07 17:11:56 +02:00
|
|
|
Opt("(", List(grammar.type_argument, sep=","), ")"),
|
2020-11-20 08:37:00 +01:00
|
|
|
Opt("with", List(grammar.aspect, sep=",")),
|
2020-11-10 19:25:00 +01:00
|
|
|
Opt(grammar.if_condition),
|
2020-10-22 15:51:34 +02:00
|
|
|
List(grammar.then, empty_valid=True),
|
|
|
|
|
";",
|
|
|
|
|
),
|
2021-10-07 17:11:56 +02:00
|
|
|
message_field_list=ast.MessageFields(
|
|
|
|
|
Opt(grammar.null_message_field), List(grammar.message_field)
|
|
|
|
|
),
|
2020-11-20 08:37:00 +01:00
|
|
|
value_range=ast.ChecksumValueRange(grammar.expression, "..", grammar.expression),
|
2020-10-22 15:51:34 +02:00
|
|
|
checksum_association=ast.ChecksumAssoc(
|
|
|
|
|
grammar.unqualified_identifier,
|
|
|
|
|
"=>",
|
|
|
|
|
"(",
|
2020-11-20 08:37:00 +01:00
|
|
|
List(Or(grammar.value_range, ast.ChecksumVal(grammar.expression)), sep=","),
|
2020-10-22 15:51:34 +02:00
|
|
|
")",
|
|
|
|
|
),
|
|
|
|
|
checksum_aspect=ast.ChecksumAspect(
|
2020-11-04 23:35:55 +01:00
|
|
|
"Checksum", "=>", "(", List(grammar.checksum_association, sep=","), ")"
|
2020-10-22 15:51:34 +02:00
|
|
|
),
|
2022-01-04 18:31:14 +09:00
|
|
|
byte_order_aspect=ast.ByteOrderAspect(
|
|
|
|
|
"Byte_Order",
|
|
|
|
|
"=>",
|
|
|
|
|
Or(
|
|
|
|
|
# pylint: disable=no-member
|
|
|
|
|
ast.ByteOrderType.alt_highorderfirst("High_Order_First"),
|
|
|
|
|
ast.ByteOrderType.alt_loworderfirst("Low_Order_First"),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
message_aspect_list=List(Or(grammar.checksum_aspect, grammar.byte_order_aspect), sep=","),
|
2020-10-22 15:51:34 +02:00
|
|
|
message_type_definition=Or(
|
2020-10-22 21:36:00 +02:00
|
|
|
ast.MessageTypeDef(
|
2020-10-22 15:51:34 +02:00
|
|
|
"message",
|
2021-10-07 17:11:56 +02:00
|
|
|
grammar.message_field_list,
|
2020-10-22 15:51:34 +02:00
|
|
|
"end",
|
|
|
|
|
"message",
|
2022-01-04 18:31:14 +09:00
|
|
|
Opt("with", grammar.message_aspect_list),
|
2020-10-22 15:51:34 +02:00
|
|
|
),
|
2020-10-22 21:36:00 +02:00
|
|
|
ast.NullMessageTypeDef("null", "message"),
|
|
|
|
|
),
|
2020-11-10 08:05:03 +01:00
|
|
|
positional_enumeration=ast.PositionalEnumerationDef(
|
|
|
|
|
List(grammar.unqualified_identifier, sep=",")
|
|
|
|
|
),
|
2020-10-22 21:36:00 +02:00
|
|
|
element_value_association=ast.ElementValueAssoc(
|
|
|
|
|
grammar.unqualified_identifier, "=>", grammar.numeric_literal
|
|
|
|
|
),
|
2020-11-10 08:05:03 +01:00
|
|
|
named_enumeration=ast.NamedEnumerationDef(List(grammar.element_value_association, sep=",")),
|
2020-11-20 08:37:00 +01:00
|
|
|
enumeration_aspects=List(Or(grammar.aspect, grammar.aspect), sep=","),
|
2020-10-22 21:36:00 +02:00
|
|
|
enumeration_type_definition=ast.EnumerationTypeDef(
|
|
|
|
|
"(",
|
|
|
|
|
Or(grammar.named_enumeration, grammar.positional_enumeration),
|
|
|
|
|
")",
|
|
|
|
|
"with",
|
|
|
|
|
grammar.enumeration_aspects,
|
2020-10-22 15:51:34 +02:00
|
|
|
),
|
2020-10-24 00:32:26 +02:00
|
|
|
type_derivation_definition=ast.TypeDerivationDef(
|
|
|
|
|
"new",
|
|
|
|
|
grammar.qualified_identifier,
|
|
|
|
|
),
|
2021-05-07 17:24:01 +02:00
|
|
|
sequence_type_definition=ast.SequenceTypeDef(
|
|
|
|
|
"sequence",
|
2020-10-23 15:59:34 +02:00
|
|
|
"of",
|
|
|
|
|
grammar.qualified_identifier,
|
|
|
|
|
),
|
2021-01-09 15:29:14 +01:00
|
|
|
type_declaration=ast.TypeDecl(
|
2020-10-22 15:51:34 +02:00
|
|
|
"type",
|
|
|
|
|
grammar.unqualified_identifier,
|
2021-08-04 18:55:13 +02:00
|
|
|
Opt(grammar.parameter_list),
|
2020-10-22 15:51:34 +02:00
|
|
|
"is",
|
2020-10-22 21:36:00 +02:00
|
|
|
Or(
|
|
|
|
|
grammar.enumeration_type_definition,
|
|
|
|
|
grammar.integer_type_definition,
|
|
|
|
|
grammar.message_type_definition,
|
2020-10-24 00:32:26 +02:00
|
|
|
grammar.type_derivation_definition,
|
2021-05-07 17:24:01 +02:00
|
|
|
grammar.sequence_type_definition,
|
2020-10-22 21:36:00 +02:00
|
|
|
),
|
2020-10-22 12:38:56 +02:00
|
|
|
),
|
2021-01-14 14:13:00 +01:00
|
|
|
type_refinement=ast.RefinementDecl(
|
2020-10-24 00:39:39 +02:00
|
|
|
"for",
|
|
|
|
|
grammar.qualified_identifier,
|
|
|
|
|
"use",
|
|
|
|
|
"(",
|
|
|
|
|
grammar.unqualified_identifier,
|
|
|
|
|
"=>",
|
|
|
|
|
grammar.qualified_identifier,
|
|
|
|
|
")",
|
|
|
|
|
Opt(grammar.if_condition),
|
|
|
|
|
),
|
2021-08-04 18:55:13 +02:00
|
|
|
parameter=ast.Parameter(grammar.unqualified_identifier, ":", grammar.qualified_identifier),
|
|
|
|
|
parameter_list=ast.Parameters("(", List(grammar.parameter, sep=";"), ")"),
|
2021-01-09 15:29:14 +01:00
|
|
|
formal_function_declaration=ast.FormalFunctionDecl(
|
2020-10-24 19:49:29 +02:00
|
|
|
"with",
|
|
|
|
|
"function",
|
|
|
|
|
grammar.unqualified_identifier,
|
2021-08-04 18:55:13 +02:00
|
|
|
Opt(grammar.parameter_list),
|
2020-10-24 19:49:29 +02:00
|
|
|
"return",
|
|
|
|
|
grammar.qualified_identifier,
|
|
|
|
|
),
|
2021-01-09 15:29:14 +01:00
|
|
|
channel_declaration=ast.FormalChannelDecl(
|
2020-10-24 19:49:29 +02:00
|
|
|
grammar.unqualified_identifier,
|
|
|
|
|
":",
|
|
|
|
|
"Channel",
|
|
|
|
|
"with",
|
|
|
|
|
List(Or(ast.Readable("Readable"), ast.Writable("Writable")), sep=","),
|
|
|
|
|
),
|
|
|
|
|
session_parameter=Or(
|
|
|
|
|
grammar.formal_function_declaration,
|
|
|
|
|
grammar.channel_declaration,
|
|
|
|
|
),
|
|
|
|
|
renaming_declaration=ast.RenamingDecl(
|
|
|
|
|
grammar.unqualified_identifier,
|
|
|
|
|
":",
|
|
|
|
|
grammar.qualified_identifier,
|
|
|
|
|
"renames",
|
2020-10-25 21:47:27 +01:00
|
|
|
grammar.extended_expression,
|
2020-10-24 19:49:29 +02:00
|
|
|
),
|
|
|
|
|
variable_declaration=ast.VariableDecl(
|
|
|
|
|
grammar.unqualified_identifier,
|
|
|
|
|
":",
|
|
|
|
|
grammar.qualified_identifier,
|
2020-10-25 01:13:18 +02:00
|
|
|
Opt(":=", grammar.extended_expression),
|
2020-10-24 19:49:29 +02:00
|
|
|
),
|
|
|
|
|
declaration=Or(grammar.renaming_declaration, grammar.variable_declaration),
|
|
|
|
|
description_aspect=ast.Description("Desc", "=>", grammar.string_literal),
|
2020-10-25 01:13:18 +02:00
|
|
|
assignment_statement=ast.Assignment(
|
|
|
|
|
grammar.unqualified_identifier, ":=", grammar.extended_expression
|
|
|
|
|
),
|
2022-06-08 13:07:07 +02:00
|
|
|
message_field_assignment_statement=ast.MessageFieldAssignment(
|
|
|
|
|
grammar.unqualified_identifier,
|
|
|
|
|
".",
|
|
|
|
|
grammar.unqualified_identifier,
|
|
|
|
|
":=",
|
|
|
|
|
grammar.extended_expression,
|
|
|
|
|
),
|
2021-05-21 16:05:14 +02:00
|
|
|
list_attribute=ast.AttributeStatement(
|
2020-10-24 19:49:29 +02:00
|
|
|
grammar.unqualified_identifier,
|
|
|
|
|
"'",
|
|
|
|
|
Or(
|
|
|
|
|
# pylint: disable=no-member
|
2021-05-21 16:05:14 +02:00
|
|
|
ast.AttrStmt.alt_append("Append"),
|
|
|
|
|
ast.AttrStmt.alt_extend("Extend"),
|
|
|
|
|
ast.AttrStmt.alt_read("Read"),
|
|
|
|
|
ast.AttrStmt.alt_write("Write"),
|
2020-10-24 19:49:29 +02:00
|
|
|
),
|
|
|
|
|
"(",
|
2020-10-25 01:13:18 +02:00
|
|
|
grammar.extended_expression,
|
2020-10-24 19:49:29 +02:00
|
|
|
")",
|
|
|
|
|
),
|
2021-08-17 12:33:13 +02:00
|
|
|
reset=ast.Reset(
|
|
|
|
|
grammar.unqualified_identifier,
|
|
|
|
|
"'",
|
|
|
|
|
"Reset",
|
|
|
|
|
Opt("(", List(grammar.message_aggregate_association, sep=","), ")"),
|
|
|
|
|
),
|
2020-10-24 19:49:29 +02:00
|
|
|
attribute_statement=Or(grammar.list_attribute, grammar.reset),
|
2022-06-08 13:07:07 +02:00
|
|
|
action=Or(
|
|
|
|
|
grammar.assignment_statement,
|
|
|
|
|
grammar.message_field_assignment_statement,
|
|
|
|
|
grammar.attribute_statement,
|
|
|
|
|
),
|
2020-10-24 19:49:29 +02:00
|
|
|
conditional_transition=ast.ConditionalTransition(
|
2021-09-22 13:45:34 +02:00
|
|
|
"goto",
|
2020-10-24 19:49:29 +02:00
|
|
|
grammar.unqualified_identifier,
|
2020-10-25 01:13:18 +02:00
|
|
|
Opt("with", grammar.description_aspect),
|
2020-10-24 23:04:45 +02:00
|
|
|
grammar.extended_if_condition,
|
2020-10-24 19:49:29 +02:00
|
|
|
),
|
|
|
|
|
transition=ast.Transition(
|
2021-09-22 13:45:34 +02:00
|
|
|
"goto",
|
2022-09-19 11:07:11 +02:00
|
|
|
grammar.unqualified_identifier,
|
2021-09-22 13:45:34 +02:00
|
|
|
Opt("with", grammar.description_aspect),
|
2020-10-24 19:49:29 +02:00
|
|
|
),
|
|
|
|
|
state_body=ast.StateBody(
|
|
|
|
|
Opt(List(grammar.declaration, sep=";"), ";"),
|
|
|
|
|
"begin",
|
|
|
|
|
Opt(List(grammar.action, sep=";"), ";"),
|
|
|
|
|
"transition",
|
|
|
|
|
List(grammar.conditional_transition, empty_valid=True),
|
|
|
|
|
grammar.transition,
|
2021-03-09 12:34:56 +01:00
|
|
|
Opt("exception", grammar.transition),
|
2020-10-24 19:49:29 +02:00
|
|
|
"end",
|
|
|
|
|
grammar.unqualified_identifier,
|
|
|
|
|
),
|
|
|
|
|
state=ast.State(
|
|
|
|
|
"state",
|
|
|
|
|
grammar.unqualified_identifier,
|
2020-10-25 01:13:18 +02:00
|
|
|
Opt("with", grammar.description_aspect),
|
2020-10-24 19:49:29 +02:00
|
|
|
"is",
|
2022-09-19 11:07:11 +02:00
|
|
|
grammar.state_body,
|
2020-10-24 19:49:29 +02:00
|
|
|
),
|
2021-01-14 14:13:00 +01:00
|
|
|
session_declaration=ast.SessionDecl(
|
2020-10-24 19:49:29 +02:00
|
|
|
"generic",
|
|
|
|
|
Opt(List(grammar.session_parameter, sep=";"), ";"),
|
|
|
|
|
"session",
|
|
|
|
|
grammar.unqualified_identifier,
|
|
|
|
|
"is",
|
|
|
|
|
Opt(List(grammar.declaration, sep=";"), ";"),
|
|
|
|
|
"begin",
|
|
|
|
|
Opt(List(grammar.state, sep=";"), ";"),
|
|
|
|
|
"end",
|
|
|
|
|
grammar.unqualified_identifier,
|
|
|
|
|
),
|
|
|
|
|
basic_declaration=Or(
|
|
|
|
|
grammar.type_declaration, grammar.type_refinement, grammar.session_declaration
|
|
|
|
|
),
|
2020-11-23 22:27:38 +01:00
|
|
|
basic_declarations=Pick(List(grammar.basic_declaration, sep=";"), ";"),
|
2021-01-14 14:13:00 +01:00
|
|
|
package_declaration=ast.Package(
|
2020-10-21 23:34:47 +02:00
|
|
|
"package",
|
2020-10-22 12:38:56 +02:00
|
|
|
grammar.unqualified_identifier,
|
2020-10-21 23:34:47 +02:00
|
|
|
"is",
|
2020-11-23 22:27:38 +01:00
|
|
|
Opt(grammar.basic_declarations),
|
2020-10-21 23:34:47 +02:00
|
|
|
"end",
|
2020-10-22 12:38:56 +02:00
|
|
|
grammar.unqualified_identifier,
|
2020-10-21 23:34:47 +02:00
|
|
|
";",
|
2020-10-20 22:17:08 +02:00
|
|
|
),
|
2020-11-04 23:35:55 +01:00
|
|
|
context_item=ast.ContextItem("with", grammar.unqualified_identifier, ";"),
|
2020-11-23 22:27:38 +01:00
|
|
|
context_clause=List(grammar.context_item, empty_valid=True),
|
|
|
|
|
specification=ast.Specification(grammar.context_clause, grammar.package_declaration),
|
2020-10-20 22:17:08 +02:00
|
|
|
)
|