Skip to content

bmizerany/linebased

Repository files navigation

linebased

Go Reference

A Go package for parsing and expanding line-based scripts.

echo hello world
define greet name
	echo Hello, $name!
greet Alice

Linebased provides both a parser and tooling for line-based DSLs. The parser extracts commands and their bodies with no quoting or escaping rules. The tooling includes an LSP server for editor integration.

Design

Linebased scripts are deliberately simple. There are no string escapes, no quoting rules, no operator precedence. A line is a command name followed by whatever text you want. That's it. The only reserved words are define and include, which provide templates and file composition.

This simplicity has a cost: you can't nest expressions or compute values inline. But it has a benefit: scripts are trivial to read, write, and debug. The parser does exactly what you expect because there's almost nothing it can do.

Multi-line bodies use tabs for continuation. Tabs are visible, unambiguous, and easy to type. Spaces at line start are a syntax error, which catches a common class of invisible bugs.

Templates exist because repetition is error-prone. Parameter substitution is the only form of abstraction provided. Templates cannot recurse, cannot redefine themselves, and cannot produce new definitions. These restrictions prevent the language from becoming a programming language.

The LSP server provides diagnostics, hover, and jump-to-definition. Editor support matters.

Example

# Define a reusable template
define greet name
	echo Hello, $name!

# Use it
greet Alice
greet Bob

# Include shared definitions (extension added automatically)
include helpers

Documentation

See the package documentation for syntax, semantics, and API reference.

Tooling

Install the linebased command:

go install blake.io/linebased/cmd/linebased@latest

Debugging with expand

See exactly what your templates produce:

$ linebased expand script.linebased
echo Hello, Alice!
echo Hello, Bob!

Add -x for shell-style tracing that shows each template call as it expands:

$ linebased expand -x script.linebased
+ script.linebased:7: outer hello
++ script.linebased:1: inner hello
echo inner: hello

The + signs show nesting depth—when outer calls inner which produces echo, you see the full expansion chain.

Coding agent instructions

For AI coding assistants (Claude, Copilot, etc.), the linebased command provides built-in guidance:

linebased agents

This outputs guidance on working with linebased files, emphasizing the expand command for debugging. Add the output to your CLAUDE.md or system prompt.

Editor support

Configure Neovim:

local lspconfig = require("lspconfig")
local configs = require("lspconfig.configs")

if not configs.linebased then
  configs.linebased = {
    default_config = {
      cmd = { "linebased", "lsp" },
      filetypes = { "linebased" },
    },
  }
end

lspconfig.linebased.setup({})

You'll get diagnostics, hovers, and jump-to-definition for .linebased files.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •