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

urlfile.gsp

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



/**
 * Reads an URL file, ie. a Universal Resource Locator starting with file://. 
 * Platform-specific paths are accepted following the URL prefix.
 eg:
 file://readme.txt
 file:///home/myaccount/myfile.txt 
 */

import quote;
import file;

symbol URLFileToken
  extends class universal::File()
  include <stdio.h>, 
          <ctype.h>, 
           "universal__File.h"
  alias "urlfile"
  test no-preprocessing
  {{
    "empty name"             : fail {}
    "only one char"          : fail {z}
    "only file:\/\/"         : fail {file://}
    "file:hello"             : fail {file:hello}
    "file:/hello"            : fail {file:/hello}
    "file:\/\/readme.txt"    : pass {file://readme.txt}
    "\"file:\/\/readme.txt\"": pass {"file://readme.txt"}
    "\"file\/\/readme.txt\"" : fail {"file//readme.txt"}
    "valid path unix"        : pass {file:///home/mehl/lloop} 
    "valid path windows"     : pass {file://c:\temp}
    "another path"           : fail {file:// \temp/joe} {file://\temp/joe}
    "path with space"        : fail {file:// /home /joe}
 }} ;

URLFileToken ::= "file:\/\/" file 
{{
  m_fs = $1.fileSystemCategory();
  setName($1.name());
}}
| quote
{{
  universal::String s = $1;
  s.toLowerCase();
  if (!s.startsWith("file:\/\/"))
    {
      reject();
    }
  else
    {
      strstream ss;
      strstream sserr;
      ss << "file:\/\/\"" << $1.substring(7, $1.length()) << "\"" << ends;
      URLFileToken url;
      if (!url.parse(
		     ss, 
		     sserr, 
		     NULL, 
		     false, /* No EOF expected */ 
		     true /* Deactivate any preprocessing */))
	{
	  reject();
	}
      else
	{
	  m_fs = url.FileTokenRef().fileSystemCategory();
	  setName(url.name());
	}  
    }
}}

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