I am using Sly package in Python to make a dummy Lexer. here is the documentation which only states that tokens which are numbers can only be identified as NUMBER as we, the programmer defines it:
@_(r'\d+')
def NUMBER(self, t):
t.value = int(t.value)
return t
Now I have tried adding a separate function for a FLOAT and INT type instead, but there are some complications:
I can't find anything to successfully read the input and identify it as a 'float' or an 'int' data type. Experimented with various things it 'yeilds', no luck.
I am now thinking of manipulating RegEx somehow but no luck in that either. I can't make it recognize a float by placing a dot between two digits like this:
@_(r'\d+.\d+') # this Expression
def FLOAT(self, t):
t.value = int(t.value)
return t
Anyways, the output I want is something like this:
#input string
123 1.23
#output string (this is a simplified version of the original output)
TOKEN:123; ID:0; TYPE:int-datatype
TOKEN:1.23; ID:1; TYPE:float-datatype
NOTE: I am very new to Sly