Scripting and event comment parsing

Event comment commands are broken down into two codes

108 - comment begins408 - more comments408 - more comments......Everytime you press enter in the comment editor, the editor creates a 408 command.The easiest way to join the comments is basically what the interpreter does: read a 108, then join all of the following 408's separated by new-line characters.

However, what if you were doing some regex parsing like this

<this is some really long tag name:which happens to continue on the second line>This will be split into two lines rather than a single line, and your regex will need to support multiple lines. Which is not a problem.Lately, I have been writing note-tags of the form

<tag name>option: valueoption: valueoption: value</tag name>And I split on new-lines, since that would be a logical delimiter. However, when I apply this to comments, the problem appears again: if one of your values happens to be really long, it's going to overflow into the next line, and suddenly my parser fails because something like

Code:
<tag name>condition: some really long formula that spans on two linesname: value</tag name>
Will incorrectly parse the condition.What is a good way to parse tags in an event comment?

Or should I use a different delimiter? Maybe semi-colons or something.
what about a certain character on the first line of continued lines, and when you're joining them you can merge anything that has that character with the previous line, before you do your regexp search?


Or yes, a different delimiter, which would require some character to be manually entered on every new line. Then you could merge anything with line breaks, followed by splitting by your chosen delimiter.
i'm not too good with regexp. i mostly trial and error. but in my script...

http://www.rpgmakervxace.net/topic/10545-est-simple-notetags-grabber/

i manage to grab comment event with line break like that.

but my technique is using string[regexp]... and then scan it to store it in an array. so i don't know how to do it with ~= like most people do with regexp.

here's part of the code that make it happen:

   def long_note_args(str)    return NO_NOTETAGS_RETURN if !note[/<#{str}?>(?:[^<]|<[^\/])*<\/#{str}?>/i]    a = note[/<#{str}?>(?:[^<]|<[^\/])*<\/#{str}?>/i].scan(/(?:!<#{str}?>|(.*)\r)/).flatten    a.delete_at(0)    noteargs = b = []    a.each do |mem|    b = mem.scan(/(?.*) (.*):|"(.*?)"| ([-\w.\w]+)|([-\w.\w]+),|,([-\w.\w]+))/).flatten.compact    noteargs.push(    end    return noteargs   endso if i create comment in an event

<com_test>cond: "whatever you want inside will be printed inside all the jibberjabber console window later. hahahaha"cond: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 222133, 999,123213</com_test>then after that comment i add script call

a=$game_map.events[@event_id]puts a.long_note_args("com_test")
it will printed two array with ALL the value separated with space and coma. ("cond" is also added as the first member of array. if you don't want it. we can just .delete(0) it)

but apparently it still have flaw. in my regexp ACTUALY i want it to grab ANYTHING that inside "" and [] and {} as it is...

but when the line break to new line it broken down. and grab it using another regexp option (coma and spaces). maybe will experiment later how to prevent that.

maybe you can study those regexp and see how to improve it and using it inside ~= method. 😀 . since that regexp above is by combining several person regexp and then testing it out. so i have no REAL depth knowledge about regexp. (only what written on REGEXP class documentation)

Original thread: https://forums.rpgmakerweb.com/threads/scripting-and-event-comment-parsing.16909/