Index: lex.l =================================================================== RCS file: /cvs/octave/src/lex.l,v retrieving revision 1.236 diff -u -r1.236 lex.l --- lex.l 8 Jun 2006 20:37:29 -0000 1.236 +++ lex.l 12 Jul 2006 06:43:45 -0000 @@ -26,6 +26,8 @@ %s COMMAND_START %s MATRIX_START +%x BLOCK_COMMENT_START + %x NESTED_FUNCTION_END %x NESTED_FUNCTION_BEGIN @@ -234,6 +236,8 @@ static unsigned int Vtoken_count = 0; +static std::string block_comment_text; + // Forward declarations for functions defined at the bottom of this // file. @@ -267,15 +271,15 @@ %} -D [0-9] -S [ \t] +D ([0-9]) +S ([ \t]) NL ((\n)|(\r)|(\r\n)) SNL ({S}|{NL}) EL (\.\.\.) BS (\\) CONT ({EL}|{BS}) -Im [iIjJ] -CCHAR [#%] +Im ([iIjJ]) +CCHAR ([#%]) COMMENT ({CCHAR}.*{NL}) SNLCMT ({SNL}|{COMMENT}) NOT ((\~)|(\!)) @@ -284,6 +288,9 @@ IDENT ([_$a-zA-Z][_$a-zA-Z0-9]*) EXPON ([DdEe][+-]?{D}+) NUMBER (({D}+\.?{D}*{EXPON}?)|(\.{D}+{EXPON}?)|(0[xX][0-9a-fA-F]+)) + +BLOCK_COMMENT_BEGIN ^({S}*\%\{{S}*{NL}) +BLOCK_COMMENT_END ^({S}*\%\}{S}*{NL}) %% . { @@ -617,6 +624,65 @@ } %{ +// Block comments. +%} + +{BLOCK_COMMENT_BEGIN} { + block_comment_text = yytext; + + lexer_flags.block_comment_nesting_level++; + + lexer_flags.saved_start_state = YY_START; + + input_line_number++; + current_input_column = 0; + + BEGIN (BLOCK_COMMENT_START); + } + +{BLOCK_COMMENT_BEGIN} { + block_comment_text += yytext; + + lexer_flags.block_comment_nesting_level++; + } + +{BLOCK_COMMENT_END} { + warning_with_id ("Octave:block-comment", + "end-block-comment outside block comment near line %d", + input_line_number); + + input_line_number++; + } + +{BLOCK_COMMENT_END} { + block_comment_text += yytext; + + input_line_number++; + current_input_column = 0; + + if (--lexer_flags.block_comment_nesting_level == 0) + { + octave_comment_buffer::append (block_comment_text, + octave_comment_elt::block); + + block_comment_text = ""; + + BEGIN (lexer_flags.saved_start_state); + } + } + +. { + block_comment_text += yytext; + } + +{NL} { + block_comment_text += yytext; + + input_line_number++; + current_input_column = 0; + } + +%{ // Gobble comments. If closest nesting is inside parentheses, don't // return a new line. %} @@ -2406,6 +2472,12 @@ // Quote marks strings intially. quote_is_transpose = false; + + // Count of the depth of block comment nesting. + block_comment_nesting_level = 0; + + // Flex start state. + saved_start_state = INITIAL; } bool