Skip to content

Commit

Permalink
Pequeña modificación parser para contar ciertos casos con los índices…
Browse files Browse the repository at this point in the history
…. Agregados tokens underset y overset y parser los procesa, falta añadirle su lectura líneal.
  • Loading branch information
David-Casas committed Jul 18, 2018
1 parent ed4dc67 commit f1c8108
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 15 deletions.
2 changes: 1 addition & 1 deletion blindtex/interpreter/reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ def is_simple(Node):
if(Node.content in with_children):
bool_it_is = False
elif(Node.content == 'block' and len(Node.get_children()) > 1):
bool_it_is = False
bool_it_is = False #There is a bug: If the block is {{a + b}} it will say it is simple.
else:
bool_it_is = True #Redundant but safe.
return bool_it_is
Expand Down
14 changes: 13 additions & 1 deletion blindtex/latex2ast/lexer.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
'CHOOSE','BINOM','PMOD',
'PHANTOM','TEXT','LABEL',
'ANYTHING','ARRAYTEXT','USER',
'NUM','KNOT', 'MOD', 'TCHAR',)
'NUM','KNOT', 'MOD', 'TCHAR','UNDERSET', 'OVERSET')

dictOfDicts = json.loads("{\"Dots\": \"dots|ldots|cdots|vdots|ddots\", \
\"Styles\": \"mathit|mathrm|mathbf|mathsf|mathtt|mathcal|boldmath\", \
Expand Down Expand Up @@ -49,6 +49,8 @@ def get_lexer():
command_BEGARRAY = r'(begin\{array\}|begin\{[pbBvV]?matrix(\*)?\})(\[.*?\])?(\{.*?\})?'
command_ENDARRAY = r'end\{array\}|end\{[pbBvV]?matrix(\*)?\}'
command_LINEBREAK = r'\\'
command_UNDERSET = r'underset'
command_OVERSET = r'overset'
COL = r'[&]'
#command_LARGEOP =
#command_ORD =
Expand Down Expand Up @@ -148,6 +150,16 @@ def t_command_LINEBREAK(t):
t.lexer.begin('INITIAL')
return t

@TOKEN(command_UNDERSET)
def t_command_UNDERSET(t):
t.lexer.begin('INITIAL')
return t

@TOKEN(command_OVERSET)
def t_command_OVERSET(t):
t.lexer.begin('INITIAL')
return t

@TOKEN(COL)
def t_COL(t):
return t
Expand Down
4 changes: 2 additions & 2 deletions blindtex/latex2ast/math_object.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ def __init__(self,
left_superscript = None,
left_subscript = None,
accent = None,
underbar = None,
under = None,
superscript = None,
subscript = None,
left_delimiter = None,
Expand All @@ -22,7 +22,7 @@ def __init__(self,
self.left_superscript = left_superscript
self.left_subscript = left_subscript
self.accent = accent
self.underbar = underbar
self.under = under
self.superscript = superscript
self.subscript = subscript
self.left_delimiter = left_delimiter
Expand Down
47 changes: 36 additions & 11 deletions blindtex/latex2ast/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,25 @@ def p_accent(p):
| ACCENT symbol
'''
p[2].accent = p[1]
p[0] = [p[2]]
p[0] = [p[2]]#Are you sure this does not create a conflict if the MathObject is complex?

def p_overset(p):
'''math_object : OVERSET argument argument '''
p[3].accent = p[2]
p[0] = [p[3]]#Are you sure this does not create a conflict if the MathObject is complex?

def p_underset(p):
'''math_object : UNDERSET argument argument '''
p[3].under = p[2]
p[0] = [p[3]]#Are you sure this does not create a conflict if the MathObject is complex?

def p_style(p):
'''
math_object : STYLE block
| STYLE symbol
'''
p[2].style = p[1]
p[0] = [p[2]]
p[0] = [p[2]]#Are you sure this does not create a conflict if the MathObject is complex?


def p_formula_scripted(p):
Expand Down Expand Up @@ -106,24 +116,39 @@ def p_simple_scripted(p):
| SUB script
'''
if(p[1] == '^'):
p[-1][0].superscript = p[2]#Adds the script to the previous element.
#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:
p[-1][0].subscript = p[2]
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_compound_scripted(p):
'''
compound_scripted : SUP script SUB script
| SUB script SUP script
'''
if(p[1] == '^'):
p[-1][0].superscript = p[2]
p[-1][0].subscript = p[4]
#See p_simple_scripted
if(p[-1][0].superscript == None and p[-1][0].subscript == None):
#If some is not and the parser reached here, something funny is happening.
p[-1][0].superscript = p[2]
p[-1][0].subscript = p[4]
else:
p[-1].append(Node(content = 'nothing_scripted', superscript = p[2], subscript = p[4]))
else:
p[-1][0].subscript = p[2]
p[-1][0].superscript = p[4]



if(p[-1][0].superscript == None and p[-1][0].subscript == None):
p[-1][0].subscript = p[2]
p[-1][0].superscript = p[4]
else:
p[-1].append(Node(content = 'nothing_scripted', superscript = p[4], subscript = p[2]))

def p_symbol(p):
"""
Expand Down

0 comments on commit f1c8108

Please sign in to comment.