Qbasicnews.com

Full Version: A question about all progging langs
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I was wondering if this was true in all programming languages.

In languages where the code (in particular, the code I would want to highlight) can "start" and "stop" at certain places in the file, for example PHP:

Code:
<?php
// code
?>

<!-- HTML here

<?php
// more php
?>

and in HTML:

Code:
<html highlightthis="yesplease">Don't highlight this</html>

In PHP, multiline comments seem to have top priority. So if you have a <?php or a ?> inside a multiline comment it is ignored, however even in a single line comment if there is a ?> mark then code interpretation stops. And in HTML, < and > marks inside <!-- comments are ignored.

Is this true of any language like this? Do multiline comments seem to have "top priority" in this respect? Does anyone know a language where even single line comments have this ability?
I'm a little rusty on my ASP, but I think that if I wrote something like this:
Code:
<% response.write "hi"
' this doesn't end the block ->  %>
response.write "hello again"
%>
The "%>" sequence in the single-line comment should not end the block -- I think... I'll have to try it at home.
Crap... just what I need, some languages behaving differently Sad. Aah well, I'll just have to code around that... but I still need examples of which languages behave like what. Like for ASP, thanks DrV Smile
Javascript and CSS can be executed from inside comment tags in HTML, for backward compatibility reasons with older browsers. It was done back during the browser wars, but it's still there.

Comments tend to be invincable in other languages, as far as I know. PHP deals with being an integrated scripting language, so the comment-breaking ?>'s are probably deliberate for lazy coders.

The line in perl programs with the location of the perl binary is done with a comment too. Besides that, and QB's "metacode", I don't know of too many functional commenting systems.
I'm not really worried about comment metacommands (I can process them fine, actually), all I'm worried about is if a scripting language will terminate if there is a closing tag in the comment.
I have seen literate programs that have the documentation embedded in the source code, for example C and LaTeX:

Code:
/*
* int \emph{func} (int \emph{x});
*
* This function computes the following formula:
*
* \begin{displaymath}
*   1 + \left(\frac{1}{1-x^{2}} \right) ^3
* \end{displaymath}
*
*/
int func(int x) {
  /* Code */
}

Another example of this is Javadoc. It would be cool if GeSHi could correctly highlight the commented LaTeX.
Yeah, Javadoc is pretty cool. Though, the autodocumentation does sort of impede it's helpfulness.
perldoc is cooler!!!1!1!!!11
Yeah, if you want to make GeSHi really cool, make it parse the LaTeX/javadoc/perldoc and convert it to HTML tags or BBCode or whatever. Smile

Also, the shebang (#!) line in a Perl script is not unique to Perl; that's a general Unix convention also used in shell scripts and elsewhere.

EDIT: Be careful with some langs - sometimes an escape character can be used to extend comments to the next line. For example, in VB:
Code:
Sub xyz()
Dim a, b, c
a = 1
' this is a comment _
b = 2
c = a + b
The "b = 2" line is part of the comment, I think. Also, in NASM:
Code:
mov ax, bx ; comment \
continued
add cx, ax
the "continued" line is part of the comment. This can be really frustrating when using \ and / as "ASCII art" characters to make comments more useful, ie:
Code:
mov ax, bx \
mov bx, cx  \
mov cx, dx   \  This doesn't do much of anything useful.
mov di, dx   /
mov ax, bx  /
mov ax, bx /
The lines "mov bx, cx", "mov cx, dx", and "mov di, dx" don't get assembled because they are in the comment. Sad I did this IRL once... drove me batty for days until I gave up and started over...
^^ Those are the reasons why I didn't make GeSHi a lexical parser Wink

loose: You're saying that in some cases there should be highlighting done inside multiline comments. That's not possible right now with GeSHi, but will be easy with version 1.1.

DrV: You're saying that in some languages an escape character at the last character of a single line comment carries the comment onwards. I'll make this feature for 1.1 also.

BUT: Is anyone aware of a language that can be ended inside a multiline comment? This is *important* - because this is one of the biggest bugs in 1.0.0.