gachapy.keylang
The tokenizer, parser, and interpreter for KeyLang, the language used by gachapy to save and load custom rarity to drop rate functions KeyLang is a simple calculator-based language. Each token in the language must be separated by a space. The expressions follow standard order of operations. The following are allowed operations: + : addition - : subtraction * : multiplication / : division ^ : exponent ( … ) : parentheses (for overriding order of operations), where … is any expression any float literal R : rarity, to be substituted upon interpretation time
KeyLang Grammar
Expr -> Term + Expr | Term - Expr | Term Term -> Factor * Term | Factor / Term | Factor Factor -> Base ^ Factor | Base Base -> Const | ( Expr ) Const -> <float literal> | <rarity> Rar -> <rarity>
Example: 2 * ( 1 + R ) / 5 ^ 2 where R = rarity
Author: Jacob Kerr, 2021
- class gachapy.keylang.Ast(left=None, right=None, data=None)[source]
The base class of the abstract syntax tree
- gachapy.keylang.interpret(ast: gachapy.keylang.Ast, rarity: float) float [source]
Evaluates the KeyLang AST to a value using the rarity
- astAst
the AST of the expression
- rarityfloat
the value for the rarity
- float
the result of the expression
- gachapy.keylang.parse(s: str) gachapy.keylang.Ast [source]
Parses the inputed KeyLang expression into a KeyLang abstract syntax tree
- sstr
the expression to parse
- Ast
the KeyLang AST representative of the expression