Skip to content

Commit

Permalink
refactor: rename expressions in grammar
Browse files Browse the repository at this point in the history
  • Loading branch information
desbma-s1n committed May 28, 2024
1 parent d5be798 commit d862269
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
26 changes: 13 additions & 13 deletions src/strace/parser/peg.pest
Original file line number Diff line number Diff line change
Expand Up @@ -12,32 +12,32 @@ name = { (ASCII_ALPHA_LOWER | ASCII_DIGIT | "_")+ }

arguments = { "(" ~ (expression ~ (", " ~ expression)*)? ~ ")" }

ret_val = { expression_int ~ (" " ~ ANY*)? }
ret_val = { int ~ (" " ~ ANY*)? }


// Subrules

expression = {
#expr_int = expression_int |
#int = int |
#struct = struct |
#buf = buffer |
#macro = macro |
#set = set |
#array = array
}

expression_int = {
#or = expression_int_or |
#lit = expression_int_literal |
#named = expression_named_constant
int = {
#or = or |
#lit = literal_int |
#named = named_constant
}
expression_int_literal = { #hex = literal_int_hex | #int = literal_int }
expression_int_or = { expression_named_constant ~ ("|" ~ expression_int)+ }
expression_named_constant = { (ASCII_ALPHA_UPPER | ASCII_DIGIT | "_")+ }
literal_int = { #hex = literal_int_hex | #dec = literal_int_dec }
or = { named_constant ~ ("|" ~ int)+ }
named_constant = { (ASCII_ALPHA_UPPER | ASCII_DIGIT | "_")+ }

literal_int_hex = { "0x" ~ ASCII_HEX_DIGIT+ }
literal_int = { int_val ~ int_metadata? }
int_val = { "-"? ~ ASCII_DIGIT+ }
literal_int_dec = { literal_int_dec_val ~ int_metadata? }
literal_int_dec_val = { "-"? ~ ASCII_DIGIT+ }
int_metadata = { "<" ~ buffer_byte+ ~ ">" }

struct = { "{" ~ (struct_member ~ (", " ~ struct_member)*)? ~ "}" }
Expand All @@ -64,10 +64,10 @@ set = {
"~"? ~
"[" ~
(
expression_int ~
int ~
(
" " ~
expression_int
int
)*
)? ~
"]"
Expand Down
4 changes: 2 additions & 2 deletions src/strace/parser/peg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ fn pair_descend(pair: Pair<'_, Rule>, levels: usize) -> Option<Pair<'_, Rule>> {
impl From<Pair<'_, Rule>> for Expression {
fn from(pair: Pair<Rule>) -> Self {
match pair.as_node_tag() {
Some("expr_int") => Expression::Integer(pair_descend(pair, 1).unwrap().into()),
Some("int") => Expression::Integer(pair_descend(pair, 1).unwrap().into()),
Some("buf") => Expression::Buffer(pair.into()),
Some("struct") => Expression::Struct(
pair.into_inner()
Expand Down Expand Up @@ -122,7 +122,7 @@ impl From<Pair<'_, Rule>> for IntegerExpression {
.unwrap(),
None,
),
Some("int") => {
Some("dec") => {
let mut children = pair.into_inner();
let val_pair = children.next().unwrap();
let metadata_pair = children.next();
Expand Down

0 comments on commit d862269

Please sign in to comment.