parser

package
v0.0.5 Latest Latest
Warning

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

Go to latest
Published: Sep 6, 2024 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Keywords = []string{
	"do",
	"if",
	"end",
	"true",
	"false",
	"nil",
}
View Source
var Parser = participle.MustBuild[Entry](
	participle.Lexer(RubyLikeLexer),
	participle.Elide("Comment", "Whitespace"),
	participle.Unquote("String"),
	participle.UseLookahead(2),
)
View Source
var RubyLikeLexer = lexer.MustSimple([]lexer.SimpleRule{
	{"True", "true"},
	{"False", "false"},
	{"Null", "nil"},
	{"Number", `\d+(?:\.\d+)?`},
	{"Identifier", `[A-Za-z_][A-Za-z0-9_]*`},
	{"HashIdentifier", `[A-Za-z_][A-Za-z0-9_]+:`},
	{"HashKeyword", `[A-Za-z0-9_]+`},
	{`String`, `'[^']*'|"[^"]*"`},
	{"Comment", `#.*(\n)?`},
	{"Whitespace", `[ \t]+`},
	{"NewLine", `[\r\n]+`},

	{"COLON", ":"},
	{"OPEN_PAREN", `\(`},
	{"CLOSE_PAREN", `\)`},
	{"OPEN_BRACKET", "{"},
	{"CLOSE_BRACKET", "}"},
	{"COMMA", ","},
})

Functions

This section is empty.

Types

type Argument

type Argument struct {
	Identifier *string    `parser:"(@Identifier ':')?"`
	Expression Expression `parser:"@@"`
}

type ArgumentList

type ArgumentList struct {
	Argument         []Argument        `parser:"(@@ (',' @@)*)?"`
	LambdaExpression *LambdaExpression `parser:"@@?"`
}

type BlockStatement

type BlockStatement struct {
	OpenBracket  string      `parser:"'{'"`
	Statements   []Statement `parser:"@@"`
	CloseBracket string      `parser:"'}'"`
}

type CompilationUnit

type CompilationUnit struct {
	Statements []Statement `parser:"@@*"`
}

type Entry

type Entry struct {
	Statements []Statement `parser:"@@*"`
}

type Expression

type Expression struct {
	// MemberAccessExpression        *MemberAccessExpression        `parser:"@@ |"`
	LambdaExpression              *LambdaExpression              `parser:"@@ |"`
	ValueExpression               *ValueExpression               `parser:"@@ |"`
	InvocationExpression          *InvocationExpression          `parser:"@@ |"`
	InvocationExpressionWithParen *InvocationExpressionWithParen `parser:"@@ |"`
	IfExpression                  *IfStatementOrExpression       `parser:"@@"`
}

type ExpressionStatement

type ExpressionStatement struct {
	Expression Expression `parser:"@@"`
}

type ExpressionWithIdentifier

type ExpressionWithIdentifier struct {
	IdentifierNameExpression *IdentifierNameExpression `parser:"@@"`
}

type HashIdentifier

type HashIdentifier struct {
	Identifier string `parser:"@Identifier ':'"`
}

type HashObject

type HashObject struct {
	OpenBracket  string `parser:"'{'"`
	Pairs        []Pair `parser:"@@ (',' @@)+"`
	CloseBracket string `parser:"'}'"`
}

type HashSymbol

type HashSymbol struct {
	Identifier string `parser:"':' @Identifier"`
}

type Identifier

type Identifier struct {
	Name string `parser:"@Identifier"`
}

func (*Identifier) Parse

func (v *Identifier) Parse(lex *lexer.PeekingLexer) error

type IdentifierNameExpression

type IdentifierNameExpression struct {
	Identifier Identifier `parser:"@@"`
}

type IfStatementOrExpression

type IfStatementOrExpression struct {
	IfKeyword  string                                     `parser:"'if'"`
	OpenParen  *string                                    `parser:"'('?"`
	Condition  IfStatementOrExpressionConditionExpression `parser:"@@"`
	CloseParen *string                                    `parser:"')'?"`
	NewParen   *string                                    `parser:"@NewLine?"`
	Statements []Statement                                `parser:"@@*"`
	EndKeyword string                                     `parser:"'end'"`
}

type IfStatementOrExpressionConditionExpression

type IfStatementOrExpressionConditionExpression struct {
	InvocationExpression          *InvocationExpression          `parser:"@@ |"`
	InvocationExpressionWithParen *InvocationExpressionWithParen `parser:"@@ |"`
	ValueExpression               *ValueExpression               `parser:"@@"`
}

type InvocationExpression

type InvocationExpression struct {
	Expression   ExpressionWithIdentifier `parser:"@@"`
	ArgumentList ArgumentList             `parser:"@@"`
}

type InvocationExpressionWithParen

type InvocationExpressionWithParen struct {
	Expression   ExpressionWithIdentifier `parser:"@@"`
	OpenParen    string                   `parser:"'('"`
	ArgumentList ArgumentList             `parser:"@@"`
	CloseParen   string                   `parser:"')'"`
}

type LambdaExpression

type LambdaExpression struct {
	DoKeyword  string      `parser:"'do'"`
	NewLine    string      `parser:"@NewLine?"`
	Statements []Statement `parser:"@@*"`
	EndKeyword string      `parser:"'end'"`
}

type Literal

type Literal struct {
	String *string `parser:"@String |"`
	Number *string `parser:"@Number |"`
	True   *string `parser:"@True |"`
	False  *string `parser:"@False |"`
	Null   *string `parser:"@Null"`
}

type MemberAccessExpression

type MemberAccessExpression struct {
	Expression MemberAccessExpressionTExpression `parser:"@@"`
	Dot        string                            `parser:"'.'"`
	Identifier Identifier                        `parser:"@@"`
}

type MemberAccessExpressionTExpression

type MemberAccessExpressionTExpression struct {
	MemberAccessExpression *MemberAccessExpression        `parser:"@@ |"`
	InvocationExpression   *InvocationExpressionWithParen `parser:"@@"`
}

type Pair

type Pair struct {
	Identifier HashIdentifier `parser:"@@"`
	Value      Value          `parser:"@@"`
}

type Statement

type Statement struct {
	Statement StatementInternal `parser:"@@"`
	NewLine   string            `parser:"@NewLine"`
}

type StatementInternal

type StatementInternal struct {
	BlockStatement      *BlockStatement          `parser:"@@ |"`
	IfStatement         *IfStatementOrExpression `parser:"@@ |"`
	ExpressionStatement *ExpressionStatement     `parser:"@@"`
}

type Value

type Value struct {
	Literal    *Literal    `parser:"@@ |"`
	HashSymbol *HashSymbol `parser:"@@ |"`
	Hash       *HashObject `parser:"@@"`
}

type ValueExpression

type ValueExpression struct {
	Value Value `parser:"@@"`
}

Jump to

Keyboard shortcuts

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