Strip block comments: Difference between revisions

Strip block comments en FreeBASIC
(Updated to work with Nim 1.4: added missing parameter type. Minor formatting. Changed "output" to "{{out}}".)
(Strip block comments en FreeBASIC)
Line 1,136:
 
F90 allows the syntax END SUBROUTINE UNBLOCK (and insists on it within a MODULE) but F77 does not, otherwise the statement could have been <code>CALL UNBLOCK("SUBROUTINE","END SUBROUTINE")</code> which would be rather more structured.
 
 
=={{header|FreeBASIC}}==
{{trans|Liberty BASIC}}
<lang freebasic>Const CRLF = Chr(13) + Chr(10)
 
Function stripBlocks(text As String, first As String, last As String) As String
Dim As String temp = ""
For i As Integer = 1 To Len(text) - Len(first)
If Mid(text, i, Len(first)) = first Then
i += Len(first)
Do
If Mid(text, i, 2) = CRLF Then temp &= CRLF
i += 1
Loop Until (Mid(text, i, Len(last)) = last) Or (i = Len(text) - Len(last))
i += Len(last) -1
Else
temp &= Mid(text, i, 1)
End If
Next i
Return temp
End Function
 
Dim As String source
source = " /**" + CRLF + _
" * Some comments" + CRLF + _
" * longer comments here that we can parse." + CRLF + _
" *" + CRLF + _
" * Rahoo " + CRLF + _
" */" + CRLF + _
" function subroutine() {" + CRLF + _
" a = /* inline comment */ b + c ;" + CRLF + _
" }" + CRLF + _
" /*/ <-- tricky comments */" + CRLF + _
"" + CRLF + _
" /**" + CRLF + _
" * Another comment." + CRLF + _
" */" + CRLF + _
" function something() {" + CRLF + _
" }" + CRLF
 
Print stripBlocks(source, "/*", "*/")
Sleep</lang>
{{out}}
<pre>
Igual que la entrada de Liberty BASIC.
</pre>
 
=={{header|Go}}==
2,169

edits