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 Terraform symbols -- ignores comments, strings, keywords 27 */ 28 29 package org.opengrok.indexer.analysis.terraform; 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 TerraformSymbolTokenizer 38 %extends TerraformLexer 39 %unicode 40 %int 41 %char 42 %include ../CommonLexer.lexh 43 %{ 44 private String lastSymbol; 45 46 /** 47 * Resets the Terraform 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 COMMENT. 111 */ 112 @Override COMMENT()113 public int COMMENT() { 114 return COMMENT; 115 } 116 117 /** 118 * Gets the constant value created by JFlex to represent SCOMMENT. 119 */ 120 @Override SCOMMENT()121 public int SCOMMENT() { 122 return SCOMMENT; 123 } 124 125 /** 126 * Gets the constant value created by JFlex to represent HERE. 127 */ 128 @Override HERE()129 public int HERE() { 130 return HERE; 131 } 132 133 /** 134 * Gets the constant value created by JFlex to represent HEREin. 135 */ 136 @Override HEREin()137 public int HEREin() { 138 return HEREin; 139 } 140 %} 141 142 %include ../Common.lexh 143 %include ../CommonURI.lexh 144 %include ../CommonPath.lexh 145 // Terraform.lexh comes after HCL so that Terraform macros supersede. 146 %include ../hcl/HCL.lexh 147 %include Terraform.lexh 148 149 %% 150 // TerraformProductions.lexh comes first so that its expressions are preferred. 151 %include TerraformProductions.lexh 152 %include ../hcl/HCLProductions.lexh 153