Documentation
¶
Index ¶
- func AddQuotes(str string) string
- func AddYaegiTensorFuncs()
- func EscapeQuotes(str string) string
- func ExecWordIsCommand(f string) bool
- func ExecWords(ln string) ([]string, error)
- type State
- func (st *State) AddChunk()
- func (st *State) AddError(err error) error
- func (st *State) AddLine(ln string)
- func (st *State) Code() string
- func (st *State) DepthError() error
- func (st *State) ResetCode()
- func (st *State) ResetDepth()
- func (st *State) TotalDepth() int
- func (st *State) TranspileCode(code string)
- func (st *State) TranspileExec(ewords []string, output bool) Tokens
- func (st *State) TranspileExecString(str string, output bool) Tokens
- func (st *State) TranspileExecTokens(toks Tokens, code string, output bool) Tokens
- func (st *State) TranspileFile(in string, out string) error
- func (st *State) TranspileGo(toks Tokens, code string) Tokens
- func (st *State) TranspileGoNDimIndex(toks Tokens, code string, gtoks *Tokens, idIdx, rbIdx int) int
- func (st *State) TranspileGoRange(toks Tokens, code string, start, end int) Tokens
- func (st *State) TranspileLine(code string) string
- func (st *State) TranspileLineTokens(code string) Tokens
- func (st *State) TranspileMath(toks Tokens, code string, fullLine bool) Tokens
- type Token
- func (tk *Token) IsBacktickString() bool
- func (tk *Token) IsBracket() bool
- func (tk *Token) IsGo() bool
- func (tk *Token) IsOp() bool
- func (tk *Token) IsPathDelim() bool
- func (tk *Token) IsPathExtraDelim() bool
- func (tk *Token) IsValidExecIdent() bool
- func (tk *Token) IsWord() bool
- func (tk *Token) String() string
- type Tokens
- func (tk *Tokens) Add(tok token.Token, str ...string) *Token
- func (tk *Tokens) AddMulti(tok ...token.Token)
- func (tk *Tokens) AddTokens(toks ...*Token) *Tokens
- func (tk Tokens) BracketDepths() (paren, brace, brack int)
- func (tk Tokens) Code() string
- func (tk Tokens) Contains(toks ...token.Token) bool
- func (tk *Tokens) DeleteLastComma()
- func (tk *Tokens) Insert(i int, tok token.Token, str ...string) *Token
- func (tk Tokens) IsAssignExpr() bool
- func (tk Tokens) Last() *Token
- func (tk Tokens) ModeEnd() int
- func (tk Tokens) Path(idx0 bool) (string, int)
- func (tk Tokens) ReplaceIdentAt(at int, str string, n int) Tokens
- func (tk Tokens) RightMatching() int
- func (tk Tokens) String() string
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AddYaegiTensorFuncs ¶
func AddYaegiTensorFuncs()
AddYaegiTensorFuncs grabs all tensor* package functions registered in yaegicore and adds them to the `tensor.Funcs` map so we can properly convert symbols to either tensors or basic literals, depending on the arg types for the current function.
func ExecWordIsCommand ¶
ExecWordIsCommand returns true if given exec word is a command-like string (excluding any paths)
Types ¶
type State ¶
type State struct {
// FuncToVar translates function definitions into variable definitions,
// which is the default for interactive use of random code fragments
// without the complete go formatting.
// For pure transpiling of a complete codebase with full proper Go formatting
// this should be turned off.
FuncToVar bool
// MathMode is on when math mode is turned on.
MathMode bool
// MathRecord is state of auto-recording of data into current directory
// in math mode.
MathRecord bool
// depth of delim at the end of the current line. if 0, was complete.
ParenDepth, BraceDepth, BrackDepth, TypeDepth, DeclDepth int
// Chunks of code lines that are accumulated during Transpile,
// each of which should be evaluated separately, to avoid
// issues with contextual effects from import, package etc.
Chunks []string
// current stack of transpiled lines, that are accumulated into
// code Chunks.
Lines []string
// stack of runtime errors.
Errors []error
// contains filtered or unexported fields
}
State holds the transpiling state
func (*State) AddChunk ¶
func (st *State) AddChunk()
AddChunk adds current lines into a chunk of code that should be compiled separately.
func (*State) AddError ¶
AddError adds the given error to the error stack if it is non-nil, and calls the Cancel function if set, to stop execution. This is the main way that goal errors are handled. It also prints the error.
func (*State) Code ¶
Code returns the current transpiled lines, split into chunks that should be compiled separately.
func (*State) DepthError ¶
DepthError reports an error if any of the parsing depths are not zero, to be called at the end of transpiling a complete block of code.
func (*State) ResetCode ¶
func (st *State) ResetCode()
ResetCode resets the stack of transpiled code
func (*State) TotalDepth ¶
TotalDepth returns the sum of any unresolved paren, brace, or bracket depths.
func (*State) TranspileCode ¶
TranspileCode processes each line of given code, adding the results to the LineStack
func (*State) TranspileExec ¶
TranspileExec returns transpiled tokens assuming Exec code, with the given bools indicating the type of run to execute.
func (*State) TranspileExecString ¶
TranspileExecString returns transpiled tokens assuming Exec code, from a string, with the given bool indicating whether [Output] is needed.
func (*State) TranspileExecTokens ¶
TranspileExecTokens returns transpiled tokens assuming Exec code, from given tokens, with the given bool indicating whether [Output] is needed.
func (*State) TranspileFile ¶
TranspileFile transpiles the given input goal file to the given output Go file. If no existing package declaration is found, then package main and func main declarations are added. This also affects how functions are interpreted.
func (*State) TranspileGo ¶
TranspileGo returns transpiled tokens assuming Go code. Unpacks any encapsulated shell or math expressions.
func (*State) TranspileGoNDimIndex ¶
func (st *State) TranspileGoNDimIndex(toks Tokens, code string, gtoks *Tokens, idIdx, rbIdx int) int
TranspileGoNDimIndex processes an ident[*] sequence of tokens, translating it into a corresponding tensor Value or Set expression, if it is a multi-dimensional indexing expression which is not valid in Go, to support simple n-dimensional tensor indexing in Go (not math) mode. Gets the current sequence of toks tokens, where the ident starts at idIdx and the ] is at rbIdx. It puts the results in gtoks generated tokens. Returns a positive index to resume processing at, if it is actually an n-dimensional expr, and -1 if not, in which case the normal process resumes.
func (*State) TranspileGoRange ¶
TranspileGoRange returns transpiled tokens assuming Go code, for given start, end (exclusive) range of given tokens and code. In general the positions in the tokens applies to the _original_ code so you should just keep the original code string. However, this is needed for a specific case.
func (*State) TranspileLine ¶
TranspileLine is the main function for parsing a single line of goal input, returning a new transpiled line of code that converts Exec code into corresponding Go function calls.
func (*State) TranspileLineTokens ¶
TranspileLineTokens returns the tokens for the full line
type Token ¶
type Token struct {
// Go token classification
Tok token.Token
// Literal string
Str string
// position in the original string.
// this is only set for the original parse,
// not for transpiled additions.
Pos token.Pos
}
Token provides full data for one token
func (*Token) IsBacktickString ¶
IsBacktickString returns true if the given STRING uses backticks
func (*Token) IsBracket ¶
IsBracket returns true if the given token is a bracket delimiter: paren, brace, bracket
func (*Token) IsPathDelim ¶
func (*Token) IsPathExtraDelim ¶
func (*Token) IsValidExecIdent ¶
IsValidExecIdent returns true if the given token is a valid component of an Exec mode identifier
type Tokens ¶
type Tokens []*Token
Tokens is a slice of Token
func TokensFromString ¶
Tokens converts the string into tokens
func (Tokens) BracketDepths ¶
BracketDepths returns the depths for the three bracket delimiters [paren, bracket, brace], based on unmatched right versions.
func (Tokens) Code ¶
Code returns concatenated Str values of the tokens, to generate a surface-valid code string.
func (Tokens) Contains ¶
Contains returns true if the token string contains any of the given token(s)
func (*Tokens) DeleteLastComma ¶
func (tk *Tokens) DeleteLastComma()
DeleteLastComma removes any final Comma. easier to generate and delete at the end
func (Tokens) IsAssignExpr ¶
IsAssignExpr checks if there are any Go assignment or define tokens outside of { } Go code.
func (Tokens) ModeEnd ¶
ModeEnd returns the position (or -1 if not found) for the next ILLEGAL mode token ($ or #) given the starting one that is at the 0 position of the current set of tokens.
func (Tokens) Path ¶
Path extracts a standard path or URL expression from the current list of tokens (starting at index 0), returning the path string and the number of tokens included in the path. Restricts processing to contiguous elements with no spaces! If it is not a path, returns nil string, 0
func (Tokens) ReplaceIdentAt ¶
ReplaceIdentAt replaces an identifier spanning n tokens starting at given index, with a single identifier with given string. This is used in Exec mode for dealing with identifiers and paths that are separately-parsed by Go.
func (Tokens) RightMatching ¶
RightMatching returns the position (or -1 if not found) for the right matching [paren, bracket, brace] given the left one that is at the 0 position of the current set of tokens.