1 /* 2 * CDDL HEADER START 3 * 4 * The contents of this file are subject to the terms of the 5 * Common Development and Distribution License (the "License"). 6 * You may not use this file except in compliance with the License. 7 * 8 * See LICENSE.txt included in this distribution for the specific 9 * language governing permissions and limitations under the License. 10 * 11 * When distributing Covered Code, include this CDDL HEADER in each 12 * file and include the License file at LICENSE.txt. 13 * If applicable, add the following below this CDDL HEADER, with the 14 * fields enclosed by brackets "[]" replaced with your own identifying 15 * information: Portions Copyright [yyyy] [name of copyright owner] 16 * 17 * CDDL HEADER END 18 */ 19 20 /* 21 * Copyright (c) 2008, 2021, Oracle and/or its affiliates. All rights reserved. 22 * Portions Copyright (c) 2017, Chris Fraire <cfraire@me.com>. 23 */ 24 25 /* 26 * Gets Tcl symbols - ignores comments, strings, keywords 27 */ 28 29 package org.opengrok.indexer.analysis.tcl; 30 31 import org.opengrok.indexer.analysis.JFlexSymbolMatcher; 32 %% 33 %public 34 %class TclSymbolTokenizer 35 %extends JFlexSymbolMatcher 36 %unicode 37 %int 38 %include ../CommonLexer.lexh 39 %char 40 %{ 41 private int braceCount; 42 43 @Override reset()44 public void reset() { 45 super.reset(); 46 braceCount = 0; 47 } 48 %} 49 50 %state STRING COMMENT SCOMMENT BRACES VARSUB2 51 52 %include ../Common.lexh 53 %include Tcl.lexh 54 %% 55 56 <YYINITIAL> { 57 58 [\{] { 59 ++braceCount; 60 yypush(BRACES); 61 } 62 } 63 64 <YYINITIAL, BRACES> { 65 {Number} { 66 // noop 67 } 68 \" { yypush(STRING); } 69 "#" { yypush(SCOMMENT); } 70 {WordOperators} { 71 // noop 72 } 73 } 74 75 <YYINITIAL, STRING, BRACES> { 76 {Backslash_sub} { 77 // noop 78 } 79 {Backslash_nl} { 80 // noop 81 } 82 {Varsub1} { 83 String capture = yytext(); 84 String sigil = capture.substring(0, 1); 85 String name = capture.substring(1); 86 if (!Consts.kwd.contains(name)) { 87 onSymbolMatched(name, yychar + 1); 88 return yystate(); 89 } 90 } 91 {Varsub2} { 92 yypush(VARSUB2); 93 String capture = yytext(); 94 int lparen_i = capture.indexOf("("); 95 String name1 = capture.substring(1, lparen_i); 96 yypushback(capture.length() - lparen_i - 1); 97 if (name1.length() > 0 && !Consts.kwd.contains(name1)) { 98 onSymbolMatched(name1, yychar + 1); 99 return yystate(); 100 } 101 } 102 {Varsub3} { 103 String capture = yytext(); 104 String name = capture.substring(2, capture.length() - 1); 105 if (!Consts.kwd.contains(name)) { 106 onSymbolMatched(name, yychar + 2); 107 return yystate(); 108 } 109 } 110 } 111 112 <VARSUB2> { 113 {name_unit}+ { 114 String name2 = yytext(); 115 yypop(); 116 if (!Consts.kwd.contains(name2)) { 117 onSymbolMatched(name2, yychar); 118 return yystate(); 119 } 120 } 121 } 122 123 <YYINITIAL, BRACES> { 124 {OrdinaryWord} { 125 String id = yytext(); 126 if (!Consts.kwd.contains(id)) { 127 onSymbolMatched(id, yychar); 128 return yystate(); 129 } 130 } 131 } 132 133 <STRING> { 134 \" { yypop(); } 135 } 136 137 <BRACES> { 138 [\}] { 139 if (--braceCount == 0) { 140 yypop(); 141 } 142 } 143 [\{] { 144 ++braceCount; 145 } 146 } 147 148 <SCOMMENT> { 149 {EOL} { yypop(); } 150 } 151 152 <YYINITIAL, STRING, COMMENT, SCOMMENT, BRACES> { 153 {WhspChar}+ | 154 [^] {} 155 } 156