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) Ranges ¶
func (e Error) Ranges() []LocationRange
Ranges returns location ranges this error occurred.
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 ¶
ColumnNumber returns the column number of the location.
func (Location) LineNumber ¶
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 ¶
MakeToken returns a token for testing purposes. TODO: this should not be necessary for testing if it's possible to serialize an AST.
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) MakeErrorWithHelp ¶
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.
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 )