Language plugins : Implementation

find_type_in_string

This function scans an input string and extracts the “type” from it. In some cases the type is explicitly stated and easy to find. In others finding the type can be tricky. In any case, scanning is reset to the beginning after the type is found.

Here is a simple case, where the type is the first word on the line, unless it is a comment which begins with //.

/*--------------------------------------------------------------------------*/
std::string LANG_VERILOG::find_type_in_string(CS& cmd)
{
  unsigned here = cmd.cursor();
  std::string type;
  if ((cmd >> "//")) {
    assert(here == 0);
    type = "dev_comment";
  }else{
    cmd >> type;
  }
  cmd.reset(here);
  return type;
}
/*--------------------------------------------------------------------------*/

This function can be considerably more complex if the type is not first in line. In some cases it is necessary to read to the end then back up.

gnucap/manual/tech/plugins/languages/find_type_in_string.txt · Last modified: 2015/12/11 15:39 (external edit)
 
Recent changes RSS feed Donate Powered by PHP Valid XHTML 1.0 Valid CSS Run by Debian Driven by DokuWiki