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

gspc_args.gsp

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



import quote;
import string;
import quoteorstring;

/* The values of the options are actually stored in member variables
 * of the extended 'OptionsData' class.
 */

symbol Arguments extends class OptionsData()
test
{{
  "valid arguments with invalid directories": fail {--use-old-stream --test-program --author "Bob" --h-dir inc --cpp-dir src  --obj-dir . --project gsp --import-path /tmp/tmp --import-path gsp --ignore-case gsp.gsp}
  "valid arguments": pass {--use-old-stream --test-program --author "Bob" --h-dir include --cpp-dir src --obj-dir . --project gsp --import-path . --ignore-case gsp.gsp}
}};

symbol SImportPathOption include "dir_exists.h";
symbol SHOutputDirOption  include "dir_exists.h";
symbol SCPPOutputDirOption include "dir_exists.h";
symbol SObjOutputDirOption include "dir_exists.h";
symbol STemplateDirOption include "dir_exists.h";

/* The list of options consists of a set of alternative options.
 * The reduction code for each alternative can be omitted if this
 * latter is anyway empty, except for the last alternative for which 
 * the reduction code must always be provided.
 */

Arguments ::= [ SOption [ Arguments ] ]
{{
}}

SOption ::= SAuthorOption 
| SProjectOption 
| SImportPathOption  
| SHOutputDirOption 
| SCPPOutputDirOption 
| SObjOutputDirOption 
| SUseOldStreamOption 
| SGenTestProgOption 
| SIgnoreCaseOption 
| STemplateDirOption
| SLicenseFileOption 
| quote_or_string 
{{
  /* Error management:
   *  If the specified grammar file name starts with "-", 
   *  it is assumed that it is an invalid or mispelled option.
   */

  if ($1.startsWith("-"))
    {
      error(cerr, $1.getStartLineNo(),"'%s' invalid option", (const char*)$1);
    }
  else
    {
#ifdef WIN32
      $1.replace("/","\\", true);
#endif
      $0.root().m_saGspFileNames.push_back($1);
    }
}}

/* Author option.
 * Can't be defined twice.
 */

SAuthorOption ::= SOptPrefix 'author' quote_or_string
{{
  if (!$0.root().m_sAuthor.empty())
    error(cerr,getStartLineNo(),"%s defined twice", #1);
  else
    $0.root().m_sAuthor = $2;
}}

/* Project option.
 * Can't be defined twice.
 */

SProjectOption ::= SOptPrefix 'project' quote_or_string
{{
  if (!$0.root().m_sProject.empty())
    error(cerr, getStartLineNo(), "%s defined twice", #1);
  else
    {
      $0.root().m_sProject = $2; 
      $0.root().m_bExplicitProjectNameGiven = true;
    }
}}

/* Import path option.
 * There can be multiple paths defined where to
 * find imported grammars.
 */

SImportPathOption ::= SOptPrefix 'import-path' quote_or_string
{{
  if (!dir_exists($2))
    error(cerr, getStartLineNo(), "invalid directory %s: %s", (const char*)$2, strerror(errno));
  else
    {
#ifdef WIN32
      $2.replace("/","\\", true);
#endif
      $0.root().m_saImportPaths.push_back($2);
    }
}}

/* Headers output directory option.
 * Can't be defined twice.
 */

SHOutputDirOption ::= SOptPrefix 'h-dir' quote_or_string
{{
  if ($0.root().m_sHOutputDir != ".")
    error(cerr,getStartLineNo(),"%s defined twice", #1);
  else
    if (!dir_exists($2))
      error(cerr, getStartLineNo(), "invalid directory %s: %s", (const char*)$2, strerror(errno));
    else
      {
#ifdef WIN32
	$2.replace("/","\\", true); 
	$2.trimRight('\\');
#else
	$2.trimRight('/');
#endif
	$0.root().m_sHOutputDir = $2;
      }
}}

/* Implementations output directory option.
 * Can't be defined twice.
 */

SCPPOutputDirOption ::= SOptPrefix 'cpp-dir' quote_or_string
{{
  if ($0.root().m_sCPPOutputDir != ".")
    error(cerr,getStartLineNo(),"%s defined twice", #1);
  else
    if (!dir_exists($2))
      error(cerr, getStartLineNo(), "invalid directory %s: %s", (const char*)$2, strerror(errno));
    else
      {
#ifdef WIN32
	$2.replace("/","\\", true); 
	$2.trimRight('\\');
#else
	$2.trimRight('/');
#endif
	$0.root().m_sCPPOutputDir = $2;
      }
}}

/* Object output directory option.
 * Can't be defined twice.
 */

SObjOutputDirOption ::= SOptPrefix 'obj-dir' quote_or_string
{{
  if ($0.root().m_sObjOutputDir != ".")
    error(cerr,getStartLineNo(),"%s defined twice", #1);
  else
    if (!dir_exists($2))
      error(cerr, getStartLineNo(), "invalid directory %s: %s", (const char*)$2, strerror(errno));
    else
      {
#ifdef WIN32	
	$2.replace("/","\\", true); 
	$2.trimRight('\\');
#else
	$2.trimRight('/');
#endif
	$0.root().m_sObjOutputDir = $2;
      }
}}

/* Use old stream option.
 * Just sets a boolean.
 */

SUseOldStreamOption ::= SOptPrefix 'use-old-stream'
{{
  $0.root().m_bUseOldStream = true;
}}

/* Generate a test program and makefile.
 * Just sets a boolean.
 */

SGenTestProgOption ::= SOptPrefix 'test-program'
{{
  $0.root().m_bGenerateTestProg = true;
}}


/* Generate parsers ignoring constants case.
 * Just sets a boolean.
 */

SIgnoreCaseOption ::= SOptPrefix 'ignore-case'
{{
  $0.root().m_bIgnoreCase = true;
}}

/* Template directory options. 
 * Source code templates are normally built-in into the generator,
 * requiring to re-compile the generator whenever any of 
 * the template changes.
 * This options allows to shortcut the generation re-compilation
 * and generate code directly for the template files located under
 * the passed directory.
 * Normally the templates are not provided to the end-users
 * and are only used for internal purposes.
 */

STemplateDirOption ::= SOptPrefix 'template-dir' quote_or_string
{{
  if ($0.root().m_sTemplateDir != ".")
    error(cerr,getStartLineNo(),"%s defined twice", #1);
  else 
    {
      if (!dir_exists($2))
	cerr << "warning: Can't access to template directory '" << $2 << "' (" << strerror(errno) << "). Command ignored." << endl;
      else
	{
#ifdef WIN32
	  $2.replace("/","\\", true);
#endif
	  $0.root().m_sTemplateDir = $2;
	  $0.root().m_bTemplateFromFile = true;
	}
    }
}}


/* Headers output directory option.
 * Can't be defined twice.
 */

SLicenseFileOption ::= SOptPrefix 'license-file' quote_or_string
{{
  if (!$0.root().m_sLicenseFile.empty())
    error(cerr,getStartLineNo(),"%s defined twice", #1);
  else
    {
#ifdef WIN32
      $2.replace("/","\\", true);
#endif
      $0.root().m_sLicenseFile = $2;
    }
}}

SOptPrefix ::= '--'
{{ 
  // Option prefix can't be followed by a white space
  if (isspace($0.stream().peek()))
    reject();
}}
| '/'
{{
  // Option prefix can't be followed by a white space
  if (isspace($0.stream().peek()))
    reject();
}}


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