PHP code example of tuqqu / go-parser

1. Go to this page and download the library: Download tuqqu/go-parser library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

tuqqu / go-parser example snippets


use GoParser\Parser;

$program = <<<GO
    package main
    
    import "fmt"
    
    func main() {
        res := add(1, 2)
        fmt.Println("1+2 =", res)
    }
GO;

$parser = new Parser($program);
$ast = $parser->parse();
$errs = $parser->getErrors();

use GoParser\{Parser, ParseMode};

$func = <<<GO
    func add(x, y int) int { 
        return x + y
    }
GO;

$parser = new Parser($func, mode: ParseMode::SingleDecl);
$decl = $parser->parseSingleDecl();