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

Config navigation syntax. #6719

Open
wants to merge 11 commits into
base: feature/script-reflection
Choose a base branch
from

Conversation

Moderocky
Copy link
Member

Description

Rudimentary config reading & navigation.

Additions

This adds:
- The types for a Config and a Node:
- Configs are the key-value structures used internally by script configuration (and code) files
- Nodes are lines in a config, potentially entries (key: value) or sections (key:)
- A getter for the loaded Skript config.sk
- Navigators for nodes in the node tree (node "..." of X, nodes of X)
- Type-based value parsers for nodes
- Downstream converters for (skript* ->) config -> node

Syntax

[the] [skript] config

[the|all] nodes of %node%
[the] node %string% (of|in) %node%

[the] %*classinfo% value[s] of %nodes%

[the] name of %node%

What does this actually do?

It allows you to read a Config node tree and its values.
This does not add support for editing config files or structures.

set {_node} to the skript config
set {_node} to node "language" in {_node}

broadcast name of {_node} # "language"
broadcast text value of {_node} # "english" by default

set {_node} to the skript config
loop nodes of {_node}:
    ...

Caveat: Scripts

Internally, Scripts are loaded as Configs. This contains a fun little experimental Script -> Config converter, which means that, technically, script files are also navigable.

on load:
    set {_node} to the current script
    set {_node} to node "on load" in {_node}
    loop nodes of {_node}:
        broadcast name of {_node}

The output of the above would be:

set {_node} to the current script
set {_node} to node "on load" in {_node}
loop nodes of {_node}

This would normally be something I would never include, but because it just happens to be supported (by coincidence more than intention) I'm personally okay with leaving it accessible, I think people could make some really cool things with it (even self-programming scripts with the follow-up PR) and I don't think it's very damaging by itself.

That said, I recognise it's probably a bit scary for some people so I don't mind what happens to it too much.


This is part of a series of linked stages around config and script management.

image

Related Issues: requires #6702

@Moderocky Moderocky mentioned this pull request May 24, 2024
@Moderocky Moderocky marked this pull request as draft May 24, 2024 19:52
Copy link
Member

@erenkarakal erenkarakal left a comment

Choose a reason for hiding this comment

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

How does the navigation work if some line has a dot in it already?
like

options:
  a.b:
    c: hi

if I wanted to get the c: line using the script navigation could I do that?

@@ -116,6 +118,9 @@ public void move(final SectionNode newParent) {
newParent.add(this);
}

@SuppressWarnings("null")
private final static Pattern linePattern = Pattern.compile("^((?:[^#]|##)*)(\\s*#(?!#).*)$");
Copy link
Member

Choose a reason for hiding this comment

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

I think you should comment what this matches since it was kinda hard to understand at first sight

Copy link
Member Author

Choose a reason for hiding this comment

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

I don't actually know what this matches, I think I moved it from somewhere else.

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 this pull request may close these issues.

3 participants