10
0
mirror of https://github.com/LCPQ/QUESTDB_website.git synced 2024-12-25 05:43:46 +01:00

Add get value from cell in the python parser

This commit is contained in:
Mickaël Véril 2019-12-17 15:27:40 +01:00
parent 575cb8d08c
commit 7de3f883c6
2 changed files with 14 additions and 9 deletions

View File

@ -1,6 +1,7 @@
from collections import OrderedDict from collections import OrderedDict
from TexSoup import TexSoup from TexSoup import TexSoup
from .LaTeX import newCommand from .LaTeX import newCommand
from .utils import getValFromCell
from TexSoup import TexNode from TexSoup import TexNode
from enum import IntEnum,auto,unique,IntFlag from enum import IntEnum,auto,unique,IntFlag
from .Format import Format from .Format import Format
@ -42,7 +43,8 @@ class dataFileBase(object):
for TexState in StateTablelist: for TexState in StateTablelist:
math=TexState.find("$") math=TexState.find("$")
lst=list(math.contents) lst=list(math.contents)
mathsoup=TexSoup(str(lst[0])) mystr=str(lst[0])
mathsoup=TexSoup(mystr)
newCommand.runAll(mathsoup,commands) newCommand.runAll(mathsoup,commands)
st=str(mathsoup) st=str(mathsoup)
m=re.match(r"^\^(?P<multiplicity>\d)(?P<symm>[^\s\[(]*)\s*(?:\[(?:\\mathrm{)?(?P<special>\w)(?:})\])?\s*\((?P<type>[^\)]*)\)",st) m=re.match(r"^\^(?P<multiplicity>\d)(?P<symm>[^\s\[(]*)\s*(?:\[(?:\\mathrm{)?(?P<special>\w)(?:})\])?\s*\((?P<type>[^\)]*)\)",st)
@ -78,12 +80,7 @@ class dataFileBase(object):
datacls=dict() datacls=dict()
for index,cell in enumerate(col[3:]): for index,cell in enumerate(col[3:]):
if str(cell)!="": if str(cell)!="":
unsafe=False val,unsafe=getValFromCell(cell)
val= list(cell.contents)[0]
if type(val) is TexNode and val.name=='emph':
unsafe=True
val=val.string
val=float(str(val))
finst=finsts[index] finst=finsts[index]
dt=finst[1] dt=finst[1]
if dt in datacls: if dt in datacls:
@ -114,7 +111,7 @@ class dataFileBase(object):
finsts=dataFileBase.convertState(table[first:last+1,1],default=default,firstState=firstState,commands=commands) finsts=dataFileBase.convertState(table[first:last+1,1],default=default,firstState=firstState,commands=commands)
for index,cell in enumerate(col[first:last+1]): for index,cell in enumerate(col[first:last+1]):
if str(cell)!="": if str(cell)!="":
val= list(cell.contents)[0] val,unsafe=getValFromCell(cell)
val=float(str(val)) val=float(str(val))
finst=finsts[index] finst=finsts[index]
dt=finst[1] dt=finst[1]

View File

@ -20,4 +20,12 @@ def desarg(tex):
else: else:
myitem=item myitem=item
lst.append(myitem) lst.append(myitem)
return nodify(lst,tex.name,tex.parent) return nodify(lst,tex.name,tex.parent)
def getValFromCell(cell):
unsafe=False
val= list(cell.contents)[0]
if type(val) is TexNode and val.name=='emph':
unsafe=True
val=val.string
val=float(str(val))
return (val,unsafe)