syntax

package
v0.0.0-...-c537dde Latest Latest
Warning

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

Go to latest
Published: Feb 25, 2025 License: BSD-3-Clause Imports: 2 Imported by: 0

Documentation

Overview

Package syntax implements GN syntax tokenizer and parser.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Error

type Error struct {
	// contains filtered or unexported fields
}

Error represents a syntax error.

func MakeErrorAt

func MakeErrorAt(location Location, ranges []LocationRange, message, helpText string) Error

MakeErrorAt makes an error at the provided location and ranges. TODO(b/388723392): just make the struct fields exported?

func (Error) Error

func (e Error) Error() string

Error returns formatted message for this error.

func (Error) HelpText

func (e Error) HelpText() string

HelpText returns help text for this error, if available.

func (Error) Location

func (e Error) Location() Location

Location returns location this error occurred.

func (Error) Message

func (e Error) Message() string

Message returns message for this error.

func (Error) Ranges

func (e Error) Ranges() []LocationRange

Ranges returns location ranges this error occurred.

func (Error) Unwrap

func (e Error) Unwrap() []error

Unwrap returns wrapped errors.

type Location

type Location struct {
	// contains filtered or unexported fields
}

Location represents a place in a source file. Used for error reporting.

func (Location) ColumnNumber

func (l Location) ColumnNumber() int

ColumnNumber returns the column number of the location.

func (Location) Describe

func (l Location) Describe(includeColumnNumber bool) string

Describe returns a string representation of the location.

func (Location) LineNumber

func (l Location) LineNumber() int

LineNumber returns the line number of the location.

type LocationRange

type LocationRange struct {
	// contains filtered or unexported fields
}

LocationRange represents a range in a source file. Used for error reporting. The end is exclusive i.e. [begin, end)

func (LocationRange) Begin

func (l LocationRange) Begin() Location

Begin returns the beginning of this location range.

func (LocationRange) Union

func (l LocationRange) Union(other LocationRange) LocationRange

Union returns a location range combined with the current location range. Returns blank if the files are not the same.

type Token

type Token struct {
	// contains filtered or unexported fields
}

Token represents a token in a GN file.

func MakeToken

func MakeToken(tokenType TokenType, value string) Token

MakeToken returns a token for testing purposes. TODO: this should not be necessary for testing if it's possible to serialize an AST.

func Tokenize

func Tokenize(inputFile *fs.InputFile) ([]Token, error)

Tokenize reads a GN input file and returns a list of tokens.

func TokenizeWithTransform

func TokenizeWithTransform(inputFile *fs.InputFile, whitespaceTransform whitespaceTransform) ([]Token, error)

TokenizeWithTransform reads a GN input file with provided whitespace transformation option and returns a list of tokens.

func (Token) MakeError

func (t Token) MakeError(message string) Error

MakeError makes an error from this token and message.

func (Token) MakeErrorWithHelp

func (t Token) MakeErrorWithHelp(message, helpText string) Error

MakeErrorWithHelp makes an error from this token and message and help.

func (Token) Range

func (t Token) Range() LocationRange

Range returns location range for this token.

func (Token) TokenType

func (t Token) TokenType() TokenType

TokenType returns type of this token.

func (Token) Value

func (t Token) Value() string

Value returns value of this token.

type TokenType

type TokenType int
const (
	// TokenInvalid represents an invalid token.
	TokenInvalid TokenType = iota
	// TokenInteger represents an integer literal.
	TokenInteger
	// TokenString represents a string literal "blah", including quotes.
	TokenString
	// TokenTrue represents a true boolean literal.
	TokenTrue
	// TokenFalse represents a false boolean literal.
	TokenFalse

	// TokenEqual represents the assignment operator "=".
	TokenEqual
	// TokenPlus represents the addition operator "+".
	TokenPlus
	// TokenMinus represents the subtraction operator "-".
	TokenMinus
	// TokenPlusEquals represents the add-and-assign operator "+=".
	TokenPlusEquals
	// TokenMinusEquals represents the subtract-and-assign operator "-=".
	TokenMinusEquals
	// TokenEqualEqual represents the equality operator "==".
	TokenEqualEqual
	// TokenNotEqual represents the inequality operator "!=".
	TokenNotEqual
	// TokenLessEqual represents the less than or equal to operator "<=".
	TokenLessEqual
	// TokenGreaterEqual represents the greater than or equal to operator ">=".
	TokenGreaterEqual
	// TokenLessThan represents the less than operator "<".
	TokenLessThan
	// TokenGreaterThan represents the greater than operator ">".
	TokenGreaterThan
	// TokenBooleanAnd represents the logical AND operator "&&".
	TokenBooleanAnd
	// TokenBooleanOr represents the logical OR operator "||".
	TokenBooleanOr
	// TokenBang represents the logical NOT operator "!".
	TokenBang
	// TokenDot represents the member access operator ".".
	TokenDot

	// TokenLeftParen represents a left parenthesis "(".
	TokenLeftParen
	// TokenRightParen represents a right parenthesis ")".
	TokenRightParen
	// TokenLeftBracket represents a left bracket "[".
	TokenLeftBracket
	// TokenRightBracket represents a right bracket "]".
	TokenRightBracket
	// TokenLeftBrace represents a left brace "{".
	TokenLeftBrace
	// TokenRightBrace represents a right brace "}".
	TokenRightBrace

	// TokenIf represents the "if" keyword.
	TokenIf
	// TokenElse represents the "else" keyword.
	TokenElse
	// TokenIdentifier represents an identifier.
	TokenIdentifier
	// TokenComma represents a comma ",".
	TokenComma
	// TokenUnclassifiedComment represents a comment #...\n, of unknown style (will be converted to one below)
	TokenUnclassifiedComment
	// TokenLineComment represents a comment #...\n on a line alone.
	TokenLineComment
	// TokenSuffixComment represents a comment #...\n on a line following other code.
	TokenSuffixComment
	// TokenBlockComment represents a comment #...\n line comment, but free-standing.
	TokenBlockComment

	// TokenUnclassifiedOperator represents an operator that hasn't been classified yet.
	TokenUnclassifiedOperator
)

Jump to

Keyboard shortcuts

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