This is a read-only archive of the old Scratch 1.x Forums.
Try searching the current Scratch discussion forums.

#1 2012-05-28 15:07:15

roijac
Scratcher
Registered: 2010-01-19
Posts: 1000+

regex help

so, i (almost) finished the core of the M30W parser, and i'll upload it as soon as i fix my firewall  hmm

but i'm stuck with in-line comments
i can't get a regex pattern to distinguish between

Code:

a block #a comment
say 'a # sign' for 5 seconds
'a string #' #lalala

anybody?

Last edited by roijac (2012-05-28 15:21:52)

Offline

 

#2 2012-05-28 15:13:11

scimonster
Community Moderator
Registered: 2010-06-13
Posts: 1000+

Re: regex help

Check for a quote before and after?

Offline

 

#3 2012-05-28 15:14:41

roijac
Scratcher
Registered: 2010-01-19
Posts: 1000+

Re: regex help

scimonster wrote:

Check for a quote before and after?

and how do you do that? and check that it's closed?

Offline

 

#4 2012-05-28 16:26:47

blob8108
Scratcher
Registered: 2007-06-25
Posts: 1000+

Re: regex help

What are you using to parse quotes in the first place?  smile

I'm not sure regex are quite the right thing for writing a parser like this...  hmm  It gets kinda messy. Then again, my attempts to write a scratchblocks parser using Construct didn't work out too well — so I probably can't claim much authority on the subject.

I believe the "correct" way of doing this is to define a grammar, rather formally, and use a proper parser to actually parse the code. It's all very computer sciency.  ._.


Things I've made: kurt | scratchblocks2 | this cake

Offline

 

#5 2012-05-28 17:14:34

ManaUser
Scratcher
Registered: 2009-03-11
Posts: 100+

Re: regex help

Not extensively tested, but

Code:

^[^'#]*('[^']*'[^'#]*)*(#(.*)$)?

might do the trick. The comment, if any, should be $3, i.e. the (.*) bit near the end.

Last edited by ManaUser (2012-05-28 17:27:29)


http://i.imgur.com/SPYSM.gif http://i.imgur.com/t9k1Z.gif http://i.imgur.com/OwYVa.gif http://i.imgur.com/0qlZq.gif

Offline

 

Board footer