1 ///////////////////////////////////////////////////////////////////////////////
3 // This is the implementation of the Prop lexical scanner.
5 ///////////////////////////////////////////////////////////////////////////////
12 #include <AD/strings/quark.h>
14 #include "keywords.ph"
19 // int PropParser::get_token()
20 // { int c = get_token2();
22 // { if (c < 256) cerr << "[" << (char)c << "]";
23 // else cerr << "[" << (PropToken)c << c << "]";
28 ///////////////////////////////////////////////////////////////////////////////
30 // The definition of the lexical scanner.
32 ///////////////////////////////////////////////////////////////////////////////
33 int PropParser::get_token()
37 matchscan[LexicalContext] while (lexbuf)
38 { <<C,PROP>> lexeme class MainKeywords:
39 { if (lexbuf.context() == C) start_sc(PROP);
42 | <<C>> /\(/: { start_quote('(',')'); emit(); }
43 | <<C>> /\[/: { start_quote('[',']'); emit(); }
44 | <<C>> /\{/: { start_quote('{','}'); emit(); }
45 | <<C>> /\(\|/: { start_quote('(',')'); start_sc(PROP); return ."(|"; }
46 | <<C>> /\[\|/: { start_quote('[',']'); start_sc(PROP); return ."[|"; }
47 | <<C>> /\{\|/: { start_quote('{','}'); start_sc(PROP); return ."{|"; }
48 | <<C>> /\.\(/: { start_quote('(',')'); start_sc(PROP); return .".("; }
49 | <<C>> /\.\[/: { start_quote('[',']'); start_sc(PROP); return .".["; }
50 | <<C>> /\.#{integer}/: { emit("._"); emit(lexbuf.text()+2); }
51 | <<C>> /\-\>#{integer}/: { emit("->_"); emit(lexbuf.text()+3); }
53 { lexbuf.push_back(1); start_sc(PROP); return '#'; }
55 { char c = end_quote(lexbuf[0]);
56 if (levels[levels_top-1] > quote_top)
57 { end_sc(); return c; }
61 | <<C>> lexeme class SepKeywords:
62 { if (levels[levels_top-1] >= quote_top)
63 { end_sc(); return ?lexeme; }
67 | <<C>> /\.{string}/: { emit_cons(lexbuf.text()+1); }
68 | <<C>> QUARK_TOK: { start_sc(PROP); return QUARK_TOK; }
69 | <<C>> BIGINT_TOK: { start_sc(PROP); return BIGINT_TOK; }
70 | <<C,PROP>> lexeme class Symbols:
71 { if (lexbuf.context() == C) emit(); else return ?lexeme; }
72 | <<C,PROP>> lexeme class Literals:
73 { if (lexbuf.context() == C) emit(); else return ?lexeme; }
75 { Quark id(lexbuf.text());
76 Bool is_from_current_scope;
77 my_exp = pv_env.lookup(id,&is_from_current_scope);
81 { if (lexbuf.lookahead() == '<' &&
82 is_poly_datatype(lookup_ty(id)))
83 { start_sc(PROP); return POLY_DATATYPE; }
85 { if (lexbuf[lexbuf.length()-1] == '\'')
87 for (i = lexbuf.length()-1; i >= 0; i--)
88 if (lexbuf[i] != '\'') break;
90 if (my_cons = find_cons(lexbuf.text()))
91 { start_sc(PROP); return CONS_EXP; }
94 if (lexbuf[0] == '?' || lexbuf[0] == '$' ||
95 lexbuf[0] == '#' && in_rewrite ||
96 lexbuf[lexbuf.length()-1] == '\'')
97 error("%Lpattern variable '%s' has no binding at this point\n",
103 | <<C>> PUNCTUATIONS: { emit(); }
104 | <<C>> /^#[ \t]*include[ \t]*(\"|\<)[^\"\>\n]*\.[pP][^\\\/\n]*(\"|\>).*/:
105 { char name_buffer[256], * q;
108 for (p = lexbuf.text(); *p != '<' && *p != '"'; p++);
109 // copy the filename to the buffer
110 for (p++, q = name_buffer; *p != '"' && *p != '>'; p++, q++) *q = *p;
112 Quark file_name(name_buffer);
113 // emit the filename sans [pP]
114 for ( ;*p != '.'; p--);
115 emit (lexbuf.text(), p - lexbuf.text() + 1);
117 open_include_file(file_name);
119 | <<C>> /[ \t\\\014]/: { emit(); }
120 | <<C>> /(\/\/.*)?\n/: { emit(); line++; }
121 | <<C,PROP>> /^##.*\n/:{ emit_header(); line++; }
122 | <<C>> /^#.*/: { emit(); }
123 | <<C,PROP>> /`/: { start_quote('`','`'); start_sc(QUOTE); }
124 | <<PROP>> /[#_]/: { return lexbuf[0]; }
125 | <<PROP>> /\(/: { start_quote('(',')'); return '('; }
126 | <<PROP>> /\{/: { start_quote('{','}'); return '{'; }
127 | <<PROP>> /\[/: { start_quote('[',']'); return '['; }
128 | <<PROP>> /\(\|/: { start_quote('(',')'); return ."(|"; }
129 | <<PROP>> /\{\|/: { start_quote('{','}'); return ."{|"; }
130 | <<PROP>> /\[\|/: { start_quote('[',']'); return ."[|"; }
131 | <<PROP>> /\.\(/: { start_quote('(',')'); return .".("; }
132 | <<PROP>> /\.\[/: { start_quote('[',']'); return .".["; }
133 | <<PROP>> /[\)\}\]]/: { return end_quote(lexbuf[0]); }
134 | <<PROP>> /\|\)/: { end_quote(')'); return ."|)"; }
135 | <<PROP>> /\|\}/: { end_quote('}'); return ."|}"; }
136 | <<PROP>> /\|\]/: { end_quote(']'); return ."|]"; }
137 | <<PROP>> lexeme class Keywords: { return ?lexeme; }
138 | <<PROP>> lexeme class SepKeywords: { return ?lexeme; }
139 | <<PROP>> /\.{string}/:
140 { my_cons = lookup_cons(lexbuf.text()+1);
144 { if ((my_cons = find_cons(lexbuf.text())) != NOcons)
146 if (lexbuf[lexbuf.length()-1] == '\'')
148 for (i = lexbuf.length()-1; i >= 0; i--)
149 if (lexbuf[i] != '\'') break;
151 if (my_cons = find_cons(lexbuf.text()))
157 | <<PROP>> QUARK_TOK: { return QUARK_TOK; }
158 | <<PROP>> BIGINT_TOK: { return BIGINT_TOK; }
159 | <<PROP>> REGEXP_TOK: { return REGEXP_TOK; }
160 | <<PROP>> PUNCTUATIONS: { return lexbuf[0]; }
161 | <<PROP>> /[ \t\014]/: { /* skip */ }
162 | <<PROP>> /(\/\/.*)?\n/: { line++; }
163 | /\/\*/: { emit(); start_sc(COMMENT); }
164 | <<COMMENT>> /\*\//: { emit(); end_sc(); }
165 | <<COMMENT>> /\n/: { emit(); line++; }
166 | <<COMMENT>> /./: { emit(); }
167 | /^#[ \t]*(line[ \t]+)?{digits}[ \t]*{string}\n/:
171 for (p = lexbuf.text(); ! isdigit(*p); p++);
173 for ( ; *p != '"'; p++);
174 for (p++, q = buffer; (*q = *p) != '"'; p++, q++);
176 file = Quark(buffer);
177 debug_msg("[%s, %i]", file, line);
180 | <<QUOTE>>/`/: { meta.emit('\0'); end_quote('`'); end_sc();
183 | <<QUOTE>>/./: { meta.emit(lexbuf[0]); }
184 | <<QUOTE>>/\n/: { line++; meta.emit(lexbuf[0]); }
185 | /^%%.*\n/: { line++; emit_doc(); }
186 | /./: { error("%Lillegal character %c\n", lexbuf[0]); }
188 if (includes_top != 0) close_include_file();