xref: /OpenGrok/opengrok-indexer/src/main/jflex/analysis/terraform/TerraformProductions.lexh (revision d219b4cea555a12b602d2d5518daa22134ad4879)
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) 2020, Chris Fraire <cfraire@me.com>.
22 */
23
24<YYINITIAL> {
25
26    "var." {Identifier}    {
27        chkLOC();
28        String capture = yytext();
29        String id = capture.substring("var.".length());
30        offerKeyword("var");
31        offer(".");
32        // Push back the ID, and let the {Identifier} handling take over.
33        yypushback(id.length());
34    }
35
36    "local." {Identifier}    {
37        chkLOC();
38        String capture = yytext();
39        String id = capture.substring("local.".length());
40        offerKeyword("local");
41        offer(".");
42        // Push back the ID, and let the {Identifier} handling take over.
43        yypushback(id.length());
44    }
45
46    "module." {Identifier}    {
47        chkLOC();
48        String capture = yytext();
49        String id = capture.substring("module.".length());
50        offerKeyword("module");
51        offer(".");
52        // Push back the ID, and let the {Identifier} handling take over.
53        yypushback(id.length());
54    }
55
56    "data." {Identifier}    {
57        chkLOC();
58        String capture = yytext();
59        String id = capture.substring("data.".length());
60        offerKeyword("data");
61        offer(".");
62        // Push back the ID, and let the {Identifier} handling take over.
63        yypushback(id.length());
64    }
65
66    "path." {Identifier}    {
67        chkLOC();
68        String capture = yytext();
69        String id = capture.substring("path.".length());
70        if (Consts.PATH_KEYWORDS.contains(id)) {
71            offerKeyword("path");
72            offer(".");
73            offerKeyword(id);
74        } else {
75            yypushback(yylength() - "path".length());
76            if (offerSymbol("path", 0, true)) {
77                yypush(POST_IDENTIFIER);
78                if (returnOnSymbol()) {
79                    return yystate();
80                }
81            }
82        }
83    }
84
85    "terraform.workspace"    {
86        chkLOC();
87        offerKeyword("terraform");
88        offer(".");
89        offerKeyword("workspace");
90    }
91}
92