parser

package
v0.20.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 11, 2025 License: AGPL-3.0 Imports: 7 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

View Source
var DebugMode = false

Functions

func ParseModule

func ParseModule(path string, src interface{}) (f *ast.Module, err error)
Example
package main

import (
	"fmt"

	"wa-lang.org/wa/internal/wat/parser"
)

func main() {
	src := `(module $hello)`

	m, err := parser.ParseModule("hello.wat", []byte(src))
	if err != nil {
		fmt.Println(err)
		return
	}

	fmt.Println(m)
	fmt.Println(m.Name)

}
Output:

(module $hello)
hello
Example (Wa)
package main

import (
	"fmt"
	"log"
	"os"

	"wa-lang.org/wa/api"
	"wa-lang.org/wa/internal/wat/parser"
)

func main() {
	const filename = "a.out.wa"
	const src = `func main { println("hello wa") }`

	_, watBytes, err := api.BuildFile(api.DefaultConfig(), filename, src)
	if err != nil {
		log.Fatal(err)
	}

	m, err := parser.ParseModule("a.out.wat", watBytes)
	if err != nil {
		os.WriteFile("a.out.wat", watBytes, 0666)
		fmt.Println(err)
		return
	}

	fmt.Println(m.Name)

}
Output:

__walang__

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL