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

Merged

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
@Moderocky Moderocky marked this pull request as ready for review November 21, 2024 08:59
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?

src/main/java/ch/njol/skript/config/Node.java Outdated Show resolved Hide resolved
Copy link
Member

@APickledWalrus APickledWalrus left a comment

Choose a reason for hiding this comment

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

My initial thoughts. I think this could work as a default module at org.skriptlang.skript.common.config. Syntax documentation also needs work (fill out examples!)

src/main/java/ch/njol/skript/config/Config.java Outdated Show resolved Hide resolved
src/main/java/ch/njol/skript/config/Node.java Outdated Show resolved Hide resolved
src/main/java/ch/njol/skript/expressions/ExprNode.java Outdated Show resolved Hide resolved
src/main/java/ch/njol/skript/expressions/ExprNode.java Outdated Show resolved Hide resolved
@sovdeeth sovdeeth added the 2.10 Targeting a 2.10.X version release label Dec 17, 2024
@Moderocky Moderocky requested a review from sovdeeth December 27, 2024 08:44
@Moderocky Moderocky force-pushed the feature/script-reflection branch 2 times, most recently from 88f2061 to 1235d8d Compare December 31, 2024 11:57
Moderocky and others added 12 commits December 31, 2024 12:03
* Create Script type.

* Support script string/name conversion.

* Script expression.

* Add script lang entry.

* Tests for script expression & names.

* Support all scripts expression.

* Script effects & tests.

* Create dummy Script handle for disabled scripts.

* Script reflection feature flag.

* Restrict literal parsing to commands & parse.

* Test feature flag for resolving name.

* Split ExprScripts by feature to support disabled scripts.

* Fix ExprName tests for new & old behaviour.

* Add tests for disabled script handles.

* Apply suggestions from code review

Co-authored-by: Patrick Miller <[email protected]>

* Improve script loading/unloading safety.

* Add feature check for script hotswapping.

* Use expression stream.

* Conformity for file names and proper loading safety.

* Document validity & add condition support.

* Add script is loaded condition + tests.

* Some changes from code review.

* More changes.

* Apply suggestions from code review

Co-authored-by: Patrick Miller <[email protected]>

* Clean up EffScriptFile and rename ExprScripts variations.

* Finish code review changes.

* Clean up script loader stuff.

* Fix conflicts.

* Suggested changes.

* Apply suggestions from code review

Co-authored-by: Patrick Miller <[email protected]>

* Finished.

---------

Co-authored-by: Patrick Miller <[email protected]>
Co-authored-by: sovdee <[email protected]>
@APickledWalrus APickledWalrus added the breaking changes Pull or feature requests that contain breaking changes (API, syntax, etc.) label Dec 31, 2024
Copy link
Member

@APickledWalrus APickledWalrus left a comment

Choose a reason for hiding this comment

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

a few things

src/main/java/ch/njol/skript/config/SectionNode.java Outdated Show resolved Hide resolved
src/main/java/ch/njol/skript/config/SectionNode.java Outdated Show resolved Hide resolved
src/main/java/ch/njol/skript/config/Node.java Outdated Show resolved Hide resolved
src/main/java/ch/njol/skript/expressions/ExprNode.java Outdated Show resolved Hide resolved
src/main/java/ch/njol/skript/expressions/ExprNode.java Outdated Show resolved Hide resolved
@APickledWalrus APickledWalrus merged commit f69abdb into SkriptLang:feature/script-reflection Dec 31, 2024
5 checks passed
@APickledWalrus APickledWalrus removed the breaking changes Pull or feature requests that contain breaking changes (API, syntax, etc.) label Jan 1, 2025
Moderocky added a commit that referenced this pull request Jan 1, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
2.10 Targeting a 2.10.X version release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants