Overview
The RoseP21Lex class is an internal utility class used for scanning tokens in STEP ISO 10303-21 (Part 21) formatted files. It is not created or used directly.
See STEP Part 21 Exchange Files for more information on writing and customizing STEP files.
comment_fn
typedef void (* RoseP21CommentFn) ( RoseP21Lex * ); static RoseP21CommentFn comment_fn;
The comment_fn static class variable can specify a hook function that will be used to process comments found in the a Part 21 file.
By default, this variable is null and the function rose_p21_read_and_discard_comment() is used to read and ignore comments. The rose_p21_read_and_preserve_comment() function can also be used to capture comments and make them available through the RoseObject::entity_comment() function.
/* somewhere in your main, before you start reading files */ /* save comments for later use with entity_comment() */ RoseP21Lex::comment_fn = rose_p21_read_and_preserve_comment; /* default behavior, discard comments */ RoseP21Lex::comment_fn = NULL; RoseP21Lex::comment_fn = rose_p21_dflt_read_comment; /* alias */ RoseP21Lex::comment_fn = rose_p21_read_and_discard_comment;
The following sample code scans and discards comments. The
function is called when the Part 21 lexer encounters the beginning of
a comment. The function is responsible for reading through to the
closing */
and incrementing the lexer line count where
appropriate. Characters are provided by the get()/unget()
functions on the stream() object associated with the lexer.
Use this as the starting point for your own function.
/* EXAMPLE */ void process_comment (RoseP21Lex * lex) { register int c; register RoseInputStream * f = lex->stream(); for (c=f->get(); c != EOF; c=f->get()) { if (c == '*') { /* Lookahead to check for the closing slash. */ int c2 = f->get(); if (c2 == EOF) break; if (c2 == '/') return; f->unget (c2); /* pushback and continue */ } else if (c == '\n') { lex-> trace()-> increment_line(); } } rose_io_ec()-> warning (End of file in comment.); }
See Also
Reading and Writing Comments; rose_p21_read_and_discard_comment(); rose_p21_read_and_preserve_comment()