kabirgh / spoiler-blocker

Apache License 2.0
2 stars 0 forks source link

Support boolean expressions #36

Open kabirgh opened 7 years ago

kabirgh commented 7 years ago

This pull request implements boolean expression evaluation of input in the 'Tags' field.

The new delimiters/operators are:

For example, the tag input Trudeau & Trump blocks posts that contain both 'Trudeau' and 'Trump' in the same post, but allows posts that contain only 'Trudeau', or only 'Trump'.

Tag lists are no longer auto-prettified. i.e. spoiler alert ,force awakens,episode viii does not display as spoiler alert, force awakens, episode viii with spaces after the commas but remains as the user inputs it.

Implementation

  1. User input is tokenized into literals, operators and parentheses (src/panel/common/internal/parser.js)
  2. The tokenized output is converted to reverse polish notation for easier evaluation (src/panel/common/internal/parser.js) and stored in the spoilers array with the key tokensArr.
  3. The token array is evaluated in src/logic/common/util/CommonUtils.js

Code problems The enum TokenType resides only in parser.js. It is not shared across files, so other files compare the tokenType to a string with the same name as the TokenType enum.

kabirgh commented 7 years ago

Changes:

Feel like commonActions is doing a lot of things right now. Not sure how/whether to refactor.