[Gambas-user] Help with RegExp
tobias
tobiasboe1 at ...20...
Sat Sep 24 14:26:24 CEST 2011
On 24.09.2011 01:16, Benoît Minisini wrote:
>> I'm not sure whether you are trying to learn regexp patterns or parse a
>> gambas sourcecode line, but if the second then this is how I do it.
>>
>>
>> ' Gambas module file
>>
>> Public Sub Main()
>> Dim sSourceCode As String ' The original source line
>> Dim sCode As String ' The part of the source line that is code
>> Dim sComment As String ' The part of the source line that is comment
>> Dim aComment As New String[]
>>
>> sSourceCode = " While surname<>\"O'Reilly\" or surname<>\"O'Malley\" Or
>> surname<> \"O'Reilly-O'Malley\" '' Loop around looking for the
>> irishman called \"O'Reilly\", \"O'Malley\" or \"O'Reilly-O'Malley\""
>>
>> Print "Original==========="
>> Print sSourceCode
>>
>> aComment = Split(sSourceCode, "'", "\"", False, True)
>>
>> Print "Parsed==========="
>> Print aComment.Join("\n")
>>
>> sCode = Trim(aComment[0])
>> aComment.Delete(0)
>> sComment = Trim(aComment.Join("'"))
>>
>> Print "Code part==========="
>> Print sCode
>> Print "Comment part==========="
>> Print sComment
>>
>> End
>>
>>
>> regards
>> Bruce
>>
> Otherwise there is a Gambas syntax analyzer in the gb.eval component if you
> need...
>
ok, i think i can do something from that idea..
i'm writing a tool to tidy up source code for someone writing a book
about gambas. the source code examples have to be standardised, sigh...
for the most of the indentation stuff, my regexp knowledge is enough,
but finding the beginning of a comment is too much for me. i'll do it
with string functions.
(comments have to be like that: "[normal
indentation][space]['][space][text]"
thanks,
tobi
More information about the User
mailing list