logo

live-bootstrap

Mirror of <https://github.com/fosslinux/live-bootstrap>

scan.lex.l (18887B)


  1. /* SPDX-FileCopyrightText: 2021 Andrius Štikonas <andrius@stikonas.eu> */
  2. /* SPDX-FileCopyrightText: 2019-2020 Giovanni Mascellani <gio@debian.org> */
  3. /* SPDX-License-Identifier: BSD-2-Clause */
  4. /* scan.l - scanner for flex input -*-C-*- */
  5. %{
  6. /* Copyright (c) 1990 The Regents of the University of California. */
  7. /* All rights reserved. */
  8. /* This code is derived from software contributed to Berkeley by */
  9. /* Vern Paxson. */
  10. /* The United States Government has rights in this work pursuant */
  11. /* to contract no. DE-AC03-76SF00098 between the United States */
  12. /* Department of Energy and the University of California. */
  13. /* This file is part of flex. */
  14. /* Redistribution and use in source and binary forms, with or without */
  15. /* modification, are permitted provided that the following conditions */
  16. /* are met: */
  17. /* 1. Redistributions of source code must retain the above copyright */
  18. /* notice, this list of conditions and the following disclaimer. */
  19. /* 2. Redistributions in binary form must reproduce the above copyright */
  20. /* notice, this list of conditions and the following disclaimer in the */
  21. /* documentation and/or other materials provided with the distribution. */
  22. /* Neither the name of the University nor the names of its contributors */
  23. /* may be used to endorse or promote products derived from this software */
  24. /* without specific prior written permission. */
  25. /* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR */
  26. /* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED */
  27. /* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR */
  28. /* PURPOSE. */
  29. #define yyin_defined
  30. #include "flexdef.h"
  31. #include "parse.h"
  32. #define ACTION_ECHO add_action( yytext )
  33. #define ACTION_IFDEF(def, should_define) \
  34. { \
  35. if ( should_define ) \
  36. action_define( def, 1 ); \
  37. }
  38. #define MARK_END_OF_PROLOG mark_prolog();
  39. #define YY_DECL \
  40. int flexscan()
  41. #define RETURNCHAR \
  42. yylval = (unsigned char) yytext[0]; \
  43. return CHAR;
  44. #define RETURNNAME \
  45. strcpy( nmstr, yytext ); \
  46. return NAME;
  47. #define PUT_BACK_STRING(str, start) \
  48. for ( i = strlen( str ) - 1; i >= start; --i ) \
  49. unput((str)[i])
  50. #define CHECK_REJECT(str) \
  51. if ( all_upper( str ) ) \
  52. reject = true;
  53. #define CHECK_YYMORE(str) \
  54. if ( all_lower( str ) ) \
  55. yymore_used = true;
  56. #define YY_USER_INIT \
  57. if ( getenv("POSIXLY_CORRECT") ) \
  58. posix_compat = true;
  59. #ifndef yy_set_bol
  60. #define yy_set_bol(x) (x ? NLSTATE : 0)
  61. #endif
  62. #define YY_NULL 0
  63. #define yyterminate() return YY_NULL
  64. %}
  65. %e 5000
  66. %p 10000
  67. %a 100000
  68. %n 5000
  69. %x SECT2 SECT2PROLOG SECT3 CODEBLOCK PICKUPDEF SC CARETISBOL NUM QUOTE
  70. %x FIRSTCCL CCL ACTION RECOVER COMMENT ACTION_STRING
  71. %x OPTION LINEDIR
  72. WS [ \t]+
  73. OPTWS [ \t]*
  74. NOT_WS [^ \t\r\n]
  75. NL \r?\n
  76. NAME ([a-zA-Z_][a-zA-Z0-9_-]*)
  77. NOT_NAME [^a-zA-Z_*\n]+
  78. SCNAME {NAME}
  79. ESCSEQ (\\([^\n]|[0-7]{1,3}|x[0-9a-fA-F]{1,2}))
  80. FIRST_CCL_CHAR ([^\\\n]|{ESCSEQ})
  81. CCL_CHAR ([^\\\n\]]|{ESCSEQ})
  82. CCL_EXPR ("[:"[a-zA-Z]+":]")
  83. LEXOPT [aceknopr]
  84. %%
  85. static int bracelevel, didadef, indented_code;
  86. static int doing_rule_action = false;
  87. static int option_sense;
  88. int doing_codeblock = false;
  89. int i;
  90. Char nmdef[MAXLINE];
  91. <INITIAL>^{WS} { indented_code = true; BEGIN(CODEBLOCK); }
  92. <INITIAL>^"/*" { ACTION_ECHO; BEGIN( COMMENT ); }
  93. <INITIAL>^#{OPTWS}line{WS} { BEGIN( LINEDIR ); }
  94. <INITIAL>^"%s"{NAME}? { return SCDECL; }
  95. <INITIAL>^"%x"{NAME}? { return XSCDECL; }
  96. <INITIAL>^"%{".*{NL} {
  97. ++linenum;
  98. line_directive_out( (FILE *) 0, 1 );
  99. indented_code = false;
  100. BEGIN(CODEBLOCK);
  101. }
  102. <INITIAL>{WS} { /* discard */ }
  103. <INITIAL>^"%%".* {
  104. sectnum = 2;
  105. bracelevel = 0;
  106. mark_defs1();
  107. line_directive_out( (FILE *) 0, 1 );
  108. BEGIN(SECT2PROLOG);
  109. return SECTEND;
  110. }
  111. <INITIAL>^"%pointer".*{NL} { yytext_is_array = false; ++linenum; }
  112. <INITIAL>^"%array".*{NL} { yytext_is_array = true; ++linenum; }
  113. <INITIAL>^"%option" { BEGIN(OPTION); return OPTION_OP; }
  114. <INITIAL>^"%"{LEXOPT}{OPTWS}[0-9]*{OPTWS}{NL} { ++linenum; /* ignore */ }
  115. <INITIAL>^"%"{LEXOPT}{WS}.*{NL} { ++linenum; /* ignore */ }
  116. <INITIAL>^"%"[^sxaceknopr{}].* { synerr( _( "unrecognized '%' directive" ) ); }
  117. <INITIAL>^{NAME} {
  118. strcpy( nmstr, yytext );
  119. didadef = false;
  120. BEGIN(PICKUPDEF);
  121. }
  122. <INITIAL>{SCNAME} { RETURNNAME; }
  123. <INITIAL>^{OPTWS}{NL} { ++linenum; /* allows blank lines in section 1 */ }
  124. <INITIAL>{OPTWS}{NL} { ACTION_ECHO; ++linenum; /* maybe end of comment line */ }
  125. <COMMENT>"*/" { ACTION_ECHO; BEGIN(INITIAL); }
  126. <COMMENT>"*" { ACTION_ECHO; }
  127. <COMMENT>[^*\n]+ { ACTION_ECHO; }
  128. <COMMENT>[^*\n]*{NL} { ++linenum; ACTION_ECHO; }
  129. <LINEDIR>\n { BEGIN(INITIAL); }
  130. <LINEDIR>[0-9]+ { linenum = myctoi( yytext ); }
  131. <LINEDIR>\"[^"\n]*\" {
  132. flex_free( (void *) infilename );
  133. infilename = copy_string( yytext + 1 );
  134. infilename[strlen( infilename ) - 1] = '\0';
  135. }
  136. <CODEBLOCK>^"%}".*{NL} { ++linenum; BEGIN(INITIAL); }
  137. <CODEBLOCK>{NAME}|{NOT_NAME}|. { ACTION_ECHO; }
  138. <CODEBLOCK>{NL} {
  139. ++linenum;
  140. ACTION_ECHO;
  141. if ( indented_code )
  142. BEGIN(INITIAL);
  143. }
  144. <PICKUPDEF>{WS} { /* separates name and definition */ }
  145. <PICKUPDEF>{NOT_WS}[^\r\n]* {
  146. strcpy( (char *) nmdef, yytext );
  147. /* Skip trailing whitespace. */
  148. for ( i = strlen( (char *) nmdef ) - 1;
  149. i >= 0 && (nmdef[i] == ' ' || nmdef[i] == '\t');
  150. --i )
  151. ;
  152. nmdef[i + 1] = '\0';
  153. ndinstal( nmstr, nmdef );
  154. didadef = true;
  155. }
  156. <PICKUPDEF>{NL} {
  157. if ( ! didadef )
  158. synerr( _( "incomplete name definition" ) );
  159. BEGIN(INITIAL);
  160. ++linenum;
  161. }
  162. <OPTION>{NL} { ++linenum; BEGIN(INITIAL); }
  163. <OPTION>{WS} { option_sense = true; }
  164. <OPTION>"=" { return '='; }
  165. <OPTION>no { option_sense = ! option_sense; }
  166. <OPTION>7bit { csize = option_sense ? 128 : 256; }
  167. <OPTION>8bit { csize = option_sense ? 256 : 128; }
  168. <OPTION>align { long_align = option_sense; }
  169. <OPTION>always-interactive {
  170. action_define( "YY_ALWAYS_INTERACTIVE", option_sense );
  171. }
  172. <OPTION>array { yytext_is_array = option_sense; }
  173. <OPTION>backup { backing_up_report = option_sense; }
  174. <OPTION>batch { interactive = ! option_sense; }
  175. <OPTION>"c++" { C_plus_plus = option_sense; }
  176. <OPTION>caseful|case-sensitive { caseins = ! option_sense; }
  177. <OPTION>caseless|case-insensitive { caseins = option_sense; }
  178. <OPTION>debug { ddebug = option_sense; }
  179. <OPTION>default { spprdflt = ! option_sense; }
  180. <OPTION>ecs { useecs = option_sense; }
  181. <OPTION>fast {
  182. useecs = usemecs = false;
  183. use_read = fullspd = true;
  184. }
  185. <OPTION>full {
  186. useecs = usemecs = false;
  187. use_read = fulltbl = true;
  188. }
  189. <OPTION>input { ACTION_IFDEF("YY_NO_INPUT", ! option_sense); }
  190. <OPTION>interactive { interactive = option_sense; }
  191. <OPTION>lex-compat { lex_compat = option_sense; }
  192. <OPTION>posix-compat { posix_compat = option_sense; }
  193. <OPTION>main {
  194. action_define( "YY_MAIN", option_sense );
  195. /* Override yywrap */
  196. if( option_sense == true )
  197. do_yywrap = false;
  198. }
  199. <OPTION>meta-ecs { usemecs = option_sense; }
  200. <OPTION>never-interactive {
  201. action_define( "YY_NEVER_INTERACTIVE", option_sense );
  202. }
  203. <OPTION>perf-report { performance_report += option_sense ? 1 : -1; }
  204. <OPTION>pointer { yytext_is_array = ! option_sense; }
  205. <OPTION>read { use_read = option_sense; }
  206. <OPTION>reentrant { reentrant = option_sense; }
  207. <OPTION>reentrant-bison {
  208. /* reentrant-bison implies reentrant. */
  209. if ((reentrant_bison_pure = option_sense) != 0)
  210. reentrant = 1;
  211. }
  212. <OPTION>reject { reject_really_used = option_sense; }
  213. <OPTION>stack { action_define( "YY_STACK_USED", option_sense ); }
  214. <OPTION>stdinit { do_stdinit = option_sense; }
  215. <OPTION>stdout { use_stdout = option_sense; }
  216. <OPTION>unistd { ACTION_IFDEF("YY_NO_UNISTD_H", ! option_sense); }
  217. <OPTION>unput { ACTION_IFDEF("YY_NO_UNPUT", ! option_sense); }
  218. <OPTION>verbose { printstats = option_sense; }
  219. <OPTION>warn { nowarn = ! option_sense; }
  220. <OPTION>yylineno { do_yylineno = option_sense; ACTION_IFDEF("YY_USE_LINENO", option_sense); }
  221. <OPTION>yymore { yymore_really_used = option_sense; }
  222. <OPTION>yywrap { do_yywrap = option_sense; }
  223. <OPTION>yy_push_state { ACTION_IFDEF("YY_NO_PUSH_STATE", ! option_sense); }
  224. <OPTION>yy_pop_state { ACTION_IFDEF("YY_NO_POP_STATE", ! option_sense); }
  225. <OPTION>yy_top_state { ACTION_IFDEF("YY_NO_TOP_STATE", ! option_sense); }
  226. <OPTION>yy_scan_buffer { ACTION_IFDEF("YY_NO_SCAN_BUFFER", ! option_sense); }
  227. <OPTION>yy_scan_bytes { ACTION_IFDEF("YY_NO_SCAN_BYTES", ! option_sense); }
  228. <OPTION>yy_scan_string { ACTION_IFDEF("YY_NO_SCAN_STRING", ! option_sense); }
  229. <OPTION>yyalloc { ACTION_IFDEF("YY_NO_FLEX_ALLOC", ! option_sense); }
  230. <OPTION>yyrealloc { ACTION_IFDEF("YY_NO_FLEX_REALLOC", ! option_sense); }
  231. <OPTION>yyfree { ACTION_IFDEF("YY_NO_FLEX_FREE", ! option_sense); }
  232. <OPTION>yyget_debug { ACTION_IFDEF("YY_NO_GET_DEBUG", ! option_sense); }
  233. <OPTION>yyset_debug { ACTION_IFDEF("YY_NO_SET_DEBUG", ! option_sense); }
  234. <OPTION>yyget_extra { ACTION_IFDEF("YY_NO_GET_EXTRA", ! option_sense); }
  235. <OPTION>yyset_extra { ACTION_IFDEF("YY_NO_SET_EXTRA", ! option_sense); }
  236. <OPTION>yyget_leng { ACTION_IFDEF("YY_NO_GET_LENG", ! option_sense); }
  237. <OPTION>yyget_text { ACTION_IFDEF("YY_NO_GET_TEXT", ! option_sense); }
  238. <OPTION>yyget_lineno { ACTION_IFDEF("YY_NO_GET_LINENO", ! option_sense); }
  239. <OPTION>yyset_lineno { ACTION_IFDEF("YY_NO_SET_LINENO", ! option_sense); }
  240. <OPTION>yyget_in { ACTION_IFDEF("YY_NO_GET_IN", ! option_sense); }
  241. <OPTION>yyset_in { ACTION_IFDEF("YY_NO_SET_IN", ! option_sense); }
  242. <OPTION>yyget_out { ACTION_IFDEF("YY_NO_GET_OUT", ! option_sense); }
  243. <OPTION>yyset_out { ACTION_IFDEF("YY_NO_SET_OUT", ! option_sense); }
  244. <OPTION>yyget_lval { ACTION_IFDEF("YY_NO_GET_LVAL", ! option_sense); }
  245. <OPTION>yyset_lval { ACTION_IFDEF("YY_NO_SET_LVAL", ! option_sense); }
  246. <OPTION>yyget_lloc { ACTION_IFDEF("YY_NO_GET_LLOC", ! option_sense); }
  247. <OPTION>yyset_lloc { ACTION_IFDEF("YY_NO_SET_LLOC", ! option_sense); }
  248. <OPTION>outfile { return OPT_OUTFILE; }
  249. <OPTION>prefix { return OPT_PREFIX; }
  250. <OPTION>yyclass { return OPT_YYCLASS; }
  251. <OPTION>header { return OPT_HEADER; }
  252. <OPTION>\"[^"\n]*\" {
  253. strcpy( nmstr, yytext + 1 );
  254. nmstr[strlen( nmstr ) - 1] = '\0';
  255. return NAME;
  256. }
  257. <OPTION>(([a-mo-z]|n[a-np-z])[a-zA-Z\-+]*)|. {
  258. format_synerr( _( "unrecognized %%option: %s" ),
  259. yytext );
  260. BEGIN(RECOVER);
  261. }
  262. <RECOVER>.*{NL} { ++linenum; BEGIN(INITIAL); }
  263. <SECT2PROLOG>^"%{".* { ++bracelevel; yyless( 2 ); }
  264. <SECT2PROLOG>^"%}".* { --bracelevel; yyless( 2 ); }
  265. <SECT2PROLOG>^{WS}.* { ACTION_ECHO; /* indented code in prolog */ }
  266. <SECT2PROLOG>^{NOT_WS}.* { /* non-indented code */
  267. if ( bracelevel <= 0 )
  268. { /* not in %{ ... %} */
  269. yyless( 0 ); /* put it all back */
  270. yy_set_bol( 1 );
  271. mark_prolog();
  272. BEGIN(SECT2);
  273. }
  274. else
  275. ACTION_ECHO;
  276. }
  277. <SECT2PROLOG>.* { ACTION_ECHO; }
  278. <SECT2PROLOG>{NL} { ++linenum; ACTION_ECHO; }
  279. <SECT2PROLOG><<EOF>> {
  280. mark_prolog();
  281. sectnum = 0;
  282. yyterminate(); /* to stop the parser */
  283. }
  284. <SECT2>^{OPTWS}{NL} { ++linenum; /* allow blank lines in section 2 */ }
  285. <SECT2>^{OPTWS}"%{" {
  286. indented_code = false;
  287. doing_codeblock = true;
  288. bracelevel = 1;
  289. synerr(_("percent brace action unsupported"));
  290. }
  291. <SECT2>^{OPTWS}"<" { BEGIN(SC); return '<'; }
  292. <SECT2>^{OPTWS}"^" { return '^'; }
  293. <SECT2>\" { BEGIN(QUOTE); return '"'; }
  294. <SECT2>"{"/[0-9] {
  295. BEGIN(NUM);
  296. if ( lex_compat || posix_compat )
  297. return BEGIN_REPEAT_POSIX;
  298. else
  299. return BEGIN_REPEAT_FLEX;
  300. }
  301. <SECT2>"$"/([ \t]|{NL}) { return '$'; }
  302. <SECT2>{WS}"%{" {
  303. bracelevel = 1;
  304. synerr(_("percent brace unsupported"));
  305. if ( in_rule )
  306. {
  307. doing_rule_action = true;
  308. in_rule = false;
  309. return '\n';
  310. }
  311. }
  312. <SECT2>{WS}"|".*{NL} { continued_action = true; ++linenum; return '\n'; }
  313. <SECT2>^{WS}"/*" {
  314. yyless( yyleng - 2 ); /* put back '/', '*' */
  315. bracelevel = 0;
  316. continued_action = false;
  317. BEGIN(ACTION);
  318. }
  319. <SECT2>^{WS} { /* allow indented rules */ }
  320. <SECT2>{WS} {
  321. /* This rule is separate from the one below because
  322. * otherwise we get variable trailing context, so
  323. * we can't build the scanner using -{f,F}.
  324. */
  325. bracelevel = 0;
  326. continued_action = false;
  327. BEGIN(ACTION);
  328. if ( in_rule )
  329. {
  330. doing_rule_action = true;
  331. in_rule = false;
  332. return '\n';
  333. }
  334. }
  335. <SECT2>{OPTWS}{NL} {
  336. bracelevel = 0;
  337. continued_action = false;
  338. BEGIN(ACTION);
  339. unput( '\n' ); /* so <ACTION> sees it */
  340. if ( in_rule )
  341. {
  342. doing_rule_action = true;
  343. in_rule = false;
  344. return '\n';
  345. }
  346. }
  347. <SECT2>^{OPTWS}"<<EOF>>" |
  348. <SECT2>"<<EOF>>" { return EOF_OP; }
  349. <SECT2>^"%%".* {
  350. sectnum = 3;
  351. BEGIN(SECT3);
  352. outn("/* Begin user sect3 */");
  353. yyterminate(); /* to stop the parser */
  354. }
  355. <SECT2>"["({FIRST_CCL_CHAR}|{CCL_EXPR})({CCL_CHAR}|{CCL_EXPR})* {
  356. int cclval;
  357. strcpy( nmstr, yytext );
  358. /* Check to see if we've already encountered this
  359. * ccl.
  360. */
  361. if ( (cclval = ccllookup( (Char *) nmstr )) != 0 )
  362. {
  363. if ( input() != ']' )
  364. synerr( _( "bad character class" ) );
  365. yylval = cclval;
  366. ++cclreuse;
  367. return PREVCCL;
  368. }
  369. else
  370. {
  371. /* We fudge a bit. We know that this ccl will
  372. * soon be numbered as lastccl + 1 by cclinit.
  373. */
  374. cclinstal( (Char *) nmstr, lastccl + 1 );
  375. /* Push back everything but the leading bracket
  376. * so the ccl can be rescanned.
  377. */
  378. yyless( 1 );
  379. BEGIN(FIRSTCCL);
  380. return '[';
  381. }
  382. }
  383. <SECT2>"{"{NAME}"}"[ \t\n\f\r\v]? {
  384. register Char *nmdefptr;
  385. int end_is_ws, end_ch;
  386. end_ch = yytext[yyleng-1];
  387. end_is_ws = end_ch != '}' ? 1 : 0;
  388. strcpy( nmstr, yytext + 1 );
  389. nmstr[yyleng - 2 - end_is_ws] = '\0'; /* chop trailing brace */
  390. if ( (nmdefptr = ndlookup( nmstr )) == 0 )
  391. format_synerr(
  392. _( "undefined definition {%s}" ),
  393. nmstr );
  394. else
  395. { /* push back name surrounded by ()'s */
  396. int len = strlen( (char *) nmdefptr );
  397. if (end_is_ws)
  398. unput(end_ch);
  399. if ( lex_compat || nmdefptr[0] == '^' ||
  400. (len > 0 && nmdefptr[len - 1] == '$')
  401. || end_is_ws)
  402. { /* don't use ()'s after all */
  403. PUT_BACK_STRING((char *) nmdefptr, 0);
  404. if ( nmdefptr[0] == '^' )
  405. BEGIN(CARETISBOL);
  406. }
  407. else
  408. {
  409. unput(')');
  410. PUT_BACK_STRING((char *) nmdefptr, 0);
  411. unput('(');
  412. }
  413. }
  414. }
  415. <SECT2>[/|*+?.(){}] { return (unsigned char) yytext[0]; }
  416. <SECT2>. { RETURNCHAR; }
  417. <SC>{OPTWS}{NL}{OPTWS} { ++linenum; /* Allow blank lines & continuations */ }
  418. <SC>[,*] { return (unsigned char) yytext[0]; }
  419. <SC>">" { BEGIN(SECT2); return '>'; }
  420. <SC>">"/^ { BEGIN(CARETISBOL); return '>'; }
  421. <SC>{SCNAME} { RETURNNAME; }
  422. <SC>. {
  423. format_synerr( _( "bad <start condition>: %s" ),
  424. yytext );
  425. }
  426. <CARETISBOL>"^" { BEGIN(SECT2); return '^'; }
  427. <QUOTE>[^"\n] { RETURNCHAR; }
  428. <QUOTE>\" { BEGIN(SECT2); return '"'; }
  429. <QUOTE>{NL} {
  430. synerr( _( "missing quote" ) );
  431. BEGIN(SECT2);
  432. ++linenum;
  433. return '"';
  434. }
  435. <FIRSTCCL>"^"/[^\]\n-] { BEGIN(CCL); return '^'; }
  436. <FIRSTCCL>"^"/("-"|"]") { return '^'; }
  437. <FIRSTCCL>. { BEGIN(CCL); RETURNCHAR; }
  438. <CCL>-/[^\]\n] { return '-'; }
  439. <CCL>[^\]\n] { RETURNCHAR; }
  440. <CCL>"]" { BEGIN(SECT2); return ']'; }
  441. <CCL>.|{NL} {
  442. synerr( _( "bad character class" ) );
  443. BEGIN(SECT2);
  444. return ']';
  445. }
  446. <FIRSTCCL,CCL>"[:alnum:]" { BEGIN(CCL); return CCE_ALNUM; }
  447. <FIRSTCCL,CCL>"[:alpha:]" { BEGIN(CCL); return CCE_ALPHA; }
  448. <FIRSTCCL,CCL>"[:blank:]" { BEGIN(CCL); return CCE_BLANK; }
  449. <FIRSTCCL,CCL>"[:cntrl:]" { BEGIN(CCL); return CCE_CNTRL; }
  450. <FIRSTCCL,CCL>"[:digit:]" { BEGIN(CCL); return CCE_DIGIT; }
  451. <FIRSTCCL,CCL>"[:graph:]" { BEGIN(CCL); return CCE_GRAPH; }
  452. <FIRSTCCL,CCL>"[:lower:]" { BEGIN(CCL); return CCE_LOWER; }
  453. <FIRSTCCL,CCL>"[:print:]" { BEGIN(CCL); return CCE_PRINT; }
  454. <FIRSTCCL,CCL>"[:punct:]" { BEGIN(CCL); return CCE_PUNCT; }
  455. <FIRSTCCL,CCL>"[:space:]" { BEGIN(CCL); return CCE_SPACE; }
  456. <FIRSTCCL,CCL>"[:upper:]" { BEGIN(CCL); return CCE_UPPER; }
  457. <FIRSTCCL,CCL>"[:xdigit:]" { BEGIN(CCL); return CCE_XDIGIT; }
  458. <FIRSTCCL,CCL>{CCL_EXPR} {
  459. format_synerr(
  460. _( "bad character class expression: %s" ),
  461. yytext );
  462. BEGIN(CCL); return CCE_ALNUM;
  463. }
  464. <NUM>[0-9]+ {
  465. yylval = myctoi( yytext );
  466. return NUMBER;
  467. }
  468. <NUM>"," { return ','; }
  469. <NUM>"}" {
  470. BEGIN(SECT2);
  471. if ( lex_compat || posix_compat )
  472. return END_REPEAT_POSIX;
  473. else
  474. return END_REPEAT_FLEX;
  475. }
  476. <NUM>. {
  477. synerr( _( "bad character inside {}'s" ) );
  478. BEGIN(SECT2);
  479. return '}';
  480. }
  481. <NUM>{NL} {
  482. synerr( _( "missing }" ) );
  483. BEGIN(SECT2);
  484. ++linenum;
  485. return '}';
  486. }
  487. <ACTION>"{" { ACTION_ECHO; ++bracelevel; }
  488. <ACTION>"}" { ACTION_ECHO; --bracelevel; }
  489. <ACTION>[^a-zA-Z_\{\}\"'/\n]+ { ACTION_ECHO; }
  490. <ACTION>{NAME} { ACTION_ECHO; }
  491. <ACTION>"'"([^'\\\n]|\\.)*"'" { ACTION_ECHO; /* character constant */ }
  492. <ACTION>\" { ACTION_ECHO; BEGIN(ACTION_STRING); }
  493. <ACTION>{NL} {
  494. ++linenum;
  495. ACTION_ECHO;
  496. if ( bracelevel == 0 )
  497. {
  498. if ( doing_rule_action )
  499. add_action( "\tYY_BREAK\n" );
  500. doing_rule_action = false;
  501. BEGIN(SECT2);
  502. }
  503. }
  504. <ACTION>. { ACTION_ECHO; }
  505. <ACTION_STRING>[^"\\\n]+ { ACTION_ECHO; }
  506. <ACTION_STRING>\\. { ACTION_ECHO; }
  507. <ACTION_STRING>{NL} { ++linenum; ACTION_ECHO; BEGIN(ACTION); }
  508. <ACTION_STRING>\" { ACTION_ECHO; BEGIN(ACTION); }
  509. <ACTION_STRING>. { ACTION_ECHO; }
  510. <COMMENT,ACTION,ACTION_STRING><<EOF>> {
  511. synerr( _( "EOF encountered inside an action" ) );
  512. yyterminate();
  513. }
  514. <SECT2,QUOTE,FIRSTCCL,CCL>{ESCSEQ} {
  515. yylval = myesc( (Char *) yytext );
  516. if ( YYSTATE == FIRSTCCL )
  517. BEGIN(CCL);
  518. return CHAR;
  519. }
  520. <SECT3>.*(\n?) { ECHO; }
  521. <SECT3><<EOF>> { sectnum = 0; yyterminate(); }
  522. .|\n { format_synerr( _( "bad character: %s" ), yytext ); }
  523. %%
  524. int yywrap()
  525. {
  526. if ( --num_input_files > 0 )
  527. {
  528. set_input_file( *++input_files );
  529. return 0;
  530. }
  531. else
  532. return 1;
  533. }
  534. /* set_input_file - open the given file (if NULL, stdin) for scanning */
  535. void set_input_file( file )
  536. char *file;
  537. {
  538. if ( file && strcmp( file, "-" ) )
  539. {
  540. infilename = copy_string( file );
  541. yyin = fopen( infilename, "r" );
  542. if ( yyin == NULL )
  543. lerrsf( _( "can't open %s" ), file );
  544. }
  545. else
  546. {
  547. yyin = stdin;
  548. infilename = copy_string( "<stdin>" );
  549. }
  550. linenum = 1;
  551. }
  552. /* Wrapper routines for accessing the scanner's malloc routines. */
  553. void *flex_alloc( size )
  554. size_t size;
  555. {
  556. return (void *) malloc( size );
  557. }
  558. void *flex_realloc( ptr, size )
  559. void *ptr;
  560. size_t size;
  561. {
  562. return (void *) realloc( ptr, size );
  563. }
  564. void flex_free( ptr )
  565. void *ptr;
  566. {
  567. if ( ptr )
  568. free( ptr );
  569. }