Trait vhdl_lang::HasTokenSpan

source ·
pub trait HasTokenSpan {
    // Required methods
    fn get_start_token(&self) -> TokenId;
    fn get_end_token(&self) -> TokenId;
    fn get_token_slice<'a>(&self, tokens: &'a dyn TokenAccess) -> &'a [Token];
    fn get_pos(&self, tokens: &dyn TokenAccess) -> SrcPos;

    // Provided methods
    fn get_span(&self, ctx: &dyn TokenAccess) -> SrcPos { ... }
    fn span(&self) -> TokenSpan { ... }
}
Expand description

AST elements for which it is necessary to get the underlying tokens can implement the HasTokenSpan trait. The trait provides getters for the start and end token.

Using the with_token_span attribute macro, the necessary fields can be inserted, and HasTokenSpan is implemented automatically.

For enums containing alternative AST elements the custom derive macro can be used directly under certain constraints:

  1. All variants must contain exactly one unnamed field.
  2. The fields of all variants must implement the HasTokenSpan trait one way or another.

Example:

use vhdl_lang_macros::{with_token_span, TokenSpan};

// With `with_token_span` a field `info` of type `(TokenId, TokenId)` is inserted.
// Additionally the `HasTokenSpan` trait is implemented using the `TokenSpan` derive macro
#[with_token_span]
#[derive(PartialEq, Debug, Clone)]
pub struct UseClause {
    pub name_list: ::vhdl_lang::ast::NameList,
}

#[with_token_span]
#[derive(PartialEq, Debug, Clone)]
pub struct ContextReference {
    pub name_list: ::vhdl_lang::ast::NameList,
}

#[with_token_span]
#[derive(PartialEq, Debug, Clone)]
pub struct LibraryClause {
    pub name_list: ::vhdl_lang::ast::IdentList,
}

// Enums can use the `TokenSpan` derive macro directly
#[derive(PartialEq, Debug, Clone, TokenSpan)]
pub enum ContextItem {
    Use(UseClause),
    Library(LibraryClause),
    Context(ContextReference),
}

Required Methods§

source

fn get_start_token(&self) -> TokenId

source

fn get_end_token(&self) -> TokenId

source

fn get_token_slice<'a>(&self, tokens: &'a dyn TokenAccess) -> &'a [Token]

source

fn get_pos(&self, tokens: &dyn TokenAccess) -> SrcPos

Provided Methods§

source

fn get_span(&self, ctx: &dyn TokenAccess) -> SrcPos

source

fn span(&self) -> TokenSpan

Implementors§

source§

impl HasTokenSpan for AnyDesignUnit

source§

impl HasTokenSpan for AnyPrimaryUnit

source§

impl HasTokenSpan for AnySecondaryUnit

source§

impl HasTokenSpan for Attribute

source§

impl HasTokenSpan for ContextItem

source§

impl HasTokenSpan for Declaration

source§

impl HasTokenSpan for AliasDeclaration

source§

impl HasTokenSpan for ArchitectureBody

source§

impl HasTokenSpan for AttributeDeclaration

source§

impl HasTokenSpan for AttributeSpecification

source§

impl HasTokenSpan for BlockStatement

source§

impl HasTokenSpan for CaseGenerateStatement

source§

impl HasTokenSpan for ComponentDeclaration

source§

impl HasTokenSpan for ConfigurationDeclaration

source§

impl HasTokenSpan for ConfigurationSpecification

source§

impl HasTokenSpan for ContextDeclaration

source§

impl HasTokenSpan for ContextReference

source§

impl HasTokenSpan for EntityDeclaration

source§

impl HasTokenSpan for FileDeclaration

source§

impl HasTokenSpan for ForGenerateStatement

source§

impl HasTokenSpan for IfGenerateStatement

source§

impl HasTokenSpan for InstantiationStatement

source§

impl HasTokenSpan for LibraryClause

source§

impl HasTokenSpan for ModeViewDeclaration

source§

impl HasTokenSpan for ModeViewElement

source§

impl HasTokenSpan for ObjectDeclaration

source§

impl HasTokenSpan for PackageBody

source§

impl HasTokenSpan for PackageDeclaration

source§

impl HasTokenSpan for PackageInstantiation

source§

impl HasTokenSpan for ProcessStatement

source§

impl HasTokenSpan for SubprogramBody

source§

impl HasTokenSpan for SubprogramDeclaration

source§

impl HasTokenSpan for SubprogramInstantiation

source§

impl HasTokenSpan for TypeDeclaration

source§

impl HasTokenSpan for UseClause