Rule

Enum Rule 

Source
pub enum Rule {
Show 103 variants EOI, file, line, WHITESPACE, COMMENT, int, uint, message_id, number, min_max, minimum, maximum, quoted_str, unit, attribute_name, string, char, quote, ident, ident_ext, signal_name, num_str_value, env_var, env_var_str, env_var_val, env_var_name, env_literal, node_var_str, node_var_val, node_name, node_literal, msg_var, msg_var_str, msg_var_val, msg_literal, signal_var, signal_literal, version, new_symbols, bit_timing, nodes, message, message_name, message_size, transmitter, signal, multiplexer_indicator, start_bit, signal_size, big_endian, little_endian, signed_type, unsigned_type, factor, offset, comment, comment_signal, comment_message, comment_node, comment_env_var, comment_message_implicit, comment_plain, attr_def, object_type, attribute_type, attribute_type_int, attribute_type_hex, attribute_type_float, attribute_type_string, attribute_type_enum, attr_value, value_table_def, value_table, table_name, table_value_description, signal_group, group_name, multiplexer_id, signal_value_type, signal_value_type_value, sig_val_integer, sig_val_IEEE_float_32Bit, sig_val_IEEE_float_64Bit, message_transmitter, ba_def_rel, ba_rel, rel_object_type, rel_object_data, ba_def_def_rel, ba_def_def, sg_mul_val, value_pair, multiplexer_name, environment_variable, env_var_type, env_var_type_int, env_var_type_float, env_var_type_string, init_value, ev_id, access_type, env_var_data, data_size,
}
Expand description

DBC (Database CAN) file parser grammar

This grammar parses DBC files used for CAN bus communication definitions. DBC files contain message definitions, signal specifications, node information, and various attributes for automotive and industrial CAN networks.

Variants§

§

EOI

End-of-input

§

file

Main DBC file structure

§

line

A single line in the DBC file - can be various types of statements or empty

§

WHITESPACE

Implicit whitespace - spaces and tabs

§

COMMENT

Line comments starting with //

§

int

Integer numbers (positive and negative, including scientific notation)

§

uint

Unsigned Integer

§

message_id

CAN ID (unsigned integer)

§

number

A number which can be integer or floating point

§

min_max

Minimum and maximum values

§

minimum

§

maximum

§

quoted_str

String literals in double quotes

§

unit

§

attribute_name

§

string

String literal content, without the surrounding quotes

§

char

§

quote

§

ident

Identifiers (node names, message names, signal names, etc.)

§

ident_ext

Extended Identifiers (same as ident, but also allowing leading digits)

§

signal_name

§

num_str_value

§

env_var

§

env_var_str

§

env_var_val

§

env_var_name

§

env_literal

§

node_var_str

§

node_var_val

§

node_name

§

node_literal

§

msg_var

§

msg_var_str

§

msg_var_val

§

msg_literal

§

signal_var

§

signal_literal

§

version

Version identifier of the DBC file.

Format: VERSION "string"

§

new_symbols

New Symbol section: NS_ : symbol1 symbol2 … The spaces and comments are explicit because each symbol must be indented on new lines. The indented lines are what tells us that they are part of the new_symbols section.

§

bit_timing

The bit timing section defines the baud-rate and the settings of the BTR registers of the network. This section is obsolete and not used anymore. Nevertheless, the keyword BS_ must appear in the DBC file.

Format: bit_timing = BS_: [baud_rate : BTR1 , BTR2 ] ;

§

nodes

Node definition: BU_: node1 node2 node3 … Just like new_symbols, the spaces and comments are explicit because each node can be either on the same line or space-indented on new lines.

§

message

Message definition: BO_ message_id message_name: message_size transmitter

§

message_name

§

message_size

§

transmitter

§

signal

Signal definition: SG_ signal_name : start_bit|signal_size@byte_order+/- (factor,offset) [min|max] “unit” receiver

The message’s signal section lists all signals placed on the message, their position in the message’s data field and their properties.

signal = 'SG_' signal_name multiplexer_indicator ':' start_bit '|'
signal_size '@' byte_order value_type '(' factor ',' offset ')'
'[' minimum '|' maximum ']' unit receiver {',' receiver} ;
signal_name = DBC_identifier ;
multiplexer_indicator = ' ' | [m multiplexer_switch_value] [M] ;
start_bit = unsigned_integer ;
signal_size = unsigned_integer ;
byte_order = '0' | '1' ; (* 0=big endian, 1=little endian *)
value_type = '+' | '-' ; (* +=unsigned, -=signed *)
factor = double ;
offset = double ;
minimum = double ;
maximum = double ;
unit = char_string ;
receiver = node_name | 'Vector__XXX' ;

Signal definition. Format: SG_ <SignalName> [M|m<MultiplexerIdentifier>] : <StartBit>|<Length>@<Endianness><Signed> (<Factor>,<Offset>) [<Min>|<Max>] "[Unit]" [ReceivingNodes] Length in bits. Signed: + = unsigned; - = signed Endianness: 1 = little-endian, Intel; 0 = big-endian, Motorola M: If M than this signals contains a multiplexer identifier. MultiplexerIdentifier: Signal definition is only used if the value of the multiplexer signal equals this value.

§

multiplexer_indicator

§

start_bit

§

signal_size

§

big_endian

§

little_endian

§

signed_type

§

unsigned_type

§

factor

§

offset

§

comment

Comment definitions: CM_ [BU_|BO_|SG_|EV_] object_name “comment_text”;

The comment section contains the object comments. For each object having a comment, an entry with the object’s type identification is defined in this section.

comments = {comment} ;
comment = 'CM_' (char_string |
'BU_' node_name char_string |
'BO_' message_id char_string |
'SG_' message_id signal_name char_string |
'EV_' env_var_name char_string)
';' ;

Note: The grammar supports both explicit type prefixes (SG_, BO_, BU_, EV_) and implicit forms. The ordering of alternatives is important in PEG parsing: more specific patterns must come before less specific ones. Message comments can be either “CM_ BO_ …” or just “CM_ …”.

§

comment_signal

Signal comment: CM_ SG_ <message_id> [<signal_name>] “comment”; Note: signal_name is optional. When omitted, this is treated as a message comment.

§

comment_message

Message comment (explicit): CM_ BO_ <message_id> “comment”;

§

comment_node

Node comment: CM_ BU_ <node_name> “comment”;

§

comment_env_var

Environment variable comment: CM_ EV_ <env_var_name> “comment”;

§

comment_message_implicit

Message comment (implicit, without BO_ prefix): CM_ <message_id> “comment”;

§

comment_plain

Plain comment (bus-level): CM_ “comment”;

§

attr_def

Attribute definition: BA_DEF_ [object_type] attribute_name attribute_type [min max];

BA_DEF_  "FloatAttribute" FLOAT 0 50.5;
BA_DEF_ BU_  "BUIntAttribute" INT 0 100;
BA_DEF_ BO_  "BOStringAttribute" STRING ;
BA_DEF_ BO_  "BOStringAttribute" STRING ;
BA_DEF_ SG_  "SGEnumAttribute" ENUM  "Val0","Val1","Val2";
BA_DEF_ SG_  "SGEnumAttribute" ENUM  "Val0","Val1","Val2";
BA_DEF_ EV_  "RWEnvVar_wData_Val" INT 0 10;
BA_DEF_ EV_  "GlobalEnvVar_Val" HEX 256 320;
§

object_type

§

attribute_type

§

attribute_type_int

§

attribute_type_hex

§

attribute_type_float

§

attribute_type_string

§

attribute_type_enum

§

attr_value

Attribute value: BA_ attribute_name [object_type] object_name value;

§

value_table_def

Value table definition: VAL_ message_id signal_name value1 “description1” value2 “description2” … ;

VAL_ RWEnvVar_wData 2 "Value2" 1 "Value1" 0 "Value0" ;
§

value_table

Value table: VAL_TABLE_ table_name value1 “description1” value2 “description2” … ;

The value table section defines the global value tables. The value descriptions in value tables define value encodings for signal raw values. In commonly used DBC files the global value tables aren’t used, but the value descriptions are defined for each signal independently.

value_tables = {value_table} ;
value_table = 'VAL_TABLE_' value_table_name {value_description} ';' ;
value_table_name = DBC_identifier ;

Format: VAL_TABLE_ <value_table_name> <value_description>;

value_description: List of IntValue "StringValue" Pairs, separated by whitespaces

§

table_name

§

table_value_description

§

signal_group

Signal group: SIG_GROUP_ message_id group_name multiplexer_id : signal1 signal2 … ;

§

group_name

§

multiplexer_id

§

signal_value_type

Signal value type: SIG_VALTYPE_ message_id signal_name : value_type;

§

signal_value_type_value

§

sig_val_integer

§

sig_val_IEEE_float_32Bit

§

sig_val_IEEE_float_64Bit

§

message_transmitter

Message transmitter: BO_TX_BU_ message_id : transmitter1,transmitter2,… ;

§

ba_def_rel

Relative attribute definition: BA_DEF_REL_ object_type attribute_name attribute_type [min max];

Control Unit – Environment Variable

BA_DEF_REL_ BU_EV_REL_  "ControlUnitEnvVarAttr" STRING ;

Node – Tx Message

BA_DEF_REL_ BU_BO_REL_  "attribute_name" STRING ;

Node – Mapped Rx Signal

BA_DEF_REL_ BU_SG_REL_  "attribute_name" STRING ;
BA_DEF_ EV_  "RWEnvVar_wData_Val" INT 0 10;
BA_DEF_ EV_  "GlobalEnvVar_Val" HEX 256 320;
BA_DEF_ SG_  "SGEnumAttribute" ENUM  "Val0","Val1","Val2";
BA_DEF_ BU_  "BUIntAttribute" INT 0 100;
BA_DEF_ BO_  "BOStringAttribute" STRING ;
BA_DEF_  "FloatAttribute" FLOAT 0 50.5;
BA_DEF_REL_ BU_EV_REL_  "ControlUnitEnvVarAttr" STRING ;
BA_DEF_REL_ BU_BO_REL_  "attribute_name" STRING ;
BA_DEF_REL_ BU_SG_REL_  "attribute_name" STRING ;
§

ba_rel

Relative attribute value: BA_REL_ attribute_name object_type object_name value;

§

rel_object_type

§

rel_object_data

§

ba_def_def_rel

Relative attribute default: BA_DEF_DEF_REL_ attribute_name default_value;

§

ba_def_def

Global attribute default: BA_DEF_DEF_ attribute_name default_value;

§

sg_mul_val

Multiplexed signal value definition: SG_MUL_VAL_ <message_id> <signal_name> <multiplexer_name> <value_pairs>;

§

value_pair

§

multiplexer_name

§

environment_variable

Environment variable definition: EV_ variable_name : type [min|max] “unit” access_type access_node node_name1 node_name2;

environment_variables = {environment_variable}
environment_variable = 'EV_' env_var_name ':' env_var_type '[' mini-
mum '|' maximum ']' unit initial_value ev_id access_type
access_node {',' access_node } ';' ;

env_var_name = DBC_identifier ;

env_var_type = '0' | '1' | '2' ; (* 0=integer, 1=float, 2=string *)

minimum = double ;
maximum = double ;

initial_value = double ;

ev_id = unsigned_integer ; (* obsolete *)

access_type = 'DUMMY_NODE_VECTOR0' | 'DUMMY_NODE_VECTOR1' |
    'DUMMY_NODE_VECTOR2' | 'DUMMY_NODE_VECTOR3' |
    'DUMMY_NODE_VECTOR8000' | 'DUMMY_NODE_VECTOR8001' |
    'DUMMY_NODE_VECTOR8002' | 'DUMMY_NODE_VECTOR8003'; (*
    0=unrestricted, 1=read, 2=write, 3=readWrite, if the value be-
    hind 'DUMMY_NODE_VECTOR' is OR-ed with 0x8000, the value type
    is always string. *)

access_node = node_name | 'VECTOR__XXX' ;

example:

EV_ UnrestrictedEnvVar: 0 [0|0] "Nm" 0 1 DUMMY_NODE_VECTOR8000  Node0;
EV_ RWEnvVar_wData: 0 [0|1234] "" 60 2 DUMMY_NODE_VECTOR3  Node2;
EV_ WriteOnlyEnvVar: 1 [0|1234] "" 60 3 DUMMY_NODE_VECTOR2  Node2;
§

env_var_type

§

env_var_type_int

§

env_var_type_float

§

env_var_type_string

§

init_value

§

ev_id

§

access_type

§

env_var_data

Environment variables data section

environment_variables_data = environment_variable_data ;
environment_variable_data = 'ENVVAR_DATA_' env_var_name ':' data_size ';' ;
data_size = unsigned_integer ;

example:

ENVVAR_DATA_ RWEnvVar_wData: 10;
§

data_size

Implementations§

Source§

impl Rule

Source

pub fn all_rules() -> &'static [Rule]

Trait Implementations§

Source§

impl Clone for Rule

Source§

fn clone(&self) -> Rule

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Rule

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Hash for Rule

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl Ord for Rule

Source§

fn cmp(&self, other: &Rule) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl Parser<Rule> for DbcParser

Source§

fn parse<'i>(rule: Rule, input: &'i str) -> Result<Pairs<'i, Rule>, Error<Rule>>

Parses a &str starting from rule.
Source§

impl PartialEq for Rule

Source§

fn eq(&self, other: &Rule) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialOrd for Rule

Source§

fn partial_cmp(&self, other: &Rule) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl Copy for Rule

Source§

impl Eq for Rule

Source§

impl StructuralPartialEq for Rule

Auto Trait Implementations§

§

impl Freeze for Rule

§

impl RefUnwindSafe for Rule

§

impl Send for Rule

§

impl Sync for Rule

§

impl Unpin for Rule

§

impl UnwindSafe for Rule

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> RuleType for T
where T: Copy + Debug + Eq + Hash + Ord,