vrml.l
上传用户:seven77cht
上传日期:2007-01-04
资源大小:486k
文件大小:5k
源码类别:

浏览器

开发平台:

Unix_Linux

  1. W               [ trn]
  2. Q               ["']
  3. NQ              [^"']
  4. F               [-a-z0-9$_.!*(),%;/?:@&=+~|]
  5. FA              [-a-z0-9$_.!*()%;/?:@&=+~|]
  6. PA              [[]
  7. PE              []]
  8. NP              [^]]
  9. %x VRML1
  10. %x VRML1NAME VRML1REF
  11. %x VRML2
  12. %x VRML2URL VRML2REF VRML2REFEND
  13. %{
  14. /***************************************
  15.   $Header: /home/amb/wwwoffle/RCS/vrml.l 1.4 1999/07/11 10:16:23 amb Exp $
  16.   WWWOFFLE - World Wide Web Offline Explorer - Version 2.5.
  17.   Parse the VRML and look for the WWWInline, WWWanchor and other things.
  18.   ******************/ /******************
  19.   Written by Walter Pfannenmueller
  20.   This file Copyright 1997,98,99 Andrew M. Bishop
  21.   It may be distributed under the GNU Public License, version 2, or
  22.   any higher version.  See section COPYING of the GNU Public license
  23.   for conditions under which this file may be redistributed.
  24.   ***************************************/
  25. #include "wwwoffle.h"
  26. #include "errors.h"
  27. #include "document.h"
  28. extern int vrml_yylex(void);
  29. #define vrml_yywrap() 1
  30. /*+ The file descriptor that we are reading from. +*/
  31. static int vrml_yyfd=-1;
  32. /*+ A RefType helper variable. +*/
  33. static RefType type;
  34. /*+ A [] indicator. +*/
  35. static int more = 0;
  36. /*++++++++++++++++++++++++++++++++++++++
  37.   Parse the VRML and look for references.
  38.   int fd The file descriptor of the file to parse.
  39.   URL *Url The reference URL to use.
  40.   ++++++++++++++++++++++++++++++++++++++*/
  41. void ParseVRML(int fd,URL *Url)
  42. {
  43.  static int first=1;
  44.  PrintMessage(Debug,"Parsing document using VRML parser.");
  45.  more=0;
  46.  vrml_yyfd=fd;
  47.  if(!first)
  48.    vrml_yyrestart(NULL);
  49.  BEGIN(INITIAL);
  50.  vrml_yylex();
  51.  first=0;
  52. }
  53. /*+ A macro to read data that can be used by the lexer. +*/
  54. #define YY_INPUT(buf,result,max_size) 
  55.         if((result=read_data(vrml_yyfd,buf,max_size))==-1) 
  56.            result=0;
  57. %}
  58. %%
  59.  /* Handle comments and other angle brackets */
  60. "#VRML V1.0"            { BEGIN(VRML1); }
  61.  
  62. "#VRML V2.0"            { BEGIN(VRML2); }
  63. .|r|n                 { }
  64.  /*
  65. VRML V1.0
  66.  */
  67.  /* Comments */
  68. <VRML1>"#".*            { BEGIN(VRML1); }
  69.  /* Strings */
  70. <VRML1>{Q}{NQ}*{Q}      { BEGIN(VRML1); }
  71. <VRML1>"WWWAnchor"      { type = RefLink;
  72.                           BEGIN(VRML1NAME); }
  73. <VRML1>"WWWInline"      { type = RefInlineObject;
  74.                           BEGIN(VRML1NAME); }
  75.  /* Texture2Transform exists as well. */
  76. <VRML1>"Texture2"{W}    { type = RefInlineObject;
  77.                           BEGIN(VRML1NAME); }
  78. <VRML1>.|r|n          { BEGIN(VRML1); }
  79.  /* VRML V1.0 Reference */
  80. <VRML1NAME>"#".*        { BEGIN(VRML1NAME); }
  81. <VRML1NAME>{Q}{NQ}*{Q}  { BEGIN(VRML1NAME); }
  82. <VRML1NAME>"file"*"name"{W}*{Q} { BEGIN(VRML1REF); }
  83. <VRML1NAME>.|r|n      { BEGIN(VRML1NAME); }
  84. <VRML1REF>{F}+          { AddReference(vrml_yytext,type);
  85.                           /* printf("AddReference %s %dn",vrml_yytext,type); */ 
  86.                           BEGIN(VRML1REF); }
  87. <VRML1REF>{Q}           { BEGIN(VRML1); }
  88.  /*
  89. VRML V2.0
  90.  */
  91.  /* Comments */
  92. <VRML2>"#".*            { BEGIN(VRML2); }
  93.  /* Strings */
  94. <VRML2>{Q}{NQ}*{Q}      { BEGIN(VRML2); }
  95. <VRML2>"Anchor"         { type = RefLink;
  96.                           BEGIN(VRML2); }
  97. <VRML2>"AudioClip"|"BackGround"|"ImageTexture"|"Inline"|"MovieTexture"|"Script"                         { type = RefInlineObject;
  98.                           BEGIN(VRML2); }
  99. <VRML2>"url"|"backUrl"|"bottomUrl"|"frontUrl"|"leftUrl"|"rightUrl"|"topUrl"              { BEGIN(VRML2URL); }
  100. <VRML2>"EXTERNPROTO"{NP}*"]" { type = RefInlineObject;
  101.                           BEGIN(VRML2URL); }
  102. <VRML2>.|r|n          { BEGIN(VRML2); }
  103.  /* URLs */
  104. <VRML2URL>{PE}         { more = 0; BEGIN(VRML2); }
  105. <VRML2URL>"#".*        { BEGIN(VRML2URL); }
  106. <VRML2URL>{W}+         { BEGIN(VRML2URL); }
  107. <VRML2URL>{PA}         { more = 1; BEGIN(VRML2URL); }
  108. <VRML2URL>{Q}          { BEGIN(VRML2REF); }
  109. <VRML2URL>","          { BEGIN(VRML2URL); }
  110. <VRML2URL>.            { unput(*vrml_yytext); BEGIN(VRML2); }
  111. <VRML2REF>"javascript:"{F}* { /* not implemented yet */ 
  112.                               /* LoadURL, GrabVrmlFromURL functions
  113.                                  could add URLs 
  114.                                */    
  115.                               BEGIN(VRML2REFEND); }
  116. <VRML2REF>"javabc:"{F}*     { /* not implemented yet */ 
  117.                               /* parsing java bytecode */
  118.                               BEGIN(VRML2REFEND); }
  119. <VRML2REF>{F}+          { AddReference(vrml_yytext,type);
  120.                           /* printf("AddReference %s %dn",vrml_yytext,type); */
  121.                           BEGIN(VRML2REFEND); }
  122. <VRML2REFEND>{NQ}*{Q}   { BEGIN(more ? VRML2URL : VRML2); }
  123. %%