Documentation
¶
Index ¶
Constants ¶
const DefaultEscapeToken = '\\'
DefaultEscapeToken is the default escape token
Variables ¶
This section is empty.
Functions ¶
func ChompHeredocContent ¶
ChompHeredocContent chomps leading tabs from the heredoc.
func SetLocation ¶
func WithLocation ¶
WithLocation extends an error with a source code location
Types ¶
type DirectiveParser ¶
type DirectiveParser struct {
// contains filtered or unexported fields
}
DirectiveParser is a parser for Dexfile directives that enforces the quirks of the directive parser.
type Heredoc ¶
func MustParseHeredoc ¶
MustParseHeredoc is a variant of ParseHeredoc that discards the error, if there was one present.
func ParseHeredoc ¶
ParseHeredoc parses a heredoc word from a target string, returning the components from the doc.
type LocationError ¶
type LocationError struct {
Locations [][]Range
// contains filtered or unexported fields
}
LocationError gives a location in source code that caused the error
type Node ¶
type Node struct {
Value string // actual content
Next *Node // the next item in the current sexp
Children []*Node // the children of this sexp
Heredocs []Heredoc // extra heredoc content attachments
Attributes map[string]bool // special attributes for this node
Original string // original line used before parsing
Flags []string // only top Node should have this set
StartLine int // the line in the original dexfile where the node begins
EndLine int // the line in the original dexfile where the node ends
PrevComment []string
}
Node is a structure used to represent a parse tree.
In the node there are three fields, Value, Next, and Children. Value is the current token's string value. Next is always the next non-child token, and children contains all the children. Here's an example:
(value next (child child-next child-next-next) next-next)
This data structure is frankly pretty lousy for handling complex languages, but lucky for us the Dexfile isn't very complicated. This structure works a little more effectively than a "proper" parse tree for our needs.
type Range ¶
Range is a code section between two positions
func DetectSyntax ¶
DetectSyntax returns the syntax of provided input.
The traditional dexfile directives '# syntax = ...' are used by default, however, the function will also fallback to c-style directives '// syntax = ...' and json-encoded directives '{ "syntax": "..." }'. Finally, starting lines with '#!' are treated as shebangs and ignored.
This allows for a flexible range of input formats, and appropriate syntax selection.