1 %top{ 2 /* 3 * Copyright (c) 2002, 2004 Tama Communications Corporation 4 * 5 * This file is part of GNU GLOBAL. 6 * 7 * This program is free software: you can redistribute it and/or modify 8 * it under the terms of the GNU General Public License as published by 9 * the Free Software Foundation, either version 3 of the License, or 10 * (at your option) any later version. 11 * 12 * This program is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * GNU General Public License for more details. 16 * 17 * You should have received a copy of the GNU General Public License 18 * along with this program. If not, see <http://www.gnu.org/licenses/>. 19 */ 20 21 /* 22 * scanner for java source code. 23 */ 24 #ifdef HAVE_CONFIG_H 25 #include <config.h> 26 #endif 27 #include <stdio.h> 28 #ifdef STDC_HEADERS 29 #include <stdlib.h> 30 #endif 31 #include "global.h" 32 #include "anchor.h" 33 #include "common.h" 34 #include "htags.h" 35 #include "../libparser/java_res.h" 36 37 #define lex_symbol_generation_rule(x) java_ ## x 38 #include "lexcommon.h" 39 40 #ifdef ECHO 41 #undef ECHO 42 #endif 43 #define ECHO echos(LEXTEXT) 44 45 #define YY_USER_ACTION DEFAULT_YY_USER_ACTION 46 47 } 48 /* Definitions */ 49 H 0[Xx][0-9A-Fa-f]+ 50 N [0-9]+ 51 L {N}L? 52 D1 {N}\.{N}([Ee][+-]?{N})? 53 D2 \.{N}([Ee][+-]?{N})? 54 NUMBER -?({L}|{D1}|{D2}) 55 ALPHA [a-zA-Z_\x80-\xff] 56 ALPHANUM [a-zA-Z_\x80-\xff0-9] 57 WORD {ALPHA}{ALPHANUM}* 58 59 %start JAVA C_COMMENT CPP_COMMENT SHELL_COMMENT STRING LITERAL PREPROCESSOR_LINE 60 %option 8bit noyywrap noyy_top_state stack never-interactive prefix="java_" 61 %% 62 /* Comment */ 63 <JAVA>"/*" { echos(comment_begin); ECHO; yy_push_state(C_COMMENT); } 64 <C_COMMENT>"*/" { ECHO; echos(comment_end); yy_pop_state(); } 65 <C_COMMENT>. { put_char(LEXTEXT[0]); } 66 <JAVA>"//" { echos(comment_begin); ECHO; yy_push_state(CPP_COMMENT); } 67 68 /* String */ 69 <JAVA>\" { ECHO; yy_push_state(STRING); } 70 <STRING>\" { ECHO; yy_pop_state(); } 71 <STRING>\\. { put_char(LEXTEXT[0]); put_char(LEXTEXT[1]); } 72 73 /* Literal */ 74 <JAVA>\' { ECHO; yy_push_state(LITERAL); } 75 <LITERAL>\' { ECHO; yy_pop_state(); } 76 <LITERAL>\\. { put_char(LEXTEXT[0]); put_char(LEXTEXT[1]); } 77 78 <JAVA>^import/[ \t] { 79 int c = 0; 80 81 put_reserved_word(LEXTEXT); 82 while ((c = input()) && c != EOF && c != '\n' && c != ';') 83 echoc(c); 84 if (c == EOF) 85 c = '\n'; 86 if (c == '\n') 87 unput(c); 88 else if (c) 89 echoc(c); 90 } 91 92 <JAVA>{NUMBER} ECHO; 93 <JAVA>{WORD} { 94 if (java_reserved_word(LEXTEXT, LEXLENG)) 95 put_reserved_word(LEXTEXT); 96 else { 97 struct anchor *a = anchor_get(LEXTEXT, LEXLENG, 0, LINENO); 98 if (a) { 99 put_anchor(gettag(a), a->type, LINENO); 100 a->done = 1; 101 } else if (grtags_is_empty) { 102 put_anchor_force(LEXTEXT, LEXLENG, LINENO); 103 } else { 104 ECHO; 105 } 106 } 107 } 108 <JAVA>[{}] { put_brace(LEXTEXT); } 109 /* New line */ 110 \n DEFAULT_END_OF_LINE_ACTION 111 . { put_char(LEXTEXT[0]); } 112 113 %% 114 void 115 java_parser_init(FILE *ip) 116 { 117 DEFAULT_BEGIN_OF_FILE_ACTION 118 BEGIN JAVA; 119 } 120