parser

package
v0.0.0-...-3d2a9e4 Latest Latest
Warning

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

Go to latest
Published: Dec 9, 2023 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

A Parser for PHP written in Go

Package usage example:

package main

import (
	"log"
	"os"

	"git.maride.cc/maride/php-parser/pkg/conf"
	"git.maride.cc/maride/php-parser/pkg/errors"
	"git.maride.cc/maride/php-parser/pkg/parser"
	"git.maride.cc/maride/php-parser/pkg/version"
	"git.maride.cc/maride/php-parser/pkg/visitor/dumper"
)

func main() {
	src := []byte(`<? echo "Hello world";`)

	// Error handler

	var parserErrors []*errors.Error
	errorHandler := func(e *errors.Error) {
		parsmakeerErrors = append(parserErrors, e)
	}

	// Parse

	rootNode, err := parser.Parse(src, conf.Config{
		Version:          &version.Version{Major: 5, Minor: 6},
		ErrorHandlerFunc: errorHandler,
	})

	if err != nil {
		log.Fatal("Error:" + err.Error())
	}

	// Dump

	goDumper := dumper.NewDumper(os.Stdout).
		WithTokens().
		WithPositions()

	rootNode.Accept(goDumper)
}

Index

Constants

This section is empty.

Variables

View Source
var ErrVersionOutOfRange = errors.New("the version is out of supported range")

ErrVersionOutOfRange is returned if the version is not supported

Functions

func Parse

func Parse(src []byte, config conf.Config) (ast.Vertex, error)

Types

type Parser

type Parser interface {
	Parse() int
	GetRootNode() ast.Vertex
}

Parser interface

Jump to

Keyboard shortcuts

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