rlscan.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. /*
  2. * Copyright 2007 Adrian Thurston <thurston@complang.org>
  3. */
  4. /* This file is part of Ragel.
  5. *
  6. * Ragel is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * Ragel is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with Ragel; if not, write to the Free Software
  18. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  19. */
  20. #ifndef _RLSCAN_H
  21. #define _RLSCAN_H
  22. #include <iostream>
  23. #include "rlscan.h"
  24. #include "vector.h"
  25. #include "rlparse.h"
  26. #include "parsedata.h"
  27. #include "avltree.h"
  28. #include "vector.h"
  29. using std::istream;
  30. using std::ostream;
  31. extern const char *Parser_lelNames[];
  32. struct Scanner
  33. {
  34. Scanner( InputData &id, const char *fileName, istream &input,
  35. Parser *inclToParser, char *inclSectionTarg,
  36. int includeDepth, bool importMachines )
  37. :
  38. id(id), fileName(fileName),
  39. input(input),
  40. inclToParser(inclToParser),
  41. inclSectionTarg(inclSectionTarg),
  42. includeDepth(includeDepth),
  43. importMachines(importMachines),
  44. cur_token(0),
  45. line(1), column(1), lastnl(0),
  46. parser(0), ignoreSection(false),
  47. parserExistsError(false),
  48. whitespaceOn(true),
  49. lastToken(0)
  50. {}
  51. bool duplicateInclude( char *inclFileName, char *inclSectionName );
  52. /* Make a list of places to look for an included file. */
  53. char **makeIncludePathChecks( const char *curFileName, const char *fileName, int len );
  54. std::ifstream *tryOpenInclude( char **pathChecks, long &found );
  55. void handleMachine();
  56. void handleInclude();
  57. void handleImport();
  58. void init();
  59. void token( int type, char *start, char *end );
  60. void token( int type, char c );
  61. void token( int type );
  62. void processToken( int type, char *tokdata, int toklen );
  63. void directToParser( Parser *toParser, const char *tokFileName, int tokLine,
  64. int tokColumn, int type, char *tokdata, int toklen );
  65. void flushImport( );
  66. void importToken( int type, char *start, char *end );
  67. void pass( int token, char *start, char *end );
  68. void pass();
  69. void updateCol();
  70. void startSection();
  71. void endSection();
  72. void do_scan();
  73. bool active();
  74. ostream &scan_error();
  75. InputData &id;
  76. const char *fileName;
  77. istream &input;
  78. Parser *inclToParser;
  79. char *inclSectionTarg;
  80. int includeDepth;
  81. bool importMachines;
  82. /* For import parsing. */
  83. int tok_cs, tok_act;
  84. int *tok_ts, *tok_te;
  85. int cur_token;
  86. static const int max_tokens = 32;
  87. int token_data[max_tokens];
  88. char *token_strings[max_tokens];
  89. int token_lens[max_tokens];
  90. /* For section processing. */
  91. int cs;
  92. char *word, *lit;
  93. int word_len, lit_len;
  94. /* For character scanning. */
  95. int line;
  96. InputLoc sectionLoc;
  97. char *ts, *te;
  98. int column;
  99. char *lastnl;
  100. /* Set by machine statements, these persist from section to section
  101. * allowing for unnamed sections. */
  102. Parser *parser;
  103. bool ignoreSection;
  104. /* This is set if ragel has already emitted an error stating that
  105. * no section name has been seen and thus no parser exists. */
  106. bool parserExistsError;
  107. /* This is for inline code. By default it is on. It goes off for
  108. * statements and values in inline blocks which are parsed. */
  109. bool whitespaceOn;
  110. /* Keeps a record of the previous token sent to the section parser. */
  111. int lastToken;
  112. };
  113. #endif