lexer

package
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Aug 24, 2026 License: MulanPSL-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package lexer 将 waiton-script 源码切分为 token 流。

处理:// 行注释、字符串字面量("...",内部标点不被切分)、 基础标点 { } ( ) ; , . = 以及标识符/关键字。空白被跳过。

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Token

type Token struct {
	Type TokenType
	Text string // 原始文本(Ident/String/关键字的字面量)
	Pos  int    // 源码字节偏移
}

Token 是词法单元。

func Lex

func Lex(src string) ([]Token, error)

Lex 将源码切分为 token 切片。遇到非法字符返回 error。

type TokenType

type TokenType int

TokenType 区分 token 类别。

const (
	EOF TokenType = iota
	Ident
	String
	// 标点
	PuncLBrace // {
	PuncRBrace // }
	PuncLParen // (
	PuncRParen // )
	PuncSemicolon
	PuncComma
	PuncDot
	PuncAssign   // =
	PuncColon    // :
	PuncLBracket // [
	PuncRBracket // ]
	PuncHash     // # 注解前缀(子集统一用 #:吸收 PS 声明上方注解模型,参数体用 {};子集无语言内置注解层,标准库是注入物非内置)
	OpArrow      // ->
	OpQuestion   // ?
	OpRange      // ..
	OpEllipsis   // ...
	// 运算符
	OpPlus  // +
	OpMinus // -
	OpStar  // *
	OpSlash // /
	OpMod   // %
	OpEq    // ==
	OpNeq   // !=
	OpLt    // <
	OpGt    // >
	OpLe    // <=
	OpGe    // >=
	OpAnd   // &&
	OpOr    // ||
	OpNot   // !
	// 关键字
	KwUse
	KwWorld
	KwFunc
	KwSelf
	KwIf
	KwElse
	KwFor
	KwWhile
	KwLoop
	KwBreak
	KwContinue
	KwMatch
	KwReturn
	KwIn
	KwLet
	KwAny
	KwTrue
	KwFalse
	Number  // 数字字面量(整数/浮点起始)
	Comment // 注释(// 行注释或 /* */ 块注释;text 为去注释符号的内容)
)

Source Files

  • lexer.go

Jump to

Keyboard shortcuts

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