MarcusFernstrom Posted November 19, 2014 Share Posted November 19, 2014 So I'm trying to make a regex that matches yuidoc. Here's an example: /** * @method myFunction */ function myFunction( param1, param2 ){ var x = arguments.param1; var y = arguments.param2; return x+y; } function secondFunction( param1, param2 ){ var x = arguments.param1; var y = arguments.param2; return x+y; } I'm trying to match any function that is *not* Yuidoc'ed, so basically I'm trying to do a lookbehind, looking for functions that are not preceeded by */ I have a pattern that matches the first example above, but can't figure out how to turn it into a negative lookbehind, so it only matches the second one. /**(?:rn*)*rn*/rn(.*) I've tried (?<!/**(?:rn*)*rn*/)rn(.*) and other variations but no success. Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted November 19, 2014 Moderators Share Posted November 19, 2014 What should your regex return with what the string you have posted? Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
MarcusFernstrom Posted November 19, 2014 Author Share Posted November 19, 2014 I'm relatively used to regex, but not the AutoIt variety, and I've never used negative lookbehind before so that's my main issue. But the idea is to grab the whole function block, do some processing and replace the original block with the processed one. Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted November 19, 2014 Moderators Share Posted November 19, 2014 Your look behind looks right, but to be honest, without seeing the EXACT output you'd expect in each array element, it's hard for me (this late to process). Being javascript, you may need to take into account DotAll, (?s) Personally, I'd do it in parts. The first part being clearing all the yuidoc'ed items, something like: Global $gsz_Str = "javascript string"; some string here ; strip all yuidoc'ed items $gsz_Str = StringRegExpReplace($gsz_Str, _ "(?s)((?:^|\v)\s*/\*\*.+?\*/)", "") The second, would probably make returning your code blocks fairly simple. Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
MarcusFernstrom Posted November 19, 2014 Author Share Posted November 19, 2014 I'm reading a file, and need to replace the non-yuidoc functions with yuidoc ones, then save it out. So my idea of the process is to: Get a list of all the matches Process the list, making the changes Do a replace using the changes and the list of matches If the regex looks ok, I must be missing something else. Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted November 19, 2014 Moderators Share Posted November 19, 2014 Ahh, I think I may get it now, you want to create the yuidoc's for your functions/classes etc like we have for our headers in our include files? Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
MarcusFernstrom Posted November 19, 2014 Author Share Posted November 19, 2014 I didn't know the AutoIt headers use it, but yes, the goal is to automatically yuidoc functions that aren't already. Another way that could work for a beta version is to strip any existing yuidoc (Easy, straight forward match/replace) and then yuidoc everything. Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted November 19, 2014 Moderators Share Posted November 19, 2014 I provided the code for the strip I believe. Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
MarcusFernstrom Posted November 19, 2014 Author Share Posted November 19, 2014 Yeah I took it for a run with just matches, seemed to grab em Link to comment Share on other sites More sharing options...
czardas Posted November 19, 2014 Share Posted November 19, 2014 (edited) Here's an example of using look behind. The regexp looks behind for yuidoc, followed by the pattern we want to match. ; Local $sRegExp = '(?<=(\*/))(\s*pattern)' MsgBox(0, '', StringRegExp(' pattern', $sRegExp)) ; Returns 0 MsgBox(0, '', StringRegExp('*/ pattern', $sRegExp)) ; Returns 1 ; Edit Sorry I missread the first post. I tried the negative look behind, but didn't get it to work in the small amount of time I had available to test it. Edited November 19, 2014 by czardas operator64 ArrayWorkshop Link to comment Share on other sites More sharing options...
jguinch Posted November 19, 2014 Share Posted November 19, 2014 I think you want to have something like this : http://regex101.com/r/qG4pZ6/1 But I don't understand why it doesn't work with AutoIt... Spoiler Network configuration UDF, _DirGetSizeByExtension, _UninstallList Firefox ConfigurationArray multi-dimensions, Printer Management UDF Link to comment Share on other sites More sharing options...
czardas Posted November 19, 2014 Share Posted November 19, 2014 (edited) I think you want to have something like this : http://regex101.com/r/qG4pZ6/1 But I don't understand why it doesn't work with AutoIt... Sometimes it can be hard to tell whether there's a bug in your own code or in the engine. Sometimes it's in both, which makes you feel slightly less stupid knowing it's not only your fault. Edited November 19, 2014 by czardas operator64 ArrayWorkshop Link to comment Share on other sites More sharing options...
mikell Posted November 19, 2014 Share Posted November 19, 2014 Often the easiest way is to get around First blow off the yuidoc'ed part(s) then split what remains #Include <Array.au3> $txt = FileRead("1.txt") $res = StringRegExpReplace($txt, '(?s)(/\*\*.*?function.*?)(?=function)', "") ;Msgbox(0,"", $res) $res = StringRegExp($res, '(?s)(function.*?)\s*(?=function|\z)', 3) _ArrayDisplay($res) ; Msgbox(0,"", $res[0]) This allows conditionals {} inside funcs etc Link to comment Share on other sites More sharing options...
Malkey Posted November 19, 2014 Share Posted November 19, 2014 (edited) This example captures the functions that do not have "*/" and linefeed preceding. Then extracts the function's name and adds a new header to the user function. #include <Array.au3> $txt = FileRead("Test2.txt") $res = """" & StringRegExpReplace($txt, '(?sm)(?<!\*/\v\v)(^function.+?\})', """ & _Yuidoc(""\1"") & """) & """"; ;ConsoleWrite( $res & @LF) ;ConsoleWrite("------------------------------------" & @LF) ConsoleWrite(Execute($res) & @LF) Func _Yuidoc($sFunc) Local $Ret = "/**" & @CRLF Local $sFuncName = "* @method " & StringRegExpReplace($sFunc, "(?s)function\h([^\(]+).+", "\1") & @CRLF Return $Ret & $sFuncName & "*/" & @CRLF & $sFunc EndFunc ;==>_YuidocEdit: RE pattern was '(?sm)(?<!*/v)(^function.+?})'. Changed to '(?sm)(?<!*/vv)(^function.+?})' to allow for @CRLF (2 vertical white spaces @CR and @LF) after "*/". Edited November 19, 2014 by Malkey Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now