ast

package
v0.0.0-...-1412480 Latest Latest
Warning

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

Go to latest
Published: Feb 26, 2022 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	Lexer = lexer.MustStateful(lexer.Rules{
		"Root": {
			{"whitespace", `[\r\t ]+`, nil},
			{"Modifier", `\b(pub)\b`, nil},
			{"Keyword", `\b(if|else|for|in|with|as|import|fun)\b`, nil},
			{"Numeric", `\b(0(b|B|o|O|x|X)[a-fA-F0-9]+)\b`, nil},
			{"Decimal", `\b(0|[1-9][0-9]*)\b`, nil},
			{"Bool", `\b(true|false)\b`, nil},
			{"String", `"`, lexer.Push("String")},
			{"RawString", "`", lexer.Push("RawString")},
			{"Heredoc", `<<[-~]?(\w+)`, lexer.Push("Heredoc")},
			{"RawHeredoc", "<<[-~]?`(\\w+)`", lexer.Push("RawHeredoc")},
			{"Brace", `{`, lexer.Push("Brace")},
			{"Paren", `\(`, lexer.Push("Paren")},
			{"Bracket", `\[`, lexer.Push("Bracket")},
			{"Ident", `\b([[:alpha:]_]\w*)\b`, nil},
			{"Operator", `(>=|<=|&&|\|\||==|!=|[-+=*/%<>^!|&])`, nil},
			{"Punct", `[@:;?.,]`, nil},
			{"Newline", `\n`, nil},
			{"Comment", `#`, lexer.Push("Comment")},
		},
		"String": {
			{"StringEnd", `"`, lexer.Pop()},
			{"Escaped", `\\.`, nil},
			{"Interpolated", `\${`, lexer.Push("Interpolated")},
			{"Char", `\$|[^"$\\]+`, nil},
		},
		"RawString": {
			{"RawStringEnd", "`", lexer.Pop()},
			{"RawChar", "[^`]+", nil},
		},
		"Heredoc": {
			{"HeredocEnd", `\b\1\b`, lexer.Pop()},
			{"Spaces", `\s+`, nil},
			{"Escaped", `\\.`, nil},
			{"Interpolated", `\${`, lexer.Push("Interpolated")},
			{"Text", `\$|[^\s$]+`, nil},
		},
		"RawHeredoc": {
			{"RawHeredocEnd", `\b\1\b`, lexer.Pop()},
			{"Whitespace", `\s+`, nil},
			{"RawText", `[^\s]+`, nil},
		},
		"Interpolated": {
			{"BraceEnd", `}`, lexer.Pop()},
			lexer.Include("Root"),
		},
		"Brace": {
			{"BraceEnd", `}`, lexer.Pop()},
			lexer.Include("Root"),
		},
		"Paren": {
			{"ParenEnd", `\)`, lexer.Pop()},
			lexer.Include("Root"),
		},
		"Bracket": {
			{"BracketEnd", `\]`, lexer.Pop()},
			lexer.Include("Root"),
		},
		"Comment": {
			{"CommentEnd", `\n`, lexer.Pop()},
			{"CommentText", `[^\n]`, nil},
		},
	})

	Parser = participle.MustBuild(
		&Module{},
		participle.Lexer(&semicolonLexerDefinition{}),
	)
)

Functions

This section is empty.

Types

type As

type As struct {
	Text string `parser:"@'as'"`
}

type AsClause

type AsClause struct {
	As     *As  `parser:"@@"`
	Effect *Ref `parser:"@@"`
}

type Association

type Association struct {
	Symbol string `parser:"@( ':' ':' )"`
	Ident  *Ident `parser:"@@"`
}

type At

type At struct {
	Text string `parser:"@'@'"`
}

type AtClause

type AtClause struct {
	At     *At    `parser:"@@"`
	Effect *Ident `parser:"@@"`
}

type Backtick

type Backtick struct {
	Text string `parser:"@(RawString | RawStringEnd)"`
}

type BlockLit

type BlockLit struct {
	Type  *Type     `parser:"@@?"`
	Block *StmtList `parser:"@@"`
}

type Call

type Call struct {
	Args *ExprList   `parser:"@@?"`
	At   *AtClause   `parser:"@@?"`
	With *WithClause `parser:"@@?"`
	As   *AsClause   `parser:"@@?"`
}

type CloseBrace

type CloseBrace struct {
	Text string `parser:"@BraceEnd"`
}

type CloseBracket

type CloseBracket struct {
	Text string `parser:"@BracketEnd"`
}

type CloseParen

type CloseParen struct {
	Text string `parser:"@ParenEnd"`
}

type Comment

type Comment struct {
	Text string `parser:"Comment @(CommentText*) CommentEnd"`
}

type Comments

type Comments struct {
	Comments []*Comment `parser:"@@+"`
}

type Condition

type Condition struct {
	OpenParen  *OpenParen  `parser:"@@"`
	Expr       *Expr       `parser:"@@"`
	CloseParen *CloseParen `parser:"@@"`
}

type Decl

type Decl struct {
	Import   *ImportDecl `parser:"( @@ ';'?"`
	Func     *FuncDecl   `parser:"| @@ ';'?"`
	Newline  *Newline    `parser:"| @@"`
	Comments *Comments   `parser:"| @@ )"`
}

type Else

type Else struct {
	Text string `parser:"@'else'"`
}

type ElseIfStmt

type ElseIfStmt struct {
	Else      *Else      `parser:"@@"`
	If        *If        `parser:"@@"`
	Condition *Condition `parser:"@@"`
	Body      *StmtList  `parser:"@@"`
}

type ElseStmt

type ElseStmt struct {
	Else *Else     `parser:"@@"`
	Body *StmtList `parser:"@@"`
}

type Entry

type Entry struct {
	Keys  []*Ident `parser:"(@@ ':')+"`
	Value *Expr    `parser:"@@"`
}

type Expr

type Expr struct {
	Unary *Unary

	Left  *Expr
	Op    Op
	Right *Expr
}

func (*Expr) Parse

func (e *Expr) Parse(lex *lexer.PeekingLexer) error

Parse expressions with a precedence climbing implementation.

type ExprList

type ExprList struct {
	OpenParen  *OpenParen  `parser:"@@"`
	Exprs      []*ExprStmt `parser:"@@*"`
	CloseParen *CloseParen `parser:"@@"`
}

type ExprStmt

type ExprStmt struct {
	Entry    *Entry    `parser:"( @@ ','?"`
	Expr     *Expr     `parser:"| @@ ','?"`
	Newline  *Newline  `parser:"| @@"`
	Comments *Comments `parser:"| @@ )"`
}

type Field

type Field struct {
	Type     *Type         `parser:"@@"`
	Variadic *string       `parser:"@( '.' '.' '.' )?"`
	Name     *Ident        `parser:"@@"`
	Default  *FieldDefault `parser:"@@?"`
}

type FieldDefault

type FieldDefault struct {
	Assign string `parser:"@'='"`
	Unary  *Unary `parser:"@@"`
}

type FieldList

type FieldList struct {
	OpenParen  *OpenParen   `parser:"@@"`
	Fields     []*FieldStmt `parser:"@@*"`
	CloseParen *CloseParen  `parser:"@@"`
}

type FieldStmt

type FieldStmt struct {
	Field    *Field    `parser:"( @@ ','?"`
	Newline  *Newline  `parser:"| @@"`
	Comments *Comments `parser:"| @@ )"`
}

type For

type For struct {
	Text string `parser:"@'for'"`
}

type ForHeader

type ForHeader struct {
	OpenParen  *OpenParen  `parser:"@@"`
	Counter    *Ident      `parser:"( @@ ',' )?"`
	Var        *Ident      `parser:"@@"`
	In         *In         `parser:"@@"`
	Iterable   *Expr       `parser:"@@"`
	CloseParen *CloseParen `parser:"@@"`
}

type ForStmt

type ForStmt struct {
	For    *For       `parser:"@@"`
	Header *ForHeader `parser:"@@"`
	Body   *StmtList  `parser:"@@"`
}

type From

type From struct {
	Text string `parser:"@'from'"`
}

type Func

type Func struct {
	Text string `parser:"@'fun'"`
}

type FuncDecl

type FuncDecl struct {
	Modifiers []*Modifier `parser:"@@*"`
	Func      *Func       `parser:"@@"`
	Name      *Ident      `parser:"@@"`
	Params    *FieldList  `parser:"@@"`
	Type      *Type       `parser:"@@"`
	Effects   *FieldList  `parser:"@@?"`
	Body      *StmtList   `parser:"@@?"`
}

type Group

type Group struct {
	OpenParen  *OpenParen  `parser:"@@"`
	Expr       *Expr       `parser:"@@"`
	CloseParen *CloseParen `parser:"@@"`
}

type Heredoc

type Heredoc struct {
	Value     string
	Start     string             `parser:"@Heredoc"`
	Fragments []*HeredocFragment `parser:"@@*"`
	End       *HeredocEnd        `parser:"@@"`
}

type HeredocEnd

type HeredocEnd struct {
	Text string `parser:"@(HeredocEnd | RawHeredocEnd)"`
}

type HeredocFragment

type HeredocFragment struct {
	Spaces       *string       `parser:"( @Spaces"`
	Escaped      *string       `parser:"| @Escaped"`
	Interpolated *Interpolated `parser:"| @@"`
	Text         *string       `parser:"| @(Text | RawText) )"`
}

type Ident

type Ident struct {
	Text string `parser:"@Ident"`
}

type If

type If struct {
	Text string `parser:"@'if'"`
}

type IfStmt

type IfStmt struct {
	If        *If           `parser:"@@"`
	Condition *Condition    `parser:"@@"`
	Body      *StmtList     `parser:"@@"`
	ElseIfs   []*ElseIfStmt `parser:"@@*"`
	Else      *ElseStmt     `parser:"@@?"`
}

type Import

type Import struct {
	Text string `parser:"@'import'"`
}

type ImportDecl

type ImportDecl struct {
	Import *Import `parser:"@@"`
	Name   *Ident  `parser:"@@"`
	From   *From   `parser:"@@"`
	Expr   *Expr   `parser:"@@"`
}

type In

type In struct {
	Text string `parser:"@'in'"`
}

type Interpolated

type Interpolated struct {
	Start *OpenInterpolated `parser:"@@"`
	Expr  *Expr             `parser:"@@?"`
	End   *CloseBrace       `parser:"@@"`
}

type Literal

type Literal struct {
	Block   *BlockLit   `parser:"( @@"`
	Decimal *int        `parser:"| @Decimal"`
	Numeric *NumericLit `parser:"| @Numeric"`
	Bool    *bool       `parser:"| @Bool"`
	String  *StringLit  `parser:"| @@ )"`
}

type Modifier

type Modifier struct {
	Public *Public `@@`
}

type Module

type Module struct {
	Comments *Comments `parser:"@@?"`

	Decls []*Decl `parser:"@@*"`
}

type Newline

type Newline struct {
	Text string `parser:"@Newline"`
}

type NumericLit

type NumericLit struct {
	Value int64
	Base  int
}

func (*NumericLit) Capture

func (l *NumericLit) Capture(tokens []string) error

type Op

type Op int
const (
	OpNone Op = iota //
	OpGe             // >=
	OpLe             // <=
	OpAnd            // &&
	OpOr             // ||
	OpEq             // ==
	OpNe             // !=
	OpSub            // -
	OpAdd            // +
	OpMul            // *
	OpDiv            // /
	OpLt             // <
	OpGt             // >
	OpMod            // %
	OpPow            // ^
	OpNot            // !
	OpMrg            // &
)

func (*Op) Capture

func (o *Op) Capture(values []string) error

type OpenBrace

type OpenBrace struct {
	Text string `parser:"@Brace"`
}

type OpenBracket

type OpenBracket struct {
	Text string `parser:"@Bracket"`
}

type OpenInterpolated

type OpenInterpolated struct {
	Text string `parser:"@Interpolated"`
}

type OpenParen

type OpenParen struct {
	Text string `parser:"@Paren"`
}

type Public

type Public struct {
	Text string `parser:"@'pub'"`
}

type Quote

type Quote struct {
	Text string `parser:"@(String | StringEnd)"`
}

type RawHeredoc

type RawHeredoc struct {
	Start     string             `parser:"@RawHeredoc"`
	Fragments []*HeredocFragment `parser:"@@*"`
	End       *HeredocEnd        `parser:"@@"`
}

type RawString

type RawString struct {
	Start *Backtick `parser:"@@"`
	Text  string    `parser:"@RawChar"`
	End   *Backtick `parser:"@@"`
}

type Ref

type Ref struct {
	Terminal *Terminal `parser:"@@"`
	Next     *RefNext  `parser:"@@?"`
}

type RefNext

type RefNext struct {
	Subscript *Subscript `parser:"( @@"`
	Selector  *Selector  `parser:"| @@"`
	Call      *Call      `parser:"| @@"`
	Splat     *Splat     `parser:"| @@ )"`
	Next      *RefNext   `@@?`
}

type Selector

type Selector struct {
	Dot   string `parser:"@'.'"`
	Ident *Ident `parser:"@@"`
}

type Splat

type Splat struct {
	Text string `parser:"@('.' '.' '.')"`
}

type Stmt

type Stmt struct {
	If       *IfStmt   `parser:"( @@ ';'?"`
	For      *ForStmt  `parser:"| @@ ';'?"`
	Entry    *Entry    `parser:"| @@ ';'?"`
	Expr     *Expr     `parser:"| @@ ';'?"`
	Newline  *Newline  `parser:"| @@"`
	Comments *Comments `parser:"| @@ )"`
}

type StmtList

type StmtList struct {
	OpenBrace  *OpenBrace  `parser:"@@"`
	Stmts      []*Stmt     `parser:"@@*"`
	CloseBrace *CloseBrace `parser:"@@"`
}

type String

type String struct {
	Start     *Quote            `parser:"@@"`
	Fragments []*StringFragment `parser:"@@*"`
	End       *Quote            `parser:"@@"`
}

type StringFragment

type StringFragment struct {
	Escaped      *string       `parser:"( @Escaped"`
	Interpolated *Interpolated `parser:"| @@"`
	Text         *string       `parser:"| @Char )"`
}

type StringLit

type StringLit struct {
	String     *String     `parser:"( @@"`
	RawString  *RawString  `parser:"| @@"`
	Heredoc    *Heredoc    `parser:"| @@"`
	RawHeredoc *RawHeredoc `parser:"| @@ )"`
}

type Subscript

type Subscript struct {
	OpenBracket  *OpenBracket  `parser:"@@"`
	LeftExpr     *Expr         `parser:"( @@?"`
	Colon        *string       `parser:"@':'?"`
	RightExpr    *Expr         `parser:"@@? )!"`
	CloseBracket *CloseBracket `parser:"@@"`
}

type Terminal

type Terminal struct {
	Group *Group   `parser:"( @@"`
	Lit   *Literal `parser:"| @@"`
	Ident *Ident   `parser:"| @@ )"`
}

type Type

type Type struct {
	Scalar      *Ident       `parser:"( @@"`
	Array       *Type        `parser:"| '[' ']' @@ )"`
	Association *Association `parser:"@@?"`
}

type Unary

type Unary struct {
	Op  Op   `parser:"@( '!' | '-' )?"`
	Ref *Ref `parser:"@@"`
}

type With

type With struct {
	Text string `parser:"@'with'"`
}

type WithClause

type WithClause struct {
	With    *With `parser:"@@"`
	Expr    *Expr `parser:"@@"`
	Closure *FuncDecl
}

Jump to

Keyboard shortcuts

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