Skip to content

Latest commit

 

History

History
50 lines (45 loc) · 10.1 KB

LANGUAGE_SPEC.md

File metadata and controls

50 lines (45 loc) · 10.1 KB

AST for mtg card search lib

<search> = <expression><search>
<expression> = (<expression><binOp><expression>)
  |(<expression><expression>)
  |(<negation><expression>)

//<expression><expression> is treated as <expression><operator><expression> where <binOp> is and

<binOp> = ((and|&&)|(or|\|\|)|(xor|^)|nand)
<negation> = (not|!)

<expressions> = <comptype><operator><parameter>

<comptype> = (p|t|c|o|set|collectors|commander|type|legal|banned|is)
<operator> = ((:|=)|<=|>=|<|>)

//not each <opetator> is defined for each <comptype>

<parameter> = (<word>|"<words>"|/<regex>/>

//the definitions for the following are given as regex which means I will end up defining regex with regex but who doesn't like a good recursion

<words> = "((\\")|[^"])+"
<regex> = /((\\/)|[^"])+/
<word> = [^:/"]([^ ])+

comptype operation definitions

Symbolic fields are defined as {x},{y} or anything that is non-real in the p/t field. Formats are defined as a lower case string that, each implementation may support different formats. Typical formats are: vintage, legacy, commander, modern, pauper, pioneer, standard, penny dreadful and oathbreaker but several other formats exist. Only the o comptype supports regex All cards with symbolic power/toughness should be put after the non-symbolic power/toughness cards.

: or = <= >= < >
p Power is equal to operand
Or if power is symbolic
Symbolic operands must be equal to the
power field not including whitespace,
case insensitive
Power is less than or equal to operand
Or if the power is symbolic
Symbolic operands are not defined
Power is greater than or equal to operand
Or if the power is symbolic
Symbolic operands are not defined
Power is less than the operand
Or if the power is symbolic
Symbolic operands are not defined
Power is greater than the operand
Or if the power is symbolic
Symbolic operands are not defined
t Toughness is equal to operand
Or if toughness is symbolic
Toughness is less than or equal to operand
Or if the power is symbolic
Symbolic operands are not defined
Toughness is less than or equal to the operand
Or if the toughness is symbolic
Symbolic operands are not defined
Toughness is less than the operand
Or if the toughness is symbolic
Symbolic operands are note defined
Toughness is greater than the operand
Or if the toughness is symbolic
Symbolic operands are not defined
c The cards colours are exclusively the colours in the
operand (each char is a seperate colour)
The cards colours are less than or equal to
the colours in the operand (each char is a
seperate colour)
The cards colours are greater than or equal to
the colours in the operand (each char is a seperate colour)
The cards colours are less than the
colours in the operand (each char is
a seperate colour)
The cards colours are greater than
the colours in the operand (each
char is a seperate colour)
set Set code or name equals the operand Not defined Not defined Not defined Not defined
collectors The cards collectors number is equal to operand The cards collectors number is less
than or equal to the operand
The collectors number is greater than or equal to the
operand
The collectors number is less than
the operand
The collectors number is greater
than the operand
commander The card's colour identity has the operand colour/s in
it (each char is a seperate colour)
The card's colour identity has less
than or equal to the operand colour/s
in it (each char is a seperate colour)
The colour identity of the card is greater than or equal
to the colours in the operand (each char is a seperate colour)
The colour identity is less than
the colours in the operand (each
char is a seperate colour)
The colour identity is greater than
the colours in the operand (each
char is a seperate colour)
type The card contains the type which is the operand Not defined Not defined Not defined Not defined
legal The card is legal in the format defined by the operand
case insensitive
Not defined Not defined Not defined Not defined
banned The card is banned in the format defined by the operand
case insensitive
Not defined Not defined Not defined Not defined
is The card has a property operand that is true Not defined Not defined Not defined Not defined
o Supports regex.
String operand:
The card has oracle text that contains the operand
Regex operand:
The card contains a susbtring that matches the regex
defined by the operand
Not defined Not defined Not defined

Usage

The AST describes how to create a query for searching cards. The implementations will take a given card and return true or false depending on whether the card matches the query.