def p_simple_scripted(p): ''' simple_scripted : SUP script | SUB script ''' if(p[1] == '^'): #This distintion is made for formulas like a^2 ^3 (double scripted) #LaTeX accepts them and we have to. #Here we create a new Node with content 'nothing_scripted' that will be processed later. if(p[-1][0].superscript == None): p[-1][0].superscript = p[2]#Adds the script to the previous element. else: p[-1].append(MathObject(content = 'nothing_scripted', superscript = p[2]))#What a duct tape fix. else: if(p[-1][0].subscript == None): p[-1][0].subscript = p[2] else: p[-1].append(MathObject(content = 'nothing_scripted', subscript = p[2]))
def p_symbol(p): """ symbol : LIM | UNKNOWN | MOD | "!" | NOT | KNOT | USER """ p[0] = MathObject(content = p[1])
def p_choose(p): ''' choose : formula CHOOSE formula ''' p[0] = MathObject(content = 'choose') p[0].append_child(p[1]) p[0].append_child(p[3][0])
def p_indexed_root(p): '''indexed_root : ROOT root_index argument ''' p[0] = MathObject(content = 'root') p[0].append_child(p[2])#The first child will be the index. p[0].append_child(p[3][0])#This is because p[5] is a list, as index returns that, but we want to append the MathObject, not the list.
def p_sqr_root(p): '''sqr_root : ROOT argument ''' p[0] = MathObject(content = 'root') p[0].append_child(p[2])
def p_col(p): '''col : COL ''' p[0] = MathObject(content = '&')
def p_array(p): '''array : BEGARRAY start ENDARRAY ''' p[0] = MathObject(content = 'array') p[0].append_child(p[2])
def p_text(p): ''' text : TEXT TCHAR | TEXT ANYTHING''' p[0] = MathObject(content = 'text') p[0].append_child(p[2])
def p_func(p): ''' symbol : FUNC ''' p[0] = MathObject(content = p[1], kind = 'MathFunctions')
def p_binrel(p): ''' symbol : KBINREL | BINREL''' p[0] = MathObject(content = p[1], kind = 'BinaryRelations')#Beware to distinguish if is in the dictionary or not.
def p_binop(p): ''' symbol : BINOP | KBINOP ''' p[0] = MathObject(content = p[1], kind = 'BinaryOperators')#Beware to distinguish if is in the dictionary or not.
def p_largeOp(p): ''' symbol : LARGEOP ''' p[0] = MathObject(content = p[1], kind = 'LargeOperators')
def p_noKind_ord(p): '''symbol : NUM | CHAR ''' p[0] = MathObject(content = p[1])
def p_ord(p): ''' symbol : ORD ''' p[0] = MathObject(content = p[1], kind = 'Ordinary')#Beware to distinguish if is in the dictionary or not.
def p_binom(p): '''binom : BINOM argument argument ''' p[0] = MathObject(content = 'binom') p[0].append_child(p[2]) p[0].append_child(p[3][0])
def p_pmod(p): ''' pmod : PMOD argument ''' p[0] = MathObject(content = 'pmod') p[0].append_child(p[2])
def p_arrow(p): ''' symbol : ARROW ''' p[0] = MathObject(content = p[1], kind = 'Arrows')
def p_label(p): '''label : LABEL ''' p[0] = MathObject(content = 'label') p[0].append_child(p[1])
def p_delimiter(p): ''' symbol : DELIMITER | kdelimiter ''' p[0] = MathObject(content = p[1], kind = 'Delimiters')
def p_lnbrk(p): '''lnbrk : LINEBREAK ''' p[0] = MathObject(content = r'\\')
def p_dots(p): ''' symbol : DOTS ''' p[0] = MathObject(content = p[1], kind = 'Dots')
def p_block(p): """ block : BEGINBLOCK formula ENDBLOCK """ p[0] = MathObject(content = 'block') p[0].append_child(p[2])
def p_fraction(p): '''fraction : FRAC argument argument ''' p[0] = MathObject(content = 'fraction') p[0].append_child(p[2]) p[0].append_child(p[3][0]) #This is because p[3] is a list, as index returns that, but we want to append the MathObject, not the list.