Skip to content

Implementation of the miniohm interface, to use Wasm grammar blobs from Go.

License

Notifications You must be signed in to change notification settings

ohmjs/miniohm-go

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

minohm-go

A Go implementation of the minohm interface, for using Ohm grammars from Go.

A grammar blob is an Ohm grammar that has been compiled to .wasm via the @ohm-js/wasm NPM package. To use a grammar blob to match some input, you need a miniohm implementation for your host language of choice (JavaScript, Go, Python, etc.) This package provides a miniohm implementation for the Go Programming Language.

Overview

  • The miniohm module is in matcher.go and cst.go.
  • An example can be found in cmd/example/main.go.

Compiling grammars to Wasm

Use the ohm2wasm command from the @ohm-js/wasm NPM package to compile a .ohm file to a Wasm grammar blob. For example:

npx ohm2wasm myGrammar.ohm

See Makefile for an example.

Matching input

Create a new WasmMatcher and use the Match function:

matcher := NewWasmMatcher(ctx)
err := matcher.LoadModule("path/to/grammar.wasm")
matcher.SetInput("text to match")
success, err := matcher.Match()
cstRoot, err := matcher.GetCstRoot()

Walking the CST

A full implementation of semantics, operations, etc. is not part of the miniohm interface. Instead, you can walk the CST (concrete syntax tree) directly using the CstNode interface. See cmd/example/main.go for an example.

Developing

Useful commands:

make # Build
make test # Run tests

About

Implementation of the miniohm interface, to use Wasm grammar blobs from Go.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Sponsor this project

 

Packages

No packages published