|
| 17 Apr 2017 10:31 AM |
How would i be able to parse lua tokens so I would be able to read a section of code? aka how could I parse something like this
for k in next,table do print( "hi" ) end if true then print( "example" ) end var = 2 func()
and parse it into for k in next,table do print( "hi" ); end if true then print( "example" ) end var = 2 print() |
|
|
| Report Abuse |
|
|
|
| 17 Apr 2017 10:33 AM |
| Trying to make a script debugger / tutor, it reads the code and prints what each line is doing (helps with solving problems and understanding code) |
|
|
| Report Abuse |
|
|
|
| 17 Apr 2017 10:33 AM |
| need to be able to parse tokens so i can read multiple things on one line and print it together |
|
|
| Report Abuse |
|
|
|
| 17 Apr 2017 10:35 AM |
string.find and a list of keywords/symbols that would need a newline
|
|
|
| Report Abuse |
|
|
|
| 17 Apr 2017 10:36 AM |
Use the string.gmatch iterator function along with the string.gsub function? You'll need to keep track of keywords that declare a new scope, and replace the space in between with something like "\n\t".
|
|
|
| Report Abuse |
|
|
|
| 17 Apr 2017 10:38 AM |
@unsub how would you get the positions of each word though?
|
|
|
| Report Abuse |
|
|
|
| 17 Apr 2017 10:38 AM |
| but how do they do it in C to compile lua code for execution? |
|
|
| Report Abuse |
|
|
|
| 17 Apr 2017 10:39 AM |
| i think i might be able to salvage from __killme's code too on the lua compiler but idk |
|
|
| Report Abuse |
|
|
|
| 17 Apr 2017 10:42 AM |
"how would you get the positions of each word though?"
That's not necessary...
"but how do they do it in C to compile lua code for execution?"
lua. org /source/5.3/
|
|
|
| Report Abuse |
|
|
|
| 17 Apr 2017 10:44 AM |
lua parser right and wow there is a 250 local var limit on functions |
|
|
| Report Abuse |
|
|
| |
|
|
| 17 Apr 2017 10:45 AM |
| would someone mind helping me with this gibberish of signs and variables |
|
|
| Report Abuse |
|
|
|
| 17 Apr 2017 11:18 AM |
meep
also how do i check if the selected token is inside a string (ignore) |
|
|
| Report Abuse |
|
|
|
| 17 Apr 2017 11:29 AM |
I mean, you could trim the original full string of code of all the content inside each string. You'll have to use weak pattern matches though because long strings could potentially exist. Make sure you account for every long string syntax.
|
|
|
| Report Abuse |
|
|
|
| 17 Apr 2017 11:36 AM |
| idk how to start doing this though, i feel like I shouldnt be matching because it would not account for all the spaces in strings |
|
|
| Report Abuse |
|
|
|
| 17 Apr 2017 12:27 PM |
ok how do i match all characters but whitespace? .-/n* ? |
|
|
| Report Abuse |
|
|
| |
|
|
| 17 Apr 2017 12:33 PM |
[ ^/n ]*
my bad
does - match also accept no matches |
|
|
| Report Abuse |
|
|
|
| 17 Apr 2017 12:34 PM |
Use "%S". The "-" quantifier is for weak matches, so yes, it accepts no matches.
|
|
|
| Report Abuse |
|
|
|
| 17 Apr 2017 12:37 PM |
i cant use %S i need to detect spaces
local s,e = t:find( "%\91%\91.-%\93%\93" ) local s1,e1 = t:find( [[%"[^ %"]-%"]] ) local s2,e2 = t:find( [[%'[^ %']-%']] )
using this for string matching |
|
|
| Report Abuse |
|
|
|
| 17 Apr 2017 12:39 PM |
ew what are you trying to do
|
|
|
| Report Abuse |
|
|
|
| 17 Apr 2017 12:40 PM |
| local function matchString(t) local s,e = t:find( "%\91%\91.-%\93%\93" ) local s1,e1 = t:find( [[%"[^ %"]-%"]] ) local s2,e2 = t:find([[%'[^ %']-%']] ) local len = #t ################# or len,e or len,s1 or len,e1 or len,s2 or len,e2 or len if s < s1 and s < s2 then return t:sub(s,e) elseif s2 < s1 and s2 < s then return t:sub(s2,e2) elseif s1 < s2 and s1 < s then return t:sub(s1,e1) else return nil end end print(matchString("local thing = [[hello 'world']]")) |
|
|
| Report Abuse |
|
|
|
| 17 Apr 2017 12:41 PM |
| local function matchString(t) local s,e = t:find( "%\91%\91.-%\93%\93" ) local s1,e1 = t:find( [[%"[^ %"]-%"]] ) local s2,e2 = t:find([[%'[^ %']-%']] ) local len = #t s, e, ### ### ### ## = s or len, e or len, s1 or len, e1 or len, s2 or len, e2 or len if s < s1 and s < s2 then return t:sub(s,e), s, e elseif s2 < s1 and s2 < s then return t:sub(s2,e2), s2, e2 elseif s1 < s2 and s1 < s then return t:sub(s1,e1), s1, e1 else return end end print(matchString("local thing = [[hello 'world']]")) how to get tokens now? |
|
|
| Report Abuse |
|
|
| |
|
|
| 17 Apr 2017 12:42 PM |
local function matchString(t) local s,e = t:find( "%\91%\91.-%\93%\93" ) local s1,e1 = t:find( [[%"[^ %"]-%"]] ) local s2,e2 = t:find([[%'[^ %']-%']] ) local len = #t --Removed if s < s1 and s < s2 then return t:sub(s,e), s, e elseif s2 < s1 and s2 < s then return t:sub(s2,e2), s2, e2 elseif s1 < s2 and s1 < s then return t:sub(s1,e1), s1, e1 else return end end print(matchString("local thing = [[hello 'world']]"))
how to get tokens now? |
|
|
| Report Abuse |
|
|