nummultiline solves both problems by returning the number of ')' line tokens to jump forward to. NoteV is a special adverb that creates 2 levels of "nesting" with first just a comment, and included in the multiline scan mainly to demonstrate special handling. The subtract lines aren't really necessary, and I'd remove them for something intended to be fast.
NoteV_z_ =: 1 : '(0 (0 :)) label_. 0 (m :)' nummultiline =: 3 NoteV nummultiline returns count of expected terminating parentheses to a line. define, : 0 , ML, ML_z_, Note, NoteV are scanned, but combinations are excluded from double counting: ML : 0, ML define though the combinations are bad form, ML intended to be used only as 0 for n in m : n ) t=. ;: :: 0: y if. t-:0 do. 0 return. end. e =. (;: 'define ML ML_z_') +./@:(=/) t e =. e +. (,each ':0') E. t e =. e - (;:'ML : 0') E. t e =. e - (;:'ML : ML') E. te =. e - (;:'ML define') E. t +/ e + 2 * (< 'NoteV') = t ) nummultiline ' 4 : 0 (2 : ''u@v'') 3 NoteV' 3 nummultiline ' 4 : 0 ' 1 nummultiline 'ML (3 :) 4 : 0 (3 : 0)' 3 nummultiline 'MLsdf ' 0 nummultiline 'ML (3 :) 4 : ML (3 : 0)' 3 tests that could fail instead, (return 3 by mistake) nummultiline ' 4 : 0 (2 : ''u n'') ML : ML ' 2 nummultiline ' 4 : 0 (2 : ''u n'') ML : 0 ' 2 ----- Original Message ----- From: 'Pascal Jasmin' via Programming <[email protected]> To: "[email protected]" <[email protected]> Sent: Wednesday, February 8, 2017 10:04 PM Subject: Re: [Jprogramming] in script file, how to tell if line is top level? It would be robust enough. Use magic constant to ensure all utilities work. code that fixes the first problem, while still finding all of the existing simple tests, ML_z_ =: 0 ismultiline_jqtide_ =: 3 : 0 if. 0=#y do. 0 return. end. t=. ;: :: 0: y if. t-:0 do. 0 return. end. if. (<'Note') = {.t do. 1 return. end. if. ('ML'; 'ML_z_') +./@:e. t do. 1 return. end. n=. I. }: t e. Multiline if. 0=#n do. 0 return. end. if. (<'define') e. (n+1){t do. 1 return. end. (,each ':0') e. (n+/1 2){t,<'' ) a =: 3 : ML +: y ) aa =: ML (3 :) -: y ) ----- Original Message ----- From: bill lam <[email protected]> To: Programming forum <[email protected]> Sent: Wednesday, February 8, 2017 7:12 PM Subject: Re: [Jprogramming] in script file, how to tell if line is top level? I didn't notice that. Anyways I think one can always contrive a problem example to defeat any ismultiline. On 9 Feb, 2017 7:59 am, "'Pascal Jasmin' via Programming" < [email protected]> wrote: found the runline code that calls qt.ijs 's ismultiline function, https://github.com/jsoftware/qtide/blob/master/lib/base/run.cpp The easy way to fix for the first "problem example" is to define a magic constant ML_z_ =: Define_z_ =: 0 then include the magic constant in the ismultiline function. It is a reasonably common pattern to have an adverb (sometimes verb) that takes as input either a string, or 0 to initiate multiline. incidentally, I think it was a mistake to define the words 'define verb noun adverb' ... Monad_z_ =: 3 : and then combinining the above, Define Monad NB. instead of monad define ... ) To address the 2nd problem example, if ismultiline returned the count of nested definitions, then probably the same mechanism that skips forward to ')' token would skip the number of times of the ismultiline value. Use of ML constant would be optional but ensure that utilities such as ctrl-r and code parsers would behave. ----- Original Message ----- From: 'Pascal Jasmin' via Programming <[email protected]> To: "[email protected]" <[email protected]> Sent: Wednesday, February 8, 2017 12:18 PM Subject: Re: [Jprogramming] in script file, how to tell if line is top level? I believe this approach is exposed in qt.ijs, as ismultiline function. It doesn't handle all cases, as shown by ctrl-R and ctrl-return for example, V =: (3 :) 0 V +: y ) F =: 0 : 0 , 0 : 0 asdf ) zxcv ) ----- Original Message ----- From: bill lam <[email protected]> To: 'Pascal Jasmin' via Programming <[email protected]> Sent: Wednesday, February 8, 2017 1:20 AM Subject: Re: [Jprogramming] in script file, how to tell if line is top level? For syntax coloring, it scans from the beginning and search matching 3 : 0 (or other equivalents) and a line without only the token ) . Ср, 08 фев 2017, jprogramming написал(а): > in 4 line script, > > 2+2 > a =: 3 : 0 > nested definition line > > ) > > the first 2 lines are "top level", but the last 2 are nested. > > is there any undocumented foreign that will return this status? How does the console know that it is in " : 0 " mode? > ---------------------------------------------------------------------- > For information about J forums see http://www.jsoftware.com/forums.htm -- regards, ==================================================== GPG key 1024D/4434BAB3 2008-08-24 gpg --keyserver subkeys.pgp.net --recv-keys 4434BAB3 gpg --keyserver subkeys.pgp.net --armor --export 4434BAB3 ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm
