Strip block comments: Difference between revisions

Line 1,818:
 
=={{header|Prolog}}==
 
Prolog enables grammar rules via the DCG that are ideally suited for this task .
 
<lang prolog>
 
:- system:set_prolog_flag(double_quotes,codes) .
 
strip_block_comments(INPUTz)
:-
strip_block_comments(INPUTz,OUTPUTz) ,
system:format("```~n",[OUTPUTz]) ,
system:format("~s~n",[OUTPUTz]) ,
system:format("```~n",[OUTPUTz])
.
 
strip_block_comments(INPUTz,OUTPUTz)
:-
prolog:phrase(block(OUTPUTz),INPUTz)
.
 
block([]) --> \+ [_] , ! .
block([CODE|OUTPUTz]) --> \+ comment , ! , [CODE] , block(OUTPUTz) .
block(OUTPUTz) --> comment , ! , block(OUTPUTz) .
 
comment --> comment_entr , zero_or_more(comment_each) , comment_exit .
comment_entr --> "/*" .
comment_each --> comment , ! .
comment_each --> \+ comment_exit , ! , [_] .
comment_exit --> "*/" .
 
zero_or_more(CALLABLE) --> call(CALLABLE) , ! , zero_or_more(CALLABLE) .
zero_or_more(_) --> ! .
 
</lang>
 
{{out}}
<pre>
/*
?- strip_block_comments(
"
/**
* Some comments
* longer comments here that we can parse.
*
* Rahoo
*/
function subroutine() {
a = /* inline comment */ b + c ;
}
/*/ <-- tricky comments */
 
/**
* Another comment.
*/
function something() {
}
").
```
 
 
function subroutine() {
a = b + c ;
}
 
function something() {
}
 
```
true .
 
?-
*/
 
/*
?- strip_block_comments("abc/*p/*q*/r*/def") .
```
abcdef
```
true .
 
?- strip_block_comments("abcdef") .
```
abcdef
```
true .
 
</pre>
 
=={{header|PureBasic}}==
Solution using regular expressions. A procedure to stripBlocks() procedure is defined that will strip comments between any two delimeters.
Anonymous user