Named comment

Named comment

Named comment is multi-line comment that has a special format for referencing its content from the program.

The format is:


/**identifier**command

Arbitrary string...

*/


From the top, they are called the start row, content row, and end row.

Start row

If a multi-line comment matches the regular expression pattern below, it is a named comment.


^/\*\*[_a-zA-Z][_a-zA-Z0-9]*\*\*


If it does not match, it is a multi-line comment.


If the comment is a named comment, the start row specifies a name and command.


The second term of the result of splitting the entire start row with ** is the name. The naming rule is the same as the identifier.

The third term is the command. To specify the command is optional. If specified, specify concat or trimcat. If any other command is specified, it will be ignored.

If the fourth and subsequent terms exist, those terms are ignored.


The start row must be an independent row. The content present on this row is never referenced as a named comment.

Content row

The content row is the content to be referenced. It is optional and there is no limit to the number of rows.

If there are content rows, they are concatenated in the order of appearance to form a single string. The concatenated string becomes the reference result.

The concatenation method depends on the specified command.

End row

The end row is a row that contains the end symbol of a multi-line comment.

The end row must be an independent row. The content present on this row is never referenced as a named comment.

An exception is thrown if the end and start rows are the same row.


/**Sample**/


This is a named comment as it matches the regular expression pattern described above. However, since the start and end rows are not independent, the format of the named comment is not satisfied. Therefore, an exception occurs.

No command

It inserts a newline character at the end of each row when concatenating the content rows. An example is shown below.


/**Sample**

function samplefunc() {

alert("Hello world!");

}

*/


The result of the reference is as follows.


function samplefunc() {⏎

alert("Hello world!");⏎

}⏎

concat

It does not insert a newline character when concatenating content rows. An example is shown below.


/**Sample**concat

function samplefunc() {

alert("Hello world!");

}

*/


The result of the reference is as follows.


function samplefunc() {      alert("Hello world!");    }

trimcat

When concatenating content rows, it removes whitespace characters before and after each row and does not insert a newline character. An example is shown below.


/**Sample**trimcat

function samplefunc() {

alert("Hello world!");

}

*/


The result of the reference is as follows.


function samplefunc() {alert("Hello world!");}

Copyright © Rice All rights reserved.