Skip to content

Commit

Permalink
add support for unary expression in grammar
Browse files Browse the repository at this point in the history
  • Loading branch information
TommYDeeee committed Jan 29, 2024
1 parent 9623d2b commit 7edfc3f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/parser/grammar/expressions/atom.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ pub(crate) fn literal(p: &mut Parser) -> Option<CompletedMarker> {
Some(m.complete(p, LITERAL))
}

const EXPR_RECOVERY_SET: TokenSet = TokenSet::new(&[VARIABLE, TRUE, FALSE, AND, OR, NOT]);
const EXPR_RECOVERY_SET: TokenSet = TokenSet::new(&[VARIABLE, TRUE, FALSE, NOT]);

// add support for while/for loops, if/else statements, etc.
pub(super) fn atom_expr(p: &mut Parser) -> Option<CompletedMarker> {
Expand Down
10 changes: 5 additions & 5 deletions yara_subset.grammar
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ SOURCE -> RULE | eps.
RULE -> rule identifier lbrace RULEBODY rbrace.
RULEBODY -> STRINGS CONDITION | CONDITION .
STRINGS -> string colon STRINGSBODY.
CONDITION -> condition colon CONDITIONBODY.
CONDITION -> condition colon EXPRESSION.
STRINGSBODY -> variable assign string STRINGSBODY | eps.
CONDITIONBODY -> LITERAL EXPRESSION | OPERATOR EXPRESSION .
EXPRESSION -> LITERAL EXPRESSION | OPERATOR EXPRESSION | eps.
EXPRESSION -> EXPRESSION OPERATOR EXPRESSION | NOTOPERATOR EXPRESSION | LITERAL.
LITERAL -> variable | BOOLEAN.
BOOLEAN -> true | false.
OPERATOR -> and | or | not.
OPERATOR -> and | or.
NOTOPERATOR -> not.

// https://smlweb.cpsc.ucalgary.ca/vital-stats.php?grammar=SOURCE+-%3E+RULE+%7C+eps.%0D%0ARULE+-%3E+rule+identifier+lbrace+RULEBODY+rbrace.%0D%0ARULEBODY+-%3E+STRINGS+CONDITION+%7C+CONDITION+.%0D%0ASTRINGS+-%3E+string+colon+STRINGSBODY.%0D%0ACONDITION+-%3E+condition+colon+CONDITIONBODY.%0D%0ASTRINGSBODY+-%3E+variable+assign+string+STRINGSBODY+%7C+eps.%0D%0ACONDITIONBODY+-%3E+LITERAL+EXPRESSION+%7C+OPERATOR+EXPRESSION+.%0D%0AEXPRESSION+-%3E+LITERAL+EXPRESSION+%7C+OPERATOR+EXPRESSION+%7C+eps.%0D%0ALITERAL+-%3E+variable+%7C+BOOLEAN.%0D%0ABOOLEAN+-%3E+true+%7C+false.%0D%0AOPERATOR+-%3E+and+%7C+or+%7C+not.
// https://smlweb.cpsc.ucalgary.ca/vital-stats.php?grammar=SOURCE+-%3E+RULE+%7C+eps.%0D%0ARULE+-%3E+rule+identifier+lbrace+RULEBODY+rbrace.%0D%0ARULEBODY+-%3E+STRINGS+CONDITION+%7C+CONDITION+.%0D%0ASTRINGS+-%3E+string+colon+STRINGSBODY.%0D%0ACONDITION+-%3E+condition+colon+EXPRESSION.%0D%0ASTRINGSBODY+-%3E+variable+assign+string+STRINGSBODY+%7C+eps.%0D%0AEXPRESSION+-%3E+EXPRESSION+OPERATOR+EXPRESSION+%7C+NOTOPERATOR+EXPRESSION+%7C+LITERAL.%0D%0ALITERAL+-%3E+variable+%7C+BOOLEAN.%0D%0ABOOLEAN+-%3E+true+%7C+false.%0D%0AOPERATOR+-%3E+and+%7C+or.%0D%0ANOTOPERATOR+-%3E+not.

0 comments on commit 7edfc3f

Please sign in to comment.