Skip to content

Commit

Permalink
parser: Fixed build with bison 3.2 (fixes #11)
Browse files Browse the repository at this point in the history
Bison 3.2 added support for movable types, but this change broke our
build. Each type is now enclosed in YY_RVREF() macro. If you use
templated type with multiple arguments it must contain comma. This comma
is however parsed by preprocessor which thinks that we have passed
multiple arguments to the function-like macro. This results in error
like:

error: too many arguments provided to function-like macro invocation

or

error: macro "YY_RVREF" passed 2 arguments, but takes just 1

This workaround fixes the problem and we can now build our parser with
pre-3.2 and 3.2+ bison versions. Since we want to abandon flex+bison
anyway, we will just use this workaround for now.
  • Loading branch information
metthal committed Nov 8, 2018
1 parent 26e0fb4 commit a35e710
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

# dev

* Fix: Build with bison 3.2 ([#11](https://github.com/avast-tl/yaramod/issues/11)).

# v2.2.1 (2018-10-03)

* Fix: Fixed build on certain specific MSVC versions.
Expand Down
19 changes: 17 additions & 2 deletions src/parser/yy/parser.y
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,22 @@
#include "yaramod/types/rule.h"
#include "yaramod/utils/trie.h"

namespace yaramod { class ParserDriver; }
namespace yaramod {

class ParserDriver;

// We need to provide alias to this type because since bison 3.2
// types are enclosed in YY_RVREF() macro. The comma in template
// parameter list is however parsed by preprocessor first and
// therefore the preprocessor thinks we are passing it 2 arguments.
// We then get error like this:
//
// error: too many arguments provided to function-like macro invocation
//
// See https://github.com/avast-tl/yaramod/issues/11 for further information.
using RegexpRangePair = std::pair<nonstd::optional<std::uint64_t>, nonstd::optional<std::uint64_t>>;

}

// Uncomment for debugging
// See also other occurrences of 'debugging' in this file and constructor of ParserDriver to enable it
Expand Down Expand Up @@ -137,7 +152,7 @@ static yy::Parser::symbol_type yylex(ParserDriver& driver)
%token REGEXP_WORD_BOUNDARY
%token REGEXP_NON_WORD_BOUNDARY
%token <std::string> REGEXP_CHAR
%token <std::pair<nonstd::optional<std::uint64_t>, nonstd::optional<std::uint64_t>>> REGEXP_RANGE
%token <yaramod::RegexpRangePair> REGEXP_RANGE
%token <std::string> REGEXP_CLASS

%type <yaramod::Rule::Modifier> rule_mod
Expand Down

0 comments on commit a35e710

Please sign in to comment.