generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripters
Home Search
 

Re: Parsing lua tokens

Previous Thread :: Next Thread 
Wunder_Wulfe is online. Wunder_Wulfe
Joined: 13 Sep 2016
Total Posts: 8356
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
Wunder_Wulfe is online. Wunder_Wulfe
Joined: 13 Sep 2016
Total Posts: 8356
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
Wunder_Wulfe is online. Wunder_Wulfe
Joined: 13 Sep 2016
Total Posts: 8356
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
Disillusions is not online. Disillusions
Joined: 10 Jul 2011
Total Posts: 6365
17 Apr 2017 10:35 AM
string.find and a list of keywords/symbols that would need a newline


Report Abuse
Unsubtleties is not online. Unsubtleties
Joined: 28 Nov 2016
Total Posts: 9203
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
Disillusions is not online. Disillusions
Joined: 10 Jul 2011
Total Posts: 6365
17 Apr 2017 10:38 AM
@unsub how would you get the positions of each word though?


Report Abuse
Wunder_Wulfe is online. Wunder_Wulfe
Joined: 13 Sep 2016
Total Posts: 8356
17 Apr 2017 10:38 AM
but how do they do it in C to compile lua code for execution?
Report Abuse
Wunder_Wulfe is online. Wunder_Wulfe
Joined: 13 Sep 2016
Total Posts: 8356
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
Unsubtleties is not online. Unsubtleties
Joined: 28 Nov 2016
Total Posts: 9203
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
Wunder_Wulfe is online. Wunder_Wulfe
Joined: 13 Sep 2016
Total Posts: 8356
17 Apr 2017 10:44 AM
lua parser right
and wow there is a 250 local var limit on functions
Report Abuse
Unsubtleties is not online. Unsubtleties
Joined: 28 Nov 2016
Total Posts: 9203
17 Apr 2017 10:44 AM
200*


Report Abuse
Wunder_Wulfe is online. Wunder_Wulfe
Joined: 13 Sep 2016
Total Posts: 8356
17 Apr 2017 10:45 AM
would someone mind helping me with this gibberish of signs and variables
Report Abuse
Wunder_Wulfe is online. Wunder_Wulfe
Joined: 13 Sep 2016
Total Posts: 8356
17 Apr 2017 11:18 AM
meep

also how do i check if the selected token is inside a string (ignore)
Report Abuse
Unsubtleties is not online. Unsubtleties
Joined: 28 Nov 2016
Total Posts: 9203
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
Wunder_Wulfe is online. Wunder_Wulfe
Joined: 13 Sep 2016
Total Posts: 8356
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
Wunder_Wulfe is online. Wunder_Wulfe
Joined: 13 Sep 2016
Total Posts: 8356
17 Apr 2017 12:27 PM
ok how do i match all characters but whitespace?
.-/n* ?
Report Abuse
Unsubtleties is not online. Unsubtleties
Joined: 28 Nov 2016
Total Posts: 9203
17 Apr 2017 12:32 PM
%S


Report Abuse
Wunder_Wulfe is online. Wunder_Wulfe
Joined: 13 Sep 2016
Total Posts: 8356
17 Apr 2017 12:33 PM
[ ^/n ]*

my bad

does - match also accept no matches
Report Abuse
Unsubtleties is not online. Unsubtleties
Joined: 28 Nov 2016
Total Posts: 9203
17 Apr 2017 12:34 PM
Use "%S". The "-" quantifier is for weak matches, so yes, it accepts no matches.


Report Abuse
Wunder_Wulfe is online. Wunder_Wulfe
Joined: 13 Sep 2016
Total Posts: 8356
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
Unsubtleties is not online. Unsubtleties
Joined: 28 Nov 2016
Total Posts: 9203
17 Apr 2017 12:39 PM
ew what are you trying to do


Report Abuse
Wunder_Wulfe is online. Wunder_Wulfe
Joined: 13 Sep 2016
Total Posts: 8356
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
Wunder_Wulfe is online. Wunder_Wulfe
Joined: 13 Sep 2016
Total Posts: 8356
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
TheCaptainTeach is online. TheCaptainTeach
Joined: 11 Jul 2015
Total Posts: 3846
17 Apr 2017 12:42 PM
^
Report Abuse
Wunder_Wulfe is online. Wunder_Wulfe
Joined: 13 Sep 2016
Total Posts: 8356
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
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image