parser

package
v0.4.4-alpha.1 Latest Latest
Warning

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

Go to latest
Published: Nov 9, 2022 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package parser implements a parser for KCL source files.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func ParseExpr

func ParseExpr(x string, opts ...Option) (f ast.Expr, err error)

func ParseFile

func ParseFile(filename string, src interface{}, opts ...Option) (f *ast.File, err error)
Example
package main

import (
	"fmt"

	"kusionstack.io/kclvm-go/pkg/compiler/parser"
)

func main() {
	const hello_k = `
# Copyright 2020 The KCL Authors. All rights reserved.

import some.pkg as pkgName

schema Person:
	name: str = 'kcl'
	age: int = 1

go = Person {
	name: 'golang'
}

if go.name == 'golang':
	print("hello KCL")
`

	f, err := parser.ParseFile("hello.k", hello_k)
	if err != nil {
		fmt.Println(err)
		return
	}

	fmt.Println(f.Module)
}
Output:

Types

type Option

type Option interface {
	// contains filtered or unexported methods
}

Jump to

Keyboard shortcuts

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