id
int32
0
167k
repo
stringlengths
5
54
path
stringlengths
4
155
func_name
stringlengths
1
118
original_string
stringlengths
52
85.5k
language
stringclasses
1 value
code
stringlengths
52
85.5k
code_tokens
listlengths
21
1.41k
docstring
stringlengths
6
2.61k
docstring_tokens
listlengths
3
215
sha
stringlengths
40
40
url
stringlengths
85
252
27,200
hyperledger/burrow
storage/rwtree.go
Save
func (rwt *RWTree) Save() ([]byte, int64, error) { // save state at a new version may still be orphaned before we save the version against the hash hash, version, err := rwt.tree.SaveVersion() if err != nil { return nil, 0, fmt.Errorf("could not save RWTree: %v", err) } // Take an immutable reference to the tree...
go
func (rwt *RWTree) Save() ([]byte, int64, error) { // save state at a new version may still be orphaned before we save the version against the hash hash, version, err := rwt.tree.SaveVersion() if err != nil { return nil, 0, fmt.Errorf("could not save RWTree: %v", err) } // Take an immutable reference to the tree...
[ "func", "(", "rwt", "*", "RWTree", ")", "Save", "(", ")", "(", "[", "]", "byte", ",", "int64", ",", "error", ")", "{", "// save state at a new version may still be orphaned before we save the version against the hash", "hash", ",", "version", ",", "err", ":=", "rw...
// Save the current write tree making writes accessible from read tree.
[ "Save", "the", "current", "write", "tree", "making", "writes", "accessible", "from", "read", "tree", "." ]
59993f5aad71a8e16ab6ed4e57e138e2398eae4e
https://github.com/hyperledger/burrow/blob/59993f5aad71a8e16ab6ed4e57e138e2398eae4e/storage/rwtree.go#L50-L63
27,201
hyperledger/burrow
execution/evm/stack.go
PushBytes
func (st *Stack) PushBytes(bz []byte) { if len(bz) != 32 { panic("Invalid bytes size: expected 32") } st.Push(LeftPadWord256(bz)) }
go
func (st *Stack) PushBytes(bz []byte) { if len(bz) != 32 { panic("Invalid bytes size: expected 32") } st.Push(LeftPadWord256(bz)) }
[ "func", "(", "st", "*", "Stack", ")", "PushBytes", "(", "bz", "[", "]", "byte", ")", "{", "if", "len", "(", "bz", ")", "!=", "32", "{", "panic", "(", "\"", "\"", ")", "\n", "}", "\n", "st", ".", "Push", "(", "LeftPadWord256", "(", "bz", ")", ...
// currently only called after sha3.Sha3
[ "currently", "only", "called", "after", "sha3", ".", "Sha3" ]
59993f5aad71a8e16ab6ed4e57e138e2398eae4e
https://github.com/hyperledger/burrow/blob/59993f5aad71a8e16ab6ed4e57e138e2398eae4e/execution/evm/stack.go#L74-L79
27,202
hyperledger/burrow
execution/evm/stack.go
PushBigInt
func (st *Stack) PushBigInt(bigInt *big.Int) Word256 { word := LeftPadWord256(U256(bigInt).Bytes()) st.Push(word) return word }
go
func (st *Stack) PushBigInt(bigInt *big.Int) Word256 { word := LeftPadWord256(U256(bigInt).Bytes()) st.Push(word) return word }
[ "func", "(", "st", "*", "Stack", ")", "PushBigInt", "(", "bigInt", "*", "big", ".", "Int", ")", "Word256", "{", "word", ":=", "LeftPadWord256", "(", "U256", "(", "bigInt", ")", ".", "Bytes", "(", ")", ")", "\n", "st", ".", "Push", "(", "word", ")...
// Pushes the bigInt as a Word256 encoding negative values in 32-byte twos complement and returns the encoded result
[ "Pushes", "the", "bigInt", "as", "a", "Word256", "encoding", "negative", "values", "in", "32", "-", "byte", "twos", "complement", "and", "returns", "the", "encoded", "result" ]
59993f5aad71a8e16ab6ed4e57e138e2398eae4e
https://github.com/hyperledger/burrow/blob/59993f5aad71a8e16ab6ed4e57e138e2398eae4e/execution/evm/stack.go#L94-L98
27,203
hyperledger/burrow
execution/evm/stack.go
Peek
func (st *Stack) Peek() Word256 { if st.ptr == 0 { st.pushErr(errors.ErrorCodeDataStackUnderflow) return Zero256 } return st.slice[st.ptr-1] }
go
func (st *Stack) Peek() Word256 { if st.ptr == 0 { st.pushErr(errors.ErrorCodeDataStackUnderflow) return Zero256 } return st.slice[st.ptr-1] }
[ "func", "(", "st", "*", "Stack", ")", "Peek", "(", ")", "Word256", "{", "if", "st", ".", "ptr", "==", "0", "{", "st", ".", "pushErr", "(", "errors", ".", "ErrorCodeDataStackUnderflow", ")", "\n", "return", "Zero256", "\n", "}", "\n", "return", "st", ...
// Not an opcode, costs no gas.
[ "Not", "an", "opcode", "costs", "no", "gas", "." ]
59993f5aad71a8e16ab6ed4e57e138e2398eae4e
https://github.com/hyperledger/burrow/blob/59993f5aad71a8e16ab6ed4e57e138e2398eae4e/execution/evm/stack.go#L170-L176
27,204
hyperledger/burrow
acm/acmstate/state_cache.go
NewCache
func NewCache(backend Reader, options ...CacheOption) *Cache { cache := &Cache{ backend: backend, accounts: make(map[crypto.Address]*accountInfo), } for _, option := range options { option(cache) } return cache }
go
func NewCache(backend Reader, options ...CacheOption) *Cache { cache := &Cache{ backend: backend, accounts: make(map[crypto.Address]*accountInfo), } for _, option := range options { option(cache) } return cache }
[ "func", "NewCache", "(", "backend", "Reader", ",", "options", "...", "CacheOption", ")", "*", "Cache", "{", "cache", ":=", "&", "Cache", "{", "backend", ":", "backend", ",", "accounts", ":", "make", "(", "map", "[", "crypto", ".", "Address", "]", "*", ...
// Returns a Cache that wraps an underlying Reader to use on a cache miss, can write to an output Writer // via Sync. Goroutine safe for concurrent access.
[ "Returns", "a", "Cache", "that", "wraps", "an", "underlying", "Reader", "to", "use", "on", "a", "cache", "miss", "can", "write", "to", "an", "output", "Writer", "via", "Sync", ".", "Goroutine", "safe", "for", "concurrent", "access", "." ]
59993f5aad71a8e16ab6ed4e57e138e2398eae4e
https://github.com/hyperledger/burrow/blob/59993f5aad71a8e16ab6ed4e57e138e2398eae4e/acm/acmstate/state_cache.go#L49-L58
27,205
hyperledger/burrow
acm/acmstate/state_cache.go
IterateCachedAccount
func (cache *Cache) IterateCachedAccount(consumer func(*acm.Account) (stop bool)) (stopped bool, err error) { // Try cache first for early exit cache.RLock() for _, info := range cache.accounts { if consumer(info.account) { cache.RUnlock() return true, nil } } cache.RUnlock() return false, nil }
go
func (cache *Cache) IterateCachedAccount(consumer func(*acm.Account) (stop bool)) (stopped bool, err error) { // Try cache first for early exit cache.RLock() for _, info := range cache.accounts { if consumer(info.account) { cache.RUnlock() return true, nil } } cache.RUnlock() return false, nil }
[ "func", "(", "cache", "*", "Cache", ")", "IterateCachedAccount", "(", "consumer", "func", "(", "*", "acm", ".", "Account", ")", "(", "stop", "bool", ")", ")", "(", "stopped", "bool", ",", "err", "error", ")", "{", "// Try cache first for early exit", "cach...
// Iterates over all cached accounts first in cache and then in backend until consumer returns true for 'stop'
[ "Iterates", "over", "all", "cached", "accounts", "first", "in", "cache", "and", "then", "in", "backend", "until", "consumer", "returns", "true", "for", "stop" ]
59993f5aad71a8e16ab6ed4e57e138e2398eae4e
https://github.com/hyperledger/burrow/blob/59993f5aad71a8e16ab6ed4e57e138e2398eae4e/acm/acmstate/state_cache.go#L125-L136
27,206
hyperledger/burrow
acm/acmstate/state_cache.go
IterateCachedStorage
func (cache *Cache) IterateCachedStorage(address crypto.Address, consumer func(key, value binary.Word256) error) error { accInfo, err := cache.get(address) if err != nil { return err } accInfo.RLock() // Try cache first for early exit for key, value := range accInfo.storage { if err := consumer(key, value); ...
go
func (cache *Cache) IterateCachedStorage(address crypto.Address, consumer func(key, value binary.Word256) error) error { accInfo, err := cache.get(address) if err != nil { return err } accInfo.RLock() // Try cache first for early exit for key, value := range accInfo.storage { if err := consumer(key, value); ...
[ "func", "(", "cache", "*", "Cache", ")", "IterateCachedStorage", "(", "address", "crypto", ".", "Address", ",", "consumer", "func", "(", "key", ",", "value", "binary", ".", "Word256", ")", "error", ")", "error", "{", "accInfo", ",", "err", ":=", "cache",...
// Iterates over all cached storage items first in cache and then in backend until consumer returns true for 'stop'
[ "Iterates", "over", "all", "cached", "storage", "items", "first", "in", "cache", "and", "then", "in", "backend", "until", "consumer", "returns", "true", "for", "stop" ]
59993f5aad71a8e16ab6ed4e57e138e2398eae4e
https://github.com/hyperledger/burrow/blob/59993f5aad71a8e16ab6ed4e57e138e2398eae4e/acm/acmstate/state_cache.go#L188-L204
27,207
hyperledger/burrow
acm/acmstate/state_cache.go
Sync
func (cache *Cache) Sync(st Writer) error { if cache.readonly { // Sync is (should be) a no-op for read-only - any modifications should have been caught in respective methods return nil } cache.Lock() defer cache.Unlock() var addresses crypto.Addresses for address := range cache.accounts { addresses = appen...
go
func (cache *Cache) Sync(st Writer) error { if cache.readonly { // Sync is (should be) a no-op for read-only - any modifications should have been caught in respective methods return nil } cache.Lock() defer cache.Unlock() var addresses crypto.Addresses for address := range cache.accounts { addresses = appen...
[ "func", "(", "cache", "*", "Cache", ")", "Sync", "(", "st", "Writer", ")", "error", "{", "if", "cache", ".", "readonly", "{", "// Sync is (should be) a no-op for read-only - any modifications should have been caught in respective methods", "return", "nil", "\n", "}", "\...
// Syncs changes to the backend in deterministic order. Sends storage updates before updating // the account they belong so that storage values can be taken account of in the update.
[ "Syncs", "changes", "to", "the", "backend", "in", "deterministic", "order", ".", "Sends", "storage", "updates", "before", "updating", "the", "account", "they", "belong", "so", "that", "storage", "values", "can", "be", "taken", "account", "of", "in", "the", "...
59993f5aad71a8e16ab6ed4e57e138e2398eae4e
https://github.com/hyperledger/burrow/blob/59993f5aad71a8e16ab6ed4e57e138e2398eae4e/acm/acmstate/state_cache.go#L208-L254
27,208
hyperledger/burrow
logging/logconfig/filter.go
matchLogLine
func matchLogLine(keyvals []interface{}, keyRegexes, valueRegexes []*regexp.Regexp, matchAll bool) bool { all := matchAll // We should be passed an aligned list of keyRegexes and valueRegexes, but since we can't error here we'll guard // against a failure of the caller to pass valid arguments length := len(keyRegex...
go
func matchLogLine(keyvals []interface{}, keyRegexes, valueRegexes []*regexp.Regexp, matchAll bool) bool { all := matchAll // We should be passed an aligned list of keyRegexes and valueRegexes, but since we can't error here we'll guard // against a failure of the caller to pass valid arguments length := len(keyRegex...
[ "func", "matchLogLine", "(", "keyvals", "[", "]", "interface", "{", "}", ",", "keyRegexes", ",", "valueRegexes", "[", "]", "*", "regexp", ".", "Regexp", ",", "matchAll", "bool", ")", "bool", "{", "all", ":=", "matchAll", "\n", "// We should be passed an alig...
// matchLogLine tries to match a log line by trying to match each key value pair with each pair of key value regexes // if matchAll is true then matchLogLine returns true iff every key value regexes finds a match or the line or regexes // are empty
[ "matchLogLine", "tries", "to", "match", "a", "log", "line", "by", "trying", "to", "match", "each", "key", "value", "pair", "with", "each", "pair", "of", "key", "value", "regexes", "if", "matchAll", "is", "true", "then", "matchLogLine", "returns", "true", "...
59993f5aad71a8e16ab6ed4e57e138e2398eae4e
https://github.com/hyperledger/burrow/blob/59993f5aad71a8e16ab6ed4e57e138e2398eae4e/logging/logconfig/filter.go#L54-L71
27,209
hyperledger/burrow
genesis/genesis.go
JSONBytes
func (genesisDoc *GenesisDoc) JSONBytes() ([]byte, error) { // Just in case genesisDoc.GenesisTime = genesisDoc.GenesisTime.UTC() return json.MarshalIndent(genesisDoc, "", "\t") }
go
func (genesisDoc *GenesisDoc) JSONBytes() ([]byte, error) { // Just in case genesisDoc.GenesisTime = genesisDoc.GenesisTime.UTC() return json.MarshalIndent(genesisDoc, "", "\t") }
[ "func", "(", "genesisDoc", "*", "GenesisDoc", ")", "JSONBytes", "(", ")", "(", "[", "]", "byte", ",", "error", ")", "{", "// Just in case", "genesisDoc", ".", "GenesisTime", "=", "genesisDoc", ".", "GenesisTime", ".", "UTC", "(", ")", "\n", "return", "js...
// JSONBytes returns the JSON canonical bytes for a given GenesisDoc or an error.
[ "JSONBytes", "returns", "the", "JSON", "canonical", "bytes", "for", "a", "given", "GenesisDoc", "or", "an", "error", "." ]
59993f5aad71a8e16ab6ed4e57e138e2398eae4e
https://github.com/hyperledger/burrow/blob/59993f5aad71a8e16ab6ed4e57e138e2398eae4e/genesis/genesis.go#L91-L95
27,210
hyperledger/burrow
genesis/genesis.go
Clone
func (genesisAccount *Account) Clone() Account { // clone the account permissions return Account{ BasicAccount: BasicAccount{ Address: genesisAccount.Address, Amount: genesisAccount.Amount, }, Name: genesisAccount.Name, Permissions: genesisAccount.Permissions.Clone(), } }
go
func (genesisAccount *Account) Clone() Account { // clone the account permissions return Account{ BasicAccount: BasicAccount{ Address: genesisAccount.Address, Amount: genesisAccount.Amount, }, Name: genesisAccount.Name, Permissions: genesisAccount.Permissions.Clone(), } }
[ "func", "(", "genesisAccount", "*", "Account", ")", "Clone", "(", ")", "Account", "{", "// clone the account permissions", "return", "Account", "{", "BasicAccount", ":", "BasicAccount", "{", "Address", ":", "genesisAccount", ".", "Address", ",", "Amount", ":", "...
// Clone clones the genesis account
[ "Clone", "clones", "the", "genesis", "account" ]
59993f5aad71a8e16ab6ed4e57e138e2398eae4e
https://github.com/hyperledger/burrow/blob/59993f5aad71a8e16ab6ed4e57e138e2398eae4e/genesis/genesis.go#L151-L161
27,211
hyperledger/burrow
genesis/genesis.go
Clone
func (gv *Validator) Clone() Validator { // clone the addresses to unbond to unbondToClone := make([]BasicAccount, len(gv.UnbondTo)) for i, basicAccount := range gv.UnbondTo { unbondToClone[i] = basicAccount.Clone() } return Validator{ BasicAccount: BasicAccount{ PublicKey: gv.PublicKey, Amount: gv.Am...
go
func (gv *Validator) Clone() Validator { // clone the addresses to unbond to unbondToClone := make([]BasicAccount, len(gv.UnbondTo)) for i, basicAccount := range gv.UnbondTo { unbondToClone[i] = basicAccount.Clone() } return Validator{ BasicAccount: BasicAccount{ PublicKey: gv.PublicKey, Amount: gv.Am...
[ "func", "(", "gv", "*", "Validator", ")", "Clone", "(", ")", "Validator", "{", "// clone the addresses to unbond to", "unbondToClone", ":=", "make", "(", "[", "]", "BasicAccount", ",", "len", "(", "gv", ".", "UnbondTo", ")", ")", "\n", "for", "i", ",", "...
// Clone clones the genesis validator
[ "Clone", "clones", "the", "genesis", "validator" ]
59993f5aad71a8e16ab6ed4e57e138e2398eae4e
https://github.com/hyperledger/burrow/blob/59993f5aad71a8e16ab6ed4e57e138e2398eae4e/genesis/genesis.go#L185-L200
27,212
hyperledger/burrow
genesis/genesis.go
MakeGenesisDocFromAccounts
func MakeGenesisDocFromAccounts(chainName string, salt []byte, genesisTime time.Time, accounts map[string]*acm.Account, validators map[string]*validator.Validator) *GenesisDoc { // Establish deterministic order of accounts by name so we obtain identical GenesisDoc // from identical input names := make([]string, 0,...
go
func MakeGenesisDocFromAccounts(chainName string, salt []byte, genesisTime time.Time, accounts map[string]*acm.Account, validators map[string]*validator.Validator) *GenesisDoc { // Establish deterministic order of accounts by name so we obtain identical GenesisDoc // from identical input names := make([]string, 0,...
[ "func", "MakeGenesisDocFromAccounts", "(", "chainName", "string", ",", "salt", "[", "]", "byte", ",", "genesisTime", "time", ".", "Time", ",", "accounts", "map", "[", "string", "]", "*", "acm", ".", "Account", ",", "validators", "map", "[", "string", "]", ...
// MakeGenesisDocFromAccounts takes a chainName and a slice of pointers to Account, // and a slice of pointers to Validator to construct a GenesisDoc, or returns an error on // failure. In particular MakeGenesisDocFromAccount uses the local time as a // timestamp for the GenesisDoc.
[ "MakeGenesisDocFromAccounts", "takes", "a", "chainName", "and", "a", "slice", "of", "pointers", "to", "Account", "and", "a", "slice", "of", "pointers", "to", "Validator", "to", "construct", "a", "GenesisDoc", "or", "returns", "an", "error", "on", "failure", "....
59993f5aad71a8e16ab6ed4e57e138e2398eae4e
https://github.com/hyperledger/burrow/blob/59993f5aad71a8e16ab6ed4e57e138e2398eae4e/genesis/genesis.go#L217-L266
27,213
hyperledger/burrow
acm/bytecode.go
Tokens
func (bc Bytecode) Tokens() ([]string, error) { // Overestimate of capacity in the presence of pushes tokens := make([]string, 0, len(bc)) for i := 0; i < len(bc); i++ { op, ok := asm.GetOpCode(bc[i]) if !ok { return tokens, fmt.Errorf("did not recognise byte %#x at position %v as an OpCode:\n %s", bc[i]...
go
func (bc Bytecode) Tokens() ([]string, error) { // Overestimate of capacity in the presence of pushes tokens := make([]string, 0, len(bc)) for i := 0; i < len(bc); i++ { op, ok := asm.GetOpCode(bc[i]) if !ok { return tokens, fmt.Errorf("did not recognise byte %#x at position %v as an OpCode:\n %s", bc[i]...
[ "func", "(", "bc", "Bytecode", ")", "Tokens", "(", ")", "(", "[", "]", "string", ",", "error", ")", "{", "// Overestimate of capacity in the presence of pushes", "tokens", ":=", "make", "(", "[", "]", "string", ",", "0", ",", "len", "(", "bc", ")", ")", ...
// Tokenises the bytecode into opcodes and values
[ "Tokenises", "the", "bytecode", "into", "opcodes", "and", "values" ]
59993f5aad71a8e16ab6ed4e57e138e2398eae4e
https://github.com/hyperledger/burrow/blob/59993f5aad71a8e16ab6ed4e57e138e2398eae4e/acm/bytecode.go#L94-L118
27,214
hyperledger/burrow
event/query/builder.go
NewBuilder
func NewBuilder(queries ...string) *Builder { qb := new(Builder) qb.queryString = qb.and(stringIterator(queries...)) return qb }
go
func NewBuilder(queries ...string) *Builder { qb := new(Builder) qb.queryString = qb.and(stringIterator(queries...)) return qb }
[ "func", "NewBuilder", "(", "queries", "...", "string", ")", "*", "Builder", "{", "qb", ":=", "new", "(", "Builder", ")", "\n", "qb", ".", "queryString", "=", "qb", ".", "and", "(", "stringIterator", "(", "queries", "...", ")", ")", "\n", "return", "q...
// Creates a new query builder with a base query that is the conjunction of all queries passed
[ "Creates", "a", "new", "query", "builder", "with", "a", "base", "query", "that", "is", "the", "conjunction", "of", "all", "queries", "passed" ]
59993f5aad71a8e16ab6ed4e57e138e2398eae4e
https://github.com/hyperledger/burrow/blob/59993f5aad71a8e16ab6ed4e57e138e2398eae4e/event/query/builder.go#L95-L99
27,215
hyperledger/burrow
event/query/builder.go
And
func (qb *Builder) And(queryBuilders ...*Builder) *Builder { return NewBuilder(qb.and(queryBuilderIterator(queryBuilders...))) }
go
func (qb *Builder) And(queryBuilders ...*Builder) *Builder { return NewBuilder(qb.and(queryBuilderIterator(queryBuilders...))) }
[ "func", "(", "qb", "*", "Builder", ")", "And", "(", "queryBuilders", "...", "*", "Builder", ")", "*", "Builder", "{", "return", "NewBuilder", "(", "qb", ".", "and", "(", "queryBuilderIterator", "(", "queryBuilders", "...", ")", ")", ")", "\n", "}" ]
// Creates the conjunction of Builder and rightQuery
[ "Creates", "the", "conjunction", "of", "Builder", "and", "rightQuery" ]
59993f5aad71a8e16ab6ed4e57e138e2398eae4e
https://github.com/hyperledger/burrow/blob/59993f5aad71a8e16ab6ed4e57e138e2398eae4e/event/query/builder.go#L120-L122
27,216
hyperledger/burrow
event/query/builder.go
AndEquals
func (qb *Builder) AndEquals(tag string, operand interface{}) *Builder { qb.condition.Tag = tag qb.condition.Op = equalString qb.condition.Operand = operandString(operand) return NewBuilder(qb.and(stringIterator(qb.conditionString()))) }
go
func (qb *Builder) AndEquals(tag string, operand interface{}) *Builder { qb.condition.Tag = tag qb.condition.Op = equalString qb.condition.Operand = operandString(operand) return NewBuilder(qb.and(stringIterator(qb.conditionString()))) }
[ "func", "(", "qb", "*", "Builder", ")", "AndEquals", "(", "tag", "string", ",", "operand", "interface", "{", "}", ")", "*", "Builder", "{", "qb", ".", "condition", ".", "Tag", "=", "tag", "\n", "qb", ".", "condition", ".", "Op", "=", "equalString", ...
// Creates the conjunction of Builder and tag = operand
[ "Creates", "the", "conjunction", "of", "Builder", "and", "tag", "=", "operand" ]
59993f5aad71a8e16ab6ed4e57e138e2398eae4e
https://github.com/hyperledger/burrow/blob/59993f5aad71a8e16ab6ed4e57e138e2398eae4e/event/query/builder.go#L125-L130
27,217
hyperledger/burrow
event/query/builder.go
stringIterator
func stringIterator(strs ...string) func(func(string)) { return func(callback func(string)) { for _, s := range strs { callback(s) } } }
go
func stringIterator(strs ...string) func(func(string)) { return func(callback func(string)) { for _, s := range strs { callback(s) } } }
[ "func", "stringIterator", "(", "strs", "...", "string", ")", "func", "(", "func", "(", "string", ")", ")", "{", "return", "func", "(", "callback", "func", "(", "string", ")", ")", "{", "for", "_", ",", "s", ":=", "range", "strs", "{", "callback", "...
// Iterators over some strings
[ "Iterators", "over", "some", "strings" ]
59993f5aad71a8e16ab6ed4e57e138e2398eae4e
https://github.com/hyperledger/burrow/blob/59993f5aad71a8e16ab6ed4e57e138e2398eae4e/event/query/builder.go#L260-L266
27,218
mvdan/sh
syntax/parser.go
NewParser
func NewParser(options ...func(*Parser)) *Parser { p := &Parser{helperBuf: new(bytes.Buffer)} for _, opt := range options { opt(p) } return p }
go
func NewParser(options ...func(*Parser)) *Parser { p := &Parser{helperBuf: new(bytes.Buffer)} for _, opt := range options { opt(p) } return p }
[ "func", "NewParser", "(", "options", "...", "func", "(", "*", "Parser", ")", ")", "*", "Parser", "{", "p", ":=", "&", "Parser", "{", "helperBuf", ":", "new", "(", "bytes", ".", "Buffer", ")", "}", "\n", "for", "_", ",", "opt", ":=", "range", "opt...
// NewParser allocates a new Parser and applies any number of options.
[ "NewParser", "allocates", "a", "new", "Parser", "and", "applies", "any", "number", "of", "options", "." ]
5700c68a35dc3882e646a5e41776e31bb2c078e3
https://github.com/mvdan/sh/blob/5700c68a35dc3882e646a5e41776e31bb2c078e3/syntax/parser.go#L69-L75
27,219
mvdan/sh
syntax/parser.go
Parse
func (p *Parser) Parse(r io.Reader, name string) (*File, error) { p.reset() p.f = &File{Name: name} p.src = r p.rune() p.next() p.f.Stmts, p.f.Last = p.stmtList() if p.err == nil { // EOF immediately after heredoc word so no newline to // trigger it p.doHeredocs() } return p.f, p.err }
go
func (p *Parser) Parse(r io.Reader, name string) (*File, error) { p.reset() p.f = &File{Name: name} p.src = r p.rune() p.next() p.f.Stmts, p.f.Last = p.stmtList() if p.err == nil { // EOF immediately after heredoc word so no newline to // trigger it p.doHeredocs() } return p.f, p.err }
[ "func", "(", "p", "*", "Parser", ")", "Parse", "(", "r", "io", ".", "Reader", ",", "name", "string", ")", "(", "*", "File", ",", "error", ")", "{", "p", ".", "reset", "(", ")", "\n", "p", ".", "f", "=", "&", "File", "{", "Name", ":", "name"...
// Parse reads and parses a shell program with an optional name. It // returns the parsed program if no issues were encountered. Otherwise, // an error is returned. Reads from r are buffered. // // Parse can be called more than once, but not concurrently. That is, a // Parser can be reused once it is done working.
[ "Parse", "reads", "and", "parses", "a", "shell", "program", "with", "an", "optional", "name", ".", "It", "returns", "the", "parsed", "program", "if", "no", "issues", "were", "encountered", ".", "Otherwise", "an", "error", "is", "returned", ".", "Reads", "f...
5700c68a35dc3882e646a5e41776e31bb2c078e3
https://github.com/mvdan/sh/blob/5700c68a35dc3882e646a5e41776e31bb2c078e3/syntax/parser.go#L83-L96
27,220
mvdan/sh
syntax/parser.go
Stmts
func (p *Parser) Stmts(r io.Reader, fn func(*Stmt) bool) error { p.reset() p.f = &File{} p.src = r p.rune() p.next() p.stmts(fn) if p.err == nil { // EOF immediately after heredoc word so no newline to // trigger it p.doHeredocs() } return p.err }
go
func (p *Parser) Stmts(r io.Reader, fn func(*Stmt) bool) error { p.reset() p.f = &File{} p.src = r p.rune() p.next() p.stmts(fn) if p.err == nil { // EOF immediately after heredoc word so no newline to // trigger it p.doHeredocs() } return p.err }
[ "func", "(", "p", "*", "Parser", ")", "Stmts", "(", "r", "io", ".", "Reader", ",", "fn", "func", "(", "*", "Stmt", ")", "bool", ")", "error", "{", "p", ".", "reset", "(", ")", "\n", "p", ".", "f", "=", "&", "File", "{", "}", "\n", "p", "....
// Stmts reads and parses statements one at a time, calling a function // each time one is parsed. If the function returns false, parsing is // stopped and the function is not called again.
[ "Stmts", "reads", "and", "parses", "statements", "one", "at", "a", "time", "calling", "a", "function", "each", "time", "one", "is", "parsed", ".", "If", "the", "function", "returns", "false", "parsing", "is", "stopped", "and", "the", "function", "is", "not...
5700c68a35dc3882e646a5e41776e31bb2c078e3
https://github.com/mvdan/sh/blob/5700c68a35dc3882e646a5e41776e31bb2c078e3/syntax/parser.go#L101-L114
27,221
mvdan/sh
syntax/parser.go
Words
func (p *Parser) Words(r io.Reader, fn func(*Word) bool) error { p.reset() p.f = &File{} p.src = r p.rune() p.next() for { p.got(_Newl) w := p.getWord() if w == nil { if p.tok != _EOF { p.curErr("%s is not a valid word", p.tok) } return p.err } if !fn(w) { return nil } } }
go
func (p *Parser) Words(r io.Reader, fn func(*Word) bool) error { p.reset() p.f = &File{} p.src = r p.rune() p.next() for { p.got(_Newl) w := p.getWord() if w == nil { if p.tok != _EOF { p.curErr("%s is not a valid word", p.tok) } return p.err } if !fn(w) { return nil } } }
[ "func", "(", "p", "*", "Parser", ")", "Words", "(", "r", "io", ".", "Reader", ",", "fn", "func", "(", "*", "Word", ")", "bool", ")", "error", "{", "p", ".", "reset", "(", ")", "\n", "p", ".", "f", "=", "&", "File", "{", "}", "\n", "p", "....
// Words reads and parses words one at a time, calling a function each time one // is parsed. If the function returns false, parsing is stopped and the function // is not called again. // // Newlines are skipped, meaning that multi-line input will work fine. If the // parser encounters a token that isn't a word, such a...
[ "Words", "reads", "and", "parses", "words", "one", "at", "a", "time", "calling", "a", "function", "each", "time", "one", "is", "parsed", ".", "If", "the", "function", "returns", "false", "parsing", "is", "stopped", "and", "the", "function", "is", "not", ...
5700c68a35dc3882e646a5e41776e31bb2c078e3
https://github.com/mvdan/sh/blob/5700c68a35dc3882e646a5e41776e31bb2c078e3/syntax/parser.go#L204-L223
27,222
mvdan/sh
syntax/parser.go
Document
func (p *Parser) Document(r io.Reader) (*Word, error) { p.reset() p.f = &File{} p.src = r p.rune() p.quote = hdocBody p.hdocStop = []byte("MVDAN_CC_SH_SYNTAX_EOF") p.parsingDoc = true p.next() w := p.getWord() return w, p.err }
go
func (p *Parser) Document(r io.Reader) (*Word, error) { p.reset() p.f = &File{} p.src = r p.rune() p.quote = hdocBody p.hdocStop = []byte("MVDAN_CC_SH_SYNTAX_EOF") p.parsingDoc = true p.next() w := p.getWord() return w, p.err }
[ "func", "(", "p", "*", "Parser", ")", "Document", "(", "r", "io", ".", "Reader", ")", "(", "*", "Word", ",", "error", ")", "{", "p", ".", "reset", "(", ")", "\n", "p", ".", "f", "=", "&", "File", "{", "}", "\n", "p", ".", "src", "=", "r",...
// Document parses a single here-document word. That is, it parses the input as // if they were lines following a <<EOF redirection. // // In practice, this is the same as parsing the input as if it were within // double quotes, but without having to escape all double quote characters. // Similarly, the here-document w...
[ "Document", "parses", "a", "single", "here", "-", "document", "word", ".", "That", "is", "it", "parses", "the", "input", "as", "if", "they", "were", "lines", "following", "a", "<<EOF", "redirection", ".", "In", "practice", "this", "is", "the", "same", "a...
5700c68a35dc3882e646a5e41776e31bb2c078e3
https://github.com/mvdan/sh/blob/5700c68a35dc3882e646a5e41776e31bb2c078e3/syntax/parser.go#L232-L243
27,223
mvdan/sh
syntax/parser.go
Incomplete
func (p *Parser) Incomplete() bool { // If we're in a quote state other than noState, we're parsing a node // such as a double-quoted string. // If there are any open statements, we need to finish them. // If we're constructing a literal, we need to finish it. return p.quote != noState || p.openStmts > 0 || p.litB...
go
func (p *Parser) Incomplete() bool { // If we're in a quote state other than noState, we're parsing a node // such as a double-quoted string. // If there are any open statements, we need to finish them. // If we're constructing a literal, we need to finish it. return p.quote != noState || p.openStmts > 0 || p.litB...
[ "func", "(", "p", "*", "Parser", ")", "Incomplete", "(", ")", "bool", "{", "// If we're in a quote state other than noState, we're parsing a node", "// such as a double-quoted string.", "// If there are any open statements, we need to finish them.", "// If we're constructing a literal, w...
// Incomplete reports whether the parser is waiting to read more bytes because // it needs to finish properly parsing a statement. // // It is only safe to call while the parser is blocked on a read. For an example // use case, see the documentation for Parser.Interactive.
[ "Incomplete", "reports", "whether", "the", "parser", "is", "waiting", "to", "read", "more", "bytes", "because", "it", "needs", "to", "finish", "properly", "parsing", "a", "statement", ".", "It", "is", "only", "safe", "to", "call", "while", "the", "parser", ...
5700c68a35dc3882e646a5e41776e31bb2c078e3
https://github.com/mvdan/sh/blob/5700c68a35dc3882e646a5e41776e31bb2c078e3/syntax/parser.go#L322-L328
27,224
mvdan/sh
syntax/parser.go
IsIncomplete
func IsIncomplete(err error) bool { perr, ok := err.(ParseError) return ok && perr.Incomplete }
go
func IsIncomplete(err error) bool { perr, ok := err.(ParseError) return ok && perr.Incomplete }
[ "func", "IsIncomplete", "(", "err", "error", ")", "bool", "{", "perr", ",", "ok", ":=", "err", ".", "(", "ParseError", ")", "\n", "return", "ok", "&&", "perr", ".", "Incomplete", "\n", "}" ]
// IsIncomplete reports whether a Parser error could have been avoided with // extra input bytes. For example, if an io.EOF was encountered while there was // an unclosed quote or parenthesis.
[ "IsIncomplete", "reports", "whether", "a", "Parser", "error", "could", "have", "been", "avoided", "with", "extra", "input", "bytes", ".", "For", "example", "if", "an", "io", ".", "EOF", "was", "encountered", "while", "there", "was", "an", "unclosed", "quote"...
5700c68a35dc3882e646a5e41776e31bb2c078e3
https://github.com/mvdan/sh/blob/5700c68a35dc3882e646a5e41776e31bb2c078e3/syntax/parser.go#L653-L656
27,225
mvdan/sh
syntax/parser.go
ValidName
func ValidName(val string) bool { if val == "" { return false } for i, r := range val { switch { case 'a' <= r && r <= 'z': case 'A' <= r && r <= 'Z': case r == '_': case i > 0 && '0' <= r && r <= '9': default: return false } } return true }
go
func ValidName(val string) bool { if val == "" { return false } for i, r := range val { switch { case 'a' <= r && r <= 'z': case 'A' <= r && r <= 'Z': case r == '_': case i > 0 && '0' <= r && r <= '9': default: return false } } return true }
[ "func", "ValidName", "(", "val", "string", ")", "bool", "{", "if", "val", "==", "\"", "\"", "{", "return", "false", "\n", "}", "\n", "for", "i", ",", "r", ":=", "range", "val", "{", "switch", "{", "case", "'a'", "<=", "r", "&&", "r", "<=", "'z'...
// ValidName returns whether val is a valid name as per the POSIX spec.
[ "ValidName", "returns", "whether", "val", "is", "a", "valid", "name", "as", "per", "the", "POSIX", "spec", "." ]
5700c68a35dc3882e646a5e41776e31bb2c078e3
https://github.com/mvdan/sh/blob/5700c68a35dc3882e646a5e41776e31bb2c078e3/syntax/parser.go#L1499-L1514
27,226
mvdan/sh
expand/environ.go
String
func (v Variable) String() string { switch v.Kind { case String: return v.Str case Indexed: if len(v.List) > 0 { return v.List[0] } case Associative: // nothing to do } return "" }
go
func (v Variable) String() string { switch v.Kind { case String: return v.Str case Indexed: if len(v.List) > 0 { return v.List[0] } case Associative: // nothing to do } return "" }
[ "func", "(", "v", "Variable", ")", "String", "(", ")", "string", "{", "switch", "v", ".", "Kind", "{", "case", "String", ":", "return", "v", ".", "Str", "\n", "case", "Indexed", ":", "if", "len", "(", "v", ".", "List", ")", ">", "0", "{", "retu...
// String returns the variable's value as a string. In general, this only makes // sense if the variable has a string value or no value at all.
[ "String", "returns", "the", "variable", "s", "value", "as", "a", "string", ".", "In", "general", "this", "only", "makes", "sense", "if", "the", "variable", "has", "a", "string", "value", "or", "no", "value", "at", "all", "." ]
5700c68a35dc3882e646a5e41776e31bb2c078e3
https://github.com/mvdan/sh/blob/5700c68a35dc3882e646a5e41776e31bb2c078e3/expand/environ.go#L88-L100
27,227
mvdan/sh
expand/environ.go
Resolve
func (v Variable) Resolve(env Environ) (string, Variable) { name := "" for i := 0; i < maxNameRefDepth; i++ { if v.Kind != NameRef { return name, v } name = v.Str // keep name for the next iteration v = env.Get(name) } return name, Variable{} }
go
func (v Variable) Resolve(env Environ) (string, Variable) { name := "" for i := 0; i < maxNameRefDepth; i++ { if v.Kind != NameRef { return name, v } name = v.Str // keep name for the next iteration v = env.Get(name) } return name, Variable{} }
[ "func", "(", "v", "Variable", ")", "Resolve", "(", "env", "Environ", ")", "(", "string", ",", "Variable", ")", "{", "name", ":=", "\"", "\"", "\n", "for", "i", ":=", "0", ";", "i", "<", "maxNameRefDepth", ";", "i", "++", "{", "if", "v", ".", "K...
// Resolve follows a number of nameref variables, returning the last reference // name that was followed and the variable that it points to.
[ "Resolve", "follows", "a", "number", "of", "nameref", "variables", "returning", "the", "last", "reference", "name", "that", "was", "followed", "and", "the", "variable", "that", "it", "points", "to", "." ]
5700c68a35dc3882e646a5e41776e31bb2c078e3
https://github.com/mvdan/sh/blob/5700c68a35dc3882e646a5e41776e31bb2c078e3/expand/environ.go#L109-L119
27,228
mvdan/sh
expand/environ.go
listEnvironWithUpper
func listEnvironWithUpper(upper bool, pairs ...string) Environ { list := append([]string{}, pairs...) if upper { // Uppercase before sorting, so that we can remove duplicates // without the need for linear search nor a map. for i, s := range list { if sep := strings.IndexByte(s, '='); sep > 0 { list[i] =...
go
func listEnvironWithUpper(upper bool, pairs ...string) Environ { list := append([]string{}, pairs...) if upper { // Uppercase before sorting, so that we can remove duplicates // without the need for linear search nor a map. for i, s := range list { if sep := strings.IndexByte(s, '='); sep > 0 { list[i] =...
[ "func", "listEnvironWithUpper", "(", "upper", "bool", ",", "pairs", "...", "string", ")", "Environ", "{", "list", ":=", "append", "(", "[", "]", "string", "{", "}", ",", "pairs", "...", ")", "\n", "if", "upper", "{", "// Uppercase before sorting, so that we ...
// listEnvironWithUpper implements ListEnviron, but letting the tests specify // whether to uppercase all names or not.
[ "listEnvironWithUpper", "implements", "ListEnviron", "but", "letting", "the", "tests", "specify", "whether", "to", "uppercase", "all", "names", "or", "not", "." ]
5700c68a35dc3882e646a5e41776e31bb2c078e3
https://github.com/mvdan/sh/blob/5700c68a35dc3882e646a5e41776e31bb2c078e3/expand/environ.go#L153-L184
27,229
mvdan/sh
interp/perm_unix.go
hasPermissionToDir
func hasPermissionToDir(info os.FileInfo) bool { user, err := user.Current() if err != nil { return true } uid, _ := strconv.Atoi(user.Uid) // super-user if uid == 0 { return true } st, _ := info.Sys().(*syscall.Stat_t) if st == nil { return true } perm := info.Mode().Perm() // user (u) if perm&0100...
go
func hasPermissionToDir(info os.FileInfo) bool { user, err := user.Current() if err != nil { return true } uid, _ := strconv.Atoi(user.Uid) // super-user if uid == 0 { return true } st, _ := info.Sys().(*syscall.Stat_t) if st == nil { return true } perm := info.Mode().Perm() // user (u) if perm&0100...
[ "func", "hasPermissionToDir", "(", "info", "os", ".", "FileInfo", ")", "bool", "{", "user", ",", "err", ":=", "user", ".", "Current", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "true", "\n", "}", "\n", "uid", ",", "_", ":=", "strconv"...
// hasPermissionToDir returns if the OS current user has execute permission // to the given directory
[ "hasPermissionToDir", "returns", "if", "the", "OS", "current", "user", "has", "execute", "permission", "to", "the", "given", "directory" ]
5700c68a35dc3882e646a5e41776e31bb2c078e3
https://github.com/mvdan/sh/blob/5700c68a35dc3882e646a5e41776e31bb2c078e3/interp/perm_unix.go#L17-L49
27,230
mvdan/sh
shell/source.go
SourceFile
func SourceFile(ctx context.Context, path string) (map[string]expand.Variable, error) { f, err := os.Open(path) if err != nil { return nil, fmt.Errorf("could not open: %v", err) } defer f.Close() file, err := syntax.NewParser().Parse(f, path) if err != nil { return nil, fmt.Errorf("could not parse: %v", err) ...
go
func SourceFile(ctx context.Context, path string) (map[string]expand.Variable, error) { f, err := os.Open(path) if err != nil { return nil, fmt.Errorf("could not open: %v", err) } defer f.Close() file, err := syntax.NewParser().Parse(f, path) if err != nil { return nil, fmt.Errorf("could not parse: %v", err) ...
[ "func", "SourceFile", "(", "ctx", "context", ".", "Context", ",", "path", "string", ")", "(", "map", "[", "string", "]", "expand", ".", "Variable", ",", "error", ")", "{", "f", ",", "err", ":=", "os", ".", "Open", "(", "path", ")", "\n", "if", "e...
// SourceFile sources a shell file from disk and returns the variables // declared in it. It is a convenience function that uses a default shell // parser, parses a file from disk, and calls SourceNode. // // This function should be used with caution, as it can interpret arbitrary // code. Untrusted shell programs shou...
[ "SourceFile", "sources", "a", "shell", "file", "from", "disk", "and", "returns", "the", "variables", "declared", "in", "it", ".", "It", "is", "a", "convenience", "function", "that", "uses", "a", "default", "shell", "parser", "parses", "a", "file", "from", ...
5700c68a35dc3882e646a5e41776e31bb2c078e3
https://github.com/mvdan/sh/blob/5700c68a35dc3882e646a5e41776e31bb2c078e3/shell/source.go#L23-L34
27,231
mvdan/sh
interp/interp.go
New
func New(opts ...func(*Runner) error) (*Runner, error) { r := &Runner{usedNew: true} r.dirStack = r.dirBootstrap[:0] for _, opt := range opts { if err := opt(r); err != nil { return nil, err } } // Set the default fallbacks, if necessary. if r.Env == nil { Env(nil)(r) } if r.Dir == "" { if err := Dir...
go
func New(opts ...func(*Runner) error) (*Runner, error) { r := &Runner{usedNew: true} r.dirStack = r.dirBootstrap[:0] for _, opt := range opts { if err := opt(r); err != nil { return nil, err } } // Set the default fallbacks, if necessary. if r.Env == nil { Env(nil)(r) } if r.Dir == "" { if err := Dir...
[ "func", "New", "(", "opts", "...", "func", "(", "*", "Runner", ")", "error", ")", "(", "*", "Runner", ",", "error", ")", "{", "r", ":=", "&", "Runner", "{", "usedNew", ":", "true", "}", "\n", "r", ".", "dirStack", "=", "r", ".", "dirBootstrap", ...
// New creates a new Runner, applying a number of options. If applying any of // the options results in an error, it is returned. // // Any unset options fall back to their defaults. For example, not supplying the // environment falls back to the process's environment, and not supplying the // standard output writer me...
[ "New", "creates", "a", "new", "Runner", "applying", "a", "number", "of", "options", ".", "If", "applying", "any", "of", "the", "options", "results", "in", "an", "error", "it", "is", "returned", ".", "Any", "unset", "options", "fall", "back", "to", "their...
5700c68a35dc3882e646a5e41776e31bb2c078e3
https://github.com/mvdan/sh/blob/5700c68a35dc3882e646a5e41776e31bb2c078e3/interp/interp.go#L34-L61
27,232
mvdan/sh
interp/interp.go
Env
func Env(env expand.Environ) func(*Runner) error { return func(r *Runner) error { if env == nil { env = expand.ListEnviron(os.Environ()...) } r.Env = env return nil } }
go
func Env(env expand.Environ) func(*Runner) error { return func(r *Runner) error { if env == nil { env = expand.ListEnviron(os.Environ()...) } r.Env = env return nil } }
[ "func", "Env", "(", "env", "expand", ".", "Environ", ")", "func", "(", "*", "Runner", ")", "error", "{", "return", "func", "(", "r", "*", "Runner", ")", "error", "{", "if", "env", "==", "nil", "{", "env", "=", "expand", ".", "ListEnviron", "(", "...
// Env sets the interpreter's environment. If nil, a copy of the current // process's environment is used.
[ "Env", "sets", "the", "interpreter", "s", "environment", ".", "If", "nil", "a", "copy", "of", "the", "current", "process", "s", "environment", "is", "used", "." ]
5700c68a35dc3882e646a5e41776e31bb2c078e3
https://github.com/mvdan/sh/blob/5700c68a35dc3882e646a5e41776e31bb2c078e3/interp/interp.go#L181-L189
27,233
mvdan/sh
interp/interp.go
Dir
func Dir(path string) func(*Runner) error { return func(r *Runner) error { if path == "" { path, err := os.Getwd() if err != nil { return fmt.Errorf("could not get current dir: %v", err) } r.Dir = path return nil } path, err := filepath.Abs(path) if err != nil { return fmt.Errorf("could n...
go
func Dir(path string) func(*Runner) error { return func(r *Runner) error { if path == "" { path, err := os.Getwd() if err != nil { return fmt.Errorf("could not get current dir: %v", err) } r.Dir = path return nil } path, err := filepath.Abs(path) if err != nil { return fmt.Errorf("could n...
[ "func", "Dir", "(", "path", "string", ")", "func", "(", "*", "Runner", ")", "error", "{", "return", "func", "(", "r", "*", "Runner", ")", "error", "{", "if", "path", "==", "\"", "\"", "{", "path", ",", "err", ":=", "os", ".", "Getwd", "(", ")",...
// Dir sets the interpreter's working directory. If empty, the process's current // directory is used.
[ "Dir", "sets", "the", "interpreter", "s", "working", "directory", ".", "If", "empty", "the", "process", "s", "current", "directory", "is", "used", "." ]
5700c68a35dc3882e646a5e41776e31bb2c078e3
https://github.com/mvdan/sh/blob/5700c68a35dc3882e646a5e41776e31bb2c078e3/interp/interp.go#L193-L217
27,234
mvdan/sh
interp/interp.go
Module
func Module(mod ModuleFunc) func(*Runner) error { return func(r *Runner) error { switch mod := mod.(type) { case ModuleExec: if mod == nil { mod = DefaultExec } r.Exec = mod case ModuleOpen: if mod == nil { mod = DefaultOpen } r.Open = mod default: return fmt.Errorf("unknown module...
go
func Module(mod ModuleFunc) func(*Runner) error { return func(r *Runner) error { switch mod := mod.(type) { case ModuleExec: if mod == nil { mod = DefaultExec } r.Exec = mod case ModuleOpen: if mod == nil { mod = DefaultOpen } r.Open = mod default: return fmt.Errorf("unknown module...
[ "func", "Module", "(", "mod", "ModuleFunc", ")", "func", "(", "*", "Runner", ")", "error", "{", "return", "func", "(", "r", "*", "Runner", ")", "error", "{", "switch", "mod", ":=", "mod", ".", "(", "type", ")", "{", "case", "ModuleExec", ":", "if",...
// Module sets an interpreter module, which can be ModuleExec or ModuleOpen. If // the value is nil, the default module implementation is used.
[ "Module", "sets", "an", "interpreter", "module", "which", "can", "be", "ModuleExec", "or", "ModuleOpen", ".", "If", "the", "value", "is", "nil", "the", "default", "module", "implementation", "is", "used", "." ]
5700c68a35dc3882e646a5e41776e31bb2c078e3
https://github.com/mvdan/sh/blob/5700c68a35dc3882e646a5e41776e31bb2c078e3/interp/interp.go#L283-L301
27,235
mvdan/sh
interp/interp.go
StdIO
func StdIO(in io.Reader, out, err io.Writer) func(*Runner) error { return func(r *Runner) error { r.Stdin = in if out == nil { out = ioutil.Discard } r.Stdout = out if err == nil { err = ioutil.Discard } r.Stderr = err return nil } }
go
func StdIO(in io.Reader, out, err io.Writer) func(*Runner) error { return func(r *Runner) error { r.Stdin = in if out == nil { out = ioutil.Discard } r.Stdout = out if err == nil { err = ioutil.Discard } r.Stderr = err return nil } }
[ "func", "StdIO", "(", "in", "io", ".", "Reader", ",", "out", ",", "err", "io", ".", "Writer", ")", "func", "(", "*", "Runner", ")", "error", "{", "return", "func", "(", "r", "*", "Runner", ")", "error", "{", "r", ".", "Stdin", "=", "in", "\n", ...
// StdIO configures an interpreter's standard input, standard output, and // standard error. If out or err are nil, they default to a writer that discards // the output.
[ "StdIO", "configures", "an", "interpreter", "s", "standard", "input", "standard", "output", "and", "standard", "error", ".", "If", "out", "or", "err", "are", "nil", "they", "default", "to", "a", "writer", "that", "discards", "the", "output", "." ]
5700c68a35dc3882e646a5e41776e31bb2c078e3
https://github.com/mvdan/sh/blob/5700c68a35dc3882e646a5e41776e31bb2c078e3/interp/interp.go#L306-L319
27,236
mvdan/sh
expand/expand.go
Literal
func Literal(cfg *Config, word *syntax.Word) (string, error) { if word == nil { return "", nil } cfg = prepareConfig(cfg) field, err := cfg.wordField(word.Parts, quoteNone) if err != nil { return "", err } return cfg.fieldJoin(field), nil }
go
func Literal(cfg *Config, word *syntax.Word) (string, error) { if word == nil { return "", nil } cfg = prepareConfig(cfg) field, err := cfg.wordField(word.Parts, quoteNone) if err != nil { return "", err } return cfg.fieldJoin(field), nil }
[ "func", "Literal", "(", "cfg", "*", "Config", ",", "word", "*", "syntax", ".", "Word", ")", "(", "string", ",", "error", ")", "{", "if", "word", "==", "nil", "{", "return", "\"", "\"", ",", "nil", "\n", "}", "\n", "cfg", "=", "prepareConfig", "("...
// Literal expands a single shell word. It is similar to Fields, but the result // is a single string. This is the behavior when a word is used as the value in // a shell variable assignment, for example. // // The config specifies shell expansion options; nil behaves the same as an // empty config.
[ "Literal", "expands", "a", "single", "shell", "word", ".", "It", "is", "similar", "to", "Fields", "but", "the", "result", "is", "a", "single", "string", ".", "This", "is", "the", "behavior", "when", "a", "word", "is", "used", "as", "the", "value", "in"...
5700c68a35dc3882e646a5e41776e31bb2c078e3
https://github.com/mvdan/sh/blob/5700c68a35dc3882e646a5e41776e31bb2c078e3/expand/expand.go#L130-L140
27,237
mvdan/sh
expand/expand.go
Document
func Document(cfg *Config, word *syntax.Word) (string, error) { if word == nil { return "", nil } cfg = prepareConfig(cfg) field, err := cfg.wordField(word.Parts, quoteDouble) if err != nil { return "", err } return cfg.fieldJoin(field), nil }
go
func Document(cfg *Config, word *syntax.Word) (string, error) { if word == nil { return "", nil } cfg = prepareConfig(cfg) field, err := cfg.wordField(word.Parts, quoteDouble) if err != nil { return "", err } return cfg.fieldJoin(field), nil }
[ "func", "Document", "(", "cfg", "*", "Config", ",", "word", "*", "syntax", ".", "Word", ")", "(", "string", ",", "error", ")", "{", "if", "word", "==", "nil", "{", "return", "\"", "\"", ",", "nil", "\n", "}", "\n", "cfg", "=", "prepareConfig", "(...
// Document expands a single shell word as if it were within double quotes. It // is simlar to Literal, but without brace expansion, tilde expansion, and // globbing. // // The config specifies shell expansion options; nil behaves the same as an // empty config.
[ "Document", "expands", "a", "single", "shell", "word", "as", "if", "it", "were", "within", "double", "quotes", ".", "It", "is", "simlar", "to", "Literal", "but", "without", "brace", "expansion", "tilde", "expansion", "and", "globbing", ".", "The", "config", ...
5700c68a35dc3882e646a5e41776e31bb2c078e3
https://github.com/mvdan/sh/blob/5700c68a35dc3882e646a5e41776e31bb2c078e3/expand/expand.go#L148-L158
27,238
mvdan/sh
expand/expand.go
Pattern
func Pattern(cfg *Config, word *syntax.Word) (string, error) { cfg = prepareConfig(cfg) field, err := cfg.wordField(word.Parts, quoteNone) if err != nil { return "", err } buf := cfg.strBuilder() for _, part := range field { if part.quote > quoteNone { buf.WriteString(syntax.QuotePattern(part.val)) } els...
go
func Pattern(cfg *Config, word *syntax.Word) (string, error) { cfg = prepareConfig(cfg) field, err := cfg.wordField(word.Parts, quoteNone) if err != nil { return "", err } buf := cfg.strBuilder() for _, part := range field { if part.quote > quoteNone { buf.WriteString(syntax.QuotePattern(part.val)) } els...
[ "func", "Pattern", "(", "cfg", "*", "Config", ",", "word", "*", "syntax", ".", "Word", ")", "(", "string", ",", "error", ")", "{", "cfg", "=", "prepareConfig", "(", "cfg", ")", "\n", "field", ",", "err", ":=", "cfg", ".", "wordField", "(", "word", ...
// Pattern expands a single shell word as a pattern, using syntax.QuotePattern // on any non-quoted parts of the input word. The result can be used on // syntax.TranslatePattern directly. // // The config specifies shell expansion options; nil behaves the same as an // empty config.
[ "Pattern", "expands", "a", "single", "shell", "word", "as", "a", "pattern", "using", "syntax", ".", "QuotePattern", "on", "any", "non", "-", "quoted", "parts", "of", "the", "input", "word", ".", "The", "result", "can", "be", "used", "on", "syntax", ".", ...
5700c68a35dc3882e646a5e41776e31bb2c078e3
https://github.com/mvdan/sh/blob/5700c68a35dc3882e646a5e41776e31bb2c078e3/expand/expand.go#L166-L181
27,239
mvdan/sh
expand/expand.go
Fields
func Fields(cfg *Config, words ...*syntax.Word) ([]string, error) { cfg = prepareConfig(cfg) fields := make([]string, 0, len(words)) dir := cfg.envGet("PWD") for _, word := range words { afterBraces := []*syntax.Word{word} if w2 := syntax.SplitBraces(word); w2 != word { afterBraces = Braces(w2) } for _, ...
go
func Fields(cfg *Config, words ...*syntax.Word) ([]string, error) { cfg = prepareConfig(cfg) fields := make([]string, 0, len(words)) dir := cfg.envGet("PWD") for _, word := range words { afterBraces := []*syntax.Word{word} if w2 := syntax.SplitBraces(word); w2 != word { afterBraces = Braces(w2) } for _, ...
[ "func", "Fields", "(", "cfg", "*", "Config", ",", "words", "...", "*", "syntax", ".", "Word", ")", "(", "[", "]", "string", ",", "error", ")", "{", "cfg", "=", "prepareConfig", "(", "cfg", ")", "\n", "fields", ":=", "make", "(", "[", "]", "string...
// Fields expands a number of words as if they were arguments in a shell // command. This includes brace expansion, tilde expansion, parameter expansion, // command substitution, arithmetic expansion, and quote removal.
[ "Fields", "expands", "a", "number", "of", "words", "as", "if", "they", "were", "arguments", "in", "a", "shell", "command", ".", "This", "includes", "brace", "expansion", "tilde", "expansion", "parameter", "expansion", "command", "substitution", "arithmetic", "ex...
5700c68a35dc3882e646a5e41776e31bb2c078e3
https://github.com/mvdan/sh/blob/5700c68a35dc3882e646a5e41776e31bb2c078e3/expand/expand.go#L363-L395
27,240
mvdan/sh
expand/expand.go
pathJoin2
func pathJoin2(elem1, elem2 string) string { if elem1 == "" { return elem2 } if strings.HasSuffix(elem1, string(filepath.Separator)) { return elem1 + elem2 } return elem1 + string(filepath.Separator) + elem2 }
go
func pathJoin2(elem1, elem2 string) string { if elem1 == "" { return elem2 } if strings.HasSuffix(elem1, string(filepath.Separator)) { return elem1 + elem2 } return elem1 + string(filepath.Separator) + elem2 }
[ "func", "pathJoin2", "(", "elem1", ",", "elem2", "string", ")", "string", "{", "if", "elem1", "==", "\"", "\"", "{", "return", "elem2", "\n", "}", "\n", "if", "strings", ".", "HasSuffix", "(", "elem1", ",", "string", "(", "filepath", ".", "Separator", ...
// pathJoin2 is a simpler version of filepath.Join without cleaning the result, // since that's needed for globbing.
[ "pathJoin2", "is", "a", "simpler", "version", "of", "filepath", ".", "Join", "without", "cleaning", "the", "result", "since", "that", "s", "needed", "for", "globbing", "." ]
5700c68a35dc3882e646a5e41776e31bb2c078e3
https://github.com/mvdan/sh/blob/5700c68a35dc3882e646a5e41776e31bb2c078e3/expand/expand.go#L651-L659
27,241
mvdan/sh
expand/expand.go
pathSplit
func pathSplit(path string) []string { path = filepath.FromSlash(path) return strings.Split(path, string(filepath.Separator)) }
go
func pathSplit(path string) []string { path = filepath.FromSlash(path) return strings.Split(path, string(filepath.Separator)) }
[ "func", "pathSplit", "(", "path", "string", ")", "[", "]", "string", "{", "path", "=", "filepath", ".", "FromSlash", "(", "path", ")", "\n", "return", "strings", ".", "Split", "(", "path", ",", "string", "(", "filepath", ".", "Separator", ")", ")", "...
// pathSplit splits a file path into its elements, retaining empty ones. Before // splitting, slashes are replaced with filepath.Separator, so that splitting // Unix paths on Windows works as well.
[ "pathSplit", "splits", "a", "file", "path", "into", "its", "elements", "retaining", "empty", "ones", ".", "Before", "splitting", "slashes", "are", "replaced", "with", "filepath", ".", "Separator", "so", "that", "splitting", "Unix", "paths", "on", "Windows", "w...
5700c68a35dc3882e646a5e41776e31bb2c078e3
https://github.com/mvdan/sh/blob/5700c68a35dc3882e646a5e41776e31bb2c078e3/expand/expand.go#L664-L667
27,242
mvdan/sh
fileutil/file.go
CouldBeScript
func CouldBeScript(info os.FileInfo) ScriptConfidence { name := info.Name() switch { case info.IsDir(), name[0] == '.': return ConfNotScript case info.Mode()&os.ModeSymlink != 0: return ConfNotScript case extRe.MatchString(name): return ConfIsScript case strings.IndexByte(name, '.') > 0: return ConfNotScr...
go
func CouldBeScript(info os.FileInfo) ScriptConfidence { name := info.Name() switch { case info.IsDir(), name[0] == '.': return ConfNotScript case info.Mode()&os.ModeSymlink != 0: return ConfNotScript case extRe.MatchString(name): return ConfIsScript case strings.IndexByte(name, '.') > 0: return ConfNotScr...
[ "func", "CouldBeScript", "(", "info", "os", ".", "FileInfo", ")", "ScriptConfidence", "{", "name", ":=", "info", ".", "Name", "(", ")", "\n", "switch", "{", "case", "info", ".", "IsDir", "(", ")", ",", "name", "[", "0", "]", "==", "'.'", ":", "retu...
// CouldBeScript reports how likely a file is to be a shell script. It // discards directories, symlinks, hidden files and files with non-shell // extensions.
[ "CouldBeScript", "reports", "how", "likely", "a", "file", "is", "to", "be", "a", "shell", "script", ".", "It", "discards", "directories", "symlinks", "hidden", "files", "and", "files", "with", "non", "-", "shell", "extensions", "." ]
5700c68a35dc3882e646a5e41776e31bb2c078e3
https://github.com/mvdan/sh/blob/5700c68a35dc3882e646a5e41776e31bb2c078e3/fileutil/file.go#L39-L55
27,243
mvdan/sh
expand/arith.go
atoi
func atoi(s string) int { n, _ := strconv.Atoi(s) return n }
go
func atoi(s string) int { n, _ := strconv.Atoi(s) return n }
[ "func", "atoi", "(", "s", "string", ")", "int", "{", "n", ",", "_", ":=", "strconv", ".", "Atoi", "(", "s", ")", "\n", "return", "n", "\n", "}" ]
// atoi is just a shorthand for strconv.Atoi that ignores the error, // just like shells do.
[ "atoi", "is", "just", "a", "shorthand", "for", "strconv", ".", "Atoi", "that", "ignores", "the", "error", "just", "like", "shells", "do", "." ]
5700c68a35dc3882e646a5e41776e31bb2c078e3
https://github.com/mvdan/sh/blob/5700c68a35dc3882e646a5e41776e31bb2c078e3/expand/arith.go#L110-L113
27,244
mvdan/sh
shell/expand.go
Fields
func Fields(s string, env func(string) string) ([]string, error) { p := syntax.NewParser() var words []*syntax.Word err := p.Words(strings.NewReader(s), func(w *syntax.Word) bool { words = append(words, w) return true }) if err != nil { return nil, err } if env == nil { env = os.Getenv } cfg := &expand...
go
func Fields(s string, env func(string) string) ([]string, error) { p := syntax.NewParser() var words []*syntax.Word err := p.Words(strings.NewReader(s), func(w *syntax.Word) bool { words = append(words, w) return true }) if err != nil { return nil, err } if env == nil { env = os.Getenv } cfg := &expand...
[ "func", "Fields", "(", "s", "string", ",", "env", "func", "(", "string", ")", "string", ")", "(", "[", "]", "string", ",", "error", ")", "{", "p", ":=", "syntax", ".", "NewParser", "(", ")", "\n", "var", "words", "[", "]", "*", "syntax", ".", "...
// Fields performs shell expansion on s as if it were a command's arguments, // using env to resolve variables. It is similar to Expand, but includes brace // expansion, tilde expansion, and globbing. // // If env is nil, the current environment variables are used. Empty variables // are treated as unset; to support va...
[ "Fields", "performs", "shell", "expansion", "on", "s", "as", "if", "it", "were", "a", "command", "s", "arguments", "using", "env", "to", "resolve", "variables", ".", "It", "is", "similar", "to", "Expand", "but", "includes", "brace", "expansion", "tilde", "...
5700c68a35dc3882e646a5e41776e31bb2c078e3
https://github.com/mvdan/sh/blob/5700c68a35dc3882e646a5e41776e31bb2c078e3/shell/expand.go#L48-L63
27,245
mvdan/sh
syntax/printer.go
KeepPadding
func KeepPadding(p *Printer) { p.keepPadding = true p.cols.Writer = p.bufWriter.(*bufio.Writer) p.bufWriter = &p.cols }
go
func KeepPadding(p *Printer) { p.keepPadding = true p.cols.Writer = p.bufWriter.(*bufio.Writer) p.bufWriter = &p.cols }
[ "func", "KeepPadding", "(", "p", "*", "Printer", ")", "{", "p", ".", "keepPadding", "=", "true", "\n", "p", ".", "cols", ".", "Writer", "=", "p", ".", "bufWriter", ".", "(", "*", "bufio", ".", "Writer", ")", "\n", "p", ".", "bufWriter", "=", "&",...
// KeepPadding will keep most nodes and tokens in the same column that // they were in the original source. This allows the user to decide how // to align and pad their code with spaces. // // Note that this feature is best-effort and will only keep the // alignment stable, so it may need some human help the first time...
[ "KeepPadding", "will", "keep", "most", "nodes", "and", "tokens", "in", "the", "same", "column", "that", "they", "were", "in", "the", "original", "source", ".", "This", "allows", "the", "user", "to", "decide", "how", "to", "align", "and", "pad", "their", ...
5700c68a35dc3882e646a5e41776e31bb2c078e3
https://github.com/mvdan/sh/blob/5700c68a35dc3882e646a5e41776e31bb2c078e3/syntax/printer.go#L42-L46
27,246
mvdan/sh
syntax/printer.go
NewPrinter
func NewPrinter(options ...func(*Printer)) *Printer { p := &Printer{ bufWriter: bufio.NewWriter(nil), tabsPrinter: new(Printer), tabWriter: new(tabwriter.Writer), } for _, opt := range options { opt(p) } return p }
go
func NewPrinter(options ...func(*Printer)) *Printer { p := &Printer{ bufWriter: bufio.NewWriter(nil), tabsPrinter: new(Printer), tabWriter: new(tabwriter.Writer), } for _, opt := range options { opt(p) } return p }
[ "func", "NewPrinter", "(", "options", "...", "func", "(", "*", "Printer", ")", ")", "*", "Printer", "{", "p", ":=", "&", "Printer", "{", "bufWriter", ":", "bufio", ".", "NewWriter", "(", "nil", ")", ",", "tabsPrinter", ":", "new", "(", "Printer", ")"...
// NewPrinter allocates a new Printer and applies any number of options.
[ "NewPrinter", "allocates", "a", "new", "Printer", "and", "applies", "any", "number", "of", "options", "." ]
5700c68a35dc3882e646a5e41776e31bb2c078e3
https://github.com/mvdan/sh/blob/5700c68a35dc3882e646a5e41776e31bb2c078e3/syntax/printer.go#L54-L64
27,247
mvdan/sh
interp/module.go
FromModuleContext
func FromModuleContext(ctx context.Context) (ModuleCtx, bool) { mc, ok := ctx.Value(moduleCtxKey{}).(ModuleCtx) return mc, ok }
go
func FromModuleContext(ctx context.Context) (ModuleCtx, bool) { mc, ok := ctx.Value(moduleCtxKey{}).(ModuleCtx) return mc, ok }
[ "func", "FromModuleContext", "(", "ctx", "context", ".", "Context", ")", "(", "ModuleCtx", ",", "bool", ")", "{", "mc", ",", "ok", ":=", "ctx", ".", "Value", "(", "moduleCtxKey", "{", "}", ")", ".", "(", "ModuleCtx", ")", "\n", "return", "mc", ",", ...
// FromModuleContext returns the ModuleCtx value stored in ctx, if any.
[ "FromModuleContext", "returns", "the", "ModuleCtx", "value", "stored", "in", "ctx", "if", "any", "." ]
5700c68a35dc3882e646a5e41776e31bb2c078e3
https://github.com/mvdan/sh/blob/5700c68a35dc3882e646a5e41776e31bb2c078e3/interp/module.go#L21-L24
27,248
mvdan/sh
syntax/walk.go
DebugPrint
func DebugPrint(w io.Writer, node Node) error { p := debugPrinter{out: w} p.print(reflect.ValueOf(node)) return p.err }
go
func DebugPrint(w io.Writer, node Node) error { p := debugPrinter{out: w} p.print(reflect.ValueOf(node)) return p.err }
[ "func", "DebugPrint", "(", "w", "io", ".", "Writer", ",", "node", "Node", ")", "error", "{", "p", ":=", "debugPrinter", "{", "out", ":", "w", "}", "\n", "p", ".", "print", "(", "reflect", ".", "ValueOf", "(", "node", ")", ")", "\n", "return", "p"...
// DebugPrint prints the provided syntax tree, spanning multiple lines and with // indentation. Can be useful to investigate the content of a syntax tree.
[ "DebugPrint", "prints", "the", "provided", "syntax", "tree", "spanning", "multiple", "lines", "and", "with", "indentation", ".", "Can", "be", "useful", "to", "investigate", "the", "content", "of", "a", "syntax", "tree", "." ]
5700c68a35dc3882e646a5e41776e31bb2c078e3
https://github.com/mvdan/sh/blob/5700c68a35dc3882e646a5e41776e31bb2c078e3/syntax/walk.go#L233-L237
27,249
mvdan/sh
syntax/lexer.go
fill
func (p *Parser) fill() { p.offs += p.bsp left := len(p.bs) - p.bsp copy(p.readBuf[:left], p.readBuf[p.bsp:]) readAgain: n, err := 0, p.readErr if err == nil { n, err = p.src.Read(p.readBuf[left:]) p.readErr = err } if n == 0 { if err == nil { goto readAgain } // don't use p.errPass as we don't want...
go
func (p *Parser) fill() { p.offs += p.bsp left := len(p.bs) - p.bsp copy(p.readBuf[:left], p.readBuf[p.bsp:]) readAgain: n, err := 0, p.readErr if err == nil { n, err = p.src.Read(p.readBuf[left:]) p.readErr = err } if n == 0 { if err == nil { goto readAgain } // don't use p.errPass as we don't want...
[ "func", "(", "p", "*", "Parser", ")", "fill", "(", ")", "{", "p", ".", "offs", "+=", "p", ".", "bsp", "\n", "left", ":=", "len", "(", "p", ".", "bs", ")", "-", "p", ".", "bsp", "\n", "copy", "(", "p", ".", "readBuf", "[", ":", "left", "]"...
// fill reads more bytes from the input src into readBuf. Any bytes that // had not yet been used at the end of the buffer are slid into the // beginning of the buffer.
[ "fill", "reads", "more", "bytes", "from", "the", "input", "src", "into", "readBuf", ".", "Any", "bytes", "that", "had", "not", "yet", "been", "used", "at", "the", "end", "of", "the", "buffer", "are", "slid", "into", "the", "beginning", "of", "the", "bu...
5700c68a35dc3882e646a5e41776e31bb2c078e3
https://github.com/mvdan/sh/blob/5700c68a35dc3882e646a5e41776e31bb2c078e3/syntax/lexer.go#L119-L146
27,250
robertkrimen/otto
file/file.go
AddFile
func (self *FileSet) AddFile(filename, src string) int { base := self.nextBase() file := &File{ name: filename, src: src, base: base, } self.files = append(self.files, file) self.last = file return base }
go
func (self *FileSet) AddFile(filename, src string) int { base := self.nextBase() file := &File{ name: filename, src: src, base: base, } self.files = append(self.files, file) self.last = file return base }
[ "func", "(", "self", "*", "FileSet", ")", "AddFile", "(", "filename", ",", "src", "string", ")", "int", "{", "base", ":=", "self", ".", "nextBase", "(", ")", "\n", "file", ":=", "&", "File", "{", "name", ":", "filename", ",", "src", ":", "src", "...
// AddFile adds a new file with the given filename and src. // // This an internal method, but exported for cross-package use.
[ "AddFile", "adds", "a", "new", "file", "with", "the", "given", "filename", "and", "src", ".", "This", "an", "internal", "method", "but", "exported", "for", "cross", "-", "package", "use", "." ]
15f95af6e78dcd2030d8195a138bd88d4f403546
https://github.com/robertkrimen/otto/blob/15f95af6e78dcd2030d8195a138bd88d4f403546/file/file.go#L65-L75
27,251
robertkrimen/otto
global.go
newBoundFunction
func (runtime *_runtime) newBoundFunction(target *_object, this Value, argumentList []Value) *_object { self := runtime.newBoundFunctionObject(target, this, argumentList) self.prototype = runtime.global.FunctionPrototype prototype := runtime.newObject() self.defineProperty("prototype", toValue_object(prototype), 01...
go
func (runtime *_runtime) newBoundFunction(target *_object, this Value, argumentList []Value) *_object { self := runtime.newBoundFunctionObject(target, this, argumentList) self.prototype = runtime.global.FunctionPrototype prototype := runtime.newObject() self.defineProperty("prototype", toValue_object(prototype), 01...
[ "func", "(", "runtime", "*", "_runtime", ")", "newBoundFunction", "(", "target", "*", "_object", ",", "this", "Value", ",", "argumentList", "[", "]", "Value", ")", "*", "_object", "{", "self", ":=", "runtime", ".", "newBoundFunctionObject", "(", "target", ...
// FIXME Only in one place...
[ "FIXME", "Only", "in", "one", "place", "..." ]
15f95af6e78dcd2030d8195a138bd88d4f403546
https://github.com/robertkrimen/otto/blob/15f95af6e78dcd2030d8195a138bd88d4f403546/global.go#L214-L221
27,252
robertkrimen/otto
script.go
CompileWithSourceMap
func (self *Otto) CompileWithSourceMap(filename string, src, sm interface{}) (*Script, error) { program, err := self.runtime.parse(filename, src, sm) if err != nil { return nil, err } cmpl_program := cmpl_parse(program) script := &Script{ version: scriptVersion, program: cmpl_program, filename: filenam...
go
func (self *Otto) CompileWithSourceMap(filename string, src, sm interface{}) (*Script, error) { program, err := self.runtime.parse(filename, src, sm) if err != nil { return nil, err } cmpl_program := cmpl_parse(program) script := &Script{ version: scriptVersion, program: cmpl_program, filename: filenam...
[ "func", "(", "self", "*", "Otto", ")", "CompileWithSourceMap", "(", "filename", "string", ",", "src", ",", "sm", "interface", "{", "}", ")", "(", "*", "Script", ",", "error", ")", "{", "program", ",", "err", ":=", "self", ".", "runtime", ".", "parse"...
// CompileWithSourceMap does the same thing as Compile, but with the obvious // difference of applying a source map.
[ "CompileWithSourceMap", "does", "the", "same", "thing", "as", "Compile", "but", "with", "the", "obvious", "difference", "of", "applying", "a", "source", "map", "." ]
15f95af6e78dcd2030d8195a138bd88d4f403546
https://github.com/robertkrimen/otto/blob/15f95af6e78dcd2030d8195a138bd88d4f403546/script.go#L35-L51
27,253
robertkrimen/otto
script.go
marshalBinary
func (self *Script) marshalBinary() ([]byte, error) { var bfr bytes.Buffer encoder := gob.NewEncoder(&bfr) err := encoder.Encode(self.version) if err != nil { return nil, err } err = encoder.Encode(self.program) if err != nil { return nil, err } err = encoder.Encode(self.filename) if err != nil { return...
go
func (self *Script) marshalBinary() ([]byte, error) { var bfr bytes.Buffer encoder := gob.NewEncoder(&bfr) err := encoder.Encode(self.version) if err != nil { return nil, err } err = encoder.Encode(self.program) if err != nil { return nil, err } err = encoder.Encode(self.filename) if err != nil { return...
[ "func", "(", "self", "*", "Script", ")", "marshalBinary", "(", ")", "(", "[", "]", "byte", ",", "error", ")", "{", "var", "bfr", "bytes", ".", "Buffer", "\n", "encoder", ":=", "gob", ".", "NewEncoder", "(", "&", "bfr", ")", "\n", "err", ":=", "en...
// MarshalBinary will marshal a script into a binary form. A marshalled script // that is later unmarshalled can be executed on the same version of the otto runtime. // // The binary format can change at any time and should be considered unspecified and opaque. //
[ "MarshalBinary", "will", "marshal", "a", "script", "into", "a", "binary", "form", ".", "A", "marshalled", "script", "that", "is", "later", "unmarshalled", "can", "be", "executed", "on", "the", "same", "version", "of", "the", "otto", "runtime", ".", "The", ...
15f95af6e78dcd2030d8195a138bd88d4f403546
https://github.com/robertkrimen/otto/blob/15f95af6e78dcd2030d8195a138bd88d4f403546/script.go#L62-L82
27,254
robertkrimen/otto
script.go
unmarshalBinary
func (self *Script) unmarshalBinary(data []byte) error { decoder := gob.NewDecoder(bytes.NewReader(data)) err := decoder.Decode(&self.version) if err != nil { goto error } if self.version != scriptVersion { err = ErrVersion goto error } err = decoder.Decode(&self.program) if err != nil { goto error } ...
go
func (self *Script) unmarshalBinary(data []byte) error { decoder := gob.NewDecoder(bytes.NewReader(data)) err := decoder.Decode(&self.version) if err != nil { goto error } if self.version != scriptVersion { err = ErrVersion goto error } err = decoder.Decode(&self.program) if err != nil { goto error } ...
[ "func", "(", "self", "*", "Script", ")", "unmarshalBinary", "(", "data", "[", "]", "byte", ")", "error", "{", "decoder", ":=", "gob", ".", "NewDecoder", "(", "bytes", ".", "NewReader", "(", "data", ")", ")", "\n", "err", ":=", "decoder", ".", "Decode...
// UnmarshalBinary will vivify a marshalled script into something usable. If the script was // originally marshalled on a different version of the otto runtime, then this method // will return an error. // // The binary format can change at any time and should be considered unspecified and opaque. //
[ "UnmarshalBinary", "will", "vivify", "a", "marshalled", "script", "into", "something", "usable", ".", "If", "the", "script", "was", "originally", "marshalled", "on", "a", "different", "version", "of", "the", "otto", "runtime", "then", "this", "method", "will", ...
15f95af6e78dcd2030d8195a138bd88d4f403546
https://github.com/robertkrimen/otto/blob/15f95af6e78dcd2030d8195a138bd88d4f403546/script.go#L90-L119
27,255
robertkrimen/otto
type_function.go
hasInstance
func (self *_object) hasInstance(of Value) bool { if !self.isCall() { // We should not have a hasInstance method panic(self.runtime.panicTypeError()) } if !of.IsObject() { return false } prototype := self.get("prototype") if !prototype.IsObject() { panic(self.runtime.panicTypeError()) } prototypeObject ...
go
func (self *_object) hasInstance(of Value) bool { if !self.isCall() { // We should not have a hasInstance method panic(self.runtime.panicTypeError()) } if !of.IsObject() { return false } prototype := self.get("prototype") if !prototype.IsObject() { panic(self.runtime.panicTypeError()) } prototypeObject ...
[ "func", "(", "self", "*", "_object", ")", "hasInstance", "(", "of", "Value", ")", "bool", "{", "if", "!", "self", ".", "isCall", "(", ")", "{", "// We should not have a hasInstance method", "panic", "(", "self", ".", "runtime", ".", "panicTypeError", "(", ...
// 15.3.5.3
[ "15", ".", "3", ".", "5", ".", "3" ]
15f95af6e78dcd2030d8195a138bd88d4f403546
https://github.com/robertkrimen/otto/blob/15f95af6e78dcd2030d8195a138bd88d4f403546/type_function.go#L259-L281
27,256
robertkrimen/otto
type_function.go
Argument
func (self FunctionCall) Argument(index int) Value { return valueOfArrayIndex(self.ArgumentList, index) }
go
func (self FunctionCall) Argument(index int) Value { return valueOfArrayIndex(self.ArgumentList, index) }
[ "func", "(", "self", "FunctionCall", ")", "Argument", "(", "index", "int", ")", "Value", "{", "return", "valueOfArrayIndex", "(", "self", ".", "ArgumentList", ",", "index", ")", "\n", "}" ]
// Argument will return the value of the argument at the given index. // // If no such argument exists, undefined is returned.
[ "Argument", "will", "return", "the", "value", "of", "the", "argument", "at", "the", "given", "index", ".", "If", "no", "such", "argument", "exists", "undefined", "is", "returned", "." ]
15f95af6e78dcd2030d8195a138bd88d4f403546
https://github.com/robertkrimen/otto/blob/15f95af6e78dcd2030d8195a138bd88d4f403546/type_function.go#L301-L303
27,257
robertkrimen/otto
otto_.go
valueToRangeIndex
func valueToRangeIndex(indexValue Value, length int64, negativeIsZero bool) int64 { index := indexValue.number().int64 if negativeIsZero { if index < 0 { index = 0 } // minimum(index, length) if index >= length { index = length } return index } if index < 0 { index += length if index < 0 { ...
go
func valueToRangeIndex(indexValue Value, length int64, negativeIsZero bool) int64 { index := indexValue.number().int64 if negativeIsZero { if index < 0 { index = 0 } // minimum(index, length) if index >= length { index = length } return index } if index < 0 { index += length if index < 0 { ...
[ "func", "valueToRangeIndex", "(", "indexValue", "Value", ",", "length", "int64", ",", "negativeIsZero", "bool", ")", "int64", "{", "index", ":=", "indexValue", ".", "number", "(", ")", ".", "int64", "\n", "if", "negativeIsZero", "{", "if", "index", "<", "0...
// A range index can be anything from 0 up to length. It is NOT safe to use as an index // to an array, but is useful for slicing and in some ECMA algorithms.
[ "A", "range", "index", "can", "be", "anything", "from", "0", "up", "to", "length", ".", "It", "is", "NOT", "safe", "to", "use", "as", "an", "index", "to", "an", "array", "but", "is", "useful", "for", "slicing", "and", "in", "some", "ECMA", "algorithm...
15f95af6e78dcd2030d8195a138bd88d4f403546
https://github.com/robertkrimen/otto/blob/15f95af6e78dcd2030d8195a138bd88d4f403546/otto_.go#L75-L99
27,258
robertkrimen/otto
parser/error.go
Error
func (self Error) Error() string { filename := self.Position.Filename if filename == "" { filename = "(anonymous)" } return fmt.Sprintf("%s: Line %d:%d %s", filename, self.Position.Line, self.Position.Column, self.Message, ) }
go
func (self Error) Error() string { filename := self.Position.Filename if filename == "" { filename = "(anonymous)" } return fmt.Sprintf("%s: Line %d:%d %s", filename, self.Position.Line, self.Position.Column, self.Message, ) }
[ "func", "(", "self", "Error", ")", "Error", "(", ")", "string", "{", "filename", ":=", "self", ".", "Position", ".", "Filename", "\n", "if", "filename", "==", "\"", "\"", "{", "filename", "=", "\"", "\"", "\n", "}", "\n", "return", "fmt", ".", "Spr...
// FIXME Should this be "SyntaxError"?
[ "FIXME", "Should", "this", "be", "SyntaxError", "?" ]
15f95af6e78dcd2030d8195a138bd88d4f403546
https://github.com/robertkrimen/otto/blob/15f95af6e78dcd2030d8195a138bd88d4f403546/parser/error.go#L59-L70
27,259
robertkrimen/otto
parser/error.go
Add
func (self *ErrorList) Add(position file.Position, msg string) { *self = append(*self, &Error{position, msg}) }
go
func (self *ErrorList) Add(position file.Position, msg string) { *self = append(*self, &Error{position, msg}) }
[ "func", "(", "self", "*", "ErrorList", ")", "Add", "(", "position", "file", ".", "Position", ",", "msg", "string", ")", "{", "*", "self", "=", "append", "(", "*", "self", ",", "&", "Error", "{", "position", ",", "msg", "}", ")", "\n", "}" ]
// Add adds an Error with given position and message to an ErrorList.
[ "Add", "adds", "an", "Error", "with", "given", "position", "and", "message", "to", "an", "ErrorList", "." ]
15f95af6e78dcd2030d8195a138bd88d4f403546
https://github.com/robertkrimen/otto/blob/15f95af6e78dcd2030d8195a138bd88d4f403546/parser/error.go#L127-L129
27,260
robertkrimen/otto
object.go
getOwnProperty
func (self *_object) getOwnProperty(name string) *_property { return self.objectClass.getOwnProperty(self, name) }
go
func (self *_object) getOwnProperty(name string) *_property { return self.objectClass.getOwnProperty(self, name) }
[ "func", "(", "self", "*", "_object", ")", "getOwnProperty", "(", "name", "string", ")", "*", "_property", "{", "return", "self", ".", "objectClass", ".", "getOwnProperty", "(", "self", ",", "name", ")", "\n", "}" ]
// 8.12 // 8.12.1
[ "8", ".", "12", "8", ".", "12", ".", "1" ]
15f95af6e78dcd2030d8195a138bd88d4f403546
https://github.com/robertkrimen/otto/blob/15f95af6e78dcd2030d8195a138bd88d4f403546/object.go#L31-L33
27,261
robertkrimen/otto
object.go
DefaultValue
func (self *_object) DefaultValue(hint _defaultValueHint) Value { if hint == defaultValueNoHint { if self.class == "Date" { // Date exception hint = defaultValueHintString } else { hint = defaultValueHintNumber } } methodSequence := []string{"valueOf", "toString"} if hint == defaultValueHintString { ...
go
func (self *_object) DefaultValue(hint _defaultValueHint) Value { if hint == defaultValueNoHint { if self.class == "Date" { // Date exception hint = defaultValueHintString } else { hint = defaultValueHintNumber } } methodSequence := []string{"valueOf", "toString"} if hint == defaultValueHintString { ...
[ "func", "(", "self", "*", "_object", ")", "DefaultValue", "(", "hint", "_defaultValueHint", ")", "Value", "{", "if", "hint", "==", "defaultValueNoHint", "{", "if", "self", ".", "class", "==", "\"", "\"", "{", "// Date exception", "hint", "=", "defaultValueHi...
// 8.12.8
[ "8", ".", "12", ".", "8" ]
15f95af6e78dcd2030d8195a138bd88d4f403546
https://github.com/robertkrimen/otto/blob/15f95af6e78dcd2030d8195a138bd88d4f403546/object.go#L73-L98
27,262
robertkrimen/otto
terst/terst.go
decorate
func decorate(call _entry, s string) string { file, line := call.File, call.Line if call.PC > 0 { // Truncate file name at last file name separator. if index := strings.LastIndex(file, "/"); index >= 0 { file = file[index+1:] } else if index = strings.LastIndex(file, "\\"); index >= 0 { file = file[index...
go
func decorate(call _entry, s string) string { file, line := call.File, call.Line if call.PC > 0 { // Truncate file name at last file name separator. if index := strings.LastIndex(file, "/"); index >= 0 { file = file[index+1:] } else if index = strings.LastIndex(file, "\\"); index >= 0 { file = file[index...
[ "func", "decorate", "(", "call", "_entry", ",", "s", "string", ")", "string", "{", "file", ",", "line", ":=", "call", ".", "File", ",", "call", ".", "Line", "\n", "if", "call", ".", "PC", ">", "0", "{", "// Truncate file name at last file name separator.",...
// decorate prefixes the string with the file and line of the call site // and inserts the final newline if needed and indentation tabs for formascing.
[ "decorate", "prefixes", "the", "string", "with", "the", "file", "and", "line", "of", "the", "call", "site", "and", "inserts", "the", "final", "newline", "if", "needed", "and", "indentation", "tabs", "for", "formascing", "." ]
15f95af6e78dcd2030d8195a138bd88d4f403546
https://github.com/robertkrimen/otto/blob/15f95af6e78dcd2030d8195a138bd88d4f403546/terst/terst.go#L502-L533
27,263
robertkrimen/otto
terst/terst.go
Caller
func Caller() *Call { scope, entry := findScope() if scope == nil { return nil } return &Call{ scope: scope, entry: entry, } }
go
func Caller() *Call { scope, entry := findScope() if scope == nil { return nil } return &Call{ scope: scope, entry: entry, } }
[ "func", "Caller", "(", ")", "*", "Call", "{", "scope", ",", "entry", ":=", "findScope", "(", ")", "\n", "if", "scope", "==", "nil", "{", "return", "nil", "\n", "}", "\n", "return", "&", "Call", "{", "scope", ":", "scope", ",", "entry", ":", "entr...
// Caller will search the stack, looking for a Terst testing scope. If a scope // is found, then Caller returns a Call for logging errors, accessing testing.T, etc. // If no scope is found, Caller returns nil.
[ "Caller", "will", "search", "the", "stack", "looking", "for", "a", "Terst", "testing", "scope", ".", "If", "a", "scope", "is", "found", "then", "Caller", "returns", "a", "Call", "for", "logging", "errors", "accessing", "testing", ".", "T", "etc", ".", "I...
15f95af6e78dcd2030d8195a138bd88d4f403546
https://github.com/robertkrimen/otto/blob/15f95af6e78dcd2030d8195a138bd88d4f403546/terst/terst.go#L567-L576
27,264
robertkrimen/otto
terst/terst.go
Log
func (cl *Call) Log(arguments ...interface{}) { cl.scope.log(cl.entry, fmt.Sprintln(arguments...)) }
go
func (cl *Call) Log(arguments ...interface{}) { cl.scope.log(cl.entry, fmt.Sprintln(arguments...)) }
[ "func", "(", "cl", "*", "Call", ")", "Log", "(", "arguments", "...", "interface", "{", "}", ")", "{", "cl", ".", "scope", ".", "log", "(", "cl", ".", "entry", ",", "fmt", ".", "Sprintln", "(", "arguments", "...", ")", ")", "\n", "}" ]
// Log is the terst version of `testing.T.Log`
[ "Log", "is", "the", "terst", "version", "of", "testing", ".", "T", ".", "Log" ]
15f95af6e78dcd2030d8195a138bd88d4f403546
https://github.com/robertkrimen/otto/blob/15f95af6e78dcd2030d8195a138bd88d4f403546/terst/terst.go#L590-L592
27,265
robertkrimen/otto
terst/terst.go
Logf
func (cl *Call) Logf(format string, arguments ...interface{}) { cl.scope.log(cl.entry, fmt.Sprintf(format, arguments...)) }
go
func (cl *Call) Logf(format string, arguments ...interface{}) { cl.scope.log(cl.entry, fmt.Sprintf(format, arguments...)) }
[ "func", "(", "cl", "*", "Call", ")", "Logf", "(", "format", "string", ",", "arguments", "...", "interface", "{", "}", ")", "{", "cl", ".", "scope", ".", "log", "(", "cl", ".", "entry", ",", "fmt", ".", "Sprintf", "(", "format", ",", "arguments", ...
// Logf is the terst version of `testing.T.Logf`
[ "Logf", "is", "the", "terst", "version", "of", "testing", ".", "T", ".", "Logf" ]
15f95af6e78dcd2030d8195a138bd88d4f403546
https://github.com/robertkrimen/otto/blob/15f95af6e78dcd2030d8195a138bd88d4f403546/terst/terst.go#L595-L597
27,266
robertkrimen/otto
terst/terst.go
Error
func (cl *Call) Error(arguments ...interface{}) { cl.scope.log(cl.entry, fmt.Sprintln(arguments...)) cl.scope.t.Fail() }
go
func (cl *Call) Error(arguments ...interface{}) { cl.scope.log(cl.entry, fmt.Sprintln(arguments...)) cl.scope.t.Fail() }
[ "func", "(", "cl", "*", "Call", ")", "Error", "(", "arguments", "...", "interface", "{", "}", ")", "{", "cl", ".", "scope", ".", "log", "(", "cl", ".", "entry", ",", "fmt", ".", "Sprintln", "(", "arguments", "...", ")", ")", "\n", "cl", ".", "s...
// Error is the terst version of `testing.T.Error`
[ "Error", "is", "the", "terst", "version", "of", "testing", ".", "T", ".", "Error" ]
15f95af6e78dcd2030d8195a138bd88d4f403546
https://github.com/robertkrimen/otto/blob/15f95af6e78dcd2030d8195a138bd88d4f403546/terst/terst.go#L600-L603
27,267
robertkrimen/otto
terst/terst.go
Errorf
func (cl *Call) Errorf(format string, arguments ...interface{}) { cl.scope.log(cl.entry, fmt.Sprintf(format, arguments...)) cl.scope.t.Fail() }
go
func (cl *Call) Errorf(format string, arguments ...interface{}) { cl.scope.log(cl.entry, fmt.Sprintf(format, arguments...)) cl.scope.t.Fail() }
[ "func", "(", "cl", "*", "Call", ")", "Errorf", "(", "format", "string", ",", "arguments", "...", "interface", "{", "}", ")", "{", "cl", ".", "scope", ".", "log", "(", "cl", ".", "entry", ",", "fmt", ".", "Sprintf", "(", "format", ",", "arguments", ...
// Errorf is the terst version of `testing.T.Errorf`
[ "Errorf", "is", "the", "terst", "version", "of", "testing", ".", "T", ".", "Errorf" ]
15f95af6e78dcd2030d8195a138bd88d4f403546
https://github.com/robertkrimen/otto/blob/15f95af6e78dcd2030d8195a138bd88d4f403546/terst/terst.go#L606-L609
27,268
robertkrimen/otto
terst/terst.go
Skip
func (cl *Call) Skip(arguments ...interface{}) { cl.scope.log(cl.entry, fmt.Sprintln(arguments...)) cl.scope.t.SkipNow() }
go
func (cl *Call) Skip(arguments ...interface{}) { cl.scope.log(cl.entry, fmt.Sprintln(arguments...)) cl.scope.t.SkipNow() }
[ "func", "(", "cl", "*", "Call", ")", "Skip", "(", "arguments", "...", "interface", "{", "}", ")", "{", "cl", ".", "scope", ".", "log", "(", "cl", ".", "entry", ",", "fmt", ".", "Sprintln", "(", "arguments", "...", ")", ")", "\n", "cl", ".", "sc...
// Skip is the terst version of `testing.T.Skip`
[ "Skip", "is", "the", "terst", "version", "of", "testing", ".", "T", ".", "Skip" ]
15f95af6e78dcd2030d8195a138bd88d4f403546
https://github.com/robertkrimen/otto/blob/15f95af6e78dcd2030d8195a138bd88d4f403546/terst/terst.go#L612-L615
27,269
robertkrimen/otto
terst/terst.go
Skipf
func (cl *Call) Skipf(format string, arguments ...interface{}) { cl.scope.log(cl.entry, fmt.Sprintf(format, arguments...)) cl.scope.t.SkipNow() }
go
func (cl *Call) Skipf(format string, arguments ...interface{}) { cl.scope.log(cl.entry, fmt.Sprintf(format, arguments...)) cl.scope.t.SkipNow() }
[ "func", "(", "cl", "*", "Call", ")", "Skipf", "(", "format", "string", ",", "arguments", "...", "interface", "{", "}", ")", "{", "cl", ".", "scope", ".", "log", "(", "cl", ".", "entry", ",", "fmt", ".", "Sprintf", "(", "format", ",", "arguments", ...
// Skipf is the terst version of `testing.T.Skipf`
[ "Skipf", "is", "the", "terst", "version", "of", "testing", ".", "T", ".", "Skipf" ]
15f95af6e78dcd2030d8195a138bd88d4f403546
https://github.com/robertkrimen/otto/blob/15f95af6e78dcd2030d8195a138bd88d4f403546/terst/terst.go#L618-L621
27,270
robertkrimen/otto
value.go
IsFunction
func (value Value) IsFunction() bool { if value.kind != valueObject { return false } return value.value.(*_object).class == "Function" }
go
func (value Value) IsFunction() bool { if value.kind != valueObject { return false } return value.value.(*_object).class == "Function" }
[ "func", "(", "value", "Value", ")", "IsFunction", "(", ")", "bool", "{", "if", "value", ".", "kind", "!=", "valueObject", "{", "return", "false", "\n", "}", "\n", "return", "value", ".", "value", ".", "(", "*", "_object", ")", ".", "class", "==", "...
// IsFunction will return true if value is a function.
[ "IsFunction", "will", "return", "true", "if", "value", "is", "a", "function", "." ]
15f95af6e78dcd2030d8195a138bd88d4f403546
https://github.com/robertkrimen/otto/blob/15f95af6e78dcd2030d8195a138bd88d4f403546/value.go#L192-L197
27,271
robertkrimen/otto
value.go
String
func (value Value) String() string { result := "" catchPanic(func() { result = value.string() }) return result }
go
func (value Value) String() string { result := "" catchPanic(func() { result = value.string() }) return result }
[ "func", "(", "value", "Value", ")", "String", "(", ")", "string", "{", "result", ":=", "\"", "\"", "\n", "catchPanic", "(", "func", "(", ")", "{", "result", "=", "value", ".", "string", "(", ")", "\n", "}", ")", "\n", "return", "result", "\n", "}...
// String will return the value as a string. // // This method will make return the empty string if there is an error.
[ "String", "will", "return", "the", "value", "as", "a", "string", ".", "This", "method", "will", "make", "return", "the", "empty", "string", "if", "there", "is", "an", "error", "." ]
15f95af6e78dcd2030d8195a138bd88d4f403546
https://github.com/robertkrimen/otto/blob/15f95af6e78dcd2030d8195a138bd88d4f403546/value.go#L384-L390
27,272
robertkrimen/otto
value.go
Object
func (value Value) Object() *Object { switch object := value.value.(type) { case *_object: return _newObject(object, value) } return nil }
go
func (value Value) Object() *Object { switch object := value.value.(type) { case *_object: return _newObject(object, value) } return nil }
[ "func", "(", "value", "Value", ")", "Object", "(", ")", "*", "Object", "{", "switch", "object", ":=", "value", ".", "value", ".", "(", "type", ")", "{", "case", "*", "_object", ":", "return", "_newObject", "(", "object", ",", "value", ")", "\n", "}...
// Object will return the object of the value, or nil if value is not an object. // // This method will not do any implicit conversion. For example, calling this method on a string primitive value will not return a String object.
[ "Object", "will", "return", "the", "object", "of", "the", "value", "or", "nil", "if", "value", "is", "not", "an", "object", ".", "This", "method", "will", "not", "do", "any", "implicit", "conversion", ".", "For", "example", "calling", "this", "method", "...
15f95af6e78dcd2030d8195a138bd88d4f403546
https://github.com/robertkrimen/otto/blob/15f95af6e78dcd2030d8195a138bd88d4f403546/value.go#L474-L480
27,273
robertkrimen/otto
repl/repl.go
DebuggerHandler
func DebuggerHandler(vm *otto.Otto) { i := atomic.AddUint32(&counter, 1) // purposefully ignoring the error here - we can't do anything useful with // it except panicking, and that'd be pretty rude. it'd be easy enough for a // consumer to define an equivalent function that _does_ panic if desired. _ = RunWithPro...
go
func DebuggerHandler(vm *otto.Otto) { i := atomic.AddUint32(&counter, 1) // purposefully ignoring the error here - we can't do anything useful with // it except panicking, and that'd be pretty rude. it'd be easy enough for a // consumer to define an equivalent function that _does_ panic if desired. _ = RunWithPro...
[ "func", "DebuggerHandler", "(", "vm", "*", "otto", ".", "Otto", ")", "{", "i", ":=", "atomic", ".", "AddUint32", "(", "&", "counter", ",", "1", ")", "\n\n", "// purposefully ignoring the error here - we can't do anything useful with", "// it except panicking, and that'd...
// DebuggerHandler implements otto's debugger handler signature, providing a // simple drop-in debugger implementation.
[ "DebuggerHandler", "implements", "otto", "s", "debugger", "handler", "signature", "providing", "a", "simple", "drop", "-", "in", "debugger", "implementation", "." ]
15f95af6e78dcd2030d8195a138bd88d4f403546
https://github.com/robertkrimen/otto/blob/15f95af6e78dcd2030d8195a138bd88d4f403546/repl/repl.go#L18-L25
27,274
robertkrimen/otto
repl/repl.go
RunWithPrompt
func RunWithPrompt(vm *otto.Otto, prompt string) error { return RunWithOptions(vm, Options{ Prompt: prompt, }) }
go
func RunWithPrompt(vm *otto.Otto, prompt string) error { return RunWithOptions(vm, Options{ Prompt: prompt, }) }
[ "func", "RunWithPrompt", "(", "vm", "*", "otto", ".", "Otto", ",", "prompt", "string", ")", "error", "{", "return", "RunWithOptions", "(", "vm", ",", "Options", "{", "Prompt", ":", "prompt", ",", "}", ")", "\n", "}" ]
// RunWithPrompt runs a REPL with the given prompt and no prelude.
[ "RunWithPrompt", "runs", "a", "REPL", "with", "the", "given", "prompt", "and", "no", "prelude", "." ]
15f95af6e78dcd2030d8195a138bd88d4f403546
https://github.com/robertkrimen/otto/blob/15f95af6e78dcd2030d8195a138bd88d4f403546/repl/repl.go#L33-L37
27,275
robertkrimen/otto
repl/repl.go
RunWithPrelude
func RunWithPrelude(vm *otto.Otto, prelude string) error { return RunWithOptions(vm, Options{ Prelude: prelude, }) }
go
func RunWithPrelude(vm *otto.Otto, prelude string) error { return RunWithOptions(vm, Options{ Prelude: prelude, }) }
[ "func", "RunWithPrelude", "(", "vm", "*", "otto", ".", "Otto", ",", "prelude", "string", ")", "error", "{", "return", "RunWithOptions", "(", "vm", ",", "Options", "{", "Prelude", ":", "prelude", ",", "}", ")", "\n", "}" ]
// RunWithPrelude runs a REPL with the default prompt and the given prelude.
[ "RunWithPrelude", "runs", "a", "REPL", "with", "the", "default", "prompt", "and", "the", "given", "prelude", "." ]
15f95af6e78dcd2030d8195a138bd88d4f403546
https://github.com/robertkrimen/otto/blob/15f95af6e78dcd2030d8195a138bd88d4f403546/repl/repl.go#L40-L44
27,276
robertkrimen/otto
repl/repl.go
RunWithPromptAndPrelude
func RunWithPromptAndPrelude(vm *otto.Otto, prompt, prelude string) error { return RunWithOptions(vm, Options{ Prompt: prompt, Prelude: prelude, }) }
go
func RunWithPromptAndPrelude(vm *otto.Otto, prompt, prelude string) error { return RunWithOptions(vm, Options{ Prompt: prompt, Prelude: prelude, }) }
[ "func", "RunWithPromptAndPrelude", "(", "vm", "*", "otto", ".", "Otto", ",", "prompt", ",", "prelude", "string", ")", "error", "{", "return", "RunWithOptions", "(", "vm", ",", "Options", "{", "Prompt", ":", "prompt", ",", "Prelude", ":", "prelude", ",", ...
// RunWithPromptAndPrelude runs a REPL with the given prompt and prelude.
[ "RunWithPromptAndPrelude", "runs", "a", "REPL", "with", "the", "given", "prompt", "and", "prelude", "." ]
15f95af6e78dcd2030d8195a138bd88d4f403546
https://github.com/robertkrimen/otto/blob/15f95af6e78dcd2030d8195a138bd88d4f403546/repl/repl.go#L47-L52
27,277
robertkrimen/otto
repl/repl.go
RunWithOptions
func RunWithOptions(vm *otto.Otto, options Options) error { prompt := options.Prompt if prompt == "" { prompt = "> " } c := &readline.Config{ Prompt: prompt, } if options.Autocomplete { c.AutoComplete = &autoCompleter{vm} } rl, err := readline.NewEx(c) if err != nil { return err } prelude := opti...
go
func RunWithOptions(vm *otto.Otto, options Options) error { prompt := options.Prompt if prompt == "" { prompt = "> " } c := &readline.Config{ Prompt: prompt, } if options.Autocomplete { c.AutoComplete = &autoCompleter{vm} } rl, err := readline.NewEx(c) if err != nil { return err } prelude := opti...
[ "func", "RunWithOptions", "(", "vm", "*", "otto", ".", "Otto", ",", "options", "Options", ")", "error", "{", "prompt", ":=", "options", ".", "Prompt", "\n", "if", "prompt", "==", "\"", "\"", "{", "prompt", "=", "\"", "\"", "\n", "}", "\n\n", "c", "...
// RunWithOptions runs a REPL with the given options.
[ "RunWithOptions", "runs", "a", "REPL", "with", "the", "given", "options", "." ]
15f95af6e78dcd2030d8195a138bd88d4f403546
https://github.com/robertkrimen/otto/blob/15f95af6e78dcd2030d8195a138bd88d4f403546/repl/repl.go#L70-L149
27,278
robertkrimen/otto
parser/lexer.go
isLineWhiteSpace
func isLineWhiteSpace(chr rune) bool { switch chr { case '\u0009', '\u000b', '\u000c', '\u0020', '\u00a0', '\ufeff': return true case '\u000a', '\u000d', '\u2028', '\u2029': return false case '\u0085': return false } return unicode.IsSpace(chr) }
go
func isLineWhiteSpace(chr rune) bool { switch chr { case '\u0009', '\u000b', '\u000c', '\u0020', '\u00a0', '\ufeff': return true case '\u000a', '\u000d', '\u2028', '\u2029': return false case '\u0085': return false } return unicode.IsSpace(chr) }
[ "func", "isLineWhiteSpace", "(", "chr", "rune", ")", "bool", "{", "switch", "chr", "{", "case", "'\\u0009'", ",", "'\\u000b'", ",", "'\\u000c'", ",", "'\\u0020'", ",", "'\\u00a0'", ",", "'\\ufeff'", ":", "return", "true", "\n", "case", "'\\u000a'", ",", "'...
// 7.2
[ "7", ".", "2" ]
15f95af6e78dcd2030d8195a138bd88d4f403546
https://github.com/robertkrimen/otto/blob/15f95af6e78dcd2030d8195a138bd88d4f403546/parser/lexer.go#L100-L110
27,279
robertkrimen/otto
parser/lexer.go
read
func (self *_RegExp_parser) read() { if self.offset < self.length { self.chrOffset = self.offset chr, width := rune(self.str[self.offset]), 1 if chr >= utf8.RuneSelf { // !ASCII chr, width = utf8.DecodeRuneInString(self.str[self.offset:]) if chr == utf8.RuneError && width == 1 { self.error(self.chrOffs...
go
func (self *_RegExp_parser) read() { if self.offset < self.length { self.chrOffset = self.offset chr, width := rune(self.str[self.offset]), 1 if chr >= utf8.RuneSelf { // !ASCII chr, width = utf8.DecodeRuneInString(self.str[self.offset:]) if chr == utf8.RuneError && width == 1 { self.error(self.chrOffs...
[ "func", "(", "self", "*", "_RegExp_parser", ")", "read", "(", ")", "{", "if", "self", ".", "offset", "<", "self", ".", "length", "{", "self", ".", "chrOffset", "=", "self", ".", "offset", "\n", "chr", ",", "width", ":=", "rune", "(", "self", ".", ...
// This is here since the functions are so similar
[ "This", "is", "here", "since", "the", "functions", "are", "so", "similar" ]
15f95af6e78dcd2030d8195a138bd88d4f403546
https://github.com/robertkrimen/otto/blob/15f95af6e78dcd2030d8195a138bd88d4f403546/parser/lexer.go#L408-L424
27,280
robertkrimen/otto
object_class.go
objectGetOwnProperty
func objectGetOwnProperty(self *_object, name string) *_property { // Return a _copy_ of the property property, exists := self._read(name) if !exists { return nil } return &property }
go
func objectGetOwnProperty(self *_object, name string) *_property { // Return a _copy_ of the property property, exists := self._read(name) if !exists { return nil } return &property }
[ "func", "objectGetOwnProperty", "(", "self", "*", "_object", ",", "name", "string", ")", "*", "_property", "{", "// Return a _copy_ of the property", "property", ",", "exists", ":=", "self", ".", "_read", "(", "name", ")", "\n", "if", "!", "exists", "{", "re...
// Allons-y // 8.12.1
[ "Allons", "-", "y", "8", ".", "12", ".", "1" ]
15f95af6e78dcd2030d8195a138bd88d4f403546
https://github.com/robertkrimen/otto/blob/15f95af6e78dcd2030d8195a138bd88d4f403546/object_class.go#L169-L176
27,281
robertkrimen/otto
parser/parser.go
ParseFunction
func ParseFunction(parameterList, body string) (*ast.FunctionLiteral, error) { src := "(function(" + parameterList + ") {\n" + body + "\n})" parser := _newParser("", src, 1, nil) program, err := parser.parse() if err != nil { return nil, err } return program.Body[0].(*ast.ExpressionStatement).Expression.(*as...
go
func ParseFunction(parameterList, body string) (*ast.FunctionLiteral, error) { src := "(function(" + parameterList + ") {\n" + body + "\n})" parser := _newParser("", src, 1, nil) program, err := parser.parse() if err != nil { return nil, err } return program.Body[0].(*ast.ExpressionStatement).Expression.(*as...
[ "func", "ParseFunction", "(", "parameterList", ",", "body", "string", ")", "(", "*", "ast", ".", "FunctionLiteral", ",", "error", ")", "{", "src", ":=", "\"", "\"", "+", "parameterList", "+", "\"", "\\n", "\"", "+", "body", "+", "\"", "\\n", "\"", "\...
// ParseFunction parses a given parameter list and body as a function and returns the // corresponding ast.FunctionLiteral node. // // The parameter list, if any, should be a comma-separated list of identifiers. //
[ "ParseFunction", "parses", "a", "given", "parameter", "list", "and", "body", "as", "a", "function", "and", "returns", "the", "corresponding", "ast", ".", "FunctionLiteral", "node", ".", "The", "parameter", "list", "if", "any", "should", "be", "a", "comma", "...
15f95af6e78dcd2030d8195a138bd88d4f403546
https://github.com/robertkrimen/otto/blob/15f95af6e78dcd2030d8195a138bd88d4f403546/parser/parser.go#L218-L229
27,282
robertkrimen/otto
token/token.go
precedence
func (tkn Token) precedence(in bool) int { switch tkn { case LOGICAL_OR: return 1 case LOGICAL_AND: return 2 case OR, OR_ASSIGN: return 3 case EXCLUSIVE_OR: return 4 case AND, AND_ASSIGN, AND_NOT, AND_NOT_ASSIGN: return 5 case EQUAL, NOT_EQUAL, STRICT_EQUAL, STRICT_NOT_EQUAL: return 6 c...
go
func (tkn Token) precedence(in bool) int { switch tkn { case LOGICAL_OR: return 1 case LOGICAL_AND: return 2 case OR, OR_ASSIGN: return 3 case EXCLUSIVE_OR: return 4 case AND, AND_ASSIGN, AND_NOT, AND_NOT_ASSIGN: return 5 case EQUAL, NOT_EQUAL, STRICT_EQUAL, STRICT_NOT_EQUAL: return 6 c...
[ "func", "(", "tkn", "Token", ")", "precedence", "(", "in", "bool", ")", "int", "{", "switch", "tkn", "{", "case", "LOGICAL_OR", ":", "return", "1", "\n\n", "case", "LOGICAL_AND", ":", "return", "2", "\n\n", "case", "OR", ",", "OR_ASSIGN", ":", "return"...
// This is not used for anything
[ "This", "is", "not", "used", "for", "anything" ]
15f95af6e78dcd2030d8195a138bd88d4f403546
https://github.com/robertkrimen/otto/blob/15f95af6e78dcd2030d8195a138bd88d4f403546/token/token.go#L28-L73
27,283
robertkrimen/otto
ast/comments.go
NewComment
func NewComment(text string, idx file.Idx) *Comment { comment := &Comment{ Begin: idx, Text: text, Position: TBD, } return comment }
go
func NewComment(text string, idx file.Idx) *Comment { comment := &Comment{ Begin: idx, Text: text, Position: TBD, } return comment }
[ "func", "NewComment", "(", "text", "string", ",", "idx", "file", ".", "Idx", ")", "*", "Comment", "{", "comment", ":=", "&", "Comment", "{", "Begin", ":", "idx", ",", "Text", ":", "text", ",", "Position", ":", "TBD", ",", "}", "\n\n", "return", "co...
// NewComment creates a new comment
[ "NewComment", "creates", "a", "new", "comment" ]
15f95af6e78dcd2030d8195a138bd88d4f403546
https://github.com/robertkrimen/otto/blob/15f95af6e78dcd2030d8195a138bd88d4f403546/ast/comments.go#L34-L42
27,284
robertkrimen/otto
ast/comments.go
String
func (cp CommentPosition) String() string { switch cp { case LEADING: return "Leading" case TRAILING: return "Trailing" case KEY: return "Key" case COLON: return "Colon" case FINAL: return "Final" case IF: return "If" case WHILE: return "While" case DO: return "Do" case FOR: return "For" ca...
go
func (cp CommentPosition) String() string { switch cp { case LEADING: return "Leading" case TRAILING: return "Trailing" case KEY: return "Key" case COLON: return "Colon" case FINAL: return "Final" case IF: return "If" case WHILE: return "While" case DO: return "Do" case FOR: return "For" ca...
[ "func", "(", "cp", "CommentPosition", ")", "String", "(", ")", "string", "{", "switch", "cp", "{", "case", "LEADING", ":", "return", "\"", "\"", "\n", "case", "TRAILING", ":", "return", "\"", "\"", "\n", "case", "KEY", ":", "return", "\"", "\"", "\n"...
// String returns a stringified version of the position
[ "String", "returns", "a", "stringified", "version", "of", "the", "position" ]
15f95af6e78dcd2030d8195a138bd88d4f403546
https://github.com/robertkrimen/otto/blob/15f95af6e78dcd2030d8195a138bd88d4f403546/ast/comments.go#L45-L70
27,285
robertkrimen/otto
ast/comments.go
FetchAll
func (c *Comments) FetchAll() []*Comment { defer func() { c.Comments = nil c.future = nil }() return append(c.Comments, c.future...) }
go
func (c *Comments) FetchAll() []*Comment { defer func() { c.Comments = nil c.future = nil }() return append(c.Comments, c.future...) }
[ "func", "(", "c", "*", "Comments", ")", "FetchAll", "(", ")", "[", "]", "*", "Comment", "{", "defer", "func", "(", ")", "{", "c", ".", "Comments", "=", "nil", "\n", "c", ".", "future", "=", "nil", "\n", "}", "(", ")", "\n\n", "return", "append"...
// FetchAll returns all the currently scanned comments, // including those from the next line
[ "FetchAll", "returns", "all", "the", "currently", "scanned", "comments", "including", "those", "from", "the", "next", "line" ]
15f95af6e78dcd2030d8195a138bd88d4f403546
https://github.com/robertkrimen/otto/blob/15f95af6e78dcd2030d8195a138bd88d4f403546/ast/comments.go#L110-L117
27,286
robertkrimen/otto
ast/comments.go
AddComment
func (c *Comments) AddComment(comment *Comment) { if c.primary { if !c.wasLineBreak { c.Comments = append(c.Comments, comment) } else { c.future = append(c.future, comment) } } else { if !c.wasLineBreak || (c.Current == nil && !c.afterBlock) { c.Comments = append(c.Comments, comment) } else { c....
go
func (c *Comments) AddComment(comment *Comment) { if c.primary { if !c.wasLineBreak { c.Comments = append(c.Comments, comment) } else { c.future = append(c.future, comment) } } else { if !c.wasLineBreak || (c.Current == nil && !c.afterBlock) { c.Comments = append(c.Comments, comment) } else { c....
[ "func", "(", "c", "*", "Comments", ")", "AddComment", "(", "comment", "*", "Comment", ")", "{", "if", "c", ".", "primary", "{", "if", "!", "c", ".", "wasLineBreak", "{", "c", ".", "Comments", "=", "append", "(", "c", ".", "Comments", ",", "comment"...
// AddComment adds a comment to the view. // Depending on the context, comments are added normally or as post line break.
[ "AddComment", "adds", "a", "comment", "to", "the", "view", ".", "Depending", "on", "the", "context", "comments", "are", "added", "normally", "or", "as", "post", "line", "break", "." ]
15f95af6e78dcd2030d8195a138bd88d4f403546
https://github.com/robertkrimen/otto/blob/15f95af6e78dcd2030d8195a138bd88d4f403546/ast/comments.go#L146-L160
27,287
robertkrimen/otto
ast/comments.go
MarkComments
func (c *Comments) MarkComments(position CommentPosition) { for _, comment := range c.Comments { if comment.Position == TBD { comment.Position = position } } for _, c := range c.future { if c.Position == TBD { c.Position = position } } }
go
func (c *Comments) MarkComments(position CommentPosition) { for _, comment := range c.Comments { if comment.Position == TBD { comment.Position = position } } for _, c := range c.future { if c.Position == TBD { c.Position = position } } }
[ "func", "(", "c", "*", "Comments", ")", "MarkComments", "(", "position", "CommentPosition", ")", "{", "for", "_", ",", "comment", ":=", "range", "c", ".", "Comments", "{", "if", "comment", ".", "Position", "==", "TBD", "{", "comment", ".", "Position", ...
// MarkComments will mark the found comments as the given position.
[ "MarkComments", "will", "mark", "the", "found", "comments", "as", "the", "given", "position", "." ]
15f95af6e78dcd2030d8195a138bd88d4f403546
https://github.com/robertkrimen/otto/blob/15f95af6e78dcd2030d8195a138bd88d4f403546/ast/comments.go#L163-L174
27,288
robertkrimen/otto
ast/comments.go
Unset
func (c *Comments) Unset() { if c.Current != nil { c.applyComments(c.Current, c.Current, TRAILING) c.Current = nil } c.wasLineBreak = false c.primary = false c.afterBlock = false }
go
func (c *Comments) Unset() { if c.Current != nil { c.applyComments(c.Current, c.Current, TRAILING) c.Current = nil } c.wasLineBreak = false c.primary = false c.afterBlock = false }
[ "func", "(", "c", "*", "Comments", ")", "Unset", "(", ")", "{", "if", "c", ".", "Current", "!=", "nil", "{", "c", ".", "applyComments", "(", "c", ".", "Current", ",", "c", ".", "Current", ",", "TRAILING", ")", "\n", "c", ".", "Current", "=", "n...
// Unset the current node and apply the comments to the current expression. // Resets context variables.
[ "Unset", "the", "current", "node", "and", "apply", "the", "comments", "to", "the", "current", "expression", ".", "Resets", "context", "variables", "." ]
15f95af6e78dcd2030d8195a138bd88d4f403546
https://github.com/robertkrimen/otto/blob/15f95af6e78dcd2030d8195a138bd88d4f403546/ast/comments.go#L178-L186
27,289
robertkrimen/otto
ast/comments.go
SetExpression
func (c *Comments) SetExpression(node Expression) { // Skipping same node if c.Current == node { return } if c.Current != nil && c.Current.Idx1() == node.Idx1() { c.Current = node return } previous := c.Current c.Current = node // Apply the found comments and futures to the node and the previous. c.appl...
go
func (c *Comments) SetExpression(node Expression) { // Skipping same node if c.Current == node { return } if c.Current != nil && c.Current.Idx1() == node.Idx1() { c.Current = node return } previous := c.Current c.Current = node // Apply the found comments and futures to the node and the previous. c.appl...
[ "func", "(", "c", "*", "Comments", ")", "SetExpression", "(", "node", "Expression", ")", "{", "// Skipping same node", "if", "c", ".", "Current", "==", "node", "{", "return", "\n", "}", "\n", "if", "c", ".", "Current", "!=", "nil", "&&", "c", ".", "C...
// SetExpression sets the current expression. // It is applied the found comments, unless the previous expression has not been unset. // It is skipped if the node is already set or if it is a part of the previous node.
[ "SetExpression", "sets", "the", "current", "expression", ".", "It", "is", "applied", "the", "found", "comments", "unless", "the", "previous", "expression", "has", "not", "been", "unset", ".", "It", "is", "skipped", "if", "the", "node", "is", "already", "set"...
15f95af6e78dcd2030d8195a138bd88d4f403546
https://github.com/robertkrimen/otto/blob/15f95af6e78dcd2030d8195a138bd88d4f403546/ast/comments.go#L191-L205
27,290
robertkrimen/otto
ast/comments.go
PostProcessNode
func (c *Comments) PostProcessNode(node Node) { c.applyComments(node, nil, TRAILING) }
go
func (c *Comments) PostProcessNode(node Node) { c.applyComments(node, nil, TRAILING) }
[ "func", "(", "c", "*", "Comments", ")", "PostProcessNode", "(", "node", "Node", ")", "{", "c", ".", "applyComments", "(", "node", ",", "nil", ",", "TRAILING", ")", "\n", "}" ]
// PostProcessNode applies all found comments to the given node
[ "PostProcessNode", "applies", "all", "found", "comments", "to", "the", "given", "node" ]
15f95af6e78dcd2030d8195a138bd88d4f403546
https://github.com/robertkrimen/otto/blob/15f95af6e78dcd2030d8195a138bd88d4f403546/ast/comments.go#L208-L210
27,291
robertkrimen/otto
ast/comments.go
applyComments
func (c *Comments) applyComments(node, previous Node, position CommentPosition) { if previous != nil { c.CommentMap.AddComments(previous, c.Comments, position) c.Comments = nil } else { c.CommentMap.AddComments(node, c.Comments, position) c.Comments = nil } // Only apply the future comments to the node if t...
go
func (c *Comments) applyComments(node, previous Node, position CommentPosition) { if previous != nil { c.CommentMap.AddComments(previous, c.Comments, position) c.Comments = nil } else { c.CommentMap.AddComments(node, c.Comments, position) c.Comments = nil } // Only apply the future comments to the node if t...
[ "func", "(", "c", "*", "Comments", ")", "applyComments", "(", "node", ",", "previous", "Node", ",", "position", "CommentPosition", ")", "{", "if", "previous", "!=", "nil", "{", "c", ".", "CommentMap", ".", "AddComments", "(", "previous", ",", "c", ".", ...
// applyComments applies both the comments and the future comments to the given node and the previous one, // based on the context.
[ "applyComments", "applies", "both", "the", "comments", "and", "the", "future", "comments", "to", "the", "given", "node", "and", "the", "previous", "one", "based", "on", "the", "context", "." ]
15f95af6e78dcd2030d8195a138bd88d4f403546
https://github.com/robertkrimen/otto/blob/15f95af6e78dcd2030d8195a138bd88d4f403546/ast/comments.go#L214-L228
27,292
robertkrimen/otto
ast/comments.go
AddComment
func (cm CommentMap) AddComment(node Node, comment *Comment) { list := cm[node] list = append(list, comment) cm[node] = list }
go
func (cm CommentMap) AddComment(node Node, comment *Comment) { list := cm[node] list = append(list, comment) cm[node] = list }
[ "func", "(", "cm", "CommentMap", ")", "AddComment", "(", "node", "Node", ",", "comment", "*", "Comment", ")", "{", "list", ":=", "cm", "[", "node", "]", "\n", "list", "=", "append", "(", "list", ",", "comment", ")", "\n\n", "cm", "[", "node", "]", ...
// AddComment adds a single comment to the map
[ "AddComment", "adds", "a", "single", "comment", "to", "the", "map" ]
15f95af6e78dcd2030d8195a138bd88d4f403546
https://github.com/robertkrimen/otto/blob/15f95af6e78dcd2030d8195a138bd88d4f403546/ast/comments.go#L239-L244
27,293
robertkrimen/otto
ast/comments.go
AddComments
func (cm CommentMap) AddComments(node Node, comments []*Comment, position CommentPosition) { for _, comment := range comments { if comment.Position == TBD { comment.Position = position } cm.AddComment(node, comment) } }
go
func (cm CommentMap) AddComments(node Node, comments []*Comment, position CommentPosition) { for _, comment := range comments { if comment.Position == TBD { comment.Position = position } cm.AddComment(node, comment) } }
[ "func", "(", "cm", "CommentMap", ")", "AddComments", "(", "node", "Node", ",", "comments", "[", "]", "*", "Comment", ",", "position", "CommentPosition", ")", "{", "for", "_", ",", "comment", ":=", "range", "comments", "{", "if", "comment", ".", "Position...
// AddComments adds a slice of comments, given a node and an updated position
[ "AddComments", "adds", "a", "slice", "of", "comments", "given", "a", "node", "and", "an", "updated", "position" ]
15f95af6e78dcd2030d8195a138bd88d4f403546
https://github.com/robertkrimen/otto/blob/15f95af6e78dcd2030d8195a138bd88d4f403546/ast/comments.go#L247-L254
27,294
robertkrimen/otto
ast/comments.go
Size
func (cm CommentMap) Size() int { size := 0 for _, comments := range cm { size += len(comments) } return size }
go
func (cm CommentMap) Size() int { size := 0 for _, comments := range cm { size += len(comments) } return size }
[ "func", "(", "cm", "CommentMap", ")", "Size", "(", ")", "int", "{", "size", ":=", "0", "\n", "for", "_", ",", "comments", ":=", "range", "cm", "{", "size", "+=", "len", "(", "comments", ")", "\n", "}", "\n\n", "return", "size", "\n", "}" ]
// Size returns the size of the map
[ "Size", "returns", "the", "size", "of", "the", "map" ]
15f95af6e78dcd2030d8195a138bd88d4f403546
https://github.com/robertkrimen/otto/blob/15f95af6e78dcd2030d8195a138bd88d4f403546/ast/comments.go#L257-L264
27,295
robertkrimen/otto
ast/comments.go
MoveComments
func (cm CommentMap) MoveComments(from, to Node, position CommentPosition) { for i, c := range cm[from] { if c.Position == position { cm.AddComment(to, c) // Remove the comment from the "from" slice cm[from][i] = cm[from][len(cm[from])-1] cm[from][len(cm[from])-1] = nil cm[from] = cm[from][:len(cm[fr...
go
func (cm CommentMap) MoveComments(from, to Node, position CommentPosition) { for i, c := range cm[from] { if c.Position == position { cm.AddComment(to, c) // Remove the comment from the "from" slice cm[from][i] = cm[from][len(cm[from])-1] cm[from][len(cm[from])-1] = nil cm[from] = cm[from][:len(cm[fr...
[ "func", "(", "cm", "CommentMap", ")", "MoveComments", "(", "from", ",", "to", "Node", ",", "position", "CommentPosition", ")", "{", "for", "i", ",", "c", ":=", "range", "cm", "[", "from", "]", "{", "if", "c", ".", "Position", "==", "position", "{", ...
// MoveComments moves comments with a given position from a node to another
[ "MoveComments", "moves", "comments", "with", "a", "given", "position", "from", "a", "node", "to", "another" ]
15f95af6e78dcd2030d8195a138bd88d4f403546
https://github.com/robertkrimen/otto/blob/15f95af6e78dcd2030d8195a138bd88d4f403546/ast/comments.go#L267-L278
27,296
robertkrimen/otto
otto.go
New
func New() *Otto { self := &Otto{ runtime: newContext(), } self.runtime.otto = self self.runtime.traceLimit = 10 self.Set("console", self.runtime.newConsole()) registry.Apply(func(entry registry.Entry) { self.Run(entry.Source()) }) return self }
go
func New() *Otto { self := &Otto{ runtime: newContext(), } self.runtime.otto = self self.runtime.traceLimit = 10 self.Set("console", self.runtime.newConsole()) registry.Apply(func(entry registry.Entry) { self.Run(entry.Source()) }) return self }
[ "func", "New", "(", ")", "*", "Otto", "{", "self", ":=", "&", "Otto", "{", "runtime", ":", "newContext", "(", ")", ",", "}", "\n", "self", ".", "runtime", ".", "otto", "=", "self", "\n", "self", ".", "runtime", ".", "traceLimit", "=", "10", "\n",...
// New will allocate a new JavaScript runtime
[ "New", "will", "allocate", "a", "new", "JavaScript", "runtime" ]
15f95af6e78dcd2030d8195a138bd88d4f403546
https://github.com/robertkrimen/otto/blob/15f95af6e78dcd2030d8195a138bd88d4f403546/otto.go#L244-L257
27,297
robertkrimen/otto
otto.go
Eval
func (self Otto) Eval(src interface{}) (Value, error) { if self.runtime.scope == nil { self.runtime.enterGlobalScope() defer self.runtime.leaveScope() } value, err := self.runtime.cmpl_eval(src, nil) if !value.safe() { value = Value{} } return value, err }
go
func (self Otto) Eval(src interface{}) (Value, error) { if self.runtime.scope == nil { self.runtime.enterGlobalScope() defer self.runtime.leaveScope() } value, err := self.runtime.cmpl_eval(src, nil) if !value.safe() { value = Value{} } return value, err }
[ "func", "(", "self", "Otto", ")", "Eval", "(", "src", "interface", "{", "}", ")", "(", "Value", ",", "error", ")", "{", "if", "self", ".", "runtime", ".", "scope", "==", "nil", "{", "self", ".", "runtime", ".", "enterGlobalScope", "(", ")", "\n", ...
// Eval will do the same thing as Run, except without leaving the current scope. // // By staying in the same scope, the code evaluated has access to everything // already defined in the current stack frame. This is most useful in, for // example, a debugger call.
[ "Eval", "will", "do", "the", "same", "thing", "as", "Run", "except", "without", "leaving", "the", "current", "scope", ".", "By", "staying", "in", "the", "same", "scope", "the", "code", "evaluated", "has", "access", "to", "everything", "already", "defined", ...
15f95af6e78dcd2030d8195a138bd88d4f403546
https://github.com/robertkrimen/otto/blob/15f95af6e78dcd2030d8195a138bd88d4f403546/otto.go#L307-L318
27,298
robertkrimen/otto
otto.go
MakeCustomError
func (self Otto) MakeCustomError(name, message string) Value { return self.runtime.toValue(self.runtime.newError(name, self.runtime.toValue(message), 0)) }
go
func (self Otto) MakeCustomError(name, message string) Value { return self.runtime.toValue(self.runtime.newError(name, self.runtime.toValue(message), 0)) }
[ "func", "(", "self", "Otto", ")", "MakeCustomError", "(", "name", ",", "message", "string", ")", "Value", "{", "return", "self", ".", "runtime", ".", "toValue", "(", "self", ".", "runtime", ".", "newError", "(", "name", ",", "self", ".", "runtime", "."...
// MakeCustomError creates a new Error object with the given name and message, // returning it as a Value.
[ "MakeCustomError", "creates", "a", "new", "Error", "object", "with", "the", "given", "name", "and", "message", "returning", "it", "as", "a", "Value", "." ]
15f95af6e78dcd2030d8195a138bd88d4f403546
https://github.com/robertkrimen/otto/blob/15f95af6e78dcd2030d8195a138bd88d4f403546/otto.go#L396-L398
27,299
robertkrimen/otto
otto.go
MakeRangeError
func (self Otto) MakeRangeError(message string) Value { return self.runtime.toValue(self.runtime.newRangeError(self.runtime.toValue(message))) }
go
func (self Otto) MakeRangeError(message string) Value { return self.runtime.toValue(self.runtime.newRangeError(self.runtime.toValue(message))) }
[ "func", "(", "self", "Otto", ")", "MakeRangeError", "(", "message", "string", ")", "Value", "{", "return", "self", ".", "runtime", ".", "toValue", "(", "self", ".", "runtime", ".", "newRangeError", "(", "self", ".", "runtime", ".", "toValue", "(", "messa...
// MakeRangeError creates a new RangeError object with the given message, // returning it as a Value.
[ "MakeRangeError", "creates", "a", "new", "RangeError", "object", "with", "the", "given", "message", "returning", "it", "as", "a", "Value", "." ]
15f95af6e78dcd2030d8195a138bd88d4f403546
https://github.com/robertkrimen/otto/blob/15f95af6e78dcd2030d8195a138bd88d4f403546/otto.go#L402-L404