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) 2010, 2021, Oracle and/or its affiliates. All rights reserved. 22 * Portions Copyright (c) 2017, 2019-2020, Chris Fraire <cfraire@me.com>. 23 */ 24 25 /* 26 * Gets R symbols -- ignores comments, strings, keywords 27 */ 28 29 package org.opengrok.indexer.analysis.r; 30 31 import java.io.IOException; 32 import java.util.regex.Pattern; 33 import org.opengrok.indexer.util.StringUtils; 34 import org.opengrok.indexer.web.HtmlConsts; 35 %% 36 %public 37 %class RSymbolTokenizer 38 %extends RLexer 39 %unicode 40 %int 41 %char 42 %include ../CommonLexer.lexh 43 %{ 44 private String lastSymbol; 45 46 /** 47 * Resets the R tracked state; {@inheritDoc} 48 */ 49 @Override reset()50 public void reset() { 51 super.reset(); 52 lastSymbol = null; 53 } 54 55 /** Does nothing. */ 56 @Override offer(String value)57 public void offer(String value) throws IOException { 58 } 59 60 @Override offerSymbol(String value,int captureOffset,boolean ignoreKwd)61 public boolean offerSymbol(String value, int captureOffset, boolean ignoreKwd) 62 throws IOException { 63 if (ignoreKwd || !Consts.KEYWORDS.contains(value)) { 64 lastSymbol = value; 65 onSymbolMatched(value, yychar + captureOffset); 66 return true; 67 } 68 lastSymbol = null; 69 return false; 70 } 71 72 /** Just forget any last-matched symbol. */ 73 @Override skipSymbol()74 public void skipSymbol() { 75 lastSymbol = null; 76 } 77 78 /** Just forget any last-matched symbol. */ 79 @Override offerKeyword(String value)80 public void offerKeyword(String value) throws IOException { 81 lastSymbol = null; 82 } 83 84 /** Does nothing. */ 85 @Override startNewLine()86 public void startNewLine() throws IOException { 87 } 88 89 /** Does nothing. */ 90 @Override disjointSpan(String className)91 public void disjointSpan(String className) throws IOException { 92 } 93 94 /** Does nothing. */ 95 @Override phLOC()96 public void phLOC() { 97 } 98 99 /** Gets the value {@code false}. */ takeAllContent()100 protected boolean takeAllContent() { 101 return false; 102 } 103 104 /** Gets a value indicating if a symbol was just matched. */ returnOnSymbol()105 protected boolean returnOnSymbol() { 106 return lastSymbol != null; 107 } 108 109 /** 110 * Gets the constant value created by JFlex to represent SCOMMENT. 111 */ 112 @Override SCOMMENT()113 public int SCOMMENT() { 114 return SCOMMENT; 115 } 116 %} 117 118 %include ../Common.lexh 119 %include ../CommonURI.lexh 120 %include ../CommonPath.lexh 121 %include R.lexh 122 123 %% 124 %include RProductions.lexh 125