Skip to content

marcos-venicius/evalset

Repository files navigation

EVALSET

The JSON sucessor?

image

The idea

This is a simple example of the evalset syntax:

root = {
    # this is the base url for the app
    base_url = "http://localhost:3030"
    app_name = "testing some stuff" # this is the name of my app
    id = 129
    other = 129.19

    route_names = {
        home = "Home"
        dashboard = "Dashboard"
    }
}

routes = [
    {
        id = mul($/root/id, 2)
        path = concat($/root/base_url, "/")
        name = $/root/route_names/home
    }
    {
        id = mul($/root/id, 3)
        path = concat($/root/base_url, "/dashboard")
        name = $/root/route_names/dashboard
    }
]

# Commas are entirely optional
dependencies = {
  test = "hello"
  outro = "now"
  number = 10
  floats = 3.1415,
  this_is_true = true,
  this_is_false = false
  this_is_nil = nil
  array = [
    "hello world"
    [
      10, 20
    ]
    {
      "this is a valid key" = "my very secret jwt token",
      my_lucy_number = 10
      child = {
        intern_node = "Hello Guys"
      }
    }
  ]
}

list = ["hello", 4239]

And, as you can see, evalset also suport "string named variables" with the following syntax:

"@angular/version" = "18.9.0"

The idea behind the project is to learn more about C, compilers, interpreters, etc.

The purpose of this language is to allow the user to create a configuration file like json but with some incremental features.

One of the features Evaluation, where the user can do math of string operations. Another feature is Variables, you can define top level variables and reference them later. In the end of the day, when the user try to get a value from a property, the property will be evaluated and returned the result to the user.

One of the thougts is to have a possibility to convert the evalset to json format, by evaluating all the fields and creating a valid json file.

Note

Probably it'll be lazy evaluated to avoid big files being slow to load, it should be optional to the user api.

Note

Comma to separate elements inside arrays, objects and function arguments are entirely optional

Data types

  • String ("....")
  • Integer (c int)
  • Float (c doubles)
  • Nullables (nil)
  • Boolean (true | false)
  • Array
  • Object
  • Paths ($/[a-zA-Z_])

To implement

I think the API to this language in C should work in a very special way.

So, we'll have a function, maybe called evalset_get which returns a "generic type".

Basically this will return the primitive types already evaluated like: int, nil, array, object, etc.

So, this function will expect an instance of the evalset and a string as second parameter.

The second parameter should basically accept an evalset syntax, which you will be able to reference variables, get indexes call builtin functions and all of it.

But, it'll not have the possibility to create variables, only to do some work upon all of them.

If you look carefully to the code, the file itself is an object of many keys, so you will be able to iterate over this keys refering to it as $/root, then inside $/root you'll have access to all other variables and do syntax like $/root["permissions"][sub_i(len($/root["permissions"]), 1)] and all kind of available syntax.

Warning

This is not the final thought about how it'll be implemented, it's just one of many ideas. But, to be honest, I like this one

Internal functions

  • sum
    • integer sum(integer, N...)
    • float sum(float, N...)
    • integer sum([]integer)
    • float sum([](float & integer))
  • join
    • string join([]string, string?)
    • []any join([]any, []any, N...)
    • string join(string, string, N...)
  • []string keys(object)
  • integer len([]any|string)
  • integer iota(), returns an integer which auto-increment every time it's called

I still have some internal functions in my, but for now, I'll leave only these ones. I'm thinking about the best way to implement this yet.

Another important point, is to have a special function to allow the user to debug, some kind of print But today we cannot parse a function without associating it to a variable

The name

The name evalset is due to the language properties you "set vars and evaluate the" so, evalset (believe it or not).

About

The JSON successor?

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Contributors