Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cfengine3 and nakedvars #767

Closed
miekg opened this issue Mar 17, 2023 · 1 comment · Fixed by #768
Closed

cfengine3 and nakedvars #767

miekg opened this issue Mar 17, 2023 · 1 comment · Fixed by #768

Comments

@miekg
Copy link
Contributor

miekg commented Mar 17, 2023

The following snippet returns error tokens with the current XML for cfengine3:

bundle agent prometheus_server
{
    files:

      IsPrometheusServer::
        "/etc/prometheus/sd_configs/node_servers.json"
          copy_from => no_backup_rdcp("$(def.distr_files_dir)/etc/prometheus/sd_configs/node_servers.json", $(sys.policy_hub)),
          perms     => mog(0666, bin, bin);
}

The $(sys.policy_hub) isn't detected at all, but returned as:

chroma.Token {Error $}
chroma.Token {Punctuation (}
chroma.Token {NameFunction sys}
chroma.Token {Error .}
chroma.Token {NameFunction policy_hub}
chroma.Token {Punctuation )}

I think this is because currently it is assumed these type a constructs are always embedded in quotes.

The following diff fixes it, but unsure if this should also be a NameVar, @olehermanse any thoughts?

diff --git cfengine3.xml cfengine3.xml
index 5c91ac7..4950305 100644
--- cfengine3.xml
+++ cfengine3.xml
@@ -111,6 +111,9 @@
       <rule pattern="@[{(][^)}]+[})]">
         <token type="NameVariable"/>
       </rule>
+      <rule pattern="\$[(][^)]+[)]">
+        <token type="NameVariable"/>
+      </rule>
       <rule pattern="[(){},;]">
         <token type="Punctuation"/>
       </rule>

baring any crazier CFengine3 files, this allows me to delete all lexer code dealing with Error tokens in the test corpus I have

@olehermanse
Copy link
Contributor

@miekg Yea, that rule looks correct to me, treating @() in the same way as $().

alecthomas pushed a commit that referenced this issue Mar 17, 2023
$(...) is a valid syntax (believe called nakedvar) that should also be
matched by the CFEngine3 lexer.

Fixes: #767

Signed-off-by: Miek Gieben <miek@miek.nl>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants