//! `randsequence` — the production grammar of IEEE 1800 §18.17. //! //! A `randsequence` statement is a little grammar of its own written inside a //! procedural block: a list of *productions*, each a name with optional //! arguments and return type, each defining one or more weighted //! *alternatives*, each alternative a run of *items* — a reference to another //! production, a code block of ordinary statements, or one of the three //! control shapes (`if`/`else`, `repeat`, `case`). //! //! Every node here carries the comment slots its own tokens open, for the //! reason the rest of the AST does: a comment written between two tokens must //! print back between those same two tokens or `verify.rs` refuses the file. use super::*; /// `randsequence (main) … endsequence` (IEEE 1800 §18.17). #[derive(Debug)] pub struct RandSequence { /// Comments written between the keyword and its `(`. pub after_kw: Vec, /// Comments written just inside the `(`. pub after_open: Vec, /// The starting production, `None` for the empty `randsequence ()`. pub start: Option, /// Comments written between that name and the `)`. pub before_close: Vec, pub productions: Vec, /// Comments written after the last production and before `endsequence`. pub dangling: Vec, } /// One production: `[type] name [(ports)] : alternative { | alternative } ;`. #[derive(Debug)] pub struct Production { pub meta: Meta, /// The production's return type, `None` when it declares none (or wrote /// `void`, which is kept here as an ordinary type name). pub ret_type: Option, pub name: String, /// Byte range of `name`. pub name_span: TextRange, /// True when the production wrote a `( … )` port list, even an empty one. pub has_parens: bool, /// The formal arguments, read as a subroutine's are (§18.17.5). pub args: Vec>, /// Comments written between the head and the `:`. pub before_colon: Vec, /// At least one; the `|`-separated right-hand sides. pub alternatives: Vec, /// Comments written between the last alternative and the `;`. pub before_semi: Vec, /// Code extent of the production, its `;` excluded. pub span: TextRange, } /// One `|`-separated right-hand side of a production, with the optional /// `:= weight` that biases it. #[derive(Debug)] pub struct Alternative { /// Comments written between the previous alternative and the `|` that /// starts this one. Always empty on the first alternative, whose left /// neighbour is the production's `:`. pub before_bar: Vec, /// Comments written between the `:` (or the `|`) and the first item. pub after_bar: Vec, pub items: Vec, /// Comments written between the last item and the `:=`. pub before_weight: Vec, /// The `:= expr` weight (§18.17.2), `None` when unweighted. pub weight: Option, } /// The `:= weight [code block]` of a weighted alternative. #[derive(Debug)] pub struct Weight { /// Comments written between the `:=` and the weight expression. pub after_op: Vec, pub expr: Expr, /// The optional code block run when the alternative is chosen. pub block: Option>, } /// One item of an alternative's right-hand side — §18.17's `rs_prod`. #[derive(Debug)] pub enum ProdItem { /// `name`, or `name(args)` — a reference to another production. Ref(ProdRef), /// `{ … }` — ordinary statements, laid out as a `begin`/`end` body is. Block(Box), /// `if (expr) item [else item]`. If { /// Comments written between the `if` and its `(`. after_kw: Vec, cond: Expr, then: Box, /// Comments written between the `then` item and the `else`. before_else: Vec, /// Comments written between the `else` and its item. after_else: Vec, els: Option>, }, /// `repeat (expr) item`. Repeat { /// Comments written between the `repeat` and its `(`. after_kw: Vec, count: Expr, body: Box, }, /// `case (expr) … endcase`, whose arms take production items rather than /// statements. Case { /// Comments written between the `case` and its `(`. after_kw: Vec, expr: Expr, items: Vec, /// Comments written after the last arm and before `endcase`. dangling: Vec, }, /// `rand join [(expr)] item item { item }` (§18.17.6). RandJoin { /// Comments written between the `rand` and the `join`. after_rand: Vec, /// The `( expr )` bias, `None` when omitted. weight: Option, items: Vec, }, } /// A reference to another production: `name` or `name(a, b)`. #[derive(Debug)] pub struct ProdRef { pub name: String, /// Byte range of `name`. pub name_span: TextRange, /// True when a `( … )` argument list was written, even an empty one. pub has_parens: bool, /// Comments written between the name and that `(`. pub before_args: Vec, pub args: Vec, } /// One arm of an `rs_case`: `expr, expr : item;` or `default [:] item;`. #[derive(Debug)] pub struct ProdCaseItem { pub meta: Meta, /// Empty for the `default` arm. pub labels: Vec, /// True when the arm was written `default`. pub is_default: bool, /// Comments written between the labels (or the `default`) and the `:`. pub before_colon: Vec, /// Comments written between the `:` and the item. A `default` arm may /// write no `:` at all, and then this is the gap after the keyword. pub after_colon: Vec, pub item: ProdItem, /// Comments written between the item and the arm's `;`. pub before_semi: Vec, /// Code extent of the arm, its `;` excluded. pub span: TextRange, } /// An `rs_code_block`: `{ declarations statements }`. The braces are the /// block's own, and what stands between them is the statement grammar. /// /// There is no slot for the gap just inside the `{`: it belongs to the first /// statement's leading comments, exactly as a `begin`/`end` block's does, and /// to `dangling` when the block holds no statement at all. #[derive(Debug)] pub struct CodeBlock { pub stmts: Vec, /// Comments written after the last statement and before the `}`. pub dangling: Vec, }