Skip to content

Add epics db - #8161

Open
minijackson wants to merge 2 commits into
nvim-treesitter:mainfrom
minijackson:add-epics_db
Open

Add epics db#8161
minijackson wants to merge 2 commits into
nvim-treesitter:mainfrom
minijackson:add-epics_db

Conversation

@minijackson

@minijackson minijackson commented Sep 30, 2025

Copy link
Copy Markdown
Contributor

Name of language

EPICS database and database definitions

Includes the epics_msi_template language, which is a fancy way of saying "EPICS macros", which are used in other languages that I'll upstream after this PR.

Representative code sample
# SPDX-FileCopyrightText: 2015 Argonne National Laboratory
#
# SPDX-License-Identifier: EPICS

record(lsi, "$(user):example:version") {
    field(DTYP, "example version")
    field(DESC, "Version string")
    field(SIZV, "$(SIZV=200)")
    field(PINI, "YES")
    field(LEN, 42)
    field(INP, {const:"Hello, world!"})
}

Parser repo

Parsed tree for code sample
(source_file ; [0, 0] - [12, 0] epics_db
  (comment ; [0, 0] - [0, 58] epics_db
    (source)) ; [0, 0] - [0, 58] comment
  (comment ; [1, 0] - [1, 1] epics_db
    (source)) ; [1, 0] - [1, 1] comment
  (comment ; [2, 0] - [2, 32] epics_db
    (source)) ; [2, 0] - [2, 32] comment
  (record_instance ; [4, 0] - [11, 1] epics_db
    type: (record_type) ; [4, 7] - [4, 10] epics_db
    name: (record_name ; [4, 12] - [4, 37] epics_db
      (macro_expansion ; [4, 13] - [4, 20] epics_db
        (macro_expansion ; [4, 13] - [4, 20] epics_msi_template
          (variable))) ; [4, 15] - [4, 19] epics_msi_template
      (string_text_fragment)) ; [4, 20] - [4, 36] epics_db
    (field ; [5, 4] - [5, 34] epics_db
      name: (field_name) ; [5, 10] - [5, 14] epics_db
      value: (string ; [5, 16] - [5, 33] epics_db
        (string_text_fragment))) ; [5, 17] - [5, 32] epics_db
    (field ; [6, 4] - [6, 33] epics_db
      name: (field_name) ; [6, 10] - [6, 14] epics_db
      value: (string ; [6, 16] - [6, 32] epics_db
        (string_text_fragment))) ; [6, 17] - [6, 31] epics_db
    (field ; [7, 4] - [7, 30] epics_db
      name: (field_name) ; [7, 10] - [7, 14] epics_db
      value: (string ; [7, 16] - [7, 29] epics_db
        (macro_expansion ; [7, 17] - [7, 28] epics_db
          (macro_expansion ; [7, 17] - [7, 28] epics_msi_template
            (variable) ; [7, 19] - [7, 23] epics_msi_template
            default: (string))))) ; [7, 24] - [7, 27] epics_msi_template
    (field ; [8, 4] - [8, 22] epics_db
      name: (field_name) ; [8, 10] - [8, 14] epics_db
      value: (string ; [8, 16] - [8, 21] epics_db
        (string_text_fragment))) ; [8, 17] - [8, 20] epics_db
    (field ; [9, 4] - [9, 18] epics_db
      name: (field_name) ; [9, 10] - [9, 13] epics_db
      value: (string)) ; [9, 15] - [9, 17] epics_db
    (field ; [10, 4] - [10, 39] epics_db
      name: (field_name) ; [10, 10] - [10, 13] epics_db
      value: (json_value ; [10, 15] - [10, 38] epics_db
        (file ; [10, 15] - [10, 38] json5
          (object ; [10, 15] - [10, 38] json5
            (member ; [10, 16] - [10, 37] json5
              name: (identifier) ; [10, 16] - [10, 21] json5
              value: (string)))))))) ; [10, 22] - [10, 37] json5

Queries

Source of queries: adapted from the queries in the tree-sitter grammar repos.

Screenshots of code sample image

@clason clason added the new language PR adding a new (or switching to a different) parser label Sep 30, 2025
@clason

clason commented Sep 30, 2025

Copy link
Copy Markdown
Contributor

Plain regex #match is too expensive; try to use #lua-match.

For floats, that should be handled by the grammar, not the queries.

Long lists of literal matches are also not ideal; it's better to make the nodes more targeted.

@minijackson

minijackson commented Sep 30, 2025

Copy link
Copy Markdown
Contributor Author

Plain regex #match is too expensive; try to use #lua-match.

It seems lua-match doesn't support the | operator, so for a LNK|INP|^OUT$ regex, it would end up being 3 different matchers. Wouldn't that be even more expensive?

For floats, that should be handled by the grammar, not the queries.

I'll see if I can do that.

Long lists of literal matches are also not ideal; it's better to make the nodes more targeted.

I'm not sure what you meant by that.

@clason

clason commented Sep 30, 2025

Copy link
Copy Markdown
Contributor

No, regexes are much more expensive (in Neovim) since they need to cross into vimscript.

@minijackson

Copy link
Copy Markdown
Contributor Author

For the number of builtin field names, because there's a lot of them, with names that are hard to remember, I wanted the editor to highlight me when I make typos. Removing them would make it less useful, in my opinion.

@clason

clason commented Sep 30, 2025

Copy link
Copy Markdown
Contributor

Syntax highlighting is not linting, so that's a no-goal (for this project). As long as correct code is highlighted correctly, we care about performance and maintainability but not about how incorrect code is highlighted.

You can add custom queries on top of that, either in your personal config or a plugin.

@minijackson

Copy link
Copy Markdown
Contributor Author

@clason I've removed most of the items in the long #any-of? list to keep only the most commonly used ones, and handled the float parsing in the tree-sitter grammar, I hope this is acceptable.

@ribru17

ribru17 commented Oct 11, 2025

Copy link
Copy Markdown
Member

I don't think this needs a separate language for string expansions, should it? We have similar constructs in javascript/python and they manage to parse this within the top-level grammar

@minijackson

Copy link
Copy Markdown
Contributor Author

@ribru17 I've separated the string expansion as a separate grammar because it's a specific language in the EPICS ecosystem that's used in at least 3-4 different grammars (.db, .dbd, .substitutions, .cmd). In intend to upstream them later, I wanted to keep the PRs small.

@ribru17 ribru17 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change looks fine but definitely would be nice to remove the large literal checks

Comment thread runtime/queries/epics_db/highlights.scm Outdated
Comment thread runtime/queries/epics_db/locals.scm Outdated
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

new language PR adding a new (or switching to a different) parser

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants