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
sequence | docstring
stringlengths 6
2.61k
| docstring_tokens
sequence | sha
stringlengths 40
40
| url
stringlengths 85
252
|
---|---|---|---|---|---|---|---|---|---|---|---|
600 | aymerick/raymond | ast/node.go | LiteralStr | func LiteralStr(node Node) (string, bool) {
if lit, ok := node.(*StringLiteral); ok {
return lit.Value, true
}
if lit, ok := node.(*BooleanLiteral); ok {
return lit.Canonical(), true
}
if lit, ok := node.(*NumberLiteral); ok {
return lit.Canonical(), true
}
return "", false
} | go | func LiteralStr(node Node) (string, bool) {
if lit, ok := node.(*StringLiteral); ok {
return lit.Value, true
}
if lit, ok := node.(*BooleanLiteral); ok {
return lit.Canonical(), true
}
if lit, ok := node.(*NumberLiteral); ok {
return lit.Canonical(), true
}
return "", false
} | [
"func",
"LiteralStr",
"(",
"node",
"Node",
")",
"(",
"string",
",",
"bool",
")",
"{",
"if",
"lit",
",",
"ok",
":=",
"node",
".",
"(",
"*",
"StringLiteral",
")",
";",
"ok",
"{",
"return",
"lit",
".",
"Value",
",",
"true",
"\n",
"}",
"\n\n",
"if",
"lit",
",",
"ok",
":=",
"node",
".",
"(",
"*",
"BooleanLiteral",
")",
";",
"ok",
"{",
"return",
"lit",
".",
"Canonical",
"(",
")",
",",
"true",
"\n",
"}",
"\n\n",
"if",
"lit",
",",
"ok",
":=",
"node",
".",
"(",
"*",
"NumberLiteral",
")",
";",
"ok",
"{",
"return",
"lit",
".",
"Canonical",
"(",
")",
",",
"true",
"\n",
"}",
"\n\n",
"return",
"\"",
"\"",
",",
"false",
"\n",
"}"
] | // LiteralStr returns the string representation of literal value, with a boolean set to false if this is not a literal. | [
"LiteralStr",
"returns",
"the",
"string",
"representation",
"of",
"literal",
"value",
"with",
"a",
"boolean",
"set",
"to",
"false",
"if",
"this",
"is",
"not",
"a",
"literal",
"."
] | b565731e1464263de0bda75f2e45d97b54b60110 | https://github.com/aymerick/raymond/blob/b565731e1464263de0bda75f2e45d97b54b60110/ast/node.go#L475-L489 |
601 | aymerick/raymond | ast/node.go | NewSubExpression | func NewSubExpression(pos int, line int) *SubExpression {
return &SubExpression{
NodeType: NodeSubExpression,
Loc: Loc{pos, line},
}
} | go | func NewSubExpression(pos int, line int) *SubExpression {
return &SubExpression{
NodeType: NodeSubExpression,
Loc: Loc{pos, line},
}
} | [
"func",
"NewSubExpression",
"(",
"pos",
"int",
",",
"line",
"int",
")",
"*",
"SubExpression",
"{",
"return",
"&",
"SubExpression",
"{",
"NodeType",
":",
"NodeSubExpression",
",",
"Loc",
":",
"Loc",
"{",
"pos",
",",
"line",
"}",
",",
"}",
"\n",
"}"
] | // NewSubExpression instanciates a new subexpression node. | [
"NewSubExpression",
"instanciates",
"a",
"new",
"subexpression",
"node",
"."
] | b565731e1464263de0bda75f2e45d97b54b60110 | https://github.com/aymerick/raymond/blob/b565731e1464263de0bda75f2e45d97b54b60110/ast/node.go#L504-L509 |
602 | aymerick/raymond | ast/node.go | NewPathExpression | func NewPathExpression(pos int, line int, data bool) *PathExpression {
result := &PathExpression{
NodeType: NodePath,
Loc: Loc{pos, line},
Data: data,
}
if data {
result.Original = "@"
}
return result
} | go | func NewPathExpression(pos int, line int, data bool) *PathExpression {
result := &PathExpression{
NodeType: NodePath,
Loc: Loc{pos, line},
Data: data,
}
if data {
result.Original = "@"
}
return result
} | [
"func",
"NewPathExpression",
"(",
"pos",
"int",
",",
"line",
"int",
",",
"data",
"bool",
")",
"*",
"PathExpression",
"{",
"result",
":=",
"&",
"PathExpression",
"{",
"NodeType",
":",
"NodePath",
",",
"Loc",
":",
"Loc",
"{",
"pos",
",",
"line",
"}",
",",
"Data",
":",
"data",
",",
"}",
"\n\n",
"if",
"data",
"{",
"result",
".",
"Original",
"=",
"\"",
"\"",
"\n",
"}",
"\n\n",
"return",
"result",
"\n",
"}"
] | // NewPathExpression instanciates a new path expression node. | [
"NewPathExpression",
"instanciates",
"a",
"new",
"path",
"expression",
"node",
"."
] | b565731e1464263de0bda75f2e45d97b54b60110 | https://github.com/aymerick/raymond/blob/b565731e1464263de0bda75f2e45d97b54b60110/ast/node.go#L538-L551 |
603 | aymerick/raymond | ast/node.go | Part | func (node *PathExpression) Part(part string) {
node.Original += part
switch part {
case "..":
node.Depth++
node.Scoped = true
case ".", "this":
node.Scoped = true
default:
node.Parts = append(node.Parts, part)
}
} | go | func (node *PathExpression) Part(part string) {
node.Original += part
switch part {
case "..":
node.Depth++
node.Scoped = true
case ".", "this":
node.Scoped = true
default:
node.Parts = append(node.Parts, part)
}
} | [
"func",
"(",
"node",
"*",
"PathExpression",
")",
"Part",
"(",
"part",
"string",
")",
"{",
"node",
".",
"Original",
"+=",
"part",
"\n\n",
"switch",
"part",
"{",
"case",
"\"",
"\"",
":",
"node",
".",
"Depth",
"++",
"\n",
"node",
".",
"Scoped",
"=",
"true",
"\n",
"case",
"\"",
"\"",
",",
"\"",
"\"",
":",
"node",
".",
"Scoped",
"=",
"true",
"\n",
"default",
":",
"node",
".",
"Parts",
"=",
"append",
"(",
"node",
".",
"Parts",
",",
"part",
")",
"\n",
"}",
"\n",
"}"
] | // Part adds path part. | [
"Part",
"adds",
"path",
"part",
"."
] | b565731e1464263de0bda75f2e45d97b54b60110 | https://github.com/aymerick/raymond/blob/b565731e1464263de0bda75f2e45d97b54b60110/ast/node.go#L564-L576 |
604 | aymerick/raymond | ast/node.go | NewStringLiteral | func NewStringLiteral(pos int, line int, val string) *StringLiteral {
return &StringLiteral{
NodeType: NodeString,
Loc: Loc{pos, line},
Value: val,
}
} | go | func NewStringLiteral(pos int, line int, val string) *StringLiteral {
return &StringLiteral{
NodeType: NodeString,
Loc: Loc{pos, line},
Value: val,
}
} | [
"func",
"NewStringLiteral",
"(",
"pos",
"int",
",",
"line",
"int",
",",
"val",
"string",
")",
"*",
"StringLiteral",
"{",
"return",
"&",
"StringLiteral",
"{",
"NodeType",
":",
"NodeString",
",",
"Loc",
":",
"Loc",
"{",
"pos",
",",
"line",
"}",
",",
"Value",
":",
"val",
",",
"}",
"\n",
"}"
] | // NewStringLiteral instanciates a new string node. | [
"NewStringLiteral",
"instanciates",
"a",
"new",
"string",
"node",
"."
] | b565731e1464263de0bda75f2e45d97b54b60110 | https://github.com/aymerick/raymond/blob/b565731e1464263de0bda75f2e45d97b54b60110/ast/node.go#L601-L608 |
605 | aymerick/raymond | ast/node.go | NewBooleanLiteral | func NewBooleanLiteral(pos int, line int, val bool, original string) *BooleanLiteral {
return &BooleanLiteral{
NodeType: NodeBoolean,
Loc: Loc{pos, line},
Value: val,
Original: original,
}
} | go | func NewBooleanLiteral(pos int, line int, val bool, original string) *BooleanLiteral {
return &BooleanLiteral{
NodeType: NodeBoolean,
Loc: Loc{pos, line},
Value: val,
Original: original,
}
} | [
"func",
"NewBooleanLiteral",
"(",
"pos",
"int",
",",
"line",
"int",
",",
"val",
"bool",
",",
"original",
"string",
")",
"*",
"BooleanLiteral",
"{",
"return",
"&",
"BooleanLiteral",
"{",
"NodeType",
":",
"NodeBoolean",
",",
"Loc",
":",
"Loc",
"{",
"pos",
",",
"line",
"}",
",",
"Value",
":",
"val",
",",
"Original",
":",
"original",
",",
"}",
"\n",
"}"
] | // NewBooleanLiteral instanciates a new boolean node. | [
"NewBooleanLiteral",
"instanciates",
"a",
"new",
"boolean",
"node",
"."
] | b565731e1464263de0bda75f2e45d97b54b60110 | https://github.com/aymerick/raymond/blob/b565731e1464263de0bda75f2e45d97b54b60110/ast/node.go#L634-L642 |
606 | aymerick/raymond | ast/node.go | NewNumberLiteral | func NewNumberLiteral(pos int, line int, val float64, isInt bool, original string) *NumberLiteral {
return &NumberLiteral{
NodeType: NodeNumber,
Loc: Loc{pos, line},
Value: val,
IsInt: isInt,
Original: original,
}
} | go | func NewNumberLiteral(pos int, line int, val float64, isInt bool, original string) *NumberLiteral {
return &NumberLiteral{
NodeType: NodeNumber,
Loc: Loc{pos, line},
Value: val,
IsInt: isInt,
Original: original,
}
} | [
"func",
"NewNumberLiteral",
"(",
"pos",
"int",
",",
"line",
"int",
",",
"val",
"float64",
",",
"isInt",
"bool",
",",
"original",
"string",
")",
"*",
"NumberLiteral",
"{",
"return",
"&",
"NumberLiteral",
"{",
"NodeType",
":",
"NodeNumber",
",",
"Loc",
":",
"Loc",
"{",
"pos",
",",
"line",
"}",
",",
"Value",
":",
"val",
",",
"IsInt",
":",
"isInt",
",",
"Original",
":",
"original",
",",
"}",
"\n",
"}"
] | // NewNumberLiteral instanciates a new number node. | [
"NewNumberLiteral",
"instanciates",
"a",
"new",
"number",
"node",
"."
] | b565731e1464263de0bda75f2e45d97b54b60110 | https://github.com/aymerick/raymond/blob/b565731e1464263de0bda75f2e45d97b54b60110/ast/node.go#L678-L687 |
607 | aymerick/raymond | ast/node.go | Number | func (node *NumberLiteral) Number() interface{} {
if node.IsInt {
return int(node.Value)
}
return node.Value
} | go | func (node *NumberLiteral) Number() interface{} {
if node.IsInt {
return int(node.Value)
}
return node.Value
} | [
"func",
"(",
"node",
"*",
"NumberLiteral",
")",
"Number",
"(",
")",
"interface",
"{",
"}",
"{",
"if",
"node",
".",
"IsInt",
"{",
"return",
"int",
"(",
"node",
".",
"Value",
")",
"\n",
"}",
"\n\n",
"return",
"node",
".",
"Value",
"\n",
"}"
] | // Number returns an integer or a float. | [
"Number",
"returns",
"an",
"integer",
"or",
"a",
"float",
"."
] | b565731e1464263de0bda75f2e45d97b54b60110 | https://github.com/aymerick/raymond/blob/b565731e1464263de0bda75f2e45d97b54b60110/ast/node.go#L709-L715 |
608 | aymerick/raymond | ast/node.go | NewHash | func NewHash(pos int, line int) *Hash {
return &Hash{
NodeType: NodeHash,
Loc: Loc{pos, line},
}
} | go | func NewHash(pos int, line int) *Hash {
return &Hash{
NodeType: NodeHash,
Loc: Loc{pos, line},
}
} | [
"func",
"NewHash",
"(",
"pos",
"int",
",",
"line",
"int",
")",
"*",
"Hash",
"{",
"return",
"&",
"Hash",
"{",
"NodeType",
":",
"NodeHash",
",",
"Loc",
":",
"Loc",
"{",
"pos",
",",
"line",
"}",
",",
"}",
"\n",
"}"
] | // NewHash instanciates a new hash node. | [
"NewHash",
"instanciates",
"a",
"new",
"hash",
"node",
"."
] | b565731e1464263de0bda75f2e45d97b54b60110 | https://github.com/aymerick/raymond/blob/b565731e1464263de0bda75f2e45d97b54b60110/ast/node.go#L730-L735 |
609 | aymerick/raymond | ast/node.go | NewHashPair | func NewHashPair(pos int, line int) *HashPair {
return &HashPair{
NodeType: NodeHashPair,
Loc: Loc{pos, line},
}
} | go | func NewHashPair(pos int, line int) *HashPair {
return &HashPair{
NodeType: NodeHashPair,
Loc: Loc{pos, line},
}
} | [
"func",
"NewHashPair",
"(",
"pos",
"int",
",",
"line",
"int",
")",
"*",
"HashPair",
"{",
"return",
"&",
"HashPair",
"{",
"NodeType",
":",
"NodeHashPair",
",",
"Loc",
":",
"Loc",
"{",
"pos",
",",
"line",
"}",
",",
"}",
"\n",
"}"
] | // NewHashPair instanciates a new hash pair node. | [
"NewHashPair",
"instanciates",
"a",
"new",
"hash",
"pair",
"node",
"."
] | b565731e1464263de0bda75f2e45d97b54b60110 | https://github.com/aymerick/raymond/blob/b565731e1464263de0bda75f2e45d97b54b60110/ast/node.go#L770-L775 |
610 | aymerick/raymond | parser/parser.go | Parse | func Parse(input string) (result *ast.Program, err error) {
// recover error
defer errRecover(&err)
parser := new(input)
// parse
result = parser.parseProgram()
// check last token
token := parser.shift()
if token.Kind != lexer.TokenEOF {
// Parsing ended before EOF
errToken(token, "Syntax error")
}
// fix whitespaces
processWhitespaces(result)
// named returned values
return
} | go | func Parse(input string) (result *ast.Program, err error) {
// recover error
defer errRecover(&err)
parser := new(input)
// parse
result = parser.parseProgram()
// check last token
token := parser.shift()
if token.Kind != lexer.TokenEOF {
// Parsing ended before EOF
errToken(token, "Syntax error")
}
// fix whitespaces
processWhitespaces(result)
// named returned values
return
} | [
"func",
"Parse",
"(",
"input",
"string",
")",
"(",
"result",
"*",
"ast",
".",
"Program",
",",
"err",
"error",
")",
"{",
"// recover error",
"defer",
"errRecover",
"(",
"&",
"err",
")",
"\n\n",
"parser",
":=",
"new",
"(",
"input",
")",
"\n\n",
"// parse",
"result",
"=",
"parser",
".",
"parseProgram",
"(",
")",
"\n\n",
"// check last token",
"token",
":=",
"parser",
".",
"shift",
"(",
")",
"\n",
"if",
"token",
".",
"Kind",
"!=",
"lexer",
".",
"TokenEOF",
"{",
"// Parsing ended before EOF",
"errToken",
"(",
"token",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"// fix whitespaces",
"processWhitespaces",
"(",
"result",
")",
"\n\n",
"// named returned values",
"return",
"\n",
"}"
] | // Parse analyzes given input and returns the AST root node. | [
"Parse",
"analyzes",
"given",
"input",
"and",
"returns",
"the",
"AST",
"root",
"node",
"."
] | b565731e1464263de0bda75f2e45d97b54b60110 | https://github.com/aymerick/raymond/blob/b565731e1464263de0bda75f2e45d97b54b60110/parser/parser.go#L47-L68 |
611 | aymerick/raymond | parser/parser.go | errNode | func errNode(node ast.Node, msg string) {
errPanic(fmt.Errorf("%s\nNode: %s", msg, node), node.Location().Line)
} | go | func errNode(node ast.Node, msg string) {
errPanic(fmt.Errorf("%s\nNode: %s", msg, node), node.Location().Line)
} | [
"func",
"errNode",
"(",
"node",
"ast",
".",
"Node",
",",
"msg",
"string",
")",
"{",
"errPanic",
"(",
"fmt",
".",
"Errorf",
"(",
"\"",
"\\n",
"\"",
",",
"msg",
",",
"node",
")",
",",
"node",
".",
"Location",
"(",
")",
".",
"Line",
")",
"\n",
"}"
] | // errNode panics with given node infos | [
"errNode",
"panics",
"with",
"given",
"node",
"infos"
] | b565731e1464263de0bda75f2e45d97b54b60110 | https://github.com/aymerick/raymond/blob/b565731e1464263de0bda75f2e45d97b54b60110/parser/parser.go#L91-L93 |
612 | aymerick/raymond | parser/parser.go | errToken | func errToken(tok *lexer.Token, msg string) {
errPanic(fmt.Errorf("%s\nToken: %s", msg, tok), tok.Line)
} | go | func errToken(tok *lexer.Token, msg string) {
errPanic(fmt.Errorf("%s\nToken: %s", msg, tok), tok.Line)
} | [
"func",
"errToken",
"(",
"tok",
"*",
"lexer",
".",
"Token",
",",
"msg",
"string",
")",
"{",
"errPanic",
"(",
"fmt",
".",
"Errorf",
"(",
"\"",
"\\n",
"\"",
",",
"msg",
",",
"tok",
")",
",",
"tok",
".",
"Line",
")",
"\n",
"}"
] | // errNode panics with given Token infos | [
"errNode",
"panics",
"with",
"given",
"Token",
"infos"
] | b565731e1464263de0bda75f2e45d97b54b60110 | https://github.com/aymerick/raymond/blob/b565731e1464263de0bda75f2e45d97b54b60110/parser/parser.go#L96-L98 |
613 | aymerick/raymond | parser/parser.go | errExpected | func errExpected(expect lexer.TokenKind, tok *lexer.Token) {
errPanic(fmt.Errorf("Expecting %s, got: '%s'", expect, tok), tok.Line)
} | go | func errExpected(expect lexer.TokenKind, tok *lexer.Token) {
errPanic(fmt.Errorf("Expecting %s, got: '%s'", expect, tok), tok.Line)
} | [
"func",
"errExpected",
"(",
"expect",
"lexer",
".",
"TokenKind",
",",
"tok",
"*",
"lexer",
".",
"Token",
")",
"{",
"errPanic",
"(",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"expect",
",",
"tok",
")",
",",
"tok",
".",
"Line",
")",
"\n",
"}"
] | // errNode panics because of an unexpected Token kind | [
"errNode",
"panics",
"because",
"of",
"an",
"unexpected",
"Token",
"kind"
] | b565731e1464263de0bda75f2e45d97b54b60110 | https://github.com/aymerick/raymond/blob/b565731e1464263de0bda75f2e45d97b54b60110/parser/parser.go#L101-L103 |
614 | aymerick/raymond | parser/parser.go | isStatement | func (p *parser) isStatement() bool {
if !p.have(1) {
return false
}
switch p.next().Kind {
case lexer.TokenOpen, lexer.TokenOpenUnescaped, lexer.TokenOpenBlock,
lexer.TokenOpenInverse, lexer.TokenOpenRawBlock, lexer.TokenOpenPartial,
lexer.TokenContent, lexer.TokenComment:
return true
}
return false
} | go | func (p *parser) isStatement() bool {
if !p.have(1) {
return false
}
switch p.next().Kind {
case lexer.TokenOpen, lexer.TokenOpenUnescaped, lexer.TokenOpenBlock,
lexer.TokenOpenInverse, lexer.TokenOpenRawBlock, lexer.TokenOpenPartial,
lexer.TokenContent, lexer.TokenComment:
return true
}
return false
} | [
"func",
"(",
"p",
"*",
"parser",
")",
"isStatement",
"(",
")",
"bool",
"{",
"if",
"!",
"p",
".",
"have",
"(",
"1",
")",
"{",
"return",
"false",
"\n",
"}",
"\n\n",
"switch",
"p",
".",
"next",
"(",
")",
".",
"Kind",
"{",
"case",
"lexer",
".",
"TokenOpen",
",",
"lexer",
".",
"TokenOpenUnescaped",
",",
"lexer",
".",
"TokenOpenBlock",
",",
"lexer",
".",
"TokenOpenInverse",
",",
"lexer",
".",
"TokenOpenRawBlock",
",",
"lexer",
".",
"TokenOpenPartial",
",",
"lexer",
".",
"TokenContent",
",",
"lexer",
".",
"TokenComment",
":",
"return",
"true",
"\n",
"}",
"\n\n",
"return",
"false",
"\n",
"}"
] | // isStatement returns true if next token starts a statement | [
"isStatement",
"returns",
"true",
"if",
"next",
"token",
"starts",
"a",
"statement"
] | b565731e1464263de0bda75f2e45d97b54b60110 | https://github.com/aymerick/raymond/blob/b565731e1464263de0bda75f2e45d97b54b60110/parser/parser.go#L150-L163 |
615 | aymerick/raymond | parser/parser.go | parseHelperNameOrSexpr | func (p *parser) parseHelperNameOrSexpr() ast.Node {
if p.isSexpr() {
// sexpr
return p.parseSexpr()
}
// helperName
return p.parseHelperName()
} | go | func (p *parser) parseHelperNameOrSexpr() ast.Node {
if p.isSexpr() {
// sexpr
return p.parseSexpr()
}
// helperName
return p.parseHelperName()
} | [
"func",
"(",
"p",
"*",
"parser",
")",
"parseHelperNameOrSexpr",
"(",
")",
"ast",
".",
"Node",
"{",
"if",
"p",
".",
"isSexpr",
"(",
")",
"{",
"// sexpr",
"return",
"p",
".",
"parseSexpr",
"(",
")",
"\n",
"}",
"\n\n",
"// helperName",
"return",
"p",
".",
"parseHelperName",
"(",
")",
"\n",
"}"
] | // helperName | sexpr | [
"helperName",
"|",
"sexpr"
] | b565731e1464263de0bda75f2e45d97b54b60110 | https://github.com/aymerick/raymond/blob/b565731e1464263de0bda75f2e45d97b54b60110/parser/parser.go#L521-L529 |
616 | aymerick/raymond | parser/parser.go | isParam | func (p *parser) isParam() bool {
return (p.isSexpr() || p.isHelperName()) && !p.isHashSegment()
} | go | func (p *parser) isParam() bool {
return (p.isSexpr() || p.isHelperName()) && !p.isHashSegment()
} | [
"func",
"(",
"p",
"*",
"parser",
")",
"isParam",
"(",
")",
"bool",
"{",
"return",
"(",
"p",
".",
"isSexpr",
"(",
")",
"||",
"p",
".",
"isHelperName",
"(",
")",
")",
"&&",
"!",
"p",
".",
"isHashSegment",
"(",
")",
"\n",
"}"
] | // Returns true if next tokens represent a `param` | [
"Returns",
"true",
"if",
"next",
"tokens",
"represent",
"a",
"param"
] | b565731e1464263de0bda75f2e45d97b54b60110 | https://github.com/aymerick/raymond/blob/b565731e1464263de0bda75f2e45d97b54b60110/parser/parser.go#L537-L539 |
617 | aymerick/raymond | parser/parser.go | isHashSegment | func (p *parser) isHashSegment() bool {
return p.have(2) && (p.next().Kind == lexer.TokenID) && (p.nextAt(1).Kind == lexer.TokenEquals)
} | go | func (p *parser) isHashSegment() bool {
return p.have(2) && (p.next().Kind == lexer.TokenID) && (p.nextAt(1).Kind == lexer.TokenEquals)
} | [
"func",
"(",
"p",
"*",
"parser",
")",
"isHashSegment",
"(",
")",
"bool",
"{",
"return",
"p",
".",
"have",
"(",
"2",
")",
"&&",
"(",
"p",
".",
"next",
"(",
")",
".",
"Kind",
"==",
"lexer",
".",
"TokenID",
")",
"&&",
"(",
"p",
".",
"nextAt",
"(",
"1",
")",
".",
"Kind",
"==",
"lexer",
".",
"TokenEquals",
")",
"\n",
"}"
] | // returns true if next tokens represents a `hashSegment` | [
"returns",
"true",
"if",
"next",
"tokens",
"represents",
"a",
"hashSegment"
] | b565731e1464263de0bda75f2e45d97b54b60110 | https://github.com/aymerick/raymond/blob/b565731e1464263de0bda75f2e45d97b54b60110/parser/parser.go#L588-L590 |
618 | aymerick/raymond | parser/parser.go | parseNumber | func parseNumber(tok *lexer.Token) (result float64, isInt bool) {
var valInt int
var err error
valInt, err = strconv.Atoi(tok.Val)
if err == nil {
isInt = true
result = float64(valInt)
} else {
isInt = false
result, err = strconv.ParseFloat(tok.Val, 64)
if err != nil {
errToken(tok, fmt.Sprintf("Failed to parse number: %s", tok.Val))
}
}
// named returned values
return
} | go | func parseNumber(tok *lexer.Token) (result float64, isInt bool) {
var valInt int
var err error
valInt, err = strconv.Atoi(tok.Val)
if err == nil {
isInt = true
result = float64(valInt)
} else {
isInt = false
result, err = strconv.ParseFloat(tok.Val, 64)
if err != nil {
errToken(tok, fmt.Sprintf("Failed to parse number: %s", tok.Val))
}
}
// named returned values
return
} | [
"func",
"parseNumber",
"(",
"tok",
"*",
"lexer",
".",
"Token",
")",
"(",
"result",
"float64",
",",
"isInt",
"bool",
")",
"{",
"var",
"valInt",
"int",
"\n",
"var",
"err",
"error",
"\n\n",
"valInt",
",",
"err",
"=",
"strconv",
".",
"Atoi",
"(",
"tok",
".",
"Val",
")",
"\n",
"if",
"err",
"==",
"nil",
"{",
"isInt",
"=",
"true",
"\n\n",
"result",
"=",
"float64",
"(",
"valInt",
")",
"\n",
"}",
"else",
"{",
"isInt",
"=",
"false",
"\n\n",
"result",
",",
"err",
"=",
"strconv",
".",
"ParseFloat",
"(",
"tok",
".",
"Val",
",",
"64",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"errToken",
"(",
"tok",
",",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"tok",
".",
"Val",
")",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"// named returned values",
"return",
"\n",
"}"
] | // parseNumber parses a number | [
"parseNumber",
"parses",
"a",
"number"
] | b565731e1464263de0bda75f2e45d97b54b60110 | https://github.com/aymerick/raymond/blob/b565731e1464263de0bda75f2e45d97b54b60110/parser/parser.go#L668-L688 |
619 | aymerick/raymond | parser/parser.go | isHelperName | func (p *parser) isHelperName() bool {
switch p.next().Kind {
case lexer.TokenBoolean, lexer.TokenNumber, lexer.TokenString, lexer.TokenData, lexer.TokenID:
return true
}
return false
} | go | func (p *parser) isHelperName() bool {
switch p.next().Kind {
case lexer.TokenBoolean, lexer.TokenNumber, lexer.TokenString, lexer.TokenData, lexer.TokenID:
return true
}
return false
} | [
"func",
"(",
"p",
"*",
"parser",
")",
"isHelperName",
"(",
")",
"bool",
"{",
"switch",
"p",
".",
"next",
"(",
")",
".",
"Kind",
"{",
"case",
"lexer",
".",
"TokenBoolean",
",",
"lexer",
".",
"TokenNumber",
",",
"lexer",
".",
"TokenString",
",",
"lexer",
".",
"TokenData",
",",
"lexer",
".",
"TokenID",
":",
"return",
"true",
"\n",
"}",
"\n\n",
"return",
"false",
"\n",
"}"
] | // Returns true if next tokens represent a `helperName` | [
"Returns",
"true",
"if",
"next",
"tokens",
"represent",
"a",
"helperName"
] | b565731e1464263de0bda75f2e45d97b54b60110 | https://github.com/aymerick/raymond/blob/b565731e1464263de0bda75f2e45d97b54b60110/parser/parser.go#L691-L698 |
620 | aymerick/raymond | parser/parser.go | ensure | func (p *parser) ensure(index int) {
if p.lexOver {
// nothing more to grab
return
}
nb := index + 1
for len(p.tokens) < nb {
// fetch next token
tok := p.lex.NextToken()
// queue it
p.tokens = append(p.tokens, &tok)
if (tok.Kind == lexer.TokenEOF) || (tok.Kind == lexer.TokenError) {
p.lexOver = true
break
}
}
} | go | func (p *parser) ensure(index int) {
if p.lexOver {
// nothing more to grab
return
}
nb := index + 1
for len(p.tokens) < nb {
// fetch next token
tok := p.lex.NextToken()
// queue it
p.tokens = append(p.tokens, &tok)
if (tok.Kind == lexer.TokenEOF) || (tok.Kind == lexer.TokenError) {
p.lexOver = true
break
}
}
} | [
"func",
"(",
"p",
"*",
"parser",
")",
"ensure",
"(",
"index",
"int",
")",
"{",
"if",
"p",
".",
"lexOver",
"{",
"// nothing more to grab",
"return",
"\n",
"}",
"\n\n",
"nb",
":=",
"index",
"+",
"1",
"\n\n",
"for",
"len",
"(",
"p",
".",
"tokens",
")",
"<",
"nb",
"{",
"// fetch next token",
"tok",
":=",
"p",
".",
"lex",
".",
"NextToken",
"(",
")",
"\n\n",
"// queue it",
"p",
".",
"tokens",
"=",
"append",
"(",
"p",
".",
"tokens",
",",
"&",
"tok",
")",
"\n\n",
"if",
"(",
"tok",
".",
"Kind",
"==",
"lexer",
".",
"TokenEOF",
")",
"||",
"(",
"tok",
".",
"Kind",
"==",
"lexer",
".",
"TokenError",
")",
"{",
"p",
".",
"lexOver",
"=",
"true",
"\n",
"break",
"\n",
"}",
"\n",
"}",
"\n",
"}"
] | // Ensures there is token to parse at given index | [
"Ensures",
"there",
"is",
"token",
"to",
"parse",
"at",
"given",
"index"
] | b565731e1464263de0bda75f2e45d97b54b60110 | https://github.com/aymerick/raymond/blob/b565731e1464263de0bda75f2e45d97b54b60110/parser/parser.go#L754-L774 |
621 | aymerick/raymond | parser/parser.go | have | func (p *parser) have(nb int) bool {
p.ensure(nb - 1)
return len(p.tokens) >= nb
} | go | func (p *parser) have(nb int) bool {
p.ensure(nb - 1)
return len(p.tokens) >= nb
} | [
"func",
"(",
"p",
"*",
"parser",
")",
"have",
"(",
"nb",
"int",
")",
"bool",
"{",
"p",
".",
"ensure",
"(",
"nb",
"-",
"1",
")",
"\n\n",
"return",
"len",
"(",
"p",
".",
"tokens",
")",
">=",
"nb",
"\n",
"}"
] | // have returns true is there are a list given number of tokens to consume left | [
"have",
"returns",
"true",
"is",
"there",
"are",
"a",
"list",
"given",
"number",
"of",
"tokens",
"to",
"consume",
"left"
] | b565731e1464263de0bda75f2e45d97b54b60110 | https://github.com/aymerick/raymond/blob/b565731e1464263de0bda75f2e45d97b54b60110/parser/parser.go#L777-L781 |
622 | aymerick/raymond | parser/parser.go | nextAt | func (p *parser) nextAt(index int) *lexer.Token {
p.ensure(index)
return p.tokens[index]
} | go | func (p *parser) nextAt(index int) *lexer.Token {
p.ensure(index)
return p.tokens[index]
} | [
"func",
"(",
"p",
"*",
"parser",
")",
"nextAt",
"(",
"index",
"int",
")",
"*",
"lexer",
".",
"Token",
"{",
"p",
".",
"ensure",
"(",
"index",
")",
"\n\n",
"return",
"p",
".",
"tokens",
"[",
"index",
"]",
"\n",
"}"
] | // nextAt returns next token at given index, without consuming it | [
"nextAt",
"returns",
"next",
"token",
"at",
"given",
"index",
"without",
"consuming",
"it"
] | b565731e1464263de0bda75f2e45d97b54b60110 | https://github.com/aymerick/raymond/blob/b565731e1464263de0bda75f2e45d97b54b60110/parser/parser.go#L784-L788 |
623 | aymerick/raymond | parser/parser.go | shift | func (p *parser) shift() *lexer.Token {
var result *lexer.Token
p.ensure(0)
result, p.tokens = p.tokens[0], p.tokens[1:]
// check error token
if result.Kind == lexer.TokenError {
errToken(result, "Lexer error")
}
return result
} | go | func (p *parser) shift() *lexer.Token {
var result *lexer.Token
p.ensure(0)
result, p.tokens = p.tokens[0], p.tokens[1:]
// check error token
if result.Kind == lexer.TokenError {
errToken(result, "Lexer error")
}
return result
} | [
"func",
"(",
"p",
"*",
"parser",
")",
"shift",
"(",
")",
"*",
"lexer",
".",
"Token",
"{",
"var",
"result",
"*",
"lexer",
".",
"Token",
"\n\n",
"p",
".",
"ensure",
"(",
"0",
")",
"\n\n",
"result",
",",
"p",
".",
"tokens",
"=",
"p",
".",
"tokens",
"[",
"0",
"]",
",",
"p",
".",
"tokens",
"[",
"1",
":",
"]",
"\n\n",
"// check error token",
"if",
"result",
".",
"Kind",
"==",
"lexer",
".",
"TokenError",
"{",
"errToken",
"(",
"result",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"return",
"result",
"\n",
"}"
] | // shift returns next token and remove it from the tokens buffer
//
// Panics if next token is `TokenError` | [
"shift",
"returns",
"next",
"token",
"and",
"remove",
"it",
"from",
"the",
"tokens",
"buffer",
"Panics",
"if",
"next",
"token",
"is",
"TokenError"
] | b565731e1464263de0bda75f2e45d97b54b60110 | https://github.com/aymerick/raymond/blob/b565731e1464263de0bda75f2e45d97b54b60110/parser/parser.go#L798-L811 |
624 | aymerick/raymond | parser/parser.go | isToken | func (p *parser) isToken(kind lexer.TokenKind) bool {
return p.have(1) && p.next().Kind == kind
} | go | func (p *parser) isToken(kind lexer.TokenKind) bool {
return p.have(1) && p.next().Kind == kind
} | [
"func",
"(",
"p",
"*",
"parser",
")",
"isToken",
"(",
"kind",
"lexer",
".",
"TokenKind",
")",
"bool",
"{",
"return",
"p",
".",
"have",
"(",
"1",
")",
"&&",
"p",
".",
"next",
"(",
")",
".",
"Kind",
"==",
"kind",
"\n",
"}"
] | // isToken returns true if next token is of given type | [
"isToken",
"returns",
"true",
"if",
"next",
"token",
"is",
"of",
"given",
"type"
] | b565731e1464263de0bda75f2e45d97b54b60110 | https://github.com/aymerick/raymond/blob/b565731e1464263de0bda75f2e45d97b54b60110/parser/parser.go#L814-L816 |
625 | aymerick/raymond | data_frame.go | Copy | func (p *DataFrame) Copy() *DataFrame {
result := NewDataFrame()
for k, v := range p.data {
result.data[k] = v
}
result.parent = p
return result
} | go | func (p *DataFrame) Copy() *DataFrame {
result := NewDataFrame()
for k, v := range p.data {
result.data[k] = v
}
result.parent = p
return result
} | [
"func",
"(",
"p",
"*",
"DataFrame",
")",
"Copy",
"(",
")",
"*",
"DataFrame",
"{",
"result",
":=",
"NewDataFrame",
"(",
")",
"\n\n",
"for",
"k",
",",
"v",
":=",
"range",
"p",
".",
"data",
"{",
"result",
".",
"data",
"[",
"k",
"]",
"=",
"v",
"\n",
"}",
"\n\n",
"result",
".",
"parent",
"=",
"p",
"\n\n",
"return",
"result",
"\n",
"}"
] | // Copy instanciates a new private data frame with receiver as parent. | [
"Copy",
"instanciates",
"a",
"new",
"private",
"data",
"frame",
"with",
"receiver",
"as",
"parent",
"."
] | b565731e1464263de0bda75f2e45d97b54b60110 | https://github.com/aymerick/raymond/blob/b565731e1464263de0bda75f2e45d97b54b60110/data_frame.go#L21-L31 |
626 | aymerick/raymond | data_frame.go | newIterDataFrame | func (p *DataFrame) newIterDataFrame(length int, i int, key interface{}) *DataFrame {
result := p.Copy()
result.Set("index", i)
result.Set("key", key)
result.Set("first", i == 0)
result.Set("last", i == length-1)
return result
} | go | func (p *DataFrame) newIterDataFrame(length int, i int, key interface{}) *DataFrame {
result := p.Copy()
result.Set("index", i)
result.Set("key", key)
result.Set("first", i == 0)
result.Set("last", i == length-1)
return result
} | [
"func",
"(",
"p",
"*",
"DataFrame",
")",
"newIterDataFrame",
"(",
"length",
"int",
",",
"i",
"int",
",",
"key",
"interface",
"{",
"}",
")",
"*",
"DataFrame",
"{",
"result",
":=",
"p",
".",
"Copy",
"(",
")",
"\n\n",
"result",
".",
"Set",
"(",
"\"",
"\"",
",",
"i",
")",
"\n",
"result",
".",
"Set",
"(",
"\"",
"\"",
",",
"key",
")",
"\n",
"result",
".",
"Set",
"(",
"\"",
"\"",
",",
"i",
"==",
"0",
")",
"\n",
"result",
".",
"Set",
"(",
"\"",
"\"",
",",
"i",
"==",
"length",
"-",
"1",
")",
"\n\n",
"return",
"result",
"\n",
"}"
] | // newIterDataFrame instanciates a new private data frame with receiver as parent and with iteration data set (@index, @key, @first, @last) | [
"newIterDataFrame",
"instanciates",
"a",
"new",
"private",
"data",
"frame",
"with",
"receiver",
"as",
"parent",
"and",
"with",
"iteration",
"data",
"set",
"("
] | b565731e1464263de0bda75f2e45d97b54b60110 | https://github.com/aymerick/raymond/blob/b565731e1464263de0bda75f2e45d97b54b60110/data_frame.go#L34-L43 |
627 | aymerick/raymond | data_frame.go | Set | func (p *DataFrame) Set(key string, val interface{}) {
p.data[key] = val
} | go | func (p *DataFrame) Set(key string, val interface{}) {
p.data[key] = val
} | [
"func",
"(",
"p",
"*",
"DataFrame",
")",
"Set",
"(",
"key",
"string",
",",
"val",
"interface",
"{",
"}",
")",
"{",
"p",
".",
"data",
"[",
"key",
"]",
"=",
"val",
"\n",
"}"
] | // Set sets a data value. | [
"Set",
"sets",
"a",
"data",
"value",
"."
] | b565731e1464263de0bda75f2e45d97b54b60110 | https://github.com/aymerick/raymond/blob/b565731e1464263de0bda75f2e45d97b54b60110/data_frame.go#L46-L48 |
628 | aymerick/raymond | data_frame.go | find | func (p *DataFrame) find(parts []string) interface{} {
data := p.data
for i, part := range parts {
val := data[part]
if val == nil {
return nil
}
if i == len(parts)-1 {
// found
return val
}
valValue := reflect.ValueOf(val)
if valValue.Kind() != reflect.Map {
// not found
return nil
}
// continue
data = mapStringInterface(valValue)
}
// not found
return nil
} | go | func (p *DataFrame) find(parts []string) interface{} {
data := p.data
for i, part := range parts {
val := data[part]
if val == nil {
return nil
}
if i == len(parts)-1 {
// found
return val
}
valValue := reflect.ValueOf(val)
if valValue.Kind() != reflect.Map {
// not found
return nil
}
// continue
data = mapStringInterface(valValue)
}
// not found
return nil
} | [
"func",
"(",
"p",
"*",
"DataFrame",
")",
"find",
"(",
"parts",
"[",
"]",
"string",
")",
"interface",
"{",
"}",
"{",
"data",
":=",
"p",
".",
"data",
"\n\n",
"for",
"i",
",",
"part",
":=",
"range",
"parts",
"{",
"val",
":=",
"data",
"[",
"part",
"]",
"\n",
"if",
"val",
"==",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n\n",
"if",
"i",
"==",
"len",
"(",
"parts",
")",
"-",
"1",
"{",
"// found",
"return",
"val",
"\n",
"}",
"\n\n",
"valValue",
":=",
"reflect",
".",
"ValueOf",
"(",
"val",
")",
"\n",
"if",
"valValue",
".",
"Kind",
"(",
")",
"!=",
"reflect",
".",
"Map",
"{",
"// not found",
"return",
"nil",
"\n",
"}",
"\n\n",
"// continue",
"data",
"=",
"mapStringInterface",
"(",
"valValue",
")",
"\n",
"}",
"\n\n",
"// not found",
"return",
"nil",
"\n",
"}"
] | // find gets a deep data value
//
// @todo This is NOT consistent with the way we resolve data in template (cf. `evalDataPathExpression()`) ! FIX THAT ! | [
"find",
"gets",
"a",
"deep",
"data",
"value"
] | b565731e1464263de0bda75f2e45d97b54b60110 | https://github.com/aymerick/raymond/blob/b565731e1464263de0bda75f2e45d97b54b60110/data_frame.go#L58-L84 |
629 | valyala/gorpc | dispatcher.go | NewBatch | func (dc *DispatcherClient) NewBatch() *DispatcherBatch {
return &DispatcherBatch{
c: dc,
b: dc.c.NewBatch(),
}
} | go | func (dc *DispatcherClient) NewBatch() *DispatcherBatch {
return &DispatcherBatch{
c: dc,
b: dc.c.NewBatch(),
}
} | [
"func",
"(",
"dc",
"*",
"DispatcherClient",
")",
"NewBatch",
"(",
")",
"*",
"DispatcherBatch",
"{",
"return",
"&",
"DispatcherBatch",
"{",
"c",
":",
"dc",
",",
"b",
":",
"dc",
".",
"c",
".",
"NewBatch",
"(",
")",
",",
"}",
"\n",
"}"
] | // NewBatch creates new RPC batch for the given DispatcherClient.
//
// It is safe creating multiple concurrent batches from a single client. | [
"NewBatch",
"creates",
"new",
"RPC",
"batch",
"for",
"the",
"given",
"DispatcherClient",
".",
"It",
"is",
"safe",
"creating",
"multiple",
"concurrent",
"batches",
"from",
"a",
"single",
"client",
"."
] | 908281bef77441f2d0ec1792189b4032a1dace0c | https://github.com/valyala/gorpc/blob/908281bef77441f2d0ec1792189b4032a1dace0c/dispatcher.go#L543-L548 |
630 | valyala/gorpc | client.go | Stop | func (c *Client) Stop() {
if c.clientStopChan == nil {
panic("gorpc.Client: the client must be started before stopping it")
}
close(c.clientStopChan)
c.stopWg.Wait()
c.clientStopChan = nil
} | go | func (c *Client) Stop() {
if c.clientStopChan == nil {
panic("gorpc.Client: the client must be started before stopping it")
}
close(c.clientStopChan)
c.stopWg.Wait()
c.clientStopChan = nil
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"Stop",
"(",
")",
"{",
"if",
"c",
".",
"clientStopChan",
"==",
"nil",
"{",
"panic",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"close",
"(",
"c",
".",
"clientStopChan",
")",
"\n",
"c",
".",
"stopWg",
".",
"Wait",
"(",
")",
"\n",
"c",
".",
"clientStopChan",
"=",
"nil",
"\n",
"}"
] | // Stop stops rpc client. Stopped client can be started again. | [
"Stop",
"stops",
"rpc",
"client",
".",
"Stopped",
"client",
"can",
"be",
"started",
"again",
"."
] | 908281bef77441f2d0ec1792189b4032a1dace0c | https://github.com/valyala/gorpc/blob/908281bef77441f2d0ec1792189b4032a1dace0c/client.go#L162-L169 |
631 | valyala/gorpc | server.go | Stop | func (s *Server) Stop() {
if s.serverStopChan == nil {
panic("gorpc.Server: server must be started before stopping it")
}
close(s.serverStopChan)
s.stopWg.Wait()
s.serverStopChan = nil
} | go | func (s *Server) Stop() {
if s.serverStopChan == nil {
panic("gorpc.Server: server must be started before stopping it")
}
close(s.serverStopChan)
s.stopWg.Wait()
s.serverStopChan = nil
} | [
"func",
"(",
"s",
"*",
"Server",
")",
"Stop",
"(",
")",
"{",
"if",
"s",
".",
"serverStopChan",
"==",
"nil",
"{",
"panic",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"close",
"(",
"s",
".",
"serverStopChan",
")",
"\n",
"s",
".",
"stopWg",
".",
"Wait",
"(",
")",
"\n",
"s",
".",
"serverStopChan",
"=",
"nil",
"\n",
"}"
] | // Stop stops rpc server. Stopped server can be started again. | [
"Stop",
"stops",
"rpc",
"server",
".",
"Stopped",
"server",
"can",
"be",
"started",
"again",
"."
] | 908281bef77441f2d0ec1792189b4032a1dace0c | https://github.com/valyala/gorpc/blob/908281bef77441f2d0ec1792189b4032a1dace0c/server.go#L163-L170 |
632 | valyala/gorpc | server.go | Serve | func (s *Server) Serve() error {
if err := s.Start(); err != nil {
return err
}
s.stopWg.Wait()
return nil
} | go | func (s *Server) Serve() error {
if err := s.Start(); err != nil {
return err
}
s.stopWg.Wait()
return nil
} | [
"func",
"(",
"s",
"*",
"Server",
")",
"Serve",
"(",
")",
"error",
"{",
"if",
"err",
":=",
"s",
".",
"Start",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"s",
".",
"stopWg",
".",
"Wait",
"(",
")",
"\n",
"return",
"nil",
"\n",
"}"
] | // Serve starts rpc server and blocks until it is stopped. | [
"Serve",
"starts",
"rpc",
"server",
"and",
"blocks",
"until",
"it",
"is",
"stopped",
"."
] | 908281bef77441f2d0ec1792189b4032a1dace0c | https://github.com/valyala/gorpc/blob/908281bef77441f2d0ec1792189b4032a1dace0c/server.go#L173-L179 |
633 | shiena/ansicolor | ansicolor.go | NewModeAnsiColorWriter | func NewModeAnsiColorWriter(w io.Writer, mode outputMode) io.Writer {
if _, ok := w.(*ansiColorWriter); !ok {
return &ansiColorWriter{
w: w,
mode: mode,
}
}
return w
} | go | func NewModeAnsiColorWriter(w io.Writer, mode outputMode) io.Writer {
if _, ok := w.(*ansiColorWriter); !ok {
return &ansiColorWriter{
w: w,
mode: mode,
}
}
return w
} | [
"func",
"NewModeAnsiColorWriter",
"(",
"w",
"io",
".",
"Writer",
",",
"mode",
"outputMode",
")",
"io",
".",
"Writer",
"{",
"if",
"_",
",",
"ok",
":=",
"w",
".",
"(",
"*",
"ansiColorWriter",
")",
";",
"!",
"ok",
"{",
"return",
"&",
"ansiColorWriter",
"{",
"w",
":",
"w",
",",
"mode",
":",
"mode",
",",
"}",
"\n",
"}",
"\n",
"return",
"w",
"\n",
"}"
] | // NewModeAnsiColorWriter create and initializes a new ansiColorWriter
// by specifying the outputMode. | [
"NewModeAnsiColorWriter",
"create",
"and",
"initializes",
"a",
"new",
"ansiColorWriter",
"by",
"specifying",
"the",
"outputMode",
"."
] | a422bbe96644373c5753384a59d678f7d261ff10 | https://github.com/shiena/ansicolor/blob/a422bbe96644373c5753384a59d678f7d261ff10/ansicolor.go#L34-L42 |
634 | andybalholm/cascadia | parser.go | parseEscape | func (p *parser) parseEscape() (result string, err error) {
if len(p.s) < p.i+2 || p.s[p.i] != '\\' {
return "", errors.New("invalid escape sequence")
}
start := p.i + 1
c := p.s[start]
switch {
case c == '\r' || c == '\n' || c == '\f':
return "", errors.New("escaped line ending outside string")
case hexDigit(c):
// unicode escape (hex)
var i int
for i = start; i < p.i+6 && i < len(p.s) && hexDigit(p.s[i]); i++ {
// empty
}
v, _ := strconv.ParseUint(p.s[start:i], 16, 21)
if len(p.s) > i {
switch p.s[i] {
case '\r':
i++
if len(p.s) > i && p.s[i] == '\n' {
i++
}
case ' ', '\t', '\n', '\f':
i++
}
}
p.i = i
return string(rune(v)), nil
}
// Return the literal character after the backslash.
result = p.s[start : start+1]
p.i += 2
return result, nil
} | go | func (p *parser) parseEscape() (result string, err error) {
if len(p.s) < p.i+2 || p.s[p.i] != '\\' {
return "", errors.New("invalid escape sequence")
}
start := p.i + 1
c := p.s[start]
switch {
case c == '\r' || c == '\n' || c == '\f':
return "", errors.New("escaped line ending outside string")
case hexDigit(c):
// unicode escape (hex)
var i int
for i = start; i < p.i+6 && i < len(p.s) && hexDigit(p.s[i]); i++ {
// empty
}
v, _ := strconv.ParseUint(p.s[start:i], 16, 21)
if len(p.s) > i {
switch p.s[i] {
case '\r':
i++
if len(p.s) > i && p.s[i] == '\n' {
i++
}
case ' ', '\t', '\n', '\f':
i++
}
}
p.i = i
return string(rune(v)), nil
}
// Return the literal character after the backslash.
result = p.s[start : start+1]
p.i += 2
return result, nil
} | [
"func",
"(",
"p",
"*",
"parser",
")",
"parseEscape",
"(",
")",
"(",
"result",
"string",
",",
"err",
"error",
")",
"{",
"if",
"len",
"(",
"p",
".",
"s",
")",
"<",
"p",
".",
"i",
"+",
"2",
"||",
"p",
".",
"s",
"[",
"p",
".",
"i",
"]",
"!=",
"'\\\\'",
"{",
"return",
"\"",
"\"",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"start",
":=",
"p",
".",
"i",
"+",
"1",
"\n",
"c",
":=",
"p",
".",
"s",
"[",
"start",
"]",
"\n",
"switch",
"{",
"case",
"c",
"==",
"'\\r'",
"||",
"c",
"==",
"'\\n'",
"||",
"c",
"==",
"'\\f'",
":",
"return",
"\"",
"\"",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"case",
"hexDigit",
"(",
"c",
")",
":",
"// unicode escape (hex)",
"var",
"i",
"int",
"\n",
"for",
"i",
"=",
"start",
";",
"i",
"<",
"p",
".",
"i",
"+",
"6",
"&&",
"i",
"<",
"len",
"(",
"p",
".",
"s",
")",
"&&",
"hexDigit",
"(",
"p",
".",
"s",
"[",
"i",
"]",
")",
";",
"i",
"++",
"{",
"// empty",
"}",
"\n",
"v",
",",
"_",
":=",
"strconv",
".",
"ParseUint",
"(",
"p",
".",
"s",
"[",
"start",
":",
"i",
"]",
",",
"16",
",",
"21",
")",
"\n",
"if",
"len",
"(",
"p",
".",
"s",
")",
">",
"i",
"{",
"switch",
"p",
".",
"s",
"[",
"i",
"]",
"{",
"case",
"'\\r'",
":",
"i",
"++",
"\n",
"if",
"len",
"(",
"p",
".",
"s",
")",
">",
"i",
"&&",
"p",
".",
"s",
"[",
"i",
"]",
"==",
"'\\n'",
"{",
"i",
"++",
"\n",
"}",
"\n",
"case",
"' '",
",",
"'\\t'",
",",
"'\\n'",
",",
"'\\f'",
":",
"i",
"++",
"\n",
"}",
"\n",
"}",
"\n",
"p",
".",
"i",
"=",
"i",
"\n",
"return",
"string",
"(",
"rune",
"(",
"v",
")",
")",
",",
"nil",
"\n",
"}",
"\n\n",
"// Return the literal character after the backslash.",
"result",
"=",
"p",
".",
"s",
"[",
"start",
":",
"start",
"+",
"1",
"]",
"\n",
"p",
".",
"i",
"+=",
"2",
"\n",
"return",
"result",
",",
"nil",
"\n",
"}"
] | // parseEscape parses a backslash escape. | [
"parseEscape",
"parses",
"a",
"backslash",
"escape",
"."
] | 680b6a57bda4f657485ad44bdea42342ead737bc | https://github.com/andybalholm/cascadia/blob/680b6a57bda4f657485ad44bdea42342ead737bc/parser.go#L21-L57 |
635 | andybalholm/cascadia | parser.go | parseIdentifier | func (p *parser) parseIdentifier() (result string, err error) {
startingDash := false
if len(p.s) > p.i && p.s[p.i] == '-' {
startingDash = true
p.i++
}
if len(p.s) <= p.i {
return "", errors.New("expected identifier, found EOF instead")
}
if c := p.s[p.i]; !(nameStart(c) || c == '\\') {
return "", fmt.Errorf("expected identifier, found %c instead", c)
}
result, err = p.parseName()
if startingDash && err == nil {
result = "-" + result
}
return
} | go | func (p *parser) parseIdentifier() (result string, err error) {
startingDash := false
if len(p.s) > p.i && p.s[p.i] == '-' {
startingDash = true
p.i++
}
if len(p.s) <= p.i {
return "", errors.New("expected identifier, found EOF instead")
}
if c := p.s[p.i]; !(nameStart(c) || c == '\\') {
return "", fmt.Errorf("expected identifier, found %c instead", c)
}
result, err = p.parseName()
if startingDash && err == nil {
result = "-" + result
}
return
} | [
"func",
"(",
"p",
"*",
"parser",
")",
"parseIdentifier",
"(",
")",
"(",
"result",
"string",
",",
"err",
"error",
")",
"{",
"startingDash",
":=",
"false",
"\n",
"if",
"len",
"(",
"p",
".",
"s",
")",
">",
"p",
".",
"i",
"&&",
"p",
".",
"s",
"[",
"p",
".",
"i",
"]",
"==",
"'-'",
"{",
"startingDash",
"=",
"true",
"\n",
"p",
".",
"i",
"++",
"\n",
"}",
"\n\n",
"if",
"len",
"(",
"p",
".",
"s",
")",
"<=",
"p",
".",
"i",
"{",
"return",
"\"",
"\"",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"if",
"c",
":=",
"p",
".",
"s",
"[",
"p",
".",
"i",
"]",
";",
"!",
"(",
"nameStart",
"(",
"c",
")",
"||",
"c",
"==",
"'\\\\'",
")",
"{",
"return",
"\"",
"\"",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"c",
")",
"\n",
"}",
"\n\n",
"result",
",",
"err",
"=",
"p",
".",
"parseName",
"(",
")",
"\n",
"if",
"startingDash",
"&&",
"err",
"==",
"nil",
"{",
"result",
"=",
"\"",
"\"",
"+",
"result",
"\n",
"}",
"\n",
"return",
"\n",
"}"
] | // parseIdentifier parses an identifier. | [
"parseIdentifier",
"parses",
"an",
"identifier",
"."
] | 680b6a57bda4f657485ad44bdea42342ead737bc | https://github.com/andybalholm/cascadia/blob/680b6a57bda4f657485ad44bdea42342ead737bc/parser.go#L77-L97 |
636 | andybalholm/cascadia | parser.go | parseString | func (p *parser) parseString() (result string, err error) {
i := p.i
if len(p.s) < i+2 {
return "", errors.New("expected string, found EOF instead")
}
quote := p.s[i]
i++
loop:
for i < len(p.s) {
switch p.s[i] {
case '\\':
if len(p.s) > i+1 {
switch c := p.s[i+1]; c {
case '\r':
if len(p.s) > i+2 && p.s[i+2] == '\n' {
i += 3
continue loop
}
fallthrough
case '\n', '\f':
i += 2
continue loop
}
}
p.i = i
val, err := p.parseEscape()
if err != nil {
return "", err
}
i = p.i
result += val
case quote:
break loop
case '\r', '\n', '\f':
return "", errors.New("unexpected end of line in string")
default:
start := i
for i < len(p.s) {
if c := p.s[i]; c == quote || c == '\\' || c == '\r' || c == '\n' || c == '\f' {
break
}
i++
}
result += p.s[start:i]
}
}
if i >= len(p.s) {
return "", errors.New("EOF in string")
}
// Consume the final quote.
i++
p.i = i
return result, nil
} | go | func (p *parser) parseString() (result string, err error) {
i := p.i
if len(p.s) < i+2 {
return "", errors.New("expected string, found EOF instead")
}
quote := p.s[i]
i++
loop:
for i < len(p.s) {
switch p.s[i] {
case '\\':
if len(p.s) > i+1 {
switch c := p.s[i+1]; c {
case '\r':
if len(p.s) > i+2 && p.s[i+2] == '\n' {
i += 3
continue loop
}
fallthrough
case '\n', '\f':
i += 2
continue loop
}
}
p.i = i
val, err := p.parseEscape()
if err != nil {
return "", err
}
i = p.i
result += val
case quote:
break loop
case '\r', '\n', '\f':
return "", errors.New("unexpected end of line in string")
default:
start := i
for i < len(p.s) {
if c := p.s[i]; c == quote || c == '\\' || c == '\r' || c == '\n' || c == '\f' {
break
}
i++
}
result += p.s[start:i]
}
}
if i >= len(p.s) {
return "", errors.New("EOF in string")
}
// Consume the final quote.
i++
p.i = i
return result, nil
} | [
"func",
"(",
"p",
"*",
"parser",
")",
"parseString",
"(",
")",
"(",
"result",
"string",
",",
"err",
"error",
")",
"{",
"i",
":=",
"p",
".",
"i",
"\n",
"if",
"len",
"(",
"p",
".",
"s",
")",
"<",
"i",
"+",
"2",
"{",
"return",
"\"",
"\"",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"quote",
":=",
"p",
".",
"s",
"[",
"i",
"]",
"\n",
"i",
"++",
"\n\n",
"loop",
":",
"for",
"i",
"<",
"len",
"(",
"p",
".",
"s",
")",
"{",
"switch",
"p",
".",
"s",
"[",
"i",
"]",
"{",
"case",
"'\\\\'",
":",
"if",
"len",
"(",
"p",
".",
"s",
")",
">",
"i",
"+",
"1",
"{",
"switch",
"c",
":=",
"p",
".",
"s",
"[",
"i",
"+",
"1",
"]",
";",
"c",
"{",
"case",
"'\\r'",
":",
"if",
"len",
"(",
"p",
".",
"s",
")",
">",
"i",
"+",
"2",
"&&",
"p",
".",
"s",
"[",
"i",
"+",
"2",
"]",
"==",
"'\\n'",
"{",
"i",
"+=",
"3",
"\n",
"continue",
"loop",
"\n",
"}",
"\n",
"fallthrough",
"\n",
"case",
"'\\n'",
",",
"'\\f'",
":",
"i",
"+=",
"2",
"\n",
"continue",
"loop",
"\n",
"}",
"\n",
"}",
"\n",
"p",
".",
"i",
"=",
"i",
"\n",
"val",
",",
"err",
":=",
"p",
".",
"parseEscape",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"err",
"\n",
"}",
"\n",
"i",
"=",
"p",
".",
"i",
"\n",
"result",
"+=",
"val",
"\n",
"case",
"quote",
":",
"break",
"loop",
"\n",
"case",
"'\\r'",
",",
"'\\n'",
",",
"'\\f'",
":",
"return",
"\"",
"\"",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"default",
":",
"start",
":=",
"i",
"\n",
"for",
"i",
"<",
"len",
"(",
"p",
".",
"s",
")",
"{",
"if",
"c",
":=",
"p",
".",
"s",
"[",
"i",
"]",
";",
"c",
"==",
"quote",
"||",
"c",
"==",
"'\\\\'",
"||",
"c",
"==",
"'\\r'",
"||",
"c",
"==",
"'\\n'",
"||",
"c",
"==",
"'\\f'",
"{",
"break",
"\n",
"}",
"\n",
"i",
"++",
"\n",
"}",
"\n",
"result",
"+=",
"p",
".",
"s",
"[",
"start",
":",
"i",
"]",
"\n",
"}",
"\n",
"}",
"\n\n",
"if",
"i",
">=",
"len",
"(",
"p",
".",
"s",
")",
"{",
"return",
"\"",
"\"",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"// Consume the final quote.",
"i",
"++",
"\n\n",
"p",
".",
"i",
"=",
"i",
"\n",
"return",
"result",
",",
"nil",
"\n",
"}"
] | // parseString parses a single- or double-quoted string. | [
"parseString",
"parses",
"a",
"single",
"-",
"or",
"double",
"-",
"quoted",
"string",
"."
] | 680b6a57bda4f657485ad44bdea42342ead737bc | https://github.com/andybalholm/cascadia/blob/680b6a57bda4f657485ad44bdea42342ead737bc/parser.go#L135-L193 |
637 | andybalholm/cascadia | parser.go | parseRegex | func (p *parser) parseRegex() (rx *regexp.Regexp, err error) {
i := p.i
if len(p.s) < i+2 {
return nil, errors.New("expected regular expression, found EOF instead")
}
// number of open parens or brackets;
// when it becomes negative, finished parsing regex
open := 0
loop:
for i < len(p.s) {
switch p.s[i] {
case '(', '[':
open++
case ')', ']':
open--
if open < 0 {
break loop
}
}
i++
}
if i >= len(p.s) {
return nil, errors.New("EOF in regular expression")
}
rx, err = regexp.Compile(p.s[p.i:i])
p.i = i
return rx, err
} | go | func (p *parser) parseRegex() (rx *regexp.Regexp, err error) {
i := p.i
if len(p.s) < i+2 {
return nil, errors.New("expected regular expression, found EOF instead")
}
// number of open parens or brackets;
// when it becomes negative, finished parsing regex
open := 0
loop:
for i < len(p.s) {
switch p.s[i] {
case '(', '[':
open++
case ')', ']':
open--
if open < 0 {
break loop
}
}
i++
}
if i >= len(p.s) {
return nil, errors.New("EOF in regular expression")
}
rx, err = regexp.Compile(p.s[p.i:i])
p.i = i
return rx, err
} | [
"func",
"(",
"p",
"*",
"parser",
")",
"parseRegex",
"(",
")",
"(",
"rx",
"*",
"regexp",
".",
"Regexp",
",",
"err",
"error",
")",
"{",
"i",
":=",
"p",
".",
"i",
"\n",
"if",
"len",
"(",
"p",
".",
"s",
")",
"<",
"i",
"+",
"2",
"{",
"return",
"nil",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"// number of open parens or brackets;",
"// when it becomes negative, finished parsing regex",
"open",
":=",
"0",
"\n\n",
"loop",
":",
"for",
"i",
"<",
"len",
"(",
"p",
".",
"s",
")",
"{",
"switch",
"p",
".",
"s",
"[",
"i",
"]",
"{",
"case",
"'('",
",",
"'['",
":",
"open",
"++",
"\n",
"case",
"')'",
",",
"']'",
":",
"open",
"--",
"\n",
"if",
"open",
"<",
"0",
"{",
"break",
"loop",
"\n",
"}",
"\n",
"}",
"\n",
"i",
"++",
"\n",
"}",
"\n\n",
"if",
"i",
">=",
"len",
"(",
"p",
".",
"s",
")",
"{",
"return",
"nil",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"rx",
",",
"err",
"=",
"regexp",
".",
"Compile",
"(",
"p",
".",
"s",
"[",
"p",
".",
"i",
":",
"i",
"]",
")",
"\n",
"p",
".",
"i",
"=",
"i",
"\n",
"return",
"rx",
",",
"err",
"\n",
"}"
] | // parseRegex parses a regular expression; the end is defined by encountering an
// unmatched closing ')' or ']' which is not consumed | [
"parseRegex",
"parses",
"a",
"regular",
"expression",
";",
"the",
"end",
"is",
"defined",
"by",
"encountering",
"an",
"unmatched",
"closing",
")",
"or",
"]",
"which",
"is",
"not",
"consumed"
] | 680b6a57bda4f657485ad44bdea42342ead737bc | https://github.com/andybalholm/cascadia/blob/680b6a57bda4f657485ad44bdea42342ead737bc/parser.go#L197-L227 |
638 | andybalholm/cascadia | parser.go | skipWhitespace | func (p *parser) skipWhitespace() bool {
i := p.i
for i < len(p.s) {
switch p.s[i] {
case ' ', '\t', '\r', '\n', '\f':
i++
continue
case '/':
if strings.HasPrefix(p.s[i:], "/*") {
end := strings.Index(p.s[i+len("/*"):], "*/")
if end != -1 {
i += end + len("/**/")
continue
}
}
}
break
}
if i > p.i {
p.i = i
return true
}
return false
} | go | func (p *parser) skipWhitespace() bool {
i := p.i
for i < len(p.s) {
switch p.s[i] {
case ' ', '\t', '\r', '\n', '\f':
i++
continue
case '/':
if strings.HasPrefix(p.s[i:], "/*") {
end := strings.Index(p.s[i+len("/*"):], "*/")
if end != -1 {
i += end + len("/**/")
continue
}
}
}
break
}
if i > p.i {
p.i = i
return true
}
return false
} | [
"func",
"(",
"p",
"*",
"parser",
")",
"skipWhitespace",
"(",
")",
"bool",
"{",
"i",
":=",
"p",
".",
"i",
"\n",
"for",
"i",
"<",
"len",
"(",
"p",
".",
"s",
")",
"{",
"switch",
"p",
".",
"s",
"[",
"i",
"]",
"{",
"case",
"' '",
",",
"'\\t'",
",",
"'\\r'",
",",
"'\\n'",
",",
"'\\f'",
":",
"i",
"++",
"\n",
"continue",
"\n",
"case",
"'/'",
":",
"if",
"strings",
".",
"HasPrefix",
"(",
"p",
".",
"s",
"[",
"i",
":",
"]",
",",
"\"",
"\"",
")",
"{",
"end",
":=",
"strings",
".",
"Index",
"(",
"p",
".",
"s",
"[",
"i",
"+",
"len",
"(",
"\"",
"\"",
")",
":",
"]",
",",
"\"",
"\"",
")",
"\n",
"if",
"end",
"!=",
"-",
"1",
"{",
"i",
"+=",
"end",
"+",
"len",
"(",
"\"",
"\"",
")",
"\n",
"continue",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"break",
"\n",
"}",
"\n\n",
"if",
"i",
">",
"p",
".",
"i",
"{",
"p",
".",
"i",
"=",
"i",
"\n",
"return",
"true",
"\n",
"}",
"\n\n",
"return",
"false",
"\n",
"}"
] | // skipWhitespace consumes whitespace characters and comments.
// It returns true if there was actually anything to skip. | [
"skipWhitespace",
"consumes",
"whitespace",
"characters",
"and",
"comments",
".",
"It",
"returns",
"true",
"if",
"there",
"was",
"actually",
"anything",
"to",
"skip",
"."
] | 680b6a57bda4f657485ad44bdea42342ead737bc | https://github.com/andybalholm/cascadia/blob/680b6a57bda4f657485ad44bdea42342ead737bc/parser.go#L231-L256 |
639 | andybalholm/cascadia | parser.go | consumeParenthesis | func (p *parser) consumeParenthesis() bool {
if p.i < len(p.s) && p.s[p.i] == '(' {
p.i++
p.skipWhitespace()
return true
}
return false
} | go | func (p *parser) consumeParenthesis() bool {
if p.i < len(p.s) && p.s[p.i] == '(' {
p.i++
p.skipWhitespace()
return true
}
return false
} | [
"func",
"(",
"p",
"*",
"parser",
")",
"consumeParenthesis",
"(",
")",
"bool",
"{",
"if",
"p",
".",
"i",
"<",
"len",
"(",
"p",
".",
"s",
")",
"&&",
"p",
".",
"s",
"[",
"p",
".",
"i",
"]",
"==",
"'('",
"{",
"p",
".",
"i",
"++",
"\n",
"p",
".",
"skipWhitespace",
"(",
")",
"\n",
"return",
"true",
"\n",
"}",
"\n",
"return",
"false",
"\n",
"}"
] | // consumeParenthesis consumes an opening parenthesis and any following
// whitespace. It returns true if there was actually a parenthesis to skip. | [
"consumeParenthesis",
"consumes",
"an",
"opening",
"parenthesis",
"and",
"any",
"following",
"whitespace",
".",
"It",
"returns",
"true",
"if",
"there",
"was",
"actually",
"a",
"parenthesis",
"to",
"skip",
"."
] | 680b6a57bda4f657485ad44bdea42342ead737bc | https://github.com/andybalholm/cascadia/blob/680b6a57bda4f657485ad44bdea42342ead737bc/parser.go#L260-L267 |
640 | andybalholm/cascadia | parser.go | consumeClosingParenthesis | func (p *parser) consumeClosingParenthesis() bool {
i := p.i
p.skipWhitespace()
if p.i < len(p.s) && p.s[p.i] == ')' {
p.i++
return true
}
p.i = i
return false
} | go | func (p *parser) consumeClosingParenthesis() bool {
i := p.i
p.skipWhitespace()
if p.i < len(p.s) && p.s[p.i] == ')' {
p.i++
return true
}
p.i = i
return false
} | [
"func",
"(",
"p",
"*",
"parser",
")",
"consumeClosingParenthesis",
"(",
")",
"bool",
"{",
"i",
":=",
"p",
".",
"i",
"\n",
"p",
".",
"skipWhitespace",
"(",
")",
"\n",
"if",
"p",
".",
"i",
"<",
"len",
"(",
"p",
".",
"s",
")",
"&&",
"p",
".",
"s",
"[",
"p",
".",
"i",
"]",
"==",
"')'",
"{",
"p",
".",
"i",
"++",
"\n",
"return",
"true",
"\n",
"}",
"\n",
"p",
".",
"i",
"=",
"i",
"\n",
"return",
"false",
"\n",
"}"
] | // consumeClosingParenthesis consumes a closing parenthesis and any preceding
// whitespace. It returns true if there was actually a parenthesis to skip. | [
"consumeClosingParenthesis",
"consumes",
"a",
"closing",
"parenthesis",
"and",
"any",
"preceding",
"whitespace",
".",
"It",
"returns",
"true",
"if",
"there",
"was",
"actually",
"a",
"parenthesis",
"to",
"skip",
"."
] | 680b6a57bda4f657485ad44bdea42342ead737bc | https://github.com/andybalholm/cascadia/blob/680b6a57bda4f657485ad44bdea42342ead737bc/parser.go#L271-L280 |
641 | andybalholm/cascadia | parser.go | parseIDSelector | func (p *parser) parseIDSelector() (Selector, error) {
if p.i >= len(p.s) {
return nil, fmt.Errorf("expected id selector (#id), found EOF instead")
}
if p.s[p.i] != '#' {
return nil, fmt.Errorf("expected id selector (#id), found '%c' instead", p.s[p.i])
}
p.i++
id, err := p.parseName()
if err != nil {
return nil, err
}
return attributeEqualsSelector("id", id), nil
} | go | func (p *parser) parseIDSelector() (Selector, error) {
if p.i >= len(p.s) {
return nil, fmt.Errorf("expected id selector (#id), found EOF instead")
}
if p.s[p.i] != '#' {
return nil, fmt.Errorf("expected id selector (#id), found '%c' instead", p.s[p.i])
}
p.i++
id, err := p.parseName()
if err != nil {
return nil, err
}
return attributeEqualsSelector("id", id), nil
} | [
"func",
"(",
"p",
"*",
"parser",
")",
"parseIDSelector",
"(",
")",
"(",
"Selector",
",",
"error",
")",
"{",
"if",
"p",
".",
"i",
">=",
"len",
"(",
"p",
".",
"s",
")",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"if",
"p",
".",
"s",
"[",
"p",
".",
"i",
"]",
"!=",
"'#'",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"p",
".",
"s",
"[",
"p",
".",
"i",
"]",
")",
"\n",
"}",
"\n\n",
"p",
".",
"i",
"++",
"\n",
"id",
",",
"err",
":=",
"p",
".",
"parseName",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"attributeEqualsSelector",
"(",
"\"",
"\"",
",",
"id",
")",
",",
"nil",
"\n",
"}"
] | // parseIDSelector parses a selector that matches by id attribute. | [
"parseIDSelector",
"parses",
"a",
"selector",
"that",
"matches",
"by",
"id",
"attribute",
"."
] | 680b6a57bda4f657485ad44bdea42342ead737bc | https://github.com/andybalholm/cascadia/blob/680b6a57bda4f657485ad44bdea42342ead737bc/parser.go#L293-L308 |
642 | andybalholm/cascadia | parser.go | parseClassSelector | func (p *parser) parseClassSelector() (Selector, error) {
if p.i >= len(p.s) {
return nil, fmt.Errorf("expected class selector (.class), found EOF instead")
}
if p.s[p.i] != '.' {
return nil, fmt.Errorf("expected class selector (.class), found '%c' instead", p.s[p.i])
}
p.i++
class, err := p.parseIdentifier()
if err != nil {
return nil, err
}
return attributeIncludesSelector("class", class), nil
} | go | func (p *parser) parseClassSelector() (Selector, error) {
if p.i >= len(p.s) {
return nil, fmt.Errorf("expected class selector (.class), found EOF instead")
}
if p.s[p.i] != '.' {
return nil, fmt.Errorf("expected class selector (.class), found '%c' instead", p.s[p.i])
}
p.i++
class, err := p.parseIdentifier()
if err != nil {
return nil, err
}
return attributeIncludesSelector("class", class), nil
} | [
"func",
"(",
"p",
"*",
"parser",
")",
"parseClassSelector",
"(",
")",
"(",
"Selector",
",",
"error",
")",
"{",
"if",
"p",
".",
"i",
">=",
"len",
"(",
"p",
".",
"s",
")",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"if",
"p",
".",
"s",
"[",
"p",
".",
"i",
"]",
"!=",
"'.'",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"p",
".",
"s",
"[",
"p",
".",
"i",
"]",
")",
"\n",
"}",
"\n\n",
"p",
".",
"i",
"++",
"\n",
"class",
",",
"err",
":=",
"p",
".",
"parseIdentifier",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"attributeIncludesSelector",
"(",
"\"",
"\"",
",",
"class",
")",
",",
"nil",
"\n",
"}"
] | // parseClassSelector parses a selector that matches by class attribute. | [
"parseClassSelector",
"parses",
"a",
"selector",
"that",
"matches",
"by",
"class",
"attribute",
"."
] | 680b6a57bda4f657485ad44bdea42342ead737bc | https://github.com/andybalholm/cascadia/blob/680b6a57bda4f657485ad44bdea42342ead737bc/parser.go#L311-L326 |
643 | andybalholm/cascadia | parser.go | parseInteger | func (p *parser) parseInteger() (int, error) {
i := p.i
start := i
for i < len(p.s) && '0' <= p.s[i] && p.s[i] <= '9' {
i++
}
if i == start {
return 0, errors.New("expected integer, but didn't find it")
}
p.i = i
val, err := strconv.Atoi(p.s[start:i])
if err != nil {
return 0, err
}
return val, nil
} | go | func (p *parser) parseInteger() (int, error) {
i := p.i
start := i
for i < len(p.s) && '0' <= p.s[i] && p.s[i] <= '9' {
i++
}
if i == start {
return 0, errors.New("expected integer, but didn't find it")
}
p.i = i
val, err := strconv.Atoi(p.s[start:i])
if err != nil {
return 0, err
}
return val, nil
} | [
"func",
"(",
"p",
"*",
"parser",
")",
"parseInteger",
"(",
")",
"(",
"int",
",",
"error",
")",
"{",
"i",
":=",
"p",
".",
"i",
"\n",
"start",
":=",
"i",
"\n",
"for",
"i",
"<",
"len",
"(",
"p",
".",
"s",
")",
"&&",
"'0'",
"<=",
"p",
".",
"s",
"[",
"i",
"]",
"&&",
"p",
".",
"s",
"[",
"i",
"]",
"<=",
"'9'",
"{",
"i",
"++",
"\n",
"}",
"\n",
"if",
"i",
"==",
"start",
"{",
"return",
"0",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"p",
".",
"i",
"=",
"i",
"\n\n",
"val",
",",
"err",
":=",
"strconv",
".",
"Atoi",
"(",
"p",
".",
"s",
"[",
"start",
":",
"i",
"]",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"0",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"val",
",",
"nil",
"\n",
"}"
] | // parseInteger parses a decimal integer. | [
"parseInteger",
"parses",
"a",
"decimal",
"integer",
"."
] | 680b6a57bda4f657485ad44bdea42342ead737bc | https://github.com/andybalholm/cascadia/blob/680b6a57bda4f657485ad44bdea42342ead737bc/parser.go#L566-L583 |
644 | andybalholm/cascadia | parser.go | parseSimpleSelectorSequence | func (p *parser) parseSimpleSelectorSequence() (Selector, error) {
var result Selector
if p.i >= len(p.s) {
return nil, errors.New("expected selector, found EOF instead")
}
switch p.s[p.i] {
case '*':
// It's the universal selector. Just skip over it, since it doesn't affect the meaning.
p.i++
case '#', '.', '[', ':':
// There's no type selector. Wait to process the other till the main loop.
default:
r, err := p.parseTypeSelector()
if err != nil {
return nil, err
}
result = r
}
loop:
for p.i < len(p.s) {
var ns Selector
var err error
switch p.s[p.i] {
case '#':
ns, err = p.parseIDSelector()
case '.':
ns, err = p.parseClassSelector()
case '[':
ns, err = p.parseAttributeSelector()
case ':':
ns, err = p.parsePseudoclassSelector()
default:
break loop
}
if err != nil {
return nil, err
}
if result == nil {
result = ns
} else {
result = intersectionSelector(result, ns)
}
}
if result == nil {
result = func(n *html.Node) bool {
return n.Type == html.ElementNode
}
}
return result, nil
} | go | func (p *parser) parseSimpleSelectorSequence() (Selector, error) {
var result Selector
if p.i >= len(p.s) {
return nil, errors.New("expected selector, found EOF instead")
}
switch p.s[p.i] {
case '*':
// It's the universal selector. Just skip over it, since it doesn't affect the meaning.
p.i++
case '#', '.', '[', ':':
// There's no type selector. Wait to process the other till the main loop.
default:
r, err := p.parseTypeSelector()
if err != nil {
return nil, err
}
result = r
}
loop:
for p.i < len(p.s) {
var ns Selector
var err error
switch p.s[p.i] {
case '#':
ns, err = p.parseIDSelector()
case '.':
ns, err = p.parseClassSelector()
case '[':
ns, err = p.parseAttributeSelector()
case ':':
ns, err = p.parsePseudoclassSelector()
default:
break loop
}
if err != nil {
return nil, err
}
if result == nil {
result = ns
} else {
result = intersectionSelector(result, ns)
}
}
if result == nil {
result = func(n *html.Node) bool {
return n.Type == html.ElementNode
}
}
return result, nil
} | [
"func",
"(",
"p",
"*",
"parser",
")",
"parseSimpleSelectorSequence",
"(",
")",
"(",
"Selector",
",",
"error",
")",
"{",
"var",
"result",
"Selector",
"\n\n",
"if",
"p",
".",
"i",
">=",
"len",
"(",
"p",
".",
"s",
")",
"{",
"return",
"nil",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"switch",
"p",
".",
"s",
"[",
"p",
".",
"i",
"]",
"{",
"case",
"'*'",
":",
"// It's the universal selector. Just skip over it, since it doesn't affect the meaning.",
"p",
".",
"i",
"++",
"\n",
"case",
"'#'",
",",
"'.'",
",",
"'['",
",",
"':'",
":",
"// There's no type selector. Wait to process the other till the main loop.",
"default",
":",
"r",
",",
"err",
":=",
"p",
".",
"parseTypeSelector",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"result",
"=",
"r",
"\n",
"}",
"\n\n",
"loop",
":",
"for",
"p",
".",
"i",
"<",
"len",
"(",
"p",
".",
"s",
")",
"{",
"var",
"ns",
"Selector",
"\n",
"var",
"err",
"error",
"\n",
"switch",
"p",
".",
"s",
"[",
"p",
".",
"i",
"]",
"{",
"case",
"'#'",
":",
"ns",
",",
"err",
"=",
"p",
".",
"parseIDSelector",
"(",
")",
"\n",
"case",
"'.'",
":",
"ns",
",",
"err",
"=",
"p",
".",
"parseClassSelector",
"(",
")",
"\n",
"case",
"'['",
":",
"ns",
",",
"err",
"=",
"p",
".",
"parseAttributeSelector",
"(",
")",
"\n",
"case",
"':'",
":",
"ns",
",",
"err",
"=",
"p",
".",
"parsePseudoclassSelector",
"(",
")",
"\n",
"default",
":",
"break",
"loop",
"\n",
"}",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"if",
"result",
"==",
"nil",
"{",
"result",
"=",
"ns",
"\n",
"}",
"else",
"{",
"result",
"=",
"intersectionSelector",
"(",
"result",
",",
"ns",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"if",
"result",
"==",
"nil",
"{",
"result",
"=",
"func",
"(",
"n",
"*",
"html",
".",
"Node",
")",
"bool",
"{",
"return",
"n",
".",
"Type",
"==",
"html",
".",
"ElementNode",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"result",
",",
"nil",
"\n",
"}"
] | // parseSimpleSelectorSequence parses a selector sequence that applies to
// a single element. | [
"parseSimpleSelectorSequence",
"parses",
"a",
"selector",
"sequence",
"that",
"applies",
"to",
"a",
"single",
"element",
"."
] | 680b6a57bda4f657485ad44bdea42342ead737bc | https://github.com/andybalholm/cascadia/blob/680b6a57bda4f657485ad44bdea42342ead737bc/parser.go#L708-L762 |
645 | andybalholm/cascadia | parser.go | parseSelector | func (p *parser) parseSelector() (result Selector, err error) {
p.skipWhitespace()
result, err = p.parseSimpleSelectorSequence()
if err != nil {
return
}
for {
var combinator byte
if p.skipWhitespace() {
combinator = ' '
}
if p.i >= len(p.s) {
return
}
switch p.s[p.i] {
case '+', '>', '~':
combinator = p.s[p.i]
p.i++
p.skipWhitespace()
case ',', ')':
// These characters can't begin a selector, but they can legally occur after one.
return
}
if combinator == 0 {
return
}
c, err := p.parseSimpleSelectorSequence()
if err != nil {
return nil, err
}
switch combinator {
case ' ':
result = descendantSelector(result, c)
case '>':
result = childSelector(result, c)
case '+':
result = siblingSelector(result, c, true)
case '~':
result = siblingSelector(result, c, false)
}
}
panic("unreachable")
} | go | func (p *parser) parseSelector() (result Selector, err error) {
p.skipWhitespace()
result, err = p.parseSimpleSelectorSequence()
if err != nil {
return
}
for {
var combinator byte
if p.skipWhitespace() {
combinator = ' '
}
if p.i >= len(p.s) {
return
}
switch p.s[p.i] {
case '+', '>', '~':
combinator = p.s[p.i]
p.i++
p.skipWhitespace()
case ',', ')':
// These characters can't begin a selector, but they can legally occur after one.
return
}
if combinator == 0 {
return
}
c, err := p.parseSimpleSelectorSequence()
if err != nil {
return nil, err
}
switch combinator {
case ' ':
result = descendantSelector(result, c)
case '>':
result = childSelector(result, c)
case '+':
result = siblingSelector(result, c, true)
case '~':
result = siblingSelector(result, c, false)
}
}
panic("unreachable")
} | [
"func",
"(",
"p",
"*",
"parser",
")",
"parseSelector",
"(",
")",
"(",
"result",
"Selector",
",",
"err",
"error",
")",
"{",
"p",
".",
"skipWhitespace",
"(",
")",
"\n",
"result",
",",
"err",
"=",
"p",
".",
"parseSimpleSelectorSequence",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n\n",
"for",
"{",
"var",
"combinator",
"byte",
"\n",
"if",
"p",
".",
"skipWhitespace",
"(",
")",
"{",
"combinator",
"=",
"' '",
"\n",
"}",
"\n",
"if",
"p",
".",
"i",
">=",
"len",
"(",
"p",
".",
"s",
")",
"{",
"return",
"\n",
"}",
"\n\n",
"switch",
"p",
".",
"s",
"[",
"p",
".",
"i",
"]",
"{",
"case",
"'+'",
",",
"'>'",
",",
"'~'",
":",
"combinator",
"=",
"p",
".",
"s",
"[",
"p",
".",
"i",
"]",
"\n",
"p",
".",
"i",
"++",
"\n",
"p",
".",
"skipWhitespace",
"(",
")",
"\n",
"case",
"','",
",",
"')'",
":",
"// These characters can't begin a selector, but they can legally occur after one.",
"return",
"\n",
"}",
"\n\n",
"if",
"combinator",
"==",
"0",
"{",
"return",
"\n",
"}",
"\n\n",
"c",
",",
"err",
":=",
"p",
".",
"parseSimpleSelectorSequence",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"switch",
"combinator",
"{",
"case",
"' '",
":",
"result",
"=",
"descendantSelector",
"(",
"result",
",",
"c",
")",
"\n",
"case",
"'>'",
":",
"result",
"=",
"childSelector",
"(",
"result",
",",
"c",
")",
"\n",
"case",
"'+'",
":",
"result",
"=",
"siblingSelector",
"(",
"result",
",",
"c",
",",
"true",
")",
"\n",
"case",
"'~'",
":",
"result",
"=",
"siblingSelector",
"(",
"result",
",",
"c",
",",
"false",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"panic",
"(",
"\"",
"\"",
")",
"\n",
"}"
] | // parseSelector parses a selector that may include combinators. | [
"parseSelector",
"parses",
"a",
"selector",
"that",
"may",
"include",
"combinators",
"."
] | 680b6a57bda4f657485ad44bdea42342ead737bc | https://github.com/andybalholm/cascadia/blob/680b6a57bda4f657485ad44bdea42342ead737bc/parser.go#L765-L813 |
646 | andybalholm/cascadia | parser.go | parseSelectorGroup | func (p *parser) parseSelectorGroup() (result Selector, err error) {
result, err = p.parseSelector()
if err != nil {
return
}
for p.i < len(p.s) {
if p.s[p.i] != ',' {
return result, nil
}
p.i++
c, err := p.parseSelector()
if err != nil {
return nil, err
}
result = unionSelector(result, c)
}
return
} | go | func (p *parser) parseSelectorGroup() (result Selector, err error) {
result, err = p.parseSelector()
if err != nil {
return
}
for p.i < len(p.s) {
if p.s[p.i] != ',' {
return result, nil
}
p.i++
c, err := p.parseSelector()
if err != nil {
return nil, err
}
result = unionSelector(result, c)
}
return
} | [
"func",
"(",
"p",
"*",
"parser",
")",
"parseSelectorGroup",
"(",
")",
"(",
"result",
"Selector",
",",
"err",
"error",
")",
"{",
"result",
",",
"err",
"=",
"p",
".",
"parseSelector",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n\n",
"for",
"p",
".",
"i",
"<",
"len",
"(",
"p",
".",
"s",
")",
"{",
"if",
"p",
".",
"s",
"[",
"p",
".",
"i",
"]",
"!=",
"','",
"{",
"return",
"result",
",",
"nil",
"\n",
"}",
"\n",
"p",
".",
"i",
"++",
"\n",
"c",
",",
"err",
":=",
"p",
".",
"parseSelector",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"result",
"=",
"unionSelector",
"(",
"result",
",",
"c",
")",
"\n",
"}",
"\n\n",
"return",
"\n",
"}"
] | // parseSelectorGroup parses a group of selectors, separated by commas. | [
"parseSelectorGroup",
"parses",
"a",
"group",
"of",
"selectors",
"separated",
"by",
"commas",
"."
] | 680b6a57bda4f657485ad44bdea42342ead737bc | https://github.com/andybalholm/cascadia/blob/680b6a57bda4f657485ad44bdea42342ead737bc/parser.go#L816-L835 |
647 | andybalholm/cascadia | fuzz/fuzz.go | Fuzz | func Fuzz(data []byte) int {
sel, err := cascadia.Compile(string(data))
if err != nil {
if sel != nil {
panic("sel != nil on error")
}
return 0
}
return 1
} | go | func Fuzz(data []byte) int {
sel, err := cascadia.Compile(string(data))
if err != nil {
if sel != nil {
panic("sel != nil on error")
}
return 0
}
return 1
} | [
"func",
"Fuzz",
"(",
"data",
"[",
"]",
"byte",
")",
"int",
"{",
"sel",
",",
"err",
":=",
"cascadia",
".",
"Compile",
"(",
"string",
"(",
"data",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"if",
"sel",
"!=",
"nil",
"{",
"panic",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"return",
"0",
"\n",
"}",
"\n",
"return",
"1",
"\n",
"}"
] | // Fuzz is the entrypoint used by the go-fuzz framework | [
"Fuzz",
"is",
"the",
"entrypoint",
"used",
"by",
"the",
"go",
"-",
"fuzz",
"framework"
] | 680b6a57bda4f657485ad44bdea42342ead737bc | https://github.com/andybalholm/cascadia/blob/680b6a57bda4f657485ad44bdea42342ead737bc/fuzz/fuzz.go#L6-L15 |
648 | andybalholm/cascadia | selector.go | hasChildMatch | func hasChildMatch(n *html.Node, a Selector) bool {
for c := n.FirstChild; c != nil; c = c.NextSibling {
if a(c) {
return true
}
}
return false
} | go | func hasChildMatch(n *html.Node, a Selector) bool {
for c := n.FirstChild; c != nil; c = c.NextSibling {
if a(c) {
return true
}
}
return false
} | [
"func",
"hasChildMatch",
"(",
"n",
"*",
"html",
".",
"Node",
",",
"a",
"Selector",
")",
"bool",
"{",
"for",
"c",
":=",
"n",
".",
"FirstChild",
";",
"c",
"!=",
"nil",
";",
"c",
"=",
"c",
".",
"NextSibling",
"{",
"if",
"a",
"(",
"c",
")",
"{",
"return",
"true",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"false",
"\n",
"}"
] | // hasChildMatch returns whether n has any child that matches a. | [
"hasChildMatch",
"returns",
"whether",
"n",
"has",
"any",
"child",
"that",
"matches",
"a",
"."
] | 680b6a57bda4f657485ad44bdea42342ead737bc | https://github.com/andybalholm/cascadia/blob/680b6a57bda4f657485ad44bdea42342ead737bc/selector.go#L18-L25 |
649 | andybalholm/cascadia | selector.go | hasDescendantMatch | func hasDescendantMatch(n *html.Node, a Selector) bool {
for c := n.FirstChild; c != nil; c = c.NextSibling {
if a(c) || (c.Type == html.ElementNode && hasDescendantMatch(c, a)) {
return true
}
}
return false
} | go | func hasDescendantMatch(n *html.Node, a Selector) bool {
for c := n.FirstChild; c != nil; c = c.NextSibling {
if a(c) || (c.Type == html.ElementNode && hasDescendantMatch(c, a)) {
return true
}
}
return false
} | [
"func",
"hasDescendantMatch",
"(",
"n",
"*",
"html",
".",
"Node",
",",
"a",
"Selector",
")",
"bool",
"{",
"for",
"c",
":=",
"n",
".",
"FirstChild",
";",
"c",
"!=",
"nil",
";",
"c",
"=",
"c",
".",
"NextSibling",
"{",
"if",
"a",
"(",
"c",
")",
"||",
"(",
"c",
".",
"Type",
"==",
"html",
".",
"ElementNode",
"&&",
"hasDescendantMatch",
"(",
"c",
",",
"a",
")",
")",
"{",
"return",
"true",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"false",
"\n",
"}"
] | // hasDescendantMatch performs a depth-first search of n's descendants,
// testing whether any of them match a. It returns true as soon as a match is
// found, or false if no match is found. | [
"hasDescendantMatch",
"performs",
"a",
"depth",
"-",
"first",
"search",
"of",
"n",
"s",
"descendants",
"testing",
"whether",
"any",
"of",
"them",
"match",
"a",
".",
"It",
"returns",
"true",
"as",
"soon",
"as",
"a",
"match",
"is",
"found",
"or",
"false",
"if",
"no",
"match",
"is",
"found",
"."
] | 680b6a57bda4f657485ad44bdea42342ead737bc | https://github.com/andybalholm/cascadia/blob/680b6a57bda4f657485ad44bdea42342ead737bc/selector.go#L30-L37 |
650 | andybalholm/cascadia | selector.go | Compile | func Compile(sel string) (Selector, error) {
p := &parser{s: sel}
compiled, err := p.parseSelectorGroup()
if err != nil {
return nil, err
}
if p.i < len(sel) {
return nil, fmt.Errorf("parsing %q: %d bytes left over", sel, len(sel)-p.i)
}
return compiled, nil
} | go | func Compile(sel string) (Selector, error) {
p := &parser{s: sel}
compiled, err := p.parseSelectorGroup()
if err != nil {
return nil, err
}
if p.i < len(sel) {
return nil, fmt.Errorf("parsing %q: %d bytes left over", sel, len(sel)-p.i)
}
return compiled, nil
} | [
"func",
"Compile",
"(",
"sel",
"string",
")",
"(",
"Selector",
",",
"error",
")",
"{",
"p",
":=",
"&",
"parser",
"{",
"s",
":",
"sel",
"}",
"\n",
"compiled",
",",
"err",
":=",
"p",
".",
"parseSelectorGroup",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"if",
"p",
".",
"i",
"<",
"len",
"(",
"sel",
")",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"sel",
",",
"len",
"(",
"sel",
")",
"-",
"p",
".",
"i",
")",
"\n",
"}",
"\n\n",
"return",
"compiled",
",",
"nil",
"\n",
"}"
] | // Compile parses a selector and returns, if successful, a Selector object
// that can be used to match against html.Node objects. | [
"Compile",
"parses",
"a",
"selector",
"and",
"returns",
"if",
"successful",
"a",
"Selector",
"object",
"that",
"can",
"be",
"used",
"to",
"match",
"against",
"html",
".",
"Node",
"objects",
"."
] | 680b6a57bda4f657485ad44bdea42342ead737bc | https://github.com/andybalholm/cascadia/blob/680b6a57bda4f657485ad44bdea42342ead737bc/selector.go#L41-L53 |
651 | andybalholm/cascadia | selector.go | MustCompile | func MustCompile(sel string) Selector {
compiled, err := Compile(sel)
if err != nil {
panic(err)
}
return compiled
} | go | func MustCompile(sel string) Selector {
compiled, err := Compile(sel)
if err != nil {
panic(err)
}
return compiled
} | [
"func",
"MustCompile",
"(",
"sel",
"string",
")",
"Selector",
"{",
"compiled",
",",
"err",
":=",
"Compile",
"(",
"sel",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"panic",
"(",
"err",
")",
"\n",
"}",
"\n",
"return",
"compiled",
"\n",
"}"
] | // MustCompile is like Compile, but panics instead of returning an error. | [
"MustCompile",
"is",
"like",
"Compile",
"but",
"panics",
"instead",
"of",
"returning",
"an",
"error",
"."
] | 680b6a57bda4f657485ad44bdea42342ead737bc | https://github.com/andybalholm/cascadia/blob/680b6a57bda4f657485ad44bdea42342ead737bc/selector.go#L56-L62 |
652 | andybalholm/cascadia | selector.go | MatchAll | func (s Selector) MatchAll(n *html.Node) []*html.Node {
return s.matchAllInto(n, nil)
} | go | func (s Selector) MatchAll(n *html.Node) []*html.Node {
return s.matchAllInto(n, nil)
} | [
"func",
"(",
"s",
"Selector",
")",
"MatchAll",
"(",
"n",
"*",
"html",
".",
"Node",
")",
"[",
"]",
"*",
"html",
".",
"Node",
"{",
"return",
"s",
".",
"matchAllInto",
"(",
"n",
",",
"nil",
")",
"\n",
"}"
] | // MatchAll returns a slice of the nodes that match the selector,
// from n and its children. | [
"MatchAll",
"returns",
"a",
"slice",
"of",
"the",
"nodes",
"that",
"match",
"the",
"selector",
"from",
"n",
"and",
"its",
"children",
"."
] | 680b6a57bda4f657485ad44bdea42342ead737bc | https://github.com/andybalholm/cascadia/blob/680b6a57bda4f657485ad44bdea42342ead737bc/selector.go#L66-L68 |
653 | andybalholm/cascadia | selector.go | MatchFirst | func (s Selector) MatchFirst(n *html.Node) *html.Node {
if s.Match(n) {
return n
}
for c := n.FirstChild; c != nil; c = c.NextSibling {
m := s.MatchFirst(c)
if m != nil {
return m
}
}
return nil
} | go | func (s Selector) MatchFirst(n *html.Node) *html.Node {
if s.Match(n) {
return n
}
for c := n.FirstChild; c != nil; c = c.NextSibling {
m := s.MatchFirst(c)
if m != nil {
return m
}
}
return nil
} | [
"func",
"(",
"s",
"Selector",
")",
"MatchFirst",
"(",
"n",
"*",
"html",
".",
"Node",
")",
"*",
"html",
".",
"Node",
"{",
"if",
"s",
".",
"Match",
"(",
"n",
")",
"{",
"return",
"n",
"\n",
"}",
"\n\n",
"for",
"c",
":=",
"n",
".",
"FirstChild",
";",
"c",
"!=",
"nil",
";",
"c",
"=",
"c",
".",
"NextSibling",
"{",
"m",
":=",
"s",
".",
"MatchFirst",
"(",
"c",
")",
"\n",
"if",
"m",
"!=",
"nil",
"{",
"return",
"m",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // MatchFirst returns the first node that matches s, from n and its children. | [
"MatchFirst",
"returns",
"the",
"first",
"node",
"that",
"matches",
"s",
"from",
"n",
"and",
"its",
"children",
"."
] | 680b6a57bda4f657485ad44bdea42342ead737bc | https://github.com/andybalholm/cascadia/blob/680b6a57bda4f657485ad44bdea42342ead737bc/selector.go#L88-L100 |
654 | andybalholm/cascadia | selector.go | Filter | func (s Selector) Filter(nodes []*html.Node) (result []*html.Node) {
for _, n := range nodes {
if s(n) {
result = append(result, n)
}
}
return result
} | go | func (s Selector) Filter(nodes []*html.Node) (result []*html.Node) {
for _, n := range nodes {
if s(n) {
result = append(result, n)
}
}
return result
} | [
"func",
"(",
"s",
"Selector",
")",
"Filter",
"(",
"nodes",
"[",
"]",
"*",
"html",
".",
"Node",
")",
"(",
"result",
"[",
"]",
"*",
"html",
".",
"Node",
")",
"{",
"for",
"_",
",",
"n",
":=",
"range",
"nodes",
"{",
"if",
"s",
"(",
"n",
")",
"{",
"result",
"=",
"append",
"(",
"result",
",",
"n",
")",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"result",
"\n",
"}"
] | // Filter returns the nodes in nodes that match the selector. | [
"Filter",
"returns",
"the",
"nodes",
"in",
"nodes",
"that",
"match",
"the",
"selector",
"."
] | 680b6a57bda4f657485ad44bdea42342ead737bc | https://github.com/andybalholm/cascadia/blob/680b6a57bda4f657485ad44bdea42342ead737bc/selector.go#L103-L110 |
655 | andybalholm/cascadia | selector.go | typeSelector | func typeSelector(tag string) Selector {
tag = toLowerASCII(tag)
return func(n *html.Node) bool {
return n.Type == html.ElementNode && n.Data == tag
}
} | go | func typeSelector(tag string) Selector {
tag = toLowerASCII(tag)
return func(n *html.Node) bool {
return n.Type == html.ElementNode && n.Data == tag
}
} | [
"func",
"typeSelector",
"(",
"tag",
"string",
")",
"Selector",
"{",
"tag",
"=",
"toLowerASCII",
"(",
"tag",
")",
"\n",
"return",
"func",
"(",
"n",
"*",
"html",
".",
"Node",
")",
"bool",
"{",
"return",
"n",
".",
"Type",
"==",
"html",
".",
"ElementNode",
"&&",
"n",
".",
"Data",
"==",
"tag",
"\n",
"}",
"\n",
"}"
] | // typeSelector returns a Selector that matches elements with a given tag name. | [
"typeSelector",
"returns",
"a",
"Selector",
"that",
"matches",
"elements",
"with",
"a",
"given",
"tag",
"name",
"."
] | 680b6a57bda4f657485ad44bdea42342ead737bc | https://github.com/andybalholm/cascadia/blob/680b6a57bda4f657485ad44bdea42342ead737bc/selector.go#L113-L118 |
656 | andybalholm/cascadia | selector.go | toLowerASCII | func toLowerASCII(s string) string {
var b []byte
for i := 0; i < len(s); i++ {
if c := s[i]; 'A' <= c && c <= 'Z' {
if b == nil {
b = make([]byte, len(s))
copy(b, s)
}
b[i] = s[i] + ('a' - 'A')
}
}
if b == nil {
return s
}
return string(b)
} | go | func toLowerASCII(s string) string {
var b []byte
for i := 0; i < len(s); i++ {
if c := s[i]; 'A' <= c && c <= 'Z' {
if b == nil {
b = make([]byte, len(s))
copy(b, s)
}
b[i] = s[i] + ('a' - 'A')
}
}
if b == nil {
return s
}
return string(b)
} | [
"func",
"toLowerASCII",
"(",
"s",
"string",
")",
"string",
"{",
"var",
"b",
"[",
"]",
"byte",
"\n",
"for",
"i",
":=",
"0",
";",
"i",
"<",
"len",
"(",
"s",
")",
";",
"i",
"++",
"{",
"if",
"c",
":=",
"s",
"[",
"i",
"]",
";",
"'A'",
"<=",
"c",
"&&",
"c",
"<=",
"'Z'",
"{",
"if",
"b",
"==",
"nil",
"{",
"b",
"=",
"make",
"(",
"[",
"]",
"byte",
",",
"len",
"(",
"s",
")",
")",
"\n",
"copy",
"(",
"b",
",",
"s",
")",
"\n",
"}",
"\n",
"b",
"[",
"i",
"]",
"=",
"s",
"[",
"i",
"]",
"+",
"(",
"'a'",
"-",
"'A'",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"if",
"b",
"==",
"nil",
"{",
"return",
"s",
"\n",
"}",
"\n\n",
"return",
"string",
"(",
"b",
")",
"\n",
"}"
] | // toLowerASCII returns s with all ASCII capital letters lowercased. | [
"toLowerASCII",
"returns",
"s",
"with",
"all",
"ASCII",
"capital",
"letters",
"lowercased",
"."
] | 680b6a57bda4f657485ad44bdea42342ead737bc | https://github.com/andybalholm/cascadia/blob/680b6a57bda4f657485ad44bdea42342ead737bc/selector.go#L121-L138 |
657 | andybalholm/cascadia | selector.go | attributeEqualsSelector | func attributeEqualsSelector(key, val string) Selector {
return attributeSelector(key,
func(s string) bool {
return s == val
})
} | go | func attributeEqualsSelector(key, val string) Selector {
return attributeSelector(key,
func(s string) bool {
return s == val
})
} | [
"func",
"attributeEqualsSelector",
"(",
"key",
",",
"val",
"string",
")",
"Selector",
"{",
"return",
"attributeSelector",
"(",
"key",
",",
"func",
"(",
"s",
"string",
")",
"bool",
"{",
"return",
"s",
"==",
"val",
"\n",
"}",
")",
"\n",
"}"
] | // attributeEqualsSelector returns a Selector that matches elements where
// the attribute named key has the value val. | [
"attributeEqualsSelector",
"returns",
"a",
"Selector",
"that",
"matches",
"elements",
"where",
"the",
"attribute",
"named",
"key",
"has",
"the",
"value",
"val",
"."
] | 680b6a57bda4f657485ad44bdea42342ead737bc | https://github.com/andybalholm/cascadia/blob/680b6a57bda4f657485ad44bdea42342ead737bc/selector.go#L165-L170 |
658 | andybalholm/cascadia | selector.go | attributeNotEqualSelector | func attributeNotEqualSelector(key, val string) Selector {
key = toLowerASCII(key)
return func(n *html.Node) bool {
if n.Type != html.ElementNode {
return false
}
for _, a := range n.Attr {
if a.Key == key && a.Val == val {
return false
}
}
return true
}
} | go | func attributeNotEqualSelector(key, val string) Selector {
key = toLowerASCII(key)
return func(n *html.Node) bool {
if n.Type != html.ElementNode {
return false
}
for _, a := range n.Attr {
if a.Key == key && a.Val == val {
return false
}
}
return true
}
} | [
"func",
"attributeNotEqualSelector",
"(",
"key",
",",
"val",
"string",
")",
"Selector",
"{",
"key",
"=",
"toLowerASCII",
"(",
"key",
")",
"\n",
"return",
"func",
"(",
"n",
"*",
"html",
".",
"Node",
")",
"bool",
"{",
"if",
"n",
".",
"Type",
"!=",
"html",
".",
"ElementNode",
"{",
"return",
"false",
"\n",
"}",
"\n",
"for",
"_",
",",
"a",
":=",
"range",
"n",
".",
"Attr",
"{",
"if",
"a",
".",
"Key",
"==",
"key",
"&&",
"a",
".",
"Val",
"==",
"val",
"{",
"return",
"false",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"true",
"\n",
"}",
"\n",
"}"
] | // attributeNotEqualSelector returns a Selector that matches elements where
// the attribute named key does not have the value val. | [
"attributeNotEqualSelector",
"returns",
"a",
"Selector",
"that",
"matches",
"elements",
"where",
"the",
"attribute",
"named",
"key",
"does",
"not",
"have",
"the",
"value",
"val",
"."
] | 680b6a57bda4f657485ad44bdea42342ead737bc | https://github.com/andybalholm/cascadia/blob/680b6a57bda4f657485ad44bdea42342ead737bc/selector.go#L174-L187 |
659 | andybalholm/cascadia | selector.go | attributeIncludesSelector | func attributeIncludesSelector(key, val string) Selector {
return attributeSelector(key,
func(s string) bool {
for s != "" {
i := strings.IndexAny(s, " \t\r\n\f")
if i == -1 {
return s == val
}
if s[:i] == val {
return true
}
s = s[i+1:]
}
return false
})
} | go | func attributeIncludesSelector(key, val string) Selector {
return attributeSelector(key,
func(s string) bool {
for s != "" {
i := strings.IndexAny(s, " \t\r\n\f")
if i == -1 {
return s == val
}
if s[:i] == val {
return true
}
s = s[i+1:]
}
return false
})
} | [
"func",
"attributeIncludesSelector",
"(",
"key",
",",
"val",
"string",
")",
"Selector",
"{",
"return",
"attributeSelector",
"(",
"key",
",",
"func",
"(",
"s",
"string",
")",
"bool",
"{",
"for",
"s",
"!=",
"\"",
"\"",
"{",
"i",
":=",
"strings",
".",
"IndexAny",
"(",
"s",
",",
"\"",
"\\t",
"\\r",
"\\n",
"\\f",
"\"",
")",
"\n",
"if",
"i",
"==",
"-",
"1",
"{",
"return",
"s",
"==",
"val",
"\n",
"}",
"\n",
"if",
"s",
"[",
":",
"i",
"]",
"==",
"val",
"{",
"return",
"true",
"\n",
"}",
"\n",
"s",
"=",
"s",
"[",
"i",
"+",
"1",
":",
"]",
"\n",
"}",
"\n",
"return",
"false",
"\n",
"}",
")",
"\n",
"}"
] | // attributeIncludesSelector returns a Selector that matches elements where
// the attribute named key is a whitespace-separated list that includes val. | [
"attributeIncludesSelector",
"returns",
"a",
"Selector",
"that",
"matches",
"elements",
"where",
"the",
"attribute",
"named",
"key",
"is",
"a",
"whitespace",
"-",
"separated",
"list",
"that",
"includes",
"val",
"."
] | 680b6a57bda4f657485ad44bdea42342ead737bc | https://github.com/andybalholm/cascadia/blob/680b6a57bda4f657485ad44bdea42342ead737bc/selector.go#L191-L206 |
660 | andybalholm/cascadia | selector.go | attributeDashmatchSelector | func attributeDashmatchSelector(key, val string) Selector {
return attributeSelector(key,
func(s string) bool {
if s == val {
return true
}
if len(s) <= len(val) {
return false
}
if s[:len(val)] == val && s[len(val)] == '-' {
return true
}
return false
})
} | go | func attributeDashmatchSelector(key, val string) Selector {
return attributeSelector(key,
func(s string) bool {
if s == val {
return true
}
if len(s) <= len(val) {
return false
}
if s[:len(val)] == val && s[len(val)] == '-' {
return true
}
return false
})
} | [
"func",
"attributeDashmatchSelector",
"(",
"key",
",",
"val",
"string",
")",
"Selector",
"{",
"return",
"attributeSelector",
"(",
"key",
",",
"func",
"(",
"s",
"string",
")",
"bool",
"{",
"if",
"s",
"==",
"val",
"{",
"return",
"true",
"\n",
"}",
"\n",
"if",
"len",
"(",
"s",
")",
"<=",
"len",
"(",
"val",
")",
"{",
"return",
"false",
"\n",
"}",
"\n",
"if",
"s",
"[",
":",
"len",
"(",
"val",
")",
"]",
"==",
"val",
"&&",
"s",
"[",
"len",
"(",
"val",
")",
"]",
"==",
"'-'",
"{",
"return",
"true",
"\n",
"}",
"\n",
"return",
"false",
"\n",
"}",
")",
"\n",
"}"
] | // attributeDashmatchSelector returns a Selector that matches elements where
// the attribute named key equals val or starts with val plus a hyphen. | [
"attributeDashmatchSelector",
"returns",
"a",
"Selector",
"that",
"matches",
"elements",
"where",
"the",
"attribute",
"named",
"key",
"equals",
"val",
"or",
"starts",
"with",
"val",
"plus",
"a",
"hyphen",
"."
] | 680b6a57bda4f657485ad44bdea42342ead737bc | https://github.com/andybalholm/cascadia/blob/680b6a57bda4f657485ad44bdea42342ead737bc/selector.go#L210-L224 |
661 | andybalholm/cascadia | selector.go | attributePrefixSelector | func attributePrefixSelector(key, val string) Selector {
return attributeSelector(key,
func(s string) bool {
if strings.TrimSpace(s) == "" {
return false
}
return strings.HasPrefix(s, val)
})
} | go | func attributePrefixSelector(key, val string) Selector {
return attributeSelector(key,
func(s string) bool {
if strings.TrimSpace(s) == "" {
return false
}
return strings.HasPrefix(s, val)
})
} | [
"func",
"attributePrefixSelector",
"(",
"key",
",",
"val",
"string",
")",
"Selector",
"{",
"return",
"attributeSelector",
"(",
"key",
",",
"func",
"(",
"s",
"string",
")",
"bool",
"{",
"if",
"strings",
".",
"TrimSpace",
"(",
"s",
")",
"==",
"\"",
"\"",
"{",
"return",
"false",
"\n",
"}",
"\n",
"return",
"strings",
".",
"HasPrefix",
"(",
"s",
",",
"val",
")",
"\n",
"}",
")",
"\n",
"}"
] | // attributePrefixSelector returns a Selector that matches elements where
// the attribute named key starts with val. | [
"attributePrefixSelector",
"returns",
"a",
"Selector",
"that",
"matches",
"elements",
"where",
"the",
"attribute",
"named",
"key",
"starts",
"with",
"val",
"."
] | 680b6a57bda4f657485ad44bdea42342ead737bc | https://github.com/andybalholm/cascadia/blob/680b6a57bda4f657485ad44bdea42342ead737bc/selector.go#L228-L236 |
662 | andybalholm/cascadia | selector.go | attributeSuffixSelector | func attributeSuffixSelector(key, val string) Selector {
return attributeSelector(key,
func(s string) bool {
if strings.TrimSpace(s) == "" {
return false
}
return strings.HasSuffix(s, val)
})
} | go | func attributeSuffixSelector(key, val string) Selector {
return attributeSelector(key,
func(s string) bool {
if strings.TrimSpace(s) == "" {
return false
}
return strings.HasSuffix(s, val)
})
} | [
"func",
"attributeSuffixSelector",
"(",
"key",
",",
"val",
"string",
")",
"Selector",
"{",
"return",
"attributeSelector",
"(",
"key",
",",
"func",
"(",
"s",
"string",
")",
"bool",
"{",
"if",
"strings",
".",
"TrimSpace",
"(",
"s",
")",
"==",
"\"",
"\"",
"{",
"return",
"false",
"\n",
"}",
"\n",
"return",
"strings",
".",
"HasSuffix",
"(",
"s",
",",
"val",
")",
"\n",
"}",
")",
"\n",
"}"
] | // attributeSuffixSelector returns a Selector that matches elements where
// the attribute named key ends with val. | [
"attributeSuffixSelector",
"returns",
"a",
"Selector",
"that",
"matches",
"elements",
"where",
"the",
"attribute",
"named",
"key",
"ends",
"with",
"val",
"."
] | 680b6a57bda4f657485ad44bdea42342ead737bc | https://github.com/andybalholm/cascadia/blob/680b6a57bda4f657485ad44bdea42342ead737bc/selector.go#L240-L248 |
663 | andybalholm/cascadia | selector.go | attributeSubstringSelector | func attributeSubstringSelector(key, val string) Selector {
return attributeSelector(key,
func(s string) bool {
if strings.TrimSpace(s) == "" {
return false
}
return strings.Contains(s, val)
})
} | go | func attributeSubstringSelector(key, val string) Selector {
return attributeSelector(key,
func(s string) bool {
if strings.TrimSpace(s) == "" {
return false
}
return strings.Contains(s, val)
})
} | [
"func",
"attributeSubstringSelector",
"(",
"key",
",",
"val",
"string",
")",
"Selector",
"{",
"return",
"attributeSelector",
"(",
"key",
",",
"func",
"(",
"s",
"string",
")",
"bool",
"{",
"if",
"strings",
".",
"TrimSpace",
"(",
"s",
")",
"==",
"\"",
"\"",
"{",
"return",
"false",
"\n",
"}",
"\n",
"return",
"strings",
".",
"Contains",
"(",
"s",
",",
"val",
")",
"\n",
"}",
")",
"\n",
"}"
] | // attributeSubstringSelector returns a Selector that matches nodes where
// the attribute named key contains val. | [
"attributeSubstringSelector",
"returns",
"a",
"Selector",
"that",
"matches",
"nodes",
"where",
"the",
"attribute",
"named",
"key",
"contains",
"val",
"."
] | 680b6a57bda4f657485ad44bdea42342ead737bc | https://github.com/andybalholm/cascadia/blob/680b6a57bda4f657485ad44bdea42342ead737bc/selector.go#L252-L260 |
664 | andybalholm/cascadia | selector.go | attributeRegexSelector | func attributeRegexSelector(key string, rx *regexp.Regexp) Selector {
return attributeSelector(key,
func(s string) bool {
return rx.MatchString(s)
})
} | go | func attributeRegexSelector(key string, rx *regexp.Regexp) Selector {
return attributeSelector(key,
func(s string) bool {
return rx.MatchString(s)
})
} | [
"func",
"attributeRegexSelector",
"(",
"key",
"string",
",",
"rx",
"*",
"regexp",
".",
"Regexp",
")",
"Selector",
"{",
"return",
"attributeSelector",
"(",
"key",
",",
"func",
"(",
"s",
"string",
")",
"bool",
"{",
"return",
"rx",
".",
"MatchString",
"(",
"s",
")",
"\n",
"}",
")",
"\n",
"}"
] | // attributeRegexSelector returns a Selector that matches nodes where
// the attribute named key matches the regular expression rx | [
"attributeRegexSelector",
"returns",
"a",
"Selector",
"that",
"matches",
"nodes",
"where",
"the",
"attribute",
"named",
"key",
"matches",
"the",
"regular",
"expression",
"rx"
] | 680b6a57bda4f657485ad44bdea42342ead737bc | https://github.com/andybalholm/cascadia/blob/680b6a57bda4f657485ad44bdea42342ead737bc/selector.go#L264-L269 |
665 | andybalholm/cascadia | selector.go | intersectionSelector | func intersectionSelector(a, b Selector) Selector {
return func(n *html.Node) bool {
return a(n) && b(n)
}
} | go | func intersectionSelector(a, b Selector) Selector {
return func(n *html.Node) bool {
return a(n) && b(n)
}
} | [
"func",
"intersectionSelector",
"(",
"a",
",",
"b",
"Selector",
")",
"Selector",
"{",
"return",
"func",
"(",
"n",
"*",
"html",
".",
"Node",
")",
"bool",
"{",
"return",
"a",
"(",
"n",
")",
"&&",
"b",
"(",
"n",
")",
"\n",
"}",
"\n",
"}"
] | // intersectionSelector returns a selector that matches nodes that match
// both a and b. | [
"intersectionSelector",
"returns",
"a",
"selector",
"that",
"matches",
"nodes",
"that",
"match",
"both",
"a",
"and",
"b",
"."
] | 680b6a57bda4f657485ad44bdea42342ead737bc | https://github.com/andybalholm/cascadia/blob/680b6a57bda4f657485ad44bdea42342ead737bc/selector.go#L273-L277 |
666 | andybalholm/cascadia | selector.go | unionSelector | func unionSelector(a, b Selector) Selector {
return func(n *html.Node) bool {
return a(n) || b(n)
}
} | go | func unionSelector(a, b Selector) Selector {
return func(n *html.Node) bool {
return a(n) || b(n)
}
} | [
"func",
"unionSelector",
"(",
"a",
",",
"b",
"Selector",
")",
"Selector",
"{",
"return",
"func",
"(",
"n",
"*",
"html",
".",
"Node",
")",
"bool",
"{",
"return",
"a",
"(",
"n",
")",
"||",
"b",
"(",
"n",
")",
"\n",
"}",
"\n",
"}"
] | // unionSelector returns a selector that matches elements that match
// either a or b. | [
"unionSelector",
"returns",
"a",
"selector",
"that",
"matches",
"elements",
"that",
"match",
"either",
"a",
"or",
"b",
"."
] | 680b6a57bda4f657485ad44bdea42342ead737bc | https://github.com/andybalholm/cascadia/blob/680b6a57bda4f657485ad44bdea42342ead737bc/selector.go#L281-L285 |
667 | andybalholm/cascadia | selector.go | negatedSelector | func negatedSelector(a Selector) Selector {
return func(n *html.Node) bool {
if n.Type != html.ElementNode {
return false
}
return !a(n)
}
} | go | func negatedSelector(a Selector) Selector {
return func(n *html.Node) bool {
if n.Type != html.ElementNode {
return false
}
return !a(n)
}
} | [
"func",
"negatedSelector",
"(",
"a",
"Selector",
")",
"Selector",
"{",
"return",
"func",
"(",
"n",
"*",
"html",
".",
"Node",
")",
"bool",
"{",
"if",
"n",
".",
"Type",
"!=",
"html",
".",
"ElementNode",
"{",
"return",
"false",
"\n",
"}",
"\n",
"return",
"!",
"a",
"(",
"n",
")",
"\n",
"}",
"\n",
"}"
] | // negatedSelector returns a selector that matches elements that do not match a. | [
"negatedSelector",
"returns",
"a",
"selector",
"that",
"matches",
"elements",
"that",
"do",
"not",
"match",
"a",
"."
] | 680b6a57bda4f657485ad44bdea42342ead737bc | https://github.com/andybalholm/cascadia/blob/680b6a57bda4f657485ad44bdea42342ead737bc/selector.go#L288-L295 |
668 | andybalholm/cascadia | selector.go | writeNodeText | func writeNodeText(n *html.Node, b *bytes.Buffer) {
switch n.Type {
case html.TextNode:
b.WriteString(n.Data)
case html.ElementNode:
for c := n.FirstChild; c != nil; c = c.NextSibling {
writeNodeText(c, b)
}
}
} | go | func writeNodeText(n *html.Node, b *bytes.Buffer) {
switch n.Type {
case html.TextNode:
b.WriteString(n.Data)
case html.ElementNode:
for c := n.FirstChild; c != nil; c = c.NextSibling {
writeNodeText(c, b)
}
}
} | [
"func",
"writeNodeText",
"(",
"n",
"*",
"html",
".",
"Node",
",",
"b",
"*",
"bytes",
".",
"Buffer",
")",
"{",
"switch",
"n",
".",
"Type",
"{",
"case",
"html",
".",
"TextNode",
":",
"b",
".",
"WriteString",
"(",
"n",
".",
"Data",
")",
"\n",
"case",
"html",
".",
"ElementNode",
":",
"for",
"c",
":=",
"n",
".",
"FirstChild",
";",
"c",
"!=",
"nil",
";",
"c",
"=",
"c",
".",
"NextSibling",
"{",
"writeNodeText",
"(",
"c",
",",
"b",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}"
] | // writeNodeText writes the text contained in n and its descendants to b. | [
"writeNodeText",
"writes",
"the",
"text",
"contained",
"in",
"n",
"and",
"its",
"descendants",
"to",
"b",
"."
] | 680b6a57bda4f657485ad44bdea42342ead737bc | https://github.com/andybalholm/cascadia/blob/680b6a57bda4f657485ad44bdea42342ead737bc/selector.go#L298-L307 |
669 | andybalholm/cascadia | selector.go | nodeText | func nodeText(n *html.Node) string {
var b bytes.Buffer
writeNodeText(n, &b)
return b.String()
} | go | func nodeText(n *html.Node) string {
var b bytes.Buffer
writeNodeText(n, &b)
return b.String()
} | [
"func",
"nodeText",
"(",
"n",
"*",
"html",
".",
"Node",
")",
"string",
"{",
"var",
"b",
"bytes",
".",
"Buffer",
"\n",
"writeNodeText",
"(",
"n",
",",
"&",
"b",
")",
"\n",
"return",
"b",
".",
"String",
"(",
")",
"\n",
"}"
] | // nodeText returns the text contained in n and its descendants. | [
"nodeText",
"returns",
"the",
"text",
"contained",
"in",
"n",
"and",
"its",
"descendants",
"."
] | 680b6a57bda4f657485ad44bdea42342ead737bc | https://github.com/andybalholm/cascadia/blob/680b6a57bda4f657485ad44bdea42342ead737bc/selector.go#L310-L314 |
670 | andybalholm/cascadia | selector.go | nodeOwnText | func nodeOwnText(n *html.Node) string {
var b bytes.Buffer
for c := n.FirstChild; c != nil; c = c.NextSibling {
if c.Type == html.TextNode {
b.WriteString(c.Data)
}
}
return b.String()
} | go | func nodeOwnText(n *html.Node) string {
var b bytes.Buffer
for c := n.FirstChild; c != nil; c = c.NextSibling {
if c.Type == html.TextNode {
b.WriteString(c.Data)
}
}
return b.String()
} | [
"func",
"nodeOwnText",
"(",
"n",
"*",
"html",
".",
"Node",
")",
"string",
"{",
"var",
"b",
"bytes",
".",
"Buffer",
"\n",
"for",
"c",
":=",
"n",
".",
"FirstChild",
";",
"c",
"!=",
"nil",
";",
"c",
"=",
"c",
".",
"NextSibling",
"{",
"if",
"c",
".",
"Type",
"==",
"html",
".",
"TextNode",
"{",
"b",
".",
"WriteString",
"(",
"c",
".",
"Data",
")",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"b",
".",
"String",
"(",
")",
"\n",
"}"
] | // nodeOwnText returns the contents of the text nodes that are direct
// children of n. | [
"nodeOwnText",
"returns",
"the",
"contents",
"of",
"the",
"text",
"nodes",
"that",
"are",
"direct",
"children",
"of",
"n",
"."
] | 680b6a57bda4f657485ad44bdea42342ead737bc | https://github.com/andybalholm/cascadia/blob/680b6a57bda4f657485ad44bdea42342ead737bc/selector.go#L318-L326 |
671 | andybalholm/cascadia | selector.go | textSubstrSelector | func textSubstrSelector(val string) Selector {
return func(n *html.Node) bool {
text := strings.ToLower(nodeText(n))
return strings.Contains(text, val)
}
} | go | func textSubstrSelector(val string) Selector {
return func(n *html.Node) bool {
text := strings.ToLower(nodeText(n))
return strings.Contains(text, val)
}
} | [
"func",
"textSubstrSelector",
"(",
"val",
"string",
")",
"Selector",
"{",
"return",
"func",
"(",
"n",
"*",
"html",
".",
"Node",
")",
"bool",
"{",
"text",
":=",
"strings",
".",
"ToLower",
"(",
"nodeText",
"(",
"n",
")",
")",
"\n",
"return",
"strings",
".",
"Contains",
"(",
"text",
",",
"val",
")",
"\n",
"}",
"\n",
"}"
] | // textSubstrSelector returns a selector that matches nodes that
// contain the given text. | [
"textSubstrSelector",
"returns",
"a",
"selector",
"that",
"matches",
"nodes",
"that",
"contain",
"the",
"given",
"text",
"."
] | 680b6a57bda4f657485ad44bdea42342ead737bc | https://github.com/andybalholm/cascadia/blob/680b6a57bda4f657485ad44bdea42342ead737bc/selector.go#L330-L335 |
672 | andybalholm/cascadia | selector.go | ownTextSubstrSelector | func ownTextSubstrSelector(val string) Selector {
return func(n *html.Node) bool {
text := strings.ToLower(nodeOwnText(n))
return strings.Contains(text, val)
}
} | go | func ownTextSubstrSelector(val string) Selector {
return func(n *html.Node) bool {
text := strings.ToLower(nodeOwnText(n))
return strings.Contains(text, val)
}
} | [
"func",
"ownTextSubstrSelector",
"(",
"val",
"string",
")",
"Selector",
"{",
"return",
"func",
"(",
"n",
"*",
"html",
".",
"Node",
")",
"bool",
"{",
"text",
":=",
"strings",
".",
"ToLower",
"(",
"nodeOwnText",
"(",
"n",
")",
")",
"\n",
"return",
"strings",
".",
"Contains",
"(",
"text",
",",
"val",
")",
"\n",
"}",
"\n",
"}"
] | // ownTextSubstrSelector returns a selector that matches nodes that
// directly contain the given text | [
"ownTextSubstrSelector",
"returns",
"a",
"selector",
"that",
"matches",
"nodes",
"that",
"directly",
"contain",
"the",
"given",
"text"
] | 680b6a57bda4f657485ad44bdea42342ead737bc | https://github.com/andybalholm/cascadia/blob/680b6a57bda4f657485ad44bdea42342ead737bc/selector.go#L339-L344 |
673 | andybalholm/cascadia | selector.go | textRegexSelector | func textRegexSelector(rx *regexp.Regexp) Selector {
return func(n *html.Node) bool {
return rx.MatchString(nodeText(n))
}
} | go | func textRegexSelector(rx *regexp.Regexp) Selector {
return func(n *html.Node) bool {
return rx.MatchString(nodeText(n))
}
} | [
"func",
"textRegexSelector",
"(",
"rx",
"*",
"regexp",
".",
"Regexp",
")",
"Selector",
"{",
"return",
"func",
"(",
"n",
"*",
"html",
".",
"Node",
")",
"bool",
"{",
"return",
"rx",
".",
"MatchString",
"(",
"nodeText",
"(",
"n",
")",
")",
"\n",
"}",
"\n",
"}"
] | // textRegexSelector returns a selector that matches nodes whose text matches
// the specified regular expression | [
"textRegexSelector",
"returns",
"a",
"selector",
"that",
"matches",
"nodes",
"whose",
"text",
"matches",
"the",
"specified",
"regular",
"expression"
] | 680b6a57bda4f657485ad44bdea42342ead737bc | https://github.com/andybalholm/cascadia/blob/680b6a57bda4f657485ad44bdea42342ead737bc/selector.go#L348-L352 |
674 | andybalholm/cascadia | selector.go | ownTextRegexSelector | func ownTextRegexSelector(rx *regexp.Regexp) Selector {
return func(n *html.Node) bool {
return rx.MatchString(nodeOwnText(n))
}
} | go | func ownTextRegexSelector(rx *regexp.Regexp) Selector {
return func(n *html.Node) bool {
return rx.MatchString(nodeOwnText(n))
}
} | [
"func",
"ownTextRegexSelector",
"(",
"rx",
"*",
"regexp",
".",
"Regexp",
")",
"Selector",
"{",
"return",
"func",
"(",
"n",
"*",
"html",
".",
"Node",
")",
"bool",
"{",
"return",
"rx",
".",
"MatchString",
"(",
"nodeOwnText",
"(",
"n",
")",
")",
"\n",
"}",
"\n",
"}"
] | // ownTextRegexSelector returns a selector that matches nodes whose text
// directly matches the specified regular expression | [
"ownTextRegexSelector",
"returns",
"a",
"selector",
"that",
"matches",
"nodes",
"whose",
"text",
"directly",
"matches",
"the",
"specified",
"regular",
"expression"
] | 680b6a57bda4f657485ad44bdea42342ead737bc | https://github.com/andybalholm/cascadia/blob/680b6a57bda4f657485ad44bdea42342ead737bc/selector.go#L356-L360 |
675 | andybalholm/cascadia | selector.go | hasChildSelector | func hasChildSelector(a Selector) Selector {
return func(n *html.Node) bool {
if n.Type != html.ElementNode {
return false
}
return hasChildMatch(n, a)
}
} | go | func hasChildSelector(a Selector) Selector {
return func(n *html.Node) bool {
if n.Type != html.ElementNode {
return false
}
return hasChildMatch(n, a)
}
} | [
"func",
"hasChildSelector",
"(",
"a",
"Selector",
")",
"Selector",
"{",
"return",
"func",
"(",
"n",
"*",
"html",
".",
"Node",
")",
"bool",
"{",
"if",
"n",
".",
"Type",
"!=",
"html",
".",
"ElementNode",
"{",
"return",
"false",
"\n",
"}",
"\n",
"return",
"hasChildMatch",
"(",
"n",
",",
"a",
")",
"\n",
"}",
"\n",
"}"
] | // hasChildSelector returns a selector that matches elements
// with a child that matches a. | [
"hasChildSelector",
"returns",
"a",
"selector",
"that",
"matches",
"elements",
"with",
"a",
"child",
"that",
"matches",
"a",
"."
] | 680b6a57bda4f657485ad44bdea42342ead737bc | https://github.com/andybalholm/cascadia/blob/680b6a57bda4f657485ad44bdea42342ead737bc/selector.go#L364-L371 |
676 | andybalholm/cascadia | selector.go | hasDescendantSelector | func hasDescendantSelector(a Selector) Selector {
return func(n *html.Node) bool {
if n.Type != html.ElementNode {
return false
}
return hasDescendantMatch(n, a)
}
} | go | func hasDescendantSelector(a Selector) Selector {
return func(n *html.Node) bool {
if n.Type != html.ElementNode {
return false
}
return hasDescendantMatch(n, a)
}
} | [
"func",
"hasDescendantSelector",
"(",
"a",
"Selector",
")",
"Selector",
"{",
"return",
"func",
"(",
"n",
"*",
"html",
".",
"Node",
")",
"bool",
"{",
"if",
"n",
".",
"Type",
"!=",
"html",
".",
"ElementNode",
"{",
"return",
"false",
"\n",
"}",
"\n",
"return",
"hasDescendantMatch",
"(",
"n",
",",
"a",
")",
"\n",
"}",
"\n",
"}"
] | // hasDescendantSelector returns a selector that matches elements
// with any descendant that matches a. | [
"hasDescendantSelector",
"returns",
"a",
"selector",
"that",
"matches",
"elements",
"with",
"any",
"descendant",
"that",
"matches",
"a",
"."
] | 680b6a57bda4f657485ad44bdea42342ead737bc | https://github.com/andybalholm/cascadia/blob/680b6a57bda4f657485ad44bdea42342ead737bc/selector.go#L375-L382 |
677 | andybalholm/cascadia | selector.go | inputSelector | func inputSelector(n *html.Node) bool {
return n.Type == html.ElementNode && (n.Data == "input" || n.Data == "select" || n.Data == "textarea" || n.Data == "button")
} | go | func inputSelector(n *html.Node) bool {
return n.Type == html.ElementNode && (n.Data == "input" || n.Data == "select" || n.Data == "textarea" || n.Data == "button")
} | [
"func",
"inputSelector",
"(",
"n",
"*",
"html",
".",
"Node",
")",
"bool",
"{",
"return",
"n",
".",
"Type",
"==",
"html",
".",
"ElementNode",
"&&",
"(",
"n",
".",
"Data",
"==",
"\"",
"\"",
"||",
"n",
".",
"Data",
"==",
"\"",
"\"",
"||",
"n",
".",
"Data",
"==",
"\"",
"\"",
"||",
"n",
".",
"Data",
"==",
"\"",
"\"",
")",
"\n",
"}"
] | // inputSelector is a Selector that matches input, select, textarea and button elements. | [
"inputSelector",
"is",
"a",
"Selector",
"that",
"matches",
"input",
"select",
"textarea",
"and",
"button",
"elements",
"."
] | 680b6a57bda4f657485ad44bdea42342ead737bc | https://github.com/andybalholm/cascadia/blob/680b6a57bda4f657485ad44bdea42342ead737bc/selector.go#L537-L539 |
678 | andybalholm/cascadia | selector.go | emptyElementSelector | func emptyElementSelector(n *html.Node) bool {
if n.Type != html.ElementNode {
return false
}
for c := n.FirstChild; c != nil; c = c.NextSibling {
switch c.Type {
case html.ElementNode, html.TextNode:
return false
}
}
return true
} | go | func emptyElementSelector(n *html.Node) bool {
if n.Type != html.ElementNode {
return false
}
for c := n.FirstChild; c != nil; c = c.NextSibling {
switch c.Type {
case html.ElementNode, html.TextNode:
return false
}
}
return true
} | [
"func",
"emptyElementSelector",
"(",
"n",
"*",
"html",
".",
"Node",
")",
"bool",
"{",
"if",
"n",
".",
"Type",
"!=",
"html",
".",
"ElementNode",
"{",
"return",
"false",
"\n",
"}",
"\n\n",
"for",
"c",
":=",
"n",
".",
"FirstChild",
";",
"c",
"!=",
"nil",
";",
"c",
"=",
"c",
".",
"NextSibling",
"{",
"switch",
"c",
".",
"Type",
"{",
"case",
"html",
".",
"ElementNode",
",",
"html",
".",
"TextNode",
":",
"return",
"false",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"true",
"\n",
"}"
] | // emptyElementSelector is a Selector that matches empty elements. | [
"emptyElementSelector",
"is",
"a",
"Selector",
"that",
"matches",
"empty",
"elements",
"."
] | 680b6a57bda4f657485ad44bdea42342ead737bc | https://github.com/andybalholm/cascadia/blob/680b6a57bda4f657485ad44bdea42342ead737bc/selector.go#L542-L555 |
679 | andybalholm/cascadia | selector.go | descendantSelector | func descendantSelector(a, d Selector) Selector {
return func(n *html.Node) bool {
if !d(n) {
return false
}
for p := n.Parent; p != nil; p = p.Parent {
if a(p) {
return true
}
}
return false
}
} | go | func descendantSelector(a, d Selector) Selector {
return func(n *html.Node) bool {
if !d(n) {
return false
}
for p := n.Parent; p != nil; p = p.Parent {
if a(p) {
return true
}
}
return false
}
} | [
"func",
"descendantSelector",
"(",
"a",
",",
"d",
"Selector",
")",
"Selector",
"{",
"return",
"func",
"(",
"n",
"*",
"html",
".",
"Node",
")",
"bool",
"{",
"if",
"!",
"d",
"(",
"n",
")",
"{",
"return",
"false",
"\n",
"}",
"\n\n",
"for",
"p",
":=",
"n",
".",
"Parent",
";",
"p",
"!=",
"nil",
";",
"p",
"=",
"p",
".",
"Parent",
"{",
"if",
"a",
"(",
"p",
")",
"{",
"return",
"true",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"false",
"\n",
"}",
"\n",
"}"
] | // descendantSelector returns a Selector that matches an element if
// it matches d and has an ancestor that matches a. | [
"descendantSelector",
"returns",
"a",
"Selector",
"that",
"matches",
"an",
"element",
"if",
"it",
"matches",
"d",
"and",
"has",
"an",
"ancestor",
"that",
"matches",
"a",
"."
] | 680b6a57bda4f657485ad44bdea42342ead737bc | https://github.com/andybalholm/cascadia/blob/680b6a57bda4f657485ad44bdea42342ead737bc/selector.go#L559-L573 |
680 | andybalholm/cascadia | selector.go | childSelector | func childSelector(a, d Selector) Selector {
return func(n *html.Node) bool {
return d(n) && n.Parent != nil && a(n.Parent)
}
} | go | func childSelector(a, d Selector) Selector {
return func(n *html.Node) bool {
return d(n) && n.Parent != nil && a(n.Parent)
}
} | [
"func",
"childSelector",
"(",
"a",
",",
"d",
"Selector",
")",
"Selector",
"{",
"return",
"func",
"(",
"n",
"*",
"html",
".",
"Node",
")",
"bool",
"{",
"return",
"d",
"(",
"n",
")",
"&&",
"n",
".",
"Parent",
"!=",
"nil",
"&&",
"a",
"(",
"n",
".",
"Parent",
")",
"\n",
"}",
"\n",
"}"
] | // childSelector returns a Selector that matches an element if
// it matches d and its parent matches a. | [
"childSelector",
"returns",
"a",
"Selector",
"that",
"matches",
"an",
"element",
"if",
"it",
"matches",
"d",
"and",
"its",
"parent",
"matches",
"a",
"."
] | 680b6a57bda4f657485ad44bdea42342ead737bc | https://github.com/andybalholm/cascadia/blob/680b6a57bda4f657485ad44bdea42342ead737bc/selector.go#L577-L581 |
681 | andybalholm/cascadia | selector.go | siblingSelector | func siblingSelector(s1, s2 Selector, adjacent bool) Selector {
return func(n *html.Node) bool {
if !s2(n) {
return false
}
if adjacent {
for n = n.PrevSibling; n != nil; n = n.PrevSibling {
if n.Type == html.TextNode || n.Type == html.CommentNode {
continue
}
return s1(n)
}
return false
}
// Walk backwards looking for element that matches s1
for c := n.PrevSibling; c != nil; c = c.PrevSibling {
if s1(c) {
return true
}
}
return false
}
} | go | func siblingSelector(s1, s2 Selector, adjacent bool) Selector {
return func(n *html.Node) bool {
if !s2(n) {
return false
}
if adjacent {
for n = n.PrevSibling; n != nil; n = n.PrevSibling {
if n.Type == html.TextNode || n.Type == html.CommentNode {
continue
}
return s1(n)
}
return false
}
// Walk backwards looking for element that matches s1
for c := n.PrevSibling; c != nil; c = c.PrevSibling {
if s1(c) {
return true
}
}
return false
}
} | [
"func",
"siblingSelector",
"(",
"s1",
",",
"s2",
"Selector",
",",
"adjacent",
"bool",
")",
"Selector",
"{",
"return",
"func",
"(",
"n",
"*",
"html",
".",
"Node",
")",
"bool",
"{",
"if",
"!",
"s2",
"(",
"n",
")",
"{",
"return",
"false",
"\n",
"}",
"\n\n",
"if",
"adjacent",
"{",
"for",
"n",
"=",
"n",
".",
"PrevSibling",
";",
"n",
"!=",
"nil",
";",
"n",
"=",
"n",
".",
"PrevSibling",
"{",
"if",
"n",
".",
"Type",
"==",
"html",
".",
"TextNode",
"||",
"n",
".",
"Type",
"==",
"html",
".",
"CommentNode",
"{",
"continue",
"\n",
"}",
"\n",
"return",
"s1",
"(",
"n",
")",
"\n",
"}",
"\n",
"return",
"false",
"\n",
"}",
"\n\n",
"// Walk backwards looking for element that matches s1",
"for",
"c",
":=",
"n",
".",
"PrevSibling",
";",
"c",
"!=",
"nil",
";",
"c",
"=",
"c",
".",
"PrevSibling",
"{",
"if",
"s1",
"(",
"c",
")",
"{",
"return",
"true",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"false",
"\n",
"}",
"\n",
"}"
] | // siblingSelector returns a Selector that matches an element
// if it matches s2 and in is preceded by an element that matches s1.
// If adjacent is true, the sibling must be immediately before the element. | [
"siblingSelector",
"returns",
"a",
"Selector",
"that",
"matches",
"an",
"element",
"if",
"it",
"matches",
"s2",
"and",
"in",
"is",
"preceded",
"by",
"an",
"element",
"that",
"matches",
"s1",
".",
"If",
"adjacent",
"is",
"true",
"the",
"sibling",
"must",
"be",
"immediately",
"before",
"the",
"element",
"."
] | 680b6a57bda4f657485ad44bdea42342ead737bc | https://github.com/andybalholm/cascadia/blob/680b6a57bda4f657485ad44bdea42342ead737bc/selector.go#L586-L611 |
682 | pkg/browser | browser.go | OpenFile | func OpenFile(path string) error {
path, err := filepath.Abs(path)
if err != nil {
return err
}
return OpenURL("file://" + path)
} | go | func OpenFile(path string) error {
path, err := filepath.Abs(path)
if err != nil {
return err
}
return OpenURL("file://" + path)
} | [
"func",
"OpenFile",
"(",
"path",
"string",
")",
"error",
"{",
"path",
",",
"err",
":=",
"filepath",
".",
"Abs",
"(",
"path",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"return",
"OpenURL",
"(",
"\"",
"\"",
"+",
"path",
")",
"\n",
"}"
] | // OpenFile opens new browser window for the file path. | [
"OpenFile",
"opens",
"new",
"browser",
"window",
"for",
"the",
"file",
"path",
"."
] | 0a3d74bf9ce488f035cf5bc36f753a711bc74334 | https://github.com/pkg/browser/blob/0a3d74bf9ce488f035cf5bc36f753a711bc74334/browser.go#L22-L28 |
683 | pkg/browser | browser.go | OpenReader | func OpenReader(r io.Reader) error {
f, err := ioutil.TempFile("", "browser")
if err != nil {
return fmt.Errorf("browser: could not create temporary file: %v", err)
}
if _, err := io.Copy(f, r); err != nil {
f.Close()
return fmt.Errorf("browser: caching temporary file failed: %v", err)
}
if err := f.Close(); err != nil {
return fmt.Errorf("browser: caching temporary file failed: %v", err)
}
oldname := f.Name()
newname := oldname + ".html"
if err := os.Rename(oldname, newname); err != nil {
return fmt.Errorf("browser: renaming temporary file failed: %v", err)
}
return OpenFile(newname)
} | go | func OpenReader(r io.Reader) error {
f, err := ioutil.TempFile("", "browser")
if err != nil {
return fmt.Errorf("browser: could not create temporary file: %v", err)
}
if _, err := io.Copy(f, r); err != nil {
f.Close()
return fmt.Errorf("browser: caching temporary file failed: %v", err)
}
if err := f.Close(); err != nil {
return fmt.Errorf("browser: caching temporary file failed: %v", err)
}
oldname := f.Name()
newname := oldname + ".html"
if err := os.Rename(oldname, newname); err != nil {
return fmt.Errorf("browser: renaming temporary file failed: %v", err)
}
return OpenFile(newname)
} | [
"func",
"OpenReader",
"(",
"r",
"io",
".",
"Reader",
")",
"error",
"{",
"f",
",",
"err",
":=",
"ioutil",
".",
"TempFile",
"(",
"\"",
"\"",
",",
"\"",
"\"",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n",
"if",
"_",
",",
"err",
":=",
"io",
".",
"Copy",
"(",
"f",
",",
"r",
")",
";",
"err",
"!=",
"nil",
"{",
"f",
".",
"Close",
"(",
")",
"\n",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n",
"if",
"err",
":=",
"f",
".",
"Close",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n",
"oldname",
":=",
"f",
".",
"Name",
"(",
")",
"\n",
"newname",
":=",
"oldname",
"+",
"\"",
"\"",
"\n",
"if",
"err",
":=",
"os",
".",
"Rename",
"(",
"oldname",
",",
"newname",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n",
"return",
"OpenFile",
"(",
"newname",
")",
"\n",
"}"
] | // OpenReader consumes the contents of r and presents the
// results in a new browser window. | [
"OpenReader",
"consumes",
"the",
"contents",
"of",
"r",
"and",
"presents",
"the",
"results",
"in",
"a",
"new",
"browser",
"window",
"."
] | 0a3d74bf9ce488f035cf5bc36f753a711bc74334 | https://github.com/pkg/browser/blob/0a3d74bf9ce488f035cf5bc36f753a711bc74334/browser.go#L32-L50 |
684 | appleboy/gofight | example/pat.go | PatEngine | func PatEngine() *pat.Router {
r := pat.New()
r.Get("/user/{name}", patUserHandler)
r.Get("/", patHelloHandler)
return r
} | go | func PatEngine() *pat.Router {
r := pat.New()
r.Get("/user/{name}", patUserHandler)
r.Get("/", patHelloHandler)
return r
} | [
"func",
"PatEngine",
"(",
")",
"*",
"pat",
".",
"Router",
"{",
"r",
":=",
"pat",
".",
"New",
"(",
")",
"\n\n",
"r",
".",
"Get",
"(",
"\"",
"\"",
",",
"patUserHandler",
")",
"\n",
"r",
".",
"Get",
"(",
"\"",
"\"",
",",
"patHelloHandler",
")",
"\n\n",
"return",
"r",
"\n",
"}"
] | // PatEngine is pat router. | [
"PatEngine",
"is",
"pat",
"router",
"."
] | 9341751b2b3c62a14808c372ce615f2f543110a4 | https://github.com/appleboy/gofight/blob/9341751b2b3c62a14808c372ce615f2f543110a4/example/pat.go#L21-L28 |
685 | appleboy/gofight | example/httprouter.go | HTTPRouterEngine | func HTTPRouterEngine() http.Handler {
r := httprouter.New()
r.GET("/", httpRouterHelloHandler)
return r
} | go | func HTTPRouterEngine() http.Handler {
r := httprouter.New()
r.GET("/", httpRouterHelloHandler)
return r
} | [
"func",
"HTTPRouterEngine",
"(",
")",
"http",
".",
"Handler",
"{",
"r",
":=",
"httprouter",
".",
"New",
"(",
")",
"\n\n",
"r",
".",
"GET",
"(",
"\"",
"\"",
",",
"httpRouterHelloHandler",
")",
"\n\n",
"return",
"r",
"\n",
"}"
] | // HTTPRouterEngine is httprouter router. | [
"HTTPRouterEngine",
"is",
"httprouter",
"router",
"."
] | 9341751b2b3c62a14808c372ce615f2f543110a4 | https://github.com/appleboy/gofight/blob/9341751b2b3c62a14808c372ce615f2f543110a4/example/httprouter.go#L14-L20 |
686 | appleboy/gofight | example/beego.go | SayHelloWorld | func (c *UserController) SayHelloWorld() {
c.Ctx.ResponseWriter.Status = 200
c.Ctx.ResponseWriter.Write([]byte("Hello, World"))
} | go | func (c *UserController) SayHelloWorld() {
c.Ctx.ResponseWriter.Status = 200
c.Ctx.ResponseWriter.Write([]byte("Hello, World"))
} | [
"func",
"(",
"c",
"*",
"UserController",
")",
"SayHelloWorld",
"(",
")",
"{",
"c",
".",
"Ctx",
".",
"ResponseWriter",
".",
"Status",
"=",
"200",
"\n",
"c",
".",
"Ctx",
".",
"ResponseWriter",
".",
"Write",
"(",
"[",
"]",
"byte",
"(",
"\"",
"\"",
")",
")",
"\n",
"}"
] | // SayHelloWorld for say hello | [
"SayHelloWorld",
"for",
"say",
"hello"
] | 9341751b2b3c62a14808c372ce615f2f543110a4 | https://github.com/appleboy/gofight/blob/9341751b2b3c62a14808c372ce615f2f543110a4/example/beego.go#L13-L16 |
687 | appleboy/gofight | example/basic.go | BasicEngine | func BasicEngine() http.Handler {
mux := http.NewServeMux()
mux.HandleFunc("/", basicHelloHandler)
return mux
} | go | func BasicEngine() http.Handler {
mux := http.NewServeMux()
mux.HandleFunc("/", basicHelloHandler)
return mux
} | [
"func",
"BasicEngine",
"(",
")",
"http",
".",
"Handler",
"{",
"mux",
":=",
"http",
".",
"NewServeMux",
"(",
")",
"\n",
"mux",
".",
"HandleFunc",
"(",
"\"",
"\"",
",",
"basicHelloHandler",
")",
"\n\n",
"return",
"mux",
"\n",
"}"
] | // BasicEngine is basic router. | [
"BasicEngine",
"is",
"basic",
"router",
"."
] | 9341751b2b3c62a14808c372ce615f2f543110a4 | https://github.com/appleboy/gofight/blob/9341751b2b3c62a14808c372ce615f2f543110a4/example/basic.go#L13-L18 |
688 | appleboy/gofight | gofight.go | SetDebug | func (rc *RequestConfig) SetDebug(enable bool) *RequestConfig {
rc.Debug = enable
return rc
} | go | func (rc *RequestConfig) SetDebug(enable bool) *RequestConfig {
rc.Debug = enable
return rc
} | [
"func",
"(",
"rc",
"*",
"RequestConfig",
")",
"SetDebug",
"(",
"enable",
"bool",
")",
"*",
"RequestConfig",
"{",
"rc",
".",
"Debug",
"=",
"enable",
"\n\n",
"return",
"rc",
"\n",
"}"
] | // SetDebug supply enable debug mode. | [
"SetDebug",
"supply",
"enable",
"debug",
"mode",
"."
] | 9341751b2b3c62a14808c372ce615f2f543110a4 | https://github.com/appleboy/gofight/blob/9341751b2b3c62a14808c372ce615f2f543110a4/gofight.go#L149-L153 |
689 | appleboy/gofight | gofight.go | GET | func (rc *RequestConfig) GET(path string) *RequestConfig {
rc.Path = path
rc.Method = "GET"
return rc
} | go | func (rc *RequestConfig) GET(path string) *RequestConfig {
rc.Path = path
rc.Method = "GET"
return rc
} | [
"func",
"(",
"rc",
"*",
"RequestConfig",
")",
"GET",
"(",
"path",
"string",
")",
"*",
"RequestConfig",
"{",
"rc",
".",
"Path",
"=",
"path",
"\n",
"rc",
".",
"Method",
"=",
"\"",
"\"",
"\n\n",
"return",
"rc",
"\n",
"}"
] | // GET is request method. | [
"GET",
"is",
"request",
"method",
"."
] | 9341751b2b3c62a14808c372ce615f2f543110a4 | https://github.com/appleboy/gofight/blob/9341751b2b3c62a14808c372ce615f2f543110a4/gofight.go#L156-L161 |
690 | appleboy/gofight | gofight.go | POST | func (rc *RequestConfig) POST(path string) *RequestConfig {
rc.Path = path
rc.Method = "POST"
return rc
} | go | func (rc *RequestConfig) POST(path string) *RequestConfig {
rc.Path = path
rc.Method = "POST"
return rc
} | [
"func",
"(",
"rc",
"*",
"RequestConfig",
")",
"POST",
"(",
"path",
"string",
")",
"*",
"RequestConfig",
"{",
"rc",
".",
"Path",
"=",
"path",
"\n",
"rc",
".",
"Method",
"=",
"\"",
"\"",
"\n\n",
"return",
"rc",
"\n",
"}"
] | // POST is request method. | [
"POST",
"is",
"request",
"method",
"."
] | 9341751b2b3c62a14808c372ce615f2f543110a4 | https://github.com/appleboy/gofight/blob/9341751b2b3c62a14808c372ce615f2f543110a4/gofight.go#L164-L169 |
691 | appleboy/gofight | gofight.go | PUT | func (rc *RequestConfig) PUT(path string) *RequestConfig {
rc.Path = path
rc.Method = "PUT"
return rc
} | go | func (rc *RequestConfig) PUT(path string) *RequestConfig {
rc.Path = path
rc.Method = "PUT"
return rc
} | [
"func",
"(",
"rc",
"*",
"RequestConfig",
")",
"PUT",
"(",
"path",
"string",
")",
"*",
"RequestConfig",
"{",
"rc",
".",
"Path",
"=",
"path",
"\n",
"rc",
".",
"Method",
"=",
"\"",
"\"",
"\n\n",
"return",
"rc",
"\n",
"}"
] | // PUT is request method. | [
"PUT",
"is",
"request",
"method",
"."
] | 9341751b2b3c62a14808c372ce615f2f543110a4 | https://github.com/appleboy/gofight/blob/9341751b2b3c62a14808c372ce615f2f543110a4/gofight.go#L172-L177 |
692 | appleboy/gofight | gofight.go | DELETE | func (rc *RequestConfig) DELETE(path string) *RequestConfig {
rc.Path = path
rc.Method = "DELETE"
return rc
} | go | func (rc *RequestConfig) DELETE(path string) *RequestConfig {
rc.Path = path
rc.Method = "DELETE"
return rc
} | [
"func",
"(",
"rc",
"*",
"RequestConfig",
")",
"DELETE",
"(",
"path",
"string",
")",
"*",
"RequestConfig",
"{",
"rc",
".",
"Path",
"=",
"path",
"\n",
"rc",
".",
"Method",
"=",
"\"",
"\"",
"\n\n",
"return",
"rc",
"\n",
"}"
] | // DELETE is request method. | [
"DELETE",
"is",
"request",
"method",
"."
] | 9341751b2b3c62a14808c372ce615f2f543110a4 | https://github.com/appleboy/gofight/blob/9341751b2b3c62a14808c372ce615f2f543110a4/gofight.go#L180-L185 |
693 | appleboy/gofight | gofight.go | PATCH | func (rc *RequestConfig) PATCH(path string) *RequestConfig {
rc.Path = path
rc.Method = "PATCH"
return rc
} | go | func (rc *RequestConfig) PATCH(path string) *RequestConfig {
rc.Path = path
rc.Method = "PATCH"
return rc
} | [
"func",
"(",
"rc",
"*",
"RequestConfig",
")",
"PATCH",
"(",
"path",
"string",
")",
"*",
"RequestConfig",
"{",
"rc",
".",
"Path",
"=",
"path",
"\n",
"rc",
".",
"Method",
"=",
"\"",
"\"",
"\n\n",
"return",
"rc",
"\n",
"}"
] | // PATCH is request method. | [
"PATCH",
"is",
"request",
"method",
"."
] | 9341751b2b3c62a14808c372ce615f2f543110a4 | https://github.com/appleboy/gofight/blob/9341751b2b3c62a14808c372ce615f2f543110a4/gofight.go#L188-L193 |
694 | appleboy/gofight | gofight.go | HEAD | func (rc *RequestConfig) HEAD(path string) *RequestConfig {
rc.Path = path
rc.Method = "HEAD"
return rc
} | go | func (rc *RequestConfig) HEAD(path string) *RequestConfig {
rc.Path = path
rc.Method = "HEAD"
return rc
} | [
"func",
"(",
"rc",
"*",
"RequestConfig",
")",
"HEAD",
"(",
"path",
"string",
")",
"*",
"RequestConfig",
"{",
"rc",
".",
"Path",
"=",
"path",
"\n",
"rc",
".",
"Method",
"=",
"\"",
"\"",
"\n\n",
"return",
"rc",
"\n",
"}"
] | // HEAD is request method. | [
"HEAD",
"is",
"request",
"method",
"."
] | 9341751b2b3c62a14808c372ce615f2f543110a4 | https://github.com/appleboy/gofight/blob/9341751b2b3c62a14808c372ce615f2f543110a4/gofight.go#L196-L201 |
695 | appleboy/gofight | gofight.go | OPTIONS | func (rc *RequestConfig) OPTIONS(path string) *RequestConfig {
rc.Path = path
rc.Method = "OPTIONS"
return rc
} | go | func (rc *RequestConfig) OPTIONS(path string) *RequestConfig {
rc.Path = path
rc.Method = "OPTIONS"
return rc
} | [
"func",
"(",
"rc",
"*",
"RequestConfig",
")",
"OPTIONS",
"(",
"path",
"string",
")",
"*",
"RequestConfig",
"{",
"rc",
".",
"Path",
"=",
"path",
"\n",
"rc",
".",
"Method",
"=",
"\"",
"\"",
"\n\n",
"return",
"rc",
"\n",
"}"
] | // OPTIONS is request method. | [
"OPTIONS",
"is",
"request",
"method",
"."
] | 9341751b2b3c62a14808c372ce615f2f543110a4 | https://github.com/appleboy/gofight/blob/9341751b2b3c62a14808c372ce615f2f543110a4/gofight.go#L204-L209 |
696 | appleboy/gofight | gofight.go | SetHeader | func (rc *RequestConfig) SetHeader(headers H) *RequestConfig {
if len(headers) > 0 {
rc.Headers = headers
}
return rc
} | go | func (rc *RequestConfig) SetHeader(headers H) *RequestConfig {
if len(headers) > 0 {
rc.Headers = headers
}
return rc
} | [
"func",
"(",
"rc",
"*",
"RequestConfig",
")",
"SetHeader",
"(",
"headers",
"H",
")",
"*",
"RequestConfig",
"{",
"if",
"len",
"(",
"headers",
")",
">",
"0",
"{",
"rc",
".",
"Headers",
"=",
"headers",
"\n",
"}",
"\n\n",
"return",
"rc",
"\n",
"}"
] | // SetHeader supply http header what you defined. | [
"SetHeader",
"supply",
"http",
"header",
"what",
"you",
"defined",
"."
] | 9341751b2b3c62a14808c372ce615f2f543110a4 | https://github.com/appleboy/gofight/blob/9341751b2b3c62a14808c372ce615f2f543110a4/gofight.go#L212-L218 |
697 | appleboy/gofight | gofight.go | SetJSON | func (rc *RequestConfig) SetJSON(body D) *RequestConfig {
if b, err := json.Marshal(body); err == nil {
rc.Body = string(b)
}
return rc
} | go | func (rc *RequestConfig) SetJSON(body D) *RequestConfig {
if b, err := json.Marshal(body); err == nil {
rc.Body = string(b)
}
return rc
} | [
"func",
"(",
"rc",
"*",
"RequestConfig",
")",
"SetJSON",
"(",
"body",
"D",
")",
"*",
"RequestConfig",
"{",
"if",
"b",
",",
"err",
":=",
"json",
".",
"Marshal",
"(",
"body",
")",
";",
"err",
"==",
"nil",
"{",
"rc",
".",
"Body",
"=",
"string",
"(",
"b",
")",
"\n",
"}",
"\n\n",
"return",
"rc",
"\n",
"}"
] | // SetJSON supply JSON body. | [
"SetJSON",
"supply",
"JSON",
"body",
"."
] | 9341751b2b3c62a14808c372ce615f2f543110a4 | https://github.com/appleboy/gofight/blob/9341751b2b3c62a14808c372ce615f2f543110a4/gofight.go#L221-L227 |
698 | appleboy/gofight | gofight.go | SetJSONInterface | func (rc *RequestConfig) SetJSONInterface(body interface{}) *RequestConfig {
if b, err := json.Marshal(body); err == nil {
rc.Body = string(b)
}
return rc
} | go | func (rc *RequestConfig) SetJSONInterface(body interface{}) *RequestConfig {
if b, err := json.Marshal(body); err == nil {
rc.Body = string(b)
}
return rc
} | [
"func",
"(",
"rc",
"*",
"RequestConfig",
")",
"SetJSONInterface",
"(",
"body",
"interface",
"{",
"}",
")",
"*",
"RequestConfig",
"{",
"if",
"b",
",",
"err",
":=",
"json",
".",
"Marshal",
"(",
"body",
")",
";",
"err",
"==",
"nil",
"{",
"rc",
".",
"Body",
"=",
"string",
"(",
"b",
")",
"\n",
"}",
"\n\n",
"return",
"rc",
"\n",
"}"
] | // SetJSONInterface supply JSON body | [
"SetJSONInterface",
"supply",
"JSON",
"body"
] | 9341751b2b3c62a14808c372ce615f2f543110a4 | https://github.com/appleboy/gofight/blob/9341751b2b3c62a14808c372ce615f2f543110a4/gofight.go#L230-L236 |
699 | appleboy/gofight | gofight.go | SetForm | func (rc *RequestConfig) SetForm(body H) *RequestConfig {
f := make(url.Values)
for k, v := range body {
f.Set(k, v)
}
rc.Body = f.Encode()
return rc
} | go | func (rc *RequestConfig) SetForm(body H) *RequestConfig {
f := make(url.Values)
for k, v := range body {
f.Set(k, v)
}
rc.Body = f.Encode()
return rc
} | [
"func",
"(",
"rc",
"*",
"RequestConfig",
")",
"SetForm",
"(",
"body",
"H",
")",
"*",
"RequestConfig",
"{",
"f",
":=",
"make",
"(",
"url",
".",
"Values",
")",
"\n\n",
"for",
"k",
",",
"v",
":=",
"range",
"body",
"{",
"f",
".",
"Set",
"(",
"k",
",",
"v",
")",
"\n",
"}",
"\n\n",
"rc",
".",
"Body",
"=",
"f",
".",
"Encode",
"(",
")",
"\n\n",
"return",
"rc",
"\n",
"}"
] | // SetForm supply form body. | [
"SetForm",
"supply",
"form",
"body",
"."
] | 9341751b2b3c62a14808c372ce615f2f543110a4 | https://github.com/appleboy/gofight/blob/9341751b2b3c62a14808c372ce615f2f543110a4/gofight.go#L239-L249 |