Home News DOC Class DL Others Cooker
Documents  >  Tutorial  >  Named comment
Named comment

Named comment is comment that have a special format for programmatically referencing its content.


目次:


Format and usage

Start line

Content line

End line

Command

How to reference

Format and usage

The format of the named comment is shown below.


/**Identifier**...

Any string...

*/


From the top, they are the start line, content line, and end line. Each should be on a separate line.

Let's see the following comment.


/**Sample**/


It looks like a single-line named comment or a multi-line comment, but it's a named comment. The reason will be described later. And the start and end lines are not independent.

An exception occurs because this comment is the named comment but does not meet the format.


Let's modify this comment to the correct named comment.


/**Sample**

*/


We have now defined a comment named "Sample". Let's refer to this programmatically.

1:

/**Sample**

2:

*/

3:

4:

rice rr;

5:

string namedComment = rr.Sample;

We can now refer the "Sample". Since "Sample" has no content line, an empty string is assigned to the namedComment.

Start line

If the beginning of a multi-line comment matches the rules below, it is a named comment.


/**Identifier**


The identifier is sandwiched between /** and **. The identifier follows the rules for identifiers in the Rice language.


The start line specifies the name and command. If you specify a command, it will look like this:


/**Identifier**Command


Specifying the command is optional. The command will be described later.


The second term which splitted the entire start line by "**" is used as the name.

If there are three or more split results, the third term is the command. When specifying the command, specify "concat" or "trimcat". If any other command is specified, it will be ignored.

If the fourth and subsequent terms are present, those terms are ignored. You can use this to add comments to named comments.


/**Sample**concat**Comment for named comment.

*/


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

Content line

The content line is content what is referenced as a named comment. It is optional and there is no limit to the number of lines.

There are no restrictions on the content of the content line. You can also use characters that cannot be used in regular string literals. In particular, you can use double quotes as is.

If there are content lines, they are concatenated in the order of appearance to form a single character string. This concatenated string is the reference result.

You can control the concatenation method with the command on the start line.

End line

The end line is the line that contains the end symbol for multi-line comments.

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

Command

You can control how content lines are concatenated with the command. There are three modes for concatenating. They are "No control", "concat", "trimcat".

Specifying the command is optional. When specifying the command, specify "concat" or "trimcat". If any other command is specified, it will be ignored.

For example:


/**Sample**Comment for named comment.

*/


There is a "Comment for named comment." at the position of the command. In such a case, the command specification is ignored and the mode is "No control".

No command

It inserts a newline character at the end of each line when concatenating content lines.

For example:


/**Sample**

function samplefunc() {

alert("Hello world!");

}

*/


The result of the reference is:


function samplefunc() {⏎

alert("Hello world!");⏎

}⏎

concat

It does not insert a newline character when concatenating content lines.

For example:


/**Sample**concat

function samplefunc() {

alert("Hello world!");

}

*/


The result of the reference is:


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

trimcat

When concatenating content lines, it removes the whitespace before and after each line and does not insert a newline character.

For example:


/**Sample**trimcat

function samplefunc() {

alert("Hello world!");

}

*/


The result of the reference is:


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

If you want a reference result without newline caracters like a string literal, specify a command. "No control" mode is added a newline character at the end even if the reference result is a single line.

How to reference

References to named comments are made via variables in the rice class.

1:

/**Sample**

2:

*/

3:

4:

rice rr;

5:

string namedComment = rr.Sample;

6:

namedComment = rr.GetComment("Sample");

See the manual for more information on the rice class.

Next
Previous
Copyright © Rice All rights reserved.