MCPcopy Index your code
hub / github.com/brettlangdon/forge

github.com/brettlangdon/forge @v0.2.3

Chat with this repo
repository ↗ · DeepWiki ↗ · release v0.2.3 ↗ · + Follow
146 symbols 394 edges 15 files 80 documented · 55% updated 9y ago★ 1099 open issues
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

forge

Build Status GoDoc

Forge is a configuration syntax and parser.

Installation

go get github.com/brettlangdon/forge

Documentation

Documentation can be viewed on godoc: https://godoc.org/github.com/brettlangdon/forge

Example

You can see example usage in the example folder.

# example.cfg

# Global directives
global = "global value";
# Primary section
primary {
  string = "primary string value";
  single = 'single quotes are allowed too';

  # Semicolons are optional
  integer = 500
  float = 80.80
  boolean = true
  negative = FALSE
  nothing = NULL

  list = [50.5, true, false, "hello", 'world'];

  # Include external files
  include "./include*.cfg";
  # Primary-sub section
  sub {
      key = "primary sub key value";
  }
}

# Secondary section
secondary {
  another = "secondary another value";
  global_reference = global;
  primary_sub_key = primary.sub.key;
  another_again = .another;  # References secondary.another
  _under = 50;
}
package main

import (
    "fmt"
    "json"

    "github.com/brettlangdon/forge"
)

func main() {
    // Parse a `SectionValue` from `example.cfg`
    settings, err := forge.ParseFile("example.cfg")
    if err != nil {
        panic(err)
    }

    // Get a single value
    if settings.Exists("global") {
        // Get `global` casted as a string
        value, _ := settings.GetString("global")
        fmt.Printf("global = \"%s\"\r\n", value)
    }

    // Get a nested value
    value, err := settings.Resolve("primary.included_setting")
    fmt.Printf("primary.included_setting = \"%s\"\r\n", value.GetValue())

    // You can also traverse down the sections manually
    primary, err := settings.GetSection("primary")
    strVal, err := primary.GetString("included_setting")
    fmt.Printf("primary.included_setting = \"%s\"\r\n", strVal)

    // Convert settings to a map
    settingsMap := settings.ToMap()
    fmt.Printf("global = \"%s\"\r\n", settingsMap["global"])

    // Convert settings to JSON
    jsonBytes, err := settings.ToJSON()
    fmt.Printf("\r\n\r\n%s\r\n", string(jsonBytes))
}

Issues/Requests?

Please feel free to open a github issue for any issues you have or any feature requests.

Extension points exported contracts — how you extend this code

Value (Interface)
Value is the base interface for Primative and Section data types [4 implementers]
value.go

Core symbols most depended-on inside this repo

GetType
called by 21
value.go
UpdateValue
called by 20
value.go
GetValue
called by 19
value.go
Get
called by 15
section.go
readToken
called by 13
parser.go
AsBoolean
called by 11
primative.go
syntaxError
called by 10
parser.go
readRune
called by 10
scanner.go

Shape

Method 83
Function 53
Struct 7
TypeAlias 2
Interface 1

Languages

Go100%

Modules by API surface

section.go32 symbols
parser.go19 symbols
primative.go17 symbols
scanner.go15 symbols
list.go15 symbols
primative_test.go9 symbols
value.go6 symbols
reference.go6 symbols
forge_test.go6 symbols
example_test.go5 symbols
token/token.go4 symbols
forge.go4 symbols

For agents

$ claude mcp add forge \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact