LLOOP Index | GSP Language | GSP Library | Framework Classes | Component Classes

shell_comment.gsp

This is the verbatim text of the file "shell_comment.gsp" part of the LLOOP package. The copyright remains with Michel MEHL. All rights reserved.



/**
 * Pre-processes shell script comments.
 *
 * Strips the input of all shell comments, 
 * i.e. all chars following # till end of line.
 */ 

preprocessor shell_comment 
{{
  static bool bInComment = false;
  static char cPrev = 0;
  static bool bInQuote = false;
  static char cQuoteChar = 0;

  if (bInComment)
    {
      if (c == '\n')
	bInComment = false; // Keep the new lines for the line count
      else
	discard();
    }
  else 
    {
      bool bIsStartingOrEndingQuote = ( ((c == '\'') || (c == '\"')) && ((c == cQuoteChar) || (cQuoteChar == 0)) && (cPrev != '\\') ) ? 1 : 0;
      bInQuote = bInQuote ^ bIsStartingOrEndingQuote ;

      if (bIsStartingOrEndingQuote)
	cQuoteChar = bInQuote ? c : 0;
      else if ((c == '\n') && bInQuote) // A new line ends a quote in any case
	{
	  bInQuote = false;
	  cQuoteChar = 0;
	}	

      if (!bInQuote && (c == '#')) // Comment detected
	{
	  bInComment = true;
	  discard();
	}
    }

  cPrev =  c;
}}

This file is part of the LLOOP Reversible Object-Oriented Parser Generator. Copyright (c) 2005-2006 Michel MEHL, France. All rights reserved. LLOOP is distributed by the company ERSA SaRL.


Copyright (c) 2005-2006 Michel MEHL, Haguenau, France
LLOOP version 1.1