id
int32 0
167k
| repo
stringlengths 5
54
| path
stringlengths 4
155
| func_name
stringlengths 1
118
| original_string
stringlengths 52
85.5k
| language
stringclasses 1
value | code
stringlengths 52
85.5k
| code_tokens
listlengths 21
1.41k
| docstring
stringlengths 6
2.61k
| docstring_tokens
listlengths 3
215
| sha
stringlengths 40
40
| url
stringlengths 85
252
|
---|---|---|---|---|---|---|---|---|---|---|---|
15,600 |
ikawaha/kagome
|
internal/dic/connection.go
|
LoadConnectionTable
|
func LoadConnectionTable(r io.Reader) (t ConnectionTable, err error) {
if err = binary.Read(r, binary.LittleEndian, &t.Row); err != nil {
return
}
if err = binary.Read(r, binary.LittleEndian, &t.Col); err != nil {
return
}
t.Vec = make([]int16, t.Row*t.Col)
for i := range t.Vec {
if err = binary.Read(r, binary.LittleEndian, &t.Vec[i]); err != nil {
return
}
}
return
}
|
go
|
func LoadConnectionTable(r io.Reader) (t ConnectionTable, err error) {
if err = binary.Read(r, binary.LittleEndian, &t.Row); err != nil {
return
}
if err = binary.Read(r, binary.LittleEndian, &t.Col); err != nil {
return
}
t.Vec = make([]int16, t.Row*t.Col)
for i := range t.Vec {
if err = binary.Read(r, binary.LittleEndian, &t.Vec[i]); err != nil {
return
}
}
return
}
|
[
"func",
"LoadConnectionTable",
"(",
"r",
"io",
".",
"Reader",
")",
"(",
"t",
"ConnectionTable",
",",
"err",
"error",
")",
"{",
"if",
"err",
"=",
"binary",
".",
"Read",
"(",
"r",
",",
"binary",
".",
"LittleEndian",
",",
"&",
"t",
".",
"Row",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n",
"if",
"err",
"=",
"binary",
".",
"Read",
"(",
"r",
",",
"binary",
".",
"LittleEndian",
",",
"&",
"t",
".",
"Col",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n",
"t",
".",
"Vec",
"=",
"make",
"(",
"[",
"]",
"int16",
",",
"t",
".",
"Row",
"*",
"t",
".",
"Col",
")",
"\n",
"for",
"i",
":=",
"range",
"t",
".",
"Vec",
"{",
"if",
"err",
"=",
"binary",
".",
"Read",
"(",
"r",
",",
"binary",
".",
"LittleEndian",
",",
"&",
"t",
".",
"Vec",
"[",
"i",
"]",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"\n",
"}"
] |
// LoadConnectionTable loads ConnectionTable from io.Reader.
|
[
"LoadConnectionTable",
"loads",
"ConnectionTable",
"from",
"io",
".",
"Reader",
"."
] |
d76ce24c16d24bc8968d32681d92db4d7ff6bd2d
|
https://github.com/ikawaha/kagome/blob/d76ce24c16d24bc8968d32681d92db4d7ff6bd2d/internal/dic/connection.go#L53-L67
|
15,601 |
ikawaha/kagome
|
internal/lattice/lattice.go
|
New
|
func New(d *dic.Dic, u *dic.UserDic) *Lattice {
la := latticePool.Get().(*Lattice)
la.dic = d
la.udic = u
return la
}
|
go
|
func New(d *dic.Dic, u *dic.UserDic) *Lattice {
la := latticePool.Get().(*Lattice)
la.dic = d
la.udic = u
return la
}
|
[
"func",
"New",
"(",
"d",
"*",
"dic",
".",
"Dic",
",",
"u",
"*",
"dic",
".",
"UserDic",
")",
"*",
"Lattice",
"{",
"la",
":=",
"latticePool",
".",
"Get",
"(",
")",
".",
"(",
"*",
"Lattice",
")",
"\n",
"la",
".",
"dic",
"=",
"d",
"\n",
"la",
".",
"udic",
"=",
"u",
"\n",
"return",
"la",
"\n",
"}"
] |
// New returns a new lattice.
|
[
"New",
"returns",
"a",
"new",
"lattice",
"."
] |
d76ce24c16d24bc8968d32681d92db4d7ff6bd2d
|
https://github.com/ikawaha/kagome/blob/d76ce24c16d24bc8968d32681d92db4d7ff6bd2d/internal/lattice/lattice.go#L65-L70
|
15,602 |
ikawaha/kagome
|
internal/lattice/lattice.go
|
Free
|
func (la *Lattice) Free() {
la.Input = ""
la.Output = la.Output[:0]
for i := range la.list {
for j := range la.list[i] {
nodePool.Put(la.list[i][j])
}
la.list[i] = la.list[i][:0]
}
la.list = la.list[:0]
la.udic = nil
latticePool.Put(la)
}
|
go
|
func (la *Lattice) Free() {
la.Input = ""
la.Output = la.Output[:0]
for i := range la.list {
for j := range la.list[i] {
nodePool.Put(la.list[i][j])
}
la.list[i] = la.list[i][:0]
}
la.list = la.list[:0]
la.udic = nil
latticePool.Put(la)
}
|
[
"func",
"(",
"la",
"*",
"Lattice",
")",
"Free",
"(",
")",
"{",
"la",
".",
"Input",
"=",
"\"",
"\"",
"\n",
"la",
".",
"Output",
"=",
"la",
".",
"Output",
"[",
":",
"0",
"]",
"\n",
"for",
"i",
":=",
"range",
"la",
".",
"list",
"{",
"for",
"j",
":=",
"range",
"la",
".",
"list",
"[",
"i",
"]",
"{",
"nodePool",
".",
"Put",
"(",
"la",
".",
"list",
"[",
"i",
"]",
"[",
"j",
"]",
")",
"\n",
"}",
"\n",
"la",
".",
"list",
"[",
"i",
"]",
"=",
"la",
".",
"list",
"[",
"i",
"]",
"[",
":",
"0",
"]",
"\n",
"}",
"\n",
"la",
".",
"list",
"=",
"la",
".",
"list",
"[",
":",
"0",
"]",
"\n",
"la",
".",
"udic",
"=",
"nil",
"\n",
"latticePool",
".",
"Put",
"(",
"la",
")",
"\n",
"}"
] |
// Free releases a memory of a lattice.
|
[
"Free",
"releases",
"a",
"memory",
"of",
"a",
"lattice",
"."
] |
d76ce24c16d24bc8968d32681d92db4d7ff6bd2d
|
https://github.com/ikawaha/kagome/blob/d76ce24c16d24bc8968d32681d92db4d7ff6bd2d/internal/lattice/lattice.go#L73-L85
|
15,603 |
ikawaha/kagome
|
internal/lattice/lattice.go
|
String
|
func (la *Lattice) String() string {
str := ""
for i, nodes := range la.list {
str += fmt.Sprintf("[%v] :\n", i)
for _, node := range nodes {
str += fmt.Sprintf("%v\n", node)
}
str += "\n"
}
return str
}
|
go
|
func (la *Lattice) String() string {
str := ""
for i, nodes := range la.list {
str += fmt.Sprintf("[%v] :\n", i)
for _, node := range nodes {
str += fmt.Sprintf("%v\n", node)
}
str += "\n"
}
return str
}
|
[
"func",
"(",
"la",
"*",
"Lattice",
")",
"String",
"(",
")",
"string",
"{",
"str",
":=",
"\"",
"\"",
"\n",
"for",
"i",
",",
"nodes",
":=",
"range",
"la",
".",
"list",
"{",
"str",
"+=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\\n",
"\"",
",",
"i",
")",
"\n",
"for",
"_",
",",
"node",
":=",
"range",
"nodes",
"{",
"str",
"+=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\\n",
"\"",
",",
"node",
")",
"\n",
"}",
"\n",
"str",
"+=",
"\"",
"\\n",
"\"",
"\n",
"}",
"\n",
"return",
"str",
"\n",
"}"
] |
// String returns a debug string of a lattice.
|
[
"String",
"returns",
"a",
"debug",
"string",
"of",
"a",
"lattice",
"."
] |
d76ce24c16d24bc8968d32681d92db4d7ff6bd2d
|
https://github.com/ikawaha/kagome/blob/d76ce24c16d24bc8968d32681d92db4d7ff6bd2d/internal/lattice/lattice.go#L186-L196
|
15,604 |
ikawaha/kagome
|
internal/lattice/lattice.go
|
Forward
|
func (la *Lattice) Forward(m TokenizeMode) {
for i, size := 1, len(la.list); i < size; i++ {
currentList := la.list[i]
for index, target := range currentList {
prevList := la.list[target.Start]
if len(prevList) == 0 {
la.list[i][index].Cost = maximumCost
continue
}
for j, n := range prevList {
var c int16
if n.Class != USER && target.Class != USER {
c = la.dic.Connection.At(int(n.Right), int(target.Left))
}
totalCost := int64(c) + int64(target.Weight) + int64(n.Cost)
if m != Normal {
totalCost += int64(additionalCost(n))
}
if totalCost > maximumCost {
totalCost = maximumCost
}
if j == 0 || int32(totalCost) < la.list[i][index].Cost {
la.list[i][index].Cost = int32(totalCost)
la.list[i][index].Prev = la.list[target.Start][j]
}
}
}
}
return
}
|
go
|
func (la *Lattice) Forward(m TokenizeMode) {
for i, size := 1, len(la.list); i < size; i++ {
currentList := la.list[i]
for index, target := range currentList {
prevList := la.list[target.Start]
if len(prevList) == 0 {
la.list[i][index].Cost = maximumCost
continue
}
for j, n := range prevList {
var c int16
if n.Class != USER && target.Class != USER {
c = la.dic.Connection.At(int(n.Right), int(target.Left))
}
totalCost := int64(c) + int64(target.Weight) + int64(n.Cost)
if m != Normal {
totalCost += int64(additionalCost(n))
}
if totalCost > maximumCost {
totalCost = maximumCost
}
if j == 0 || int32(totalCost) < la.list[i][index].Cost {
la.list[i][index].Cost = int32(totalCost)
la.list[i][index].Prev = la.list[target.Start][j]
}
}
}
}
return
}
|
[
"func",
"(",
"la",
"*",
"Lattice",
")",
"Forward",
"(",
"m",
"TokenizeMode",
")",
"{",
"for",
"i",
",",
"size",
":=",
"1",
",",
"len",
"(",
"la",
".",
"list",
")",
";",
"i",
"<",
"size",
";",
"i",
"++",
"{",
"currentList",
":=",
"la",
".",
"list",
"[",
"i",
"]",
"\n",
"for",
"index",
",",
"target",
":=",
"range",
"currentList",
"{",
"prevList",
":=",
"la",
".",
"list",
"[",
"target",
".",
"Start",
"]",
"\n",
"if",
"len",
"(",
"prevList",
")",
"==",
"0",
"{",
"la",
".",
"list",
"[",
"i",
"]",
"[",
"index",
"]",
".",
"Cost",
"=",
"maximumCost",
"\n",
"continue",
"\n",
"}",
"\n",
"for",
"j",
",",
"n",
":=",
"range",
"prevList",
"{",
"var",
"c",
"int16",
"\n",
"if",
"n",
".",
"Class",
"!=",
"USER",
"&&",
"target",
".",
"Class",
"!=",
"USER",
"{",
"c",
"=",
"la",
".",
"dic",
".",
"Connection",
".",
"At",
"(",
"int",
"(",
"n",
".",
"Right",
")",
",",
"int",
"(",
"target",
".",
"Left",
")",
")",
"\n",
"}",
"\n",
"totalCost",
":=",
"int64",
"(",
"c",
")",
"+",
"int64",
"(",
"target",
".",
"Weight",
")",
"+",
"int64",
"(",
"n",
".",
"Cost",
")",
"\n",
"if",
"m",
"!=",
"Normal",
"{",
"totalCost",
"+=",
"int64",
"(",
"additionalCost",
"(",
"n",
")",
")",
"\n",
"}",
"\n",
"if",
"totalCost",
">",
"maximumCost",
"{",
"totalCost",
"=",
"maximumCost",
"\n",
"}",
"\n",
"if",
"j",
"==",
"0",
"||",
"int32",
"(",
"totalCost",
")",
"<",
"la",
".",
"list",
"[",
"i",
"]",
"[",
"index",
"]",
".",
"Cost",
"{",
"la",
".",
"list",
"[",
"i",
"]",
"[",
"index",
"]",
".",
"Cost",
"=",
"int32",
"(",
"totalCost",
")",
"\n",
"la",
".",
"list",
"[",
"i",
"]",
"[",
"index",
"]",
".",
"Prev",
"=",
"la",
".",
"list",
"[",
"target",
".",
"Start",
"]",
"[",
"j",
"]",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"\n",
"}"
] |
// Forward runs forward algorithm of the Viterbi.
|
[
"Forward",
"runs",
"forward",
"algorithm",
"of",
"the",
"Viterbi",
"."
] |
d76ce24c16d24bc8968d32681d92db4d7ff6bd2d
|
https://github.com/ikawaha/kagome/blob/d76ce24c16d24bc8968d32681d92db4d7ff6bd2d/internal/lattice/lattice.go#L219-L248
|
15,605 |
ikawaha/kagome
|
internal/lattice/lattice.go
|
Backward
|
func (la *Lattice) Backward(m TokenizeMode) {
const bufferExpandRatio = 2
size := len(la.list)
if size == 0 {
return
}
if cap(la.Output) < size {
la.Output = make([]*node, 0, size*bufferExpandRatio)
} else {
la.Output = la.Output[:0]
}
for p := la.list[size-1][0]; p != nil; p = p.Prev {
if m != Extended || p.Class != UNKNOWN {
la.Output = append(la.Output, p)
continue
}
runeLen := utf8.RuneCountInString(p.Surface)
stack := make([]*node, 0, runeLen)
i := 0
for _, r := range p.Surface {
n := nodePool.Get().(*node)
n.ID = p.ID
n.Start = p.Start + i
n.Class = DUMMY
n.Surface = string(r)
stack = append(stack, n)
i++
}
for j, end := 0, len(stack); j < end; j++ {
la.Output = append(la.Output, stack[runeLen-1-j])
}
}
}
|
go
|
func (la *Lattice) Backward(m TokenizeMode) {
const bufferExpandRatio = 2
size := len(la.list)
if size == 0 {
return
}
if cap(la.Output) < size {
la.Output = make([]*node, 0, size*bufferExpandRatio)
} else {
la.Output = la.Output[:0]
}
for p := la.list[size-1][0]; p != nil; p = p.Prev {
if m != Extended || p.Class != UNKNOWN {
la.Output = append(la.Output, p)
continue
}
runeLen := utf8.RuneCountInString(p.Surface)
stack := make([]*node, 0, runeLen)
i := 0
for _, r := range p.Surface {
n := nodePool.Get().(*node)
n.ID = p.ID
n.Start = p.Start + i
n.Class = DUMMY
n.Surface = string(r)
stack = append(stack, n)
i++
}
for j, end := 0, len(stack); j < end; j++ {
la.Output = append(la.Output, stack[runeLen-1-j])
}
}
}
|
[
"func",
"(",
"la",
"*",
"Lattice",
")",
"Backward",
"(",
"m",
"TokenizeMode",
")",
"{",
"const",
"bufferExpandRatio",
"=",
"2",
"\n",
"size",
":=",
"len",
"(",
"la",
".",
"list",
")",
"\n",
"if",
"size",
"==",
"0",
"{",
"return",
"\n",
"}",
"\n",
"if",
"cap",
"(",
"la",
".",
"Output",
")",
"<",
"size",
"{",
"la",
".",
"Output",
"=",
"make",
"(",
"[",
"]",
"*",
"node",
",",
"0",
",",
"size",
"*",
"bufferExpandRatio",
")",
"\n",
"}",
"else",
"{",
"la",
".",
"Output",
"=",
"la",
".",
"Output",
"[",
":",
"0",
"]",
"\n",
"}",
"\n",
"for",
"p",
":=",
"la",
".",
"list",
"[",
"size",
"-",
"1",
"]",
"[",
"0",
"]",
";",
"p",
"!=",
"nil",
";",
"p",
"=",
"p",
".",
"Prev",
"{",
"if",
"m",
"!=",
"Extended",
"||",
"p",
".",
"Class",
"!=",
"UNKNOWN",
"{",
"la",
".",
"Output",
"=",
"append",
"(",
"la",
".",
"Output",
",",
"p",
")",
"\n",
"continue",
"\n",
"}",
"\n",
"runeLen",
":=",
"utf8",
".",
"RuneCountInString",
"(",
"p",
".",
"Surface",
")",
"\n",
"stack",
":=",
"make",
"(",
"[",
"]",
"*",
"node",
",",
"0",
",",
"runeLen",
")",
"\n",
"i",
":=",
"0",
"\n",
"for",
"_",
",",
"r",
":=",
"range",
"p",
".",
"Surface",
"{",
"n",
":=",
"nodePool",
".",
"Get",
"(",
")",
".",
"(",
"*",
"node",
")",
"\n",
"n",
".",
"ID",
"=",
"p",
".",
"ID",
"\n",
"n",
".",
"Start",
"=",
"p",
".",
"Start",
"+",
"i",
"\n",
"n",
".",
"Class",
"=",
"DUMMY",
"\n",
"n",
".",
"Surface",
"=",
"string",
"(",
"r",
")",
"\n",
"stack",
"=",
"append",
"(",
"stack",
",",
"n",
")",
"\n",
"i",
"++",
"\n",
"}",
"\n",
"for",
"j",
",",
"end",
":=",
"0",
",",
"len",
"(",
"stack",
")",
";",
"j",
"<",
"end",
";",
"j",
"++",
"{",
"la",
".",
"Output",
"=",
"append",
"(",
"la",
".",
"Output",
",",
"stack",
"[",
"runeLen",
"-",
"1",
"-",
"j",
"]",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}"
] |
// Backward runs backward algorithm of the Viterbi.
|
[
"Backward",
"runs",
"backward",
"algorithm",
"of",
"the",
"Viterbi",
"."
] |
d76ce24c16d24bc8968d32681d92db4d7ff6bd2d
|
https://github.com/ikawaha/kagome/blob/d76ce24c16d24bc8968d32681d92db4d7ff6bd2d/internal/lattice/lattice.go#L251-L283
|
15,606 |
ikawaha/kagome
|
internal/lattice/lattice.go
|
Dot
|
func (la *Lattice) Dot(w io.Writer) {
bests := make(map[*node]struct{})
for _, n := range la.Output {
bests[n] = struct{}{}
}
type edge struct {
from *node
to *node
}
edges := make([]edge, 0, 1024)
for i, size := 1, len(la.list); i < size; i++ {
currents := la.list[i]
for _, to := range currents {
if to.Class == UNKNOWN {
if _, ok := bests[to]; !ok {
continue
}
}
prevs := la.list[to.Start]
if len(prevs) == 0 {
continue
}
for _, from := range prevs {
if from.Class == UNKNOWN {
if _, ok := bests[from]; !ok {
continue
}
}
edges = append(edges, edge{from, to})
}
}
}
fmt.Fprintln(w, "graph lattice {")
fmt.Fprintln(w, "dpi=48;")
fmt.Fprintln(w, "graph [style=filled, splines=true, overlap=false, fontsize=30, rankdir=LR]")
fmt.Fprintln(w, "edge [fontname=Helvetica, fontcolor=red, color=\"#606060\"]")
fmt.Fprintln(w, "node [shape=box, style=filled, fillcolor=\"#e8e8f0\", fontname=Helvetica]")
for i, list := range la.list {
for _, n := range list {
if n.Class == UNKNOWN {
if _, ok := bests[n]; !ok {
continue
}
}
surf := n.Surface
if n.ID == BosEosID {
if i == 0 {
surf = "BOS"
} else {
surf = "EOS"
}
}
features := features(la.dic, la.udic, n)
pos := "---"
if len(features) > 1 {
pos = features[0]
}
if _, ok := bests[n]; ok {
fmt.Fprintf(w, "\t\"%p\" [label=\"%s\\n%s\\n%d\",shape=ellipse, peripheries=2];\n", n, surf, pos, n.Weight)
} else if n.Class != UNKNOWN {
fmt.Fprintf(w, "\t\"%p\" [label=\"%s\\n%s\\n%d\"];\n", n, surf, pos, n.Weight)
}
}
}
for _, e := range edges {
var c int16
if e.from.Class != USER && e.to.Class != USER {
c = la.dic.Connection.At(int(e.from.Right), int(e.to.Left))
}
_, l := bests[e.from]
_, r := bests[e.to]
if l && r {
fmt.Fprintf(w, "\t\"%p\" -- \"%p\" [label=\"%d\", style=bold, color=blue, fontcolor=blue];\n",
e.from, e.to, c)
} else {
fmt.Fprintf(w, "\t\"%p\" -- \"%p\" [label=\"%d\"];\n",
e.from, e.to, c)
}
}
fmt.Fprintln(w, "}")
}
|
go
|
func (la *Lattice) Dot(w io.Writer) {
bests := make(map[*node]struct{})
for _, n := range la.Output {
bests[n] = struct{}{}
}
type edge struct {
from *node
to *node
}
edges := make([]edge, 0, 1024)
for i, size := 1, len(la.list); i < size; i++ {
currents := la.list[i]
for _, to := range currents {
if to.Class == UNKNOWN {
if _, ok := bests[to]; !ok {
continue
}
}
prevs := la.list[to.Start]
if len(prevs) == 0 {
continue
}
for _, from := range prevs {
if from.Class == UNKNOWN {
if _, ok := bests[from]; !ok {
continue
}
}
edges = append(edges, edge{from, to})
}
}
}
fmt.Fprintln(w, "graph lattice {")
fmt.Fprintln(w, "dpi=48;")
fmt.Fprintln(w, "graph [style=filled, splines=true, overlap=false, fontsize=30, rankdir=LR]")
fmt.Fprintln(w, "edge [fontname=Helvetica, fontcolor=red, color=\"#606060\"]")
fmt.Fprintln(w, "node [shape=box, style=filled, fillcolor=\"#e8e8f0\", fontname=Helvetica]")
for i, list := range la.list {
for _, n := range list {
if n.Class == UNKNOWN {
if _, ok := bests[n]; !ok {
continue
}
}
surf := n.Surface
if n.ID == BosEosID {
if i == 0 {
surf = "BOS"
} else {
surf = "EOS"
}
}
features := features(la.dic, la.udic, n)
pos := "---"
if len(features) > 1 {
pos = features[0]
}
if _, ok := bests[n]; ok {
fmt.Fprintf(w, "\t\"%p\" [label=\"%s\\n%s\\n%d\",shape=ellipse, peripheries=2];\n", n, surf, pos, n.Weight)
} else if n.Class != UNKNOWN {
fmt.Fprintf(w, "\t\"%p\" [label=\"%s\\n%s\\n%d\"];\n", n, surf, pos, n.Weight)
}
}
}
for _, e := range edges {
var c int16
if e.from.Class != USER && e.to.Class != USER {
c = la.dic.Connection.At(int(e.from.Right), int(e.to.Left))
}
_, l := bests[e.from]
_, r := bests[e.to]
if l && r {
fmt.Fprintf(w, "\t\"%p\" -- \"%p\" [label=\"%d\", style=bold, color=blue, fontcolor=blue];\n",
e.from, e.to, c)
} else {
fmt.Fprintf(w, "\t\"%p\" -- \"%p\" [label=\"%d\"];\n",
e.from, e.to, c)
}
}
fmt.Fprintln(w, "}")
}
|
[
"func",
"(",
"la",
"*",
"Lattice",
")",
"Dot",
"(",
"w",
"io",
".",
"Writer",
")",
"{",
"bests",
":=",
"make",
"(",
"map",
"[",
"*",
"node",
"]",
"struct",
"{",
"}",
")",
"\n",
"for",
"_",
",",
"n",
":=",
"range",
"la",
".",
"Output",
"{",
"bests",
"[",
"n",
"]",
"=",
"struct",
"{",
"}",
"{",
"}",
"\n",
"}",
"\n",
"type",
"edge",
"struct",
"{",
"from",
"*",
"node",
"\n",
"to",
"*",
"node",
"\n",
"}",
"\n",
"edges",
":=",
"make",
"(",
"[",
"]",
"edge",
",",
"0",
",",
"1024",
")",
"\n",
"for",
"i",
",",
"size",
":=",
"1",
",",
"len",
"(",
"la",
".",
"list",
")",
";",
"i",
"<",
"size",
";",
"i",
"++",
"{",
"currents",
":=",
"la",
".",
"list",
"[",
"i",
"]",
"\n",
"for",
"_",
",",
"to",
":=",
"range",
"currents",
"{",
"if",
"to",
".",
"Class",
"==",
"UNKNOWN",
"{",
"if",
"_",
",",
"ok",
":=",
"bests",
"[",
"to",
"]",
";",
"!",
"ok",
"{",
"continue",
"\n",
"}",
"\n",
"}",
"\n",
"prevs",
":=",
"la",
".",
"list",
"[",
"to",
".",
"Start",
"]",
"\n",
"if",
"len",
"(",
"prevs",
")",
"==",
"0",
"{",
"continue",
"\n",
"}",
"\n",
"for",
"_",
",",
"from",
":=",
"range",
"prevs",
"{",
"if",
"from",
".",
"Class",
"==",
"UNKNOWN",
"{",
"if",
"_",
",",
"ok",
":=",
"bests",
"[",
"from",
"]",
";",
"!",
"ok",
"{",
"continue",
"\n",
"}",
"\n",
"}",
"\n",
"edges",
"=",
"append",
"(",
"edges",
",",
"edge",
"{",
"from",
",",
"to",
"}",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"fmt",
".",
"Fprintln",
"(",
"w",
",",
"\"",
"\"",
")",
"\n",
"fmt",
".",
"Fprintln",
"(",
"w",
",",
"\"",
"\"",
")",
"\n",
"fmt",
".",
"Fprintln",
"(",
"w",
",",
"\"",
"\"",
")",
"\n",
"fmt",
".",
"Fprintln",
"(",
"w",
",",
"\"",
"\\\"",
"\\\"",
"\"",
")",
"\n",
"fmt",
".",
"Fprintln",
"(",
"w",
",",
"\"",
"\\\"",
"\\\"",
"\"",
")",
"\n",
"for",
"i",
",",
"list",
":=",
"range",
"la",
".",
"list",
"{",
"for",
"_",
",",
"n",
":=",
"range",
"list",
"{",
"if",
"n",
".",
"Class",
"==",
"UNKNOWN",
"{",
"if",
"_",
",",
"ok",
":=",
"bests",
"[",
"n",
"]",
";",
"!",
"ok",
"{",
"continue",
"\n",
"}",
"\n",
"}",
"\n",
"surf",
":=",
"n",
".",
"Surface",
"\n",
"if",
"n",
".",
"ID",
"==",
"BosEosID",
"{",
"if",
"i",
"==",
"0",
"{",
"surf",
"=",
"\"",
"\"",
"\n",
"}",
"else",
"{",
"surf",
"=",
"\"",
"\"",
"\n",
"}",
"\n",
"}",
"\n",
"features",
":=",
"features",
"(",
"la",
".",
"dic",
",",
"la",
".",
"udic",
",",
"n",
")",
"\n",
"pos",
":=",
"\"",
"\"",
"\n",
"if",
"len",
"(",
"features",
")",
">",
"1",
"{",
"pos",
"=",
"features",
"[",
"0",
"]",
"\n",
"}",
"\n",
"if",
"_",
",",
"ok",
":=",
"bests",
"[",
"n",
"]",
";",
"ok",
"{",
"fmt",
".",
"Fprintf",
"(",
"w",
",",
"\"",
"\\t",
"\\\"",
"\\\"",
"\\\"",
"\\\\",
"\\\\",
"\\\"",
"\\n",
"\"",
",",
"n",
",",
"surf",
",",
"pos",
",",
"n",
".",
"Weight",
")",
"\n",
"}",
"else",
"if",
"n",
".",
"Class",
"!=",
"UNKNOWN",
"{",
"fmt",
".",
"Fprintf",
"(",
"w",
",",
"\"",
"\\t",
"\\\"",
"\\\"",
"\\\"",
"\\\\",
"\\\\",
"\\\"",
"\\n",
"\"",
",",
"n",
",",
"surf",
",",
"pos",
",",
"n",
".",
"Weight",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"for",
"_",
",",
"e",
":=",
"range",
"edges",
"{",
"var",
"c",
"int16",
"\n",
"if",
"e",
".",
"from",
".",
"Class",
"!=",
"USER",
"&&",
"e",
".",
"to",
".",
"Class",
"!=",
"USER",
"{",
"c",
"=",
"la",
".",
"dic",
".",
"Connection",
".",
"At",
"(",
"int",
"(",
"e",
".",
"from",
".",
"Right",
")",
",",
"int",
"(",
"e",
".",
"to",
".",
"Left",
")",
")",
"\n",
"}",
"\n",
"_",
",",
"l",
":=",
"bests",
"[",
"e",
".",
"from",
"]",
"\n",
"_",
",",
"r",
":=",
"bests",
"[",
"e",
".",
"to",
"]",
"\n",
"if",
"l",
"&&",
"r",
"{",
"fmt",
".",
"Fprintf",
"(",
"w",
",",
"\"",
"\\t",
"\\\"",
"\\\"",
"\\\"",
"\\\"",
"\\\"",
"\\\"",
"\\n",
"\"",
",",
"e",
".",
"from",
",",
"e",
".",
"to",
",",
"c",
")",
"\n",
"}",
"else",
"{",
"fmt",
".",
"Fprintf",
"(",
"w",
",",
"\"",
"\\t",
"\\\"",
"\\\"",
"\\\"",
"\\\"",
"\\\"",
"\\\"",
"\\n",
"\"",
",",
"e",
".",
"from",
",",
"e",
".",
"to",
",",
"c",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"fmt",
".",
"Fprintln",
"(",
"w",
",",
"\"",
"\"",
")",
"\n",
"}"
] |
// Dot outputs the lattice in the graphviz dot format.
|
[
"Dot",
"outputs",
"the",
"lattice",
"in",
"the",
"graphviz",
"dot",
"format",
"."
] |
d76ce24c16d24bc8968d32681d92db4d7ff6bd2d
|
https://github.com/ikawaha/kagome/blob/d76ce24c16d24bc8968d32681d92db4d7ff6bd2d/internal/lattice/lattice.go#L318-L399
|
15,607 |
ikawaha/kagome
|
tokenizer/token.go
|
Features
|
func (t Token) Features() []string {
switch lattice.NodeClass(t.Class) {
case lattice.DUMMY:
return nil
case lattice.KNOWN:
var c int
if t.dic.Contents != nil {
c = len(t.dic.Contents[t.ID])
}
features := make([]string, 0, len(t.dic.POSTable.POSs[t.ID])+c)
for _, id := range t.dic.POSTable.POSs[t.ID] {
features = append(features, t.dic.POSTable.NameList[id])
}
if t.dic.Contents != nil {
features = append(features, t.dic.Contents[t.ID]...)
}
return features
case lattice.UNKNOWN:
features := make([]string, len(t.dic.UnkContents[t.ID]))
for i := range t.dic.UnkContents[t.ID] {
features[i] = t.dic.UnkContents[t.ID][i]
}
return features
case lattice.USER:
pos := t.udic.Contents[t.ID].Pos
tokens := strings.Join(t.udic.Contents[t.ID].Tokens, "/")
yomi := strings.Join(t.udic.Contents[t.ID].Yomi, "/")
return []string{pos, tokens, yomi}
}
return nil
}
|
go
|
func (t Token) Features() []string {
switch lattice.NodeClass(t.Class) {
case lattice.DUMMY:
return nil
case lattice.KNOWN:
var c int
if t.dic.Contents != nil {
c = len(t.dic.Contents[t.ID])
}
features := make([]string, 0, len(t.dic.POSTable.POSs[t.ID])+c)
for _, id := range t.dic.POSTable.POSs[t.ID] {
features = append(features, t.dic.POSTable.NameList[id])
}
if t.dic.Contents != nil {
features = append(features, t.dic.Contents[t.ID]...)
}
return features
case lattice.UNKNOWN:
features := make([]string, len(t.dic.UnkContents[t.ID]))
for i := range t.dic.UnkContents[t.ID] {
features[i] = t.dic.UnkContents[t.ID][i]
}
return features
case lattice.USER:
pos := t.udic.Contents[t.ID].Pos
tokens := strings.Join(t.udic.Contents[t.ID].Tokens, "/")
yomi := strings.Join(t.udic.Contents[t.ID].Yomi, "/")
return []string{pos, tokens, yomi}
}
return nil
}
|
[
"func",
"(",
"t",
"Token",
")",
"Features",
"(",
")",
"[",
"]",
"string",
"{",
"switch",
"lattice",
".",
"NodeClass",
"(",
"t",
".",
"Class",
")",
"{",
"case",
"lattice",
".",
"DUMMY",
":",
"return",
"nil",
"\n",
"case",
"lattice",
".",
"KNOWN",
":",
"var",
"c",
"int",
"\n",
"if",
"t",
".",
"dic",
".",
"Contents",
"!=",
"nil",
"{",
"c",
"=",
"len",
"(",
"t",
".",
"dic",
".",
"Contents",
"[",
"t",
".",
"ID",
"]",
")",
"\n",
"}",
"\n",
"features",
":=",
"make",
"(",
"[",
"]",
"string",
",",
"0",
",",
"len",
"(",
"t",
".",
"dic",
".",
"POSTable",
".",
"POSs",
"[",
"t",
".",
"ID",
"]",
")",
"+",
"c",
")",
"\n",
"for",
"_",
",",
"id",
":=",
"range",
"t",
".",
"dic",
".",
"POSTable",
".",
"POSs",
"[",
"t",
".",
"ID",
"]",
"{",
"features",
"=",
"append",
"(",
"features",
",",
"t",
".",
"dic",
".",
"POSTable",
".",
"NameList",
"[",
"id",
"]",
")",
"\n",
"}",
"\n",
"if",
"t",
".",
"dic",
".",
"Contents",
"!=",
"nil",
"{",
"features",
"=",
"append",
"(",
"features",
",",
"t",
".",
"dic",
".",
"Contents",
"[",
"t",
".",
"ID",
"]",
"...",
")",
"\n",
"}",
"\n",
"return",
"features",
"\n",
"case",
"lattice",
".",
"UNKNOWN",
":",
"features",
":=",
"make",
"(",
"[",
"]",
"string",
",",
"len",
"(",
"t",
".",
"dic",
".",
"UnkContents",
"[",
"t",
".",
"ID",
"]",
")",
")",
"\n",
"for",
"i",
":=",
"range",
"t",
".",
"dic",
".",
"UnkContents",
"[",
"t",
".",
"ID",
"]",
"{",
"features",
"[",
"i",
"]",
"=",
"t",
".",
"dic",
".",
"UnkContents",
"[",
"t",
".",
"ID",
"]",
"[",
"i",
"]",
"\n",
"}",
"\n",
"return",
"features",
"\n",
"case",
"lattice",
".",
"USER",
":",
"pos",
":=",
"t",
".",
"udic",
".",
"Contents",
"[",
"t",
".",
"ID",
"]",
".",
"Pos",
"\n",
"tokens",
":=",
"strings",
".",
"Join",
"(",
"t",
".",
"udic",
".",
"Contents",
"[",
"t",
".",
"ID",
"]",
".",
"Tokens",
",",
"\"",
"\"",
")",
"\n",
"yomi",
":=",
"strings",
".",
"Join",
"(",
"t",
".",
"udic",
".",
"Contents",
"[",
"t",
".",
"ID",
"]",
".",
"Yomi",
",",
"\"",
"\"",
")",
"\n",
"return",
"[",
"]",
"string",
"{",
"pos",
",",
"tokens",
",",
"yomi",
"}",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] |
// Features returns contents of a token.
|
[
"Features",
"returns",
"contents",
"of",
"a",
"token",
"."
] |
d76ce24c16d24bc8968d32681d92db4d7ff6bd2d
|
https://github.com/ikawaha/kagome/blob/d76ce24c16d24bc8968d32681d92db4d7ff6bd2d/tokenizer/token.go#L66-L96
|
15,608 |
ikawaha/kagome
|
tokenizer/token.go
|
Pos
|
func (t Token) Pos() string {
f := t.Features()
if len(f) < 1 {
return ""
}
return f[0]
}
|
go
|
func (t Token) Pos() string {
f := t.Features()
if len(f) < 1 {
return ""
}
return f[0]
}
|
[
"func",
"(",
"t",
"Token",
")",
"Pos",
"(",
")",
"string",
"{",
"f",
":=",
"t",
".",
"Features",
"(",
")",
"\n",
"if",
"len",
"(",
"f",
")",
"<",
"1",
"{",
"return",
"\"",
"\"",
"\n",
"}",
"\n",
"return",
"f",
"[",
"0",
"]",
"\n",
"}"
] |
// Pos returns the first element of features.
|
[
"Pos",
"returns",
"the",
"first",
"element",
"of",
"features",
"."
] |
d76ce24c16d24bc8968d32681d92db4d7ff6bd2d
|
https://github.com/ikawaha/kagome/blob/d76ce24c16d24bc8968d32681d92db4d7ff6bd2d/tokenizer/token.go#L99-L105
|
15,609 |
ikawaha/kagome
|
tokenizer/token.go
|
String
|
func (t Token) String() string {
return fmt.Sprintf("%v(%v, %v)%v[%v]", t.Surface, t.Start, t.End, t.Class, t.ID)
}
|
go
|
func (t Token) String() string {
return fmt.Sprintf("%v(%v, %v)%v[%v]", t.Surface, t.Start, t.End, t.Class, t.ID)
}
|
[
"func",
"(",
"t",
"Token",
")",
"String",
"(",
")",
"string",
"{",
"return",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"t",
".",
"Surface",
",",
"t",
".",
"Start",
",",
"t",
".",
"End",
",",
"t",
".",
"Class",
",",
"t",
".",
"ID",
")",
"\n",
"}"
] |
// String returns a string representation of a token.
|
[
"String",
"returns",
"a",
"string",
"representation",
"of",
"a",
"token",
"."
] |
d76ce24c16d24bc8968d32681d92db4d7ff6bd2d
|
https://github.com/ikawaha/kagome/blob/d76ce24c16d24bc8968d32681d92db4d7ff6bd2d/tokenizer/token.go#L108-L110
|
15,610 |
ikawaha/kagome
|
tokenizer/dic.go
|
NewDic
|
func NewDic(path string) (Dic, error) {
d, err := dic.Load(path)
return Dic{d}, err
}
|
go
|
func NewDic(path string) (Dic, error) {
d, err := dic.Load(path)
return Dic{d}, err
}
|
[
"func",
"NewDic",
"(",
"path",
"string",
")",
"(",
"Dic",
",",
"error",
")",
"{",
"d",
",",
"err",
":=",
"dic",
".",
"Load",
"(",
"path",
")",
"\n",
"return",
"Dic",
"{",
"d",
"}",
",",
"err",
"\n",
"}"
] |
// NewDic loads a dictionary from a file.
|
[
"NewDic",
"loads",
"a",
"dictionary",
"from",
"a",
"file",
"."
] |
d76ce24c16d24bc8968d32681d92db4d7ff6bd2d
|
https://github.com/ikawaha/kagome/blob/d76ce24c16d24bc8968d32681d92db4d7ff6bd2d/tokenizer/dic.go#L55-L58
|
15,611 |
ikawaha/kagome
|
internal/dic/unkdic.go
|
ReadUnkDic
|
func ReadUnkDic(r io.Reader) (UnkDic, error) {
d := UnkDic{}
ui, err := readMap(r)
if err != nil {
return d, fmt.Errorf("UnkIndex: %v", err)
}
d.UnkIndex = ui
ud, err := readMap(r)
if err != nil {
return d, fmt.Errorf("UnkIndexDup: %v", err)
}
d.UnkIndexDup = ud
dec := gob.NewDecoder(r)
if err := dec.Decode(&d.UnkMorphs); err != nil {
return d, fmt.Errorf("UnkMorphs: %v", err)
}
if err := dec.Decode(&d.UnkContents); err != nil {
return d, fmt.Errorf("UnkContents: %v", err)
}
return d, nil
}
|
go
|
func ReadUnkDic(r io.Reader) (UnkDic, error) {
d := UnkDic{}
ui, err := readMap(r)
if err != nil {
return d, fmt.Errorf("UnkIndex: %v", err)
}
d.UnkIndex = ui
ud, err := readMap(r)
if err != nil {
return d, fmt.Errorf("UnkIndexDup: %v", err)
}
d.UnkIndexDup = ud
dec := gob.NewDecoder(r)
if err := dec.Decode(&d.UnkMorphs); err != nil {
return d, fmt.Errorf("UnkMorphs: %v", err)
}
if err := dec.Decode(&d.UnkContents); err != nil {
return d, fmt.Errorf("UnkContents: %v", err)
}
return d, nil
}
|
[
"func",
"ReadUnkDic",
"(",
"r",
"io",
".",
"Reader",
")",
"(",
"UnkDic",
",",
"error",
")",
"{",
"d",
":=",
"UnkDic",
"{",
"}",
"\n",
"ui",
",",
"err",
":=",
"readMap",
"(",
"r",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"d",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n",
"d",
".",
"UnkIndex",
"=",
"ui",
"\n",
"ud",
",",
"err",
":=",
"readMap",
"(",
"r",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"d",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n",
"d",
".",
"UnkIndexDup",
"=",
"ud",
"\n\n",
"dec",
":=",
"gob",
".",
"NewDecoder",
"(",
"r",
")",
"\n",
"if",
"err",
":=",
"dec",
".",
"Decode",
"(",
"&",
"d",
".",
"UnkMorphs",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"d",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n",
"if",
"err",
":=",
"dec",
".",
"Decode",
"(",
"&",
"d",
".",
"UnkContents",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"d",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n",
"return",
"d",
",",
"nil",
"\n",
"}"
] |
// ReadUnkDic loads an unknown word dictionary.
|
[
"ReadUnkDic",
"loads",
"an",
"unknown",
"word",
"dictionary",
"."
] |
d76ce24c16d24bc8968d32681d92db4d7ff6bd2d
|
https://github.com/ikawaha/kagome/blob/d76ce24c16d24bc8968d32681d92db4d7ff6bd2d/internal/dic/unkdic.go#L117-L138
|
15,612 |
wellington/go-libsass
|
options.go
|
Option
|
func (c *sass) Option(opts ...option) error {
for _, opt := range opts {
err := opt(c)
if err != nil {
return err
}
}
return nil
}
|
go
|
func (c *sass) Option(opts ...option) error {
for _, opt := range opts {
err := opt(c)
if err != nil {
return err
}
}
return nil
}
|
[
"func",
"(",
"c",
"*",
"sass",
")",
"Option",
"(",
"opts",
"...",
"option",
")",
"error",
"{",
"for",
"_",
",",
"opt",
":=",
"range",
"opts",
"{",
"err",
":=",
"opt",
"(",
"c",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] |
// Option allows the modifying of internal compiler state
|
[
"Option",
"allows",
"the",
"modifying",
"of",
"internal",
"compiler",
"state"
] |
f870eaa15594bb64b1908df39d0812704f0ceb8f
|
https://github.com/wellington/go-libsass/blob/f870eaa15594bb64b1908df39d0812704f0ceb8f/options.go#L8-L16
|
15,613 |
wellington/go-libsass
|
options.go
|
BasePath
|
func BasePath(basePath string) option {
return func(c *sass) error {
c.httpPath = basePath
// FIXME: remove from context
c.ctx.HTTPPath = basePath
return nil
}
}
|
go
|
func BasePath(basePath string) option {
return func(c *sass) error {
c.httpPath = basePath
// FIXME: remove from context
c.ctx.HTTPPath = basePath
return nil
}
}
|
[
"func",
"BasePath",
"(",
"basePath",
"string",
")",
"option",
"{",
"return",
"func",
"(",
"c",
"*",
"sass",
")",
"error",
"{",
"c",
".",
"httpPath",
"=",
"basePath",
"\n",
"// FIXME: remove from context",
"c",
".",
"ctx",
".",
"HTTPPath",
"=",
"basePath",
"\n",
"return",
"nil",
"\n",
"}",
"\n",
"}"
] |
// BasePath sets the internal path provided to handlers requiring
// a base path for http calls. This is useful for hosted solutions
// that need to provided absolute paths to assets.
|
[
"BasePath",
"sets",
"the",
"internal",
"path",
"provided",
"to",
"handlers",
"requiring",
"a",
"base",
"path",
"for",
"http",
"calls",
".",
"This",
"is",
"useful",
"for",
"hosted",
"solutions",
"that",
"need",
"to",
"provided",
"absolute",
"paths",
"to",
"assets",
"."
] |
f870eaa15594bb64b1908df39d0812704f0ceb8f
|
https://github.com/wellington/go-libsass/blob/f870eaa15594bb64b1908df39d0812704f0ceb8f/options.go#L21-L28
|
15,614 |
wellington/go-libsass
|
options.go
|
BuildDir
|
func BuildDir(path string) option {
return func(c *sass) error {
c.ctx.BuildDir = path
return nil
}
}
|
go
|
func BuildDir(path string) option {
return func(c *sass) error {
c.ctx.BuildDir = path
return nil
}
}
|
[
"func",
"BuildDir",
"(",
"path",
"string",
")",
"option",
"{",
"return",
"func",
"(",
"c",
"*",
"sass",
")",
"error",
"{",
"c",
".",
"ctx",
".",
"BuildDir",
"=",
"path",
"\n",
"return",
"nil",
"\n",
"}",
"\n",
"}"
] |
// BuildDir only used for spriting, how terrible!
|
[
"BuildDir",
"only",
"used",
"for",
"spriting",
"how",
"terrible!"
] |
f870eaa15594bb64b1908df39d0812704f0ceb8f
|
https://github.com/wellington/go-libsass/blob/f870eaa15594bb64b1908df39d0812704f0ceb8f/options.go#L31-L36
|
15,615 |
wellington/go-libsass
|
options.go
|
CacheBust
|
func CacheBust(t string) option {
return func(c *sass) error {
if t == "ts" {
t = "timestamp"
}
c.cachebust = t
return nil
}
}
|
go
|
func CacheBust(t string) option {
return func(c *sass) error {
if t == "ts" {
t = "timestamp"
}
c.cachebust = t
return nil
}
}
|
[
"func",
"CacheBust",
"(",
"t",
"string",
")",
"option",
"{",
"return",
"func",
"(",
"c",
"*",
"sass",
")",
"error",
"{",
"if",
"t",
"==",
"\"",
"\"",
"{",
"t",
"=",
"\"",
"\"",
"\n",
"}",
"\n",
"c",
".",
"cachebust",
"=",
"t",
"\n",
"return",
"nil",
"\n",
"}",
"\n",
"}"
] |
// CacheBust append timestamps to static assets to prevent caching
|
[
"CacheBust",
"append",
"timestamps",
"to",
"static",
"assets",
"to",
"prevent",
"caching"
] |
f870eaa15594bb64b1908df39d0812704f0ceb8f
|
https://github.com/wellington/go-libsass/blob/f870eaa15594bb64b1908df39d0812704f0ceb8f/options.go#L39-L47
|
15,616 |
wellington/go-libsass
|
options.go
|
Comments
|
func Comments(b bool) option {
return func(c *sass) error {
c.ctx.Comments = b
return nil
}
}
|
go
|
func Comments(b bool) option {
return func(c *sass) error {
c.ctx.Comments = b
return nil
}
}
|
[
"func",
"Comments",
"(",
"b",
"bool",
")",
"option",
"{",
"return",
"func",
"(",
"c",
"*",
"sass",
")",
"error",
"{",
"c",
".",
"ctx",
".",
"Comments",
"=",
"b",
"\n",
"return",
"nil",
"\n",
"}",
"\n",
"}"
] |
// Comments toggles whether comments should be included in the output
|
[
"Comments",
"toggles",
"whether",
"comments",
"should",
"be",
"included",
"in",
"the",
"output"
] |
f870eaa15594bb64b1908df39d0812704f0ceb8f
|
https://github.com/wellington/go-libsass/blob/f870eaa15594bb64b1908df39d0812704f0ceb8f/options.go#L50-L55
|
15,617 |
wellington/go-libsass
|
options.go
|
HTTPPath
|
func HTTPPath(u string) option {
return func(c *sass) error {
c.httpPath = u
c.ctx.HTTPPath = u
return nil
}
}
|
go
|
func HTTPPath(u string) option {
return func(c *sass) error {
c.httpPath = u
c.ctx.HTTPPath = u
return nil
}
}
|
[
"func",
"HTTPPath",
"(",
"u",
"string",
")",
"option",
"{",
"return",
"func",
"(",
"c",
"*",
"sass",
")",
"error",
"{",
"c",
".",
"httpPath",
"=",
"u",
"\n",
"c",
".",
"ctx",
".",
"HTTPPath",
"=",
"u",
"\n",
"return",
"nil",
"\n",
"}",
"\n",
"}"
] |
// HTTPPath prefixes all sprites and generated images with this uri.
// Enabling wellington to serve images when used in HTTP mode
|
[
"HTTPPath",
"prefixes",
"all",
"sprites",
"and",
"generated",
"images",
"with",
"this",
"uri",
".",
"Enabling",
"wellington",
"to",
"serve",
"images",
"when",
"used",
"in",
"HTTP",
"mode"
] |
f870eaa15594bb64b1908df39d0812704f0ceb8f
|
https://github.com/wellington/go-libsass/blob/f870eaa15594bb64b1908df39d0812704f0ceb8f/options.go#L67-L73
|
15,618 |
wellington/go-libsass
|
options.go
|
ImgBuildDir
|
func ImgBuildDir(path string) option {
return func(c *sass) error {
c.ctx.GenImgDir = path
return nil
}
}
|
go
|
func ImgBuildDir(path string) option {
return func(c *sass) error {
c.ctx.GenImgDir = path
return nil
}
}
|
[
"func",
"ImgBuildDir",
"(",
"path",
"string",
")",
"option",
"{",
"return",
"func",
"(",
"c",
"*",
"sass",
")",
"error",
"{",
"c",
".",
"ctx",
".",
"GenImgDir",
"=",
"path",
"\n",
"return",
"nil",
"\n",
"}",
"\n",
"}"
] |
// ImgBuildDir specifies the destination directory for images
|
[
"ImgBuildDir",
"specifies",
"the",
"destination",
"directory",
"for",
"images"
] |
f870eaa15594bb64b1908df39d0812704f0ceb8f
|
https://github.com/wellington/go-libsass/blob/f870eaa15594bb64b1908df39d0812704f0ceb8f/options.go#L76-L81
|
15,619 |
wellington/go-libsass
|
options.go
|
ImgDir
|
func ImgDir(path string) option {
return func(c *sass) error {
c.ctx.ImageDir = path
return nil
}
}
|
go
|
func ImgDir(path string) option {
return func(c *sass) error {
c.ctx.ImageDir = path
return nil
}
}
|
[
"func",
"ImgDir",
"(",
"path",
"string",
")",
"option",
"{",
"return",
"func",
"(",
"c",
"*",
"sass",
")",
"error",
"{",
"c",
".",
"ctx",
".",
"ImageDir",
"=",
"path",
"\n",
"return",
"nil",
"\n",
"}",
"\n",
"}"
] |
// ImgDir specifies where to locate images for spriting
|
[
"ImgDir",
"specifies",
"where",
"to",
"locate",
"images",
"for",
"spriting"
] |
f870eaa15594bb64b1908df39d0812704f0ceb8f
|
https://github.com/wellington/go-libsass/blob/f870eaa15594bb64b1908df39d0812704f0ceb8f/options.go#L84-L89
|
15,620 |
wellington/go-libsass
|
options.go
|
ImportsOption
|
func ImportsOption(imports *Imports) option {
return func(c *sass) error {
c.ctx.Imports = imports
return nil
}
}
|
go
|
func ImportsOption(imports *Imports) option {
return func(c *sass) error {
c.ctx.Imports = imports
return nil
}
}
|
[
"func",
"ImportsOption",
"(",
"imports",
"*",
"Imports",
")",
"option",
"{",
"return",
"func",
"(",
"c",
"*",
"sass",
")",
"error",
"{",
"c",
".",
"ctx",
".",
"Imports",
"=",
"imports",
"\n",
"return",
"nil",
"\n",
"}",
"\n",
"}"
] |
// ImportsOption specifies configuration for import resolution
|
[
"ImportsOption",
"specifies",
"configuration",
"for",
"import",
"resolution"
] |
f870eaa15594bb64b1908df39d0812704f0ceb8f
|
https://github.com/wellington/go-libsass/blob/f870eaa15594bb64b1908df39d0812704f0ceb8f/options.go#L92-L97
|
15,621 |
wellington/go-libsass
|
options.go
|
IncludePaths
|
func IncludePaths(includes []string) option {
return func(c *sass) error {
c.includePaths = includes
c.ctx.IncludePaths = includes
return nil
}
}
|
go
|
func IncludePaths(includes []string) option {
return func(c *sass) error {
c.includePaths = includes
c.ctx.IncludePaths = includes
return nil
}
}
|
[
"func",
"IncludePaths",
"(",
"includes",
"[",
"]",
"string",
")",
"option",
"{",
"return",
"func",
"(",
"c",
"*",
"sass",
")",
"error",
"{",
"c",
".",
"includePaths",
"=",
"includes",
"\n",
"c",
".",
"ctx",
".",
"IncludePaths",
"=",
"includes",
"\n",
"return",
"nil",
"\n",
"}",
"\n",
"}"
] |
// IncludePaths adds additional directories to search for Sass files
|
[
"IncludePaths",
"adds",
"additional",
"directories",
"to",
"search",
"for",
"Sass",
"files"
] |
f870eaa15594bb64b1908df39d0812704f0ceb8f
|
https://github.com/wellington/go-libsass/blob/f870eaa15594bb64b1908df39d0812704f0ceb8f/options.go#L100-L106
|
15,622 |
wellington/go-libsass
|
options.go
|
LineComments
|
func LineComments(b bool) option {
return func(c *sass) error {
c.cmt = b
return nil
}
}
|
go
|
func LineComments(b bool) option {
return func(c *sass) error {
c.cmt = b
return nil
}
}
|
[
"func",
"LineComments",
"(",
"b",
"bool",
")",
"option",
"{",
"return",
"func",
"(",
"c",
"*",
"sass",
")",
"error",
"{",
"c",
".",
"cmt",
"=",
"b",
"\n",
"return",
"nil",
"\n",
"}",
"\n",
"}"
] |
// LineComments removes the line by line playby of the Sass compiler
|
[
"LineComments",
"removes",
"the",
"line",
"by",
"line",
"playby",
"of",
"the",
"Sass",
"compiler"
] |
f870eaa15594bb64b1908df39d0812704f0ceb8f
|
https://github.com/wellington/go-libsass/blob/f870eaa15594bb64b1908df39d0812704f0ceb8f/options.go#L109-L114
|
15,623 |
wellington/go-libsass
|
options.go
|
Precision
|
func Precision(prec int) option {
return func(c *sass) error {
c.ctx.Precision = prec
return nil
}
}
|
go
|
func Precision(prec int) option {
return func(c *sass) error {
c.ctx.Precision = prec
return nil
}
}
|
[
"func",
"Precision",
"(",
"prec",
"int",
")",
"option",
"{",
"return",
"func",
"(",
"c",
"*",
"sass",
")",
"error",
"{",
"c",
".",
"ctx",
".",
"Precision",
"=",
"prec",
"\n",
"return",
"nil",
"\n",
"}",
"\n",
"}"
] |
// Precision specifies the number of points beyond the decimal
// place is preserved during math calculations.
|
[
"Precision",
"specifies",
"the",
"number",
"of",
"points",
"beyond",
"the",
"decimal",
"place",
"is",
"preserved",
"during",
"math",
"calculations",
"."
] |
f870eaa15594bb64b1908df39d0812704f0ceb8f
|
https://github.com/wellington/go-libsass/blob/f870eaa15594bb64b1908df39d0812704f0ceb8f/options.go#L127-L132
|
15,624 |
wellington/go-libsass
|
options.go
|
SourceMap
|
func SourceMap(b bool, path, sourceMapRoot string) option {
return func(c *sass) error {
c.ctx.includeMap = b
c.mappath = path
if len(sourceMapRoot) > 0 {
c.sourceMapRoot = sourceMapRoot
}
return nil
}
}
|
go
|
func SourceMap(b bool, path, sourceMapRoot string) option {
return func(c *sass) error {
c.ctx.includeMap = b
c.mappath = path
if len(sourceMapRoot) > 0 {
c.sourceMapRoot = sourceMapRoot
}
return nil
}
}
|
[
"func",
"SourceMap",
"(",
"b",
"bool",
",",
"path",
",",
"sourceMapRoot",
"string",
")",
"option",
"{",
"return",
"func",
"(",
"c",
"*",
"sass",
")",
"error",
"{",
"c",
".",
"ctx",
".",
"includeMap",
"=",
"b",
"\n",
"c",
".",
"mappath",
"=",
"path",
"\n",
"if",
"len",
"(",
"sourceMapRoot",
")",
">",
"0",
"{",
"c",
".",
"sourceMapRoot",
"=",
"sourceMapRoot",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}",
"\n",
"}"
] |
// SourceMap behaves differently depending on compiler used. For
// compile, it will embed sourcemap into the source. For file
// compile, it will include a separate file with the source map.
|
[
"SourceMap",
"behaves",
"differently",
"depending",
"on",
"compiler",
"used",
".",
"For",
"compile",
"it",
"will",
"embed",
"sourcemap",
"into",
"the",
"source",
".",
"For",
"file",
"compile",
"it",
"will",
"include",
"a",
"separate",
"file",
"with",
"the",
"source",
"map",
"."
] |
f870eaa15594bb64b1908df39d0812704f0ceb8f
|
https://github.com/wellington/go-libsass/blob/f870eaa15594bb64b1908df39d0812704f0ceb8f/options.go#L137-L146
|
15,625 |
wellington/go-libsass
|
options.go
|
Path
|
func Path(path string) option {
return func(c *sass) error {
c.srcFile = path
c.ctx.MainFile = path
return nil
}
}
|
go
|
func Path(path string) option {
return func(c *sass) error {
c.srcFile = path
c.ctx.MainFile = path
return nil
}
}
|
[
"func",
"Path",
"(",
"path",
"string",
")",
"option",
"{",
"return",
"func",
"(",
"c",
"*",
"sass",
")",
"error",
"{",
"c",
".",
"srcFile",
"=",
"path",
"\n",
"c",
".",
"ctx",
".",
"MainFile",
"=",
"path",
"\n",
"return",
"nil",
"\n",
"}",
"\n",
"}"
] |
// Path specifies a file to read instead of using the provided
// io.Reader. This activates file compiling that includes line numbers
// in the resulting output.
|
[
"Path",
"specifies",
"a",
"file",
"to",
"read",
"instead",
"of",
"using",
"the",
"provided",
"io",
".",
"Reader",
".",
"This",
"activates",
"file",
"compiling",
"that",
"includes",
"line",
"numbers",
"in",
"the",
"resulting",
"output",
"."
] |
f870eaa15594bb64b1908df39d0812704f0ceb8f
|
https://github.com/wellington/go-libsass/blob/f870eaa15594bb64b1908df39d0812704f0ceb8f/options.go#L151-L157
|
15,626 |
wellington/go-libsass
|
options.go
|
Payload
|
func Payload(load context.Context) option {
return func(c *sass) error {
c.ctx.Payload = load
return nil
}
}
|
go
|
func Payload(load context.Context) option {
return func(c *sass) error {
c.ctx.Payload = load
return nil
}
}
|
[
"func",
"Payload",
"(",
"load",
"context",
".",
"Context",
")",
"option",
"{",
"return",
"func",
"(",
"c",
"*",
"sass",
")",
"error",
"{",
"c",
".",
"ctx",
".",
"Payload",
"=",
"load",
"\n",
"return",
"nil",
"\n",
"}",
"\n",
"}"
] |
// Payload gives access to sprite and image information for handlers
// to perform spriting functions.
|
[
"Payload",
"gives",
"access",
"to",
"sprite",
"and",
"image",
"information",
"for",
"handlers",
"to",
"perform",
"spriting",
"functions",
"."
] |
f870eaa15594bb64b1908df39d0812704f0ceb8f
|
https://github.com/wellington/go-libsass/blob/f870eaa15594bb64b1908df39d0812704f0ceb8f/options.go#L161-L166
|
15,627 |
wellington/go-libsass
|
libs/safemap.go
|
Set
|
func (s *SafeMap) Set(ie interface{}) int {
idx := s.nextidx()
s.Lock()
s.m[idx] = ie
defer s.Unlock()
return idx
}
|
go
|
func (s *SafeMap) Set(ie interface{}) int {
idx := s.nextidx()
s.Lock()
s.m[idx] = ie
defer s.Unlock()
return idx
}
|
[
"func",
"(",
"s",
"*",
"SafeMap",
")",
"Set",
"(",
"ie",
"interface",
"{",
"}",
")",
"int",
"{",
"idx",
":=",
"s",
".",
"nextidx",
"(",
")",
"\n",
"s",
".",
"Lock",
"(",
")",
"\n",
"s",
".",
"m",
"[",
"idx",
"]",
"=",
"ie",
"\n",
"defer",
"s",
".",
"Unlock",
"(",
")",
"\n\n",
"return",
"idx",
"\n",
"}"
] |
// set accepts an entry and returns an index for it
|
[
"set",
"accepts",
"an",
"entry",
"and",
"returns",
"an",
"index",
"for",
"it"
] |
f870eaa15594bb64b1908df39d0812704f0ceb8f
|
https://github.com/wellington/go-libsass/blob/f870eaa15594bb64b1908df39d0812704f0ceb8f/libs/safemap.go#L37-L44
|
15,628 |
wellington/go-libsass
|
importer.go
|
Add
|
func (p *Imports) Add(prev string, path string, bs []byte) error {
p.Lock()
defer p.Unlock()
// TODO: align these with libsass name "stdin"
if len(prev) == 0 || prev == "string" {
prev = "stdin"
}
im := Import{
bytes: bs,
mod: time.Now(),
Prev: prev,
Path: path,
}
p.m[prev+":"+path] = im
return nil
}
|
go
|
func (p *Imports) Add(prev string, path string, bs []byte) error {
p.Lock()
defer p.Unlock()
// TODO: align these with libsass name "stdin"
if len(prev) == 0 || prev == "string" {
prev = "stdin"
}
im := Import{
bytes: bs,
mod: time.Now(),
Prev: prev,
Path: path,
}
p.m[prev+":"+path] = im
return nil
}
|
[
"func",
"(",
"p",
"*",
"Imports",
")",
"Add",
"(",
"prev",
"string",
",",
"path",
"string",
",",
"bs",
"[",
"]",
"byte",
")",
"error",
"{",
"p",
".",
"Lock",
"(",
")",
"\n",
"defer",
"p",
".",
"Unlock",
"(",
")",
"\n\n",
"// TODO: align these with libsass name \"stdin\"",
"if",
"len",
"(",
"prev",
")",
"==",
"0",
"||",
"prev",
"==",
"\"",
"\"",
"{",
"prev",
"=",
"\"",
"\"",
"\n",
"}",
"\n",
"im",
":=",
"Import",
"{",
"bytes",
":",
"bs",
",",
"mod",
":",
"time",
".",
"Now",
"(",
")",
",",
"Prev",
":",
"prev",
",",
"Path",
":",
"path",
",",
"}",
"\n\n",
"p",
".",
"m",
"[",
"prev",
"+",
"\"",
"\"",
"+",
"path",
"]",
"=",
"im",
"\n",
"return",
"nil",
"\n",
"}"
] |
// Add registers an import in the context.Imports
|
[
"Add",
"registers",
"an",
"import",
"in",
"the",
"context",
".",
"Imports"
] |
f870eaa15594bb64b1908df39d0812704f0ceb8f
|
https://github.com/wellington/go-libsass/blob/f870eaa15594bb64b1908df39d0812704f0ceb8f/importer.go#L65-L82
|
15,629 |
wellington/go-libsass
|
importer.go
|
Del
|
func (p *Imports) Del(path string) {
p.Lock()
defer p.Unlock()
delete(p.m, path)
}
|
go
|
func (p *Imports) Del(path string) {
p.Lock()
defer p.Unlock()
delete(p.m, path)
}
|
[
"func",
"(",
"p",
"*",
"Imports",
")",
"Del",
"(",
"path",
"string",
")",
"{",
"p",
".",
"Lock",
"(",
")",
"\n",
"defer",
"p",
".",
"Unlock",
"(",
")",
"\n\n",
"delete",
"(",
"p",
".",
"m",
",",
"path",
")",
"\n",
"}"
] |
// Del removes the import from the context.Imports
|
[
"Del",
"removes",
"the",
"import",
"from",
"the",
"context",
".",
"Imports"
] |
f870eaa15594bb64b1908df39d0812704f0ceb8f
|
https://github.com/wellington/go-libsass/blob/f870eaa15594bb64b1908df39d0812704f0ceb8f/importer.go#L85-L90
|
15,630 |
wellington/go-libsass
|
importer.go
|
Get
|
func (p *Imports) Get(prev, path string) ([]byte, error) {
p.RLock()
defer p.RUnlock()
for _, imp := range p.m {
if imp.Prev == prev && imp.Path == path {
return imp.bytes, nil
}
}
return nil, ErrImportNotFound
}
|
go
|
func (p *Imports) Get(prev, path string) ([]byte, error) {
p.RLock()
defer p.RUnlock()
for _, imp := range p.m {
if imp.Prev == prev && imp.Path == path {
return imp.bytes, nil
}
}
return nil, ErrImportNotFound
}
|
[
"func",
"(",
"p",
"*",
"Imports",
")",
"Get",
"(",
"prev",
",",
"path",
"string",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"p",
".",
"RLock",
"(",
")",
"\n",
"defer",
"p",
".",
"RUnlock",
"(",
")",
"\n",
"for",
"_",
",",
"imp",
":=",
"range",
"p",
".",
"m",
"{",
"if",
"imp",
".",
"Prev",
"==",
"prev",
"&&",
"imp",
".",
"Path",
"==",
"path",
"{",
"return",
"imp",
".",
"bytes",
",",
"nil",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"nil",
",",
"ErrImportNotFound",
"\n",
"}"
] |
// Get retrieves import bytes by path
|
[
"Get",
"retrieves",
"import",
"bytes",
"by",
"path"
] |
f870eaa15594bb64b1908df39d0812704f0ceb8f
|
https://github.com/wellington/go-libsass/blob/f870eaa15594bb64b1908df39d0812704f0ceb8f/importer.go#L93-L102
|
15,631 |
wellington/go-libsass
|
importer.go
|
Bind
|
func (p *Imports) Bind(opts libs.SassOptions) {
entries := make([]libs.ImportEntry, p.Len())
i := 0
p.RLock()
for _, ent := range p.m {
bs := ent.bytes
entries[i] = libs.ImportEntry{
Parent: ent.Prev,
Path: ent.Path,
Source: string(bs),
}
i++
}
p.RUnlock()
resolver := func(url string, prev string) (newURL string, body string, resolved bool) {
if p.resolver != nil {
newURL, body, resolved = p.resolver(url, prev)
if resolved {
return
}
}
entry, err := libs.GetEntry(entries, prev, url)
if err == nil {
return url, entry, true
}
return "", "", false
}
// set entries somewhere so GC doesn't collect it
p.idx = libs.BindImporter(opts, resolver)
}
|
go
|
func (p *Imports) Bind(opts libs.SassOptions) {
entries := make([]libs.ImportEntry, p.Len())
i := 0
p.RLock()
for _, ent := range p.m {
bs := ent.bytes
entries[i] = libs.ImportEntry{
Parent: ent.Prev,
Path: ent.Path,
Source: string(bs),
}
i++
}
p.RUnlock()
resolver := func(url string, prev string) (newURL string, body string, resolved bool) {
if p.resolver != nil {
newURL, body, resolved = p.resolver(url, prev)
if resolved {
return
}
}
entry, err := libs.GetEntry(entries, prev, url)
if err == nil {
return url, entry, true
}
return "", "", false
}
// set entries somewhere so GC doesn't collect it
p.idx = libs.BindImporter(opts, resolver)
}
|
[
"func",
"(",
"p",
"*",
"Imports",
")",
"Bind",
"(",
"opts",
"libs",
".",
"SassOptions",
")",
"{",
"entries",
":=",
"make",
"(",
"[",
"]",
"libs",
".",
"ImportEntry",
",",
"p",
".",
"Len",
"(",
")",
")",
"\n",
"i",
":=",
"0",
"\n\n",
"p",
".",
"RLock",
"(",
")",
"\n",
"for",
"_",
",",
"ent",
":=",
"range",
"p",
".",
"m",
"{",
"bs",
":=",
"ent",
".",
"bytes",
"\n",
"entries",
"[",
"i",
"]",
"=",
"libs",
".",
"ImportEntry",
"{",
"Parent",
":",
"ent",
".",
"Prev",
",",
"Path",
":",
"ent",
".",
"Path",
",",
"Source",
":",
"string",
"(",
"bs",
")",
",",
"}",
"\n",
"i",
"++",
"\n",
"}",
"\n",
"p",
".",
"RUnlock",
"(",
")",
"\n\n",
"resolver",
":=",
"func",
"(",
"url",
"string",
",",
"prev",
"string",
")",
"(",
"newURL",
"string",
",",
"body",
"string",
",",
"resolved",
"bool",
")",
"{",
"if",
"p",
".",
"resolver",
"!=",
"nil",
"{",
"newURL",
",",
"body",
",",
"resolved",
"=",
"p",
".",
"resolver",
"(",
"url",
",",
"prev",
")",
"\n",
"if",
"resolved",
"{",
"return",
"\n",
"}",
"\n",
"}",
"\n",
"entry",
",",
"err",
":=",
"libs",
".",
"GetEntry",
"(",
"entries",
",",
"prev",
",",
"url",
")",
"\n",
"if",
"err",
"==",
"nil",
"{",
"return",
"url",
",",
"entry",
",",
"true",
"\n",
"}",
"\n",
"return",
"\"",
"\"",
",",
"\"",
"\"",
",",
"false",
"\n",
"}",
"\n\n",
"// set entries somewhere so GC doesn't collect it",
"p",
".",
"idx",
"=",
"libs",
".",
"BindImporter",
"(",
"opts",
",",
"resolver",
")",
"\n",
"}"
] |
// Bind accepts a SassOptions and adds the registered
// importers in the context.
|
[
"Bind",
"accepts",
"a",
"SassOptions",
"and",
"adds",
"the",
"registered",
"importers",
"in",
"the",
"context",
"."
] |
f870eaa15594bb64b1908df39d0812704f0ceb8f
|
https://github.com/wellington/go-libsass/blob/f870eaa15594bb64b1908df39d0812704f0ceb8f/importer.go#L119-L151
|
15,632 |
wellington/go-libsass
|
libs/encoding.go
|
MakeError
|
func MakeError(s string) UnionSassValue {
cs := C.CString(s)
defer C.free(unsafe.Pointer(cs))
return C.sass_make_error(cs)
}
|
go
|
func MakeError(s string) UnionSassValue {
cs := C.CString(s)
defer C.free(unsafe.Pointer(cs))
return C.sass_make_error(cs)
}
|
[
"func",
"MakeError",
"(",
"s",
"string",
")",
"UnionSassValue",
"{",
"cs",
":=",
"C",
".",
"CString",
"(",
"s",
")",
"\n",
"defer",
"C",
".",
"free",
"(",
"unsafe",
".",
"Pointer",
"(",
"cs",
")",
")",
"\n",
"return",
"C",
".",
"sass_make_error",
"(",
"cs",
")",
"\n",
"}"
] |
// MakeError creates Sass error from a string
|
[
"MakeError",
"creates",
"Sass",
"error",
"from",
"a",
"string"
] |
f870eaa15594bb64b1908df39d0812704f0ceb8f
|
https://github.com/wellington/go-libsass/blob/f870eaa15594bb64b1908df39d0812704f0ceb8f/libs/encoding.go#L38-L42
|
15,633 |
wellington/go-libsass
|
libs/encoding.go
|
MakeWarning
|
func MakeWarning(s string) UnionSassValue {
cs := C.CString(s)
defer C.free(unsafe.Pointer(cs))
return C.sass_make_warning(cs)
}
|
go
|
func MakeWarning(s string) UnionSassValue {
cs := C.CString(s)
defer C.free(unsafe.Pointer(cs))
return C.sass_make_warning(cs)
}
|
[
"func",
"MakeWarning",
"(",
"s",
"string",
")",
"UnionSassValue",
"{",
"cs",
":=",
"C",
".",
"CString",
"(",
"s",
")",
"\n",
"defer",
"C",
".",
"free",
"(",
"unsafe",
".",
"Pointer",
"(",
"cs",
")",
")",
"\n",
"return",
"C",
".",
"sass_make_warning",
"(",
"cs",
")",
"\n",
"}"
] |
// MakeWarning creates Sass warning from a string
|
[
"MakeWarning",
"creates",
"Sass",
"warning",
"from",
"a",
"string"
] |
f870eaa15594bb64b1908df39d0812704f0ceb8f
|
https://github.com/wellington/go-libsass/blob/f870eaa15594bb64b1908df39d0812704f0ceb8f/libs/encoding.go#L45-L49
|
15,634 |
wellington/go-libsass
|
libs/encoding.go
|
MakeColor
|
func MakeColor(c color.RGBA) UnionSassValue {
r := C.double(c.R)
g := C.double(c.G)
b := C.double(c.B)
a := C.double(c.A)
return C.sass_make_color(r, g, b, a)
}
|
go
|
func MakeColor(c color.RGBA) UnionSassValue {
r := C.double(c.R)
g := C.double(c.G)
b := C.double(c.B)
a := C.double(c.A)
return C.sass_make_color(r, g, b, a)
}
|
[
"func",
"MakeColor",
"(",
"c",
"color",
".",
"RGBA",
")",
"UnionSassValue",
"{",
"r",
":=",
"C",
".",
"double",
"(",
"c",
".",
"R",
")",
"\n",
"g",
":=",
"C",
".",
"double",
"(",
"c",
".",
"G",
")",
"\n",
"b",
":=",
"C",
".",
"double",
"(",
"c",
".",
"B",
")",
"\n",
"a",
":=",
"C",
".",
"double",
"(",
"c",
".",
"A",
")",
"\n",
"return",
"C",
".",
"sass_make_color",
"(",
"r",
",",
"g",
",",
"b",
",",
"a",
")",
"\n",
"}"
] |
// MakeColor creates a Sass color from color.RGBA
|
[
"MakeColor",
"creates",
"a",
"Sass",
"color",
"from",
"color",
".",
"RGBA"
] |
f870eaa15594bb64b1908df39d0812704f0ceb8f
|
https://github.com/wellington/go-libsass/blob/f870eaa15594bb64b1908df39d0812704f0ceb8f/libs/encoding.go#L66-L72
|
15,635 |
wellington/go-libsass
|
libs/encoding.go
|
MakeList
|
func MakeList(len int) UnionSassValue {
return C.sass_make_list(C.size_t(len), C.SASS_COMMA, false)
}
|
go
|
func MakeList(len int) UnionSassValue {
return C.sass_make_list(C.size_t(len), C.SASS_COMMA, false)
}
|
[
"func",
"MakeList",
"(",
"len",
"int",
")",
"UnionSassValue",
"{",
"return",
"C",
".",
"sass_make_list",
"(",
"C",
".",
"size_t",
"(",
"len",
")",
",",
"C",
".",
"SASS_COMMA",
",",
"false",
")",
"\n",
"}"
] |
// MakeList creates a Sass List
|
[
"MakeList",
"creates",
"a",
"Sass",
"List"
] |
f870eaa15594bb64b1908df39d0812704f0ceb8f
|
https://github.com/wellington/go-libsass/blob/f870eaa15594bb64b1908df39d0812704f0ceb8f/libs/encoding.go#L75-L77
|
15,636 |
wellington/go-libsass
|
libs/encoding.go
|
Slice
|
func Slice(usv UnionSassValue, inf interface{}) {
if !IsList(usv) {
panic("sass value is not a list")
}
l := Len(usv)
r := reflect.ValueOf(inf)
if r.Kind() == reflect.Ptr {
r = r.Elem()
}
if !r.CanSet() {
panic("value is not addressable")
}
// if a non-slice is passed, make a slice
t := r.Type()
if r.Kind() != reflect.Slice {
t = reflect.SliceOf(t)
}
d := reflect.MakeSlice(t, l, l)
for i := 0; i < l; i++ {
sv := Index(usv, i)
inf := Interface(sv)
rf := reflect.ValueOf(inf)
// Special case for nil
if inf == nil {
d.Index(i).Set(reflect.ValueOf("<nil>"))
continue
}
d.Index(i).Set(rf)
}
r.Set(d)
}
|
go
|
func Slice(usv UnionSassValue, inf interface{}) {
if !IsList(usv) {
panic("sass value is not a list")
}
l := Len(usv)
r := reflect.ValueOf(inf)
if r.Kind() == reflect.Ptr {
r = r.Elem()
}
if !r.CanSet() {
panic("value is not addressable")
}
// if a non-slice is passed, make a slice
t := r.Type()
if r.Kind() != reflect.Slice {
t = reflect.SliceOf(t)
}
d := reflect.MakeSlice(t, l, l)
for i := 0; i < l; i++ {
sv := Index(usv, i)
inf := Interface(sv)
rf := reflect.ValueOf(inf)
// Special case for nil
if inf == nil {
d.Index(i).Set(reflect.ValueOf("<nil>"))
continue
}
d.Index(i).Set(rf)
}
r.Set(d)
}
|
[
"func",
"Slice",
"(",
"usv",
"UnionSassValue",
",",
"inf",
"interface",
"{",
"}",
")",
"{",
"if",
"!",
"IsList",
"(",
"usv",
")",
"{",
"panic",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"l",
":=",
"Len",
"(",
"usv",
")",
"\n",
"r",
":=",
"reflect",
".",
"ValueOf",
"(",
"inf",
")",
"\n",
"if",
"r",
".",
"Kind",
"(",
")",
"==",
"reflect",
".",
"Ptr",
"{",
"r",
"=",
"r",
".",
"Elem",
"(",
")",
"\n",
"}",
"\n",
"if",
"!",
"r",
".",
"CanSet",
"(",
")",
"{",
"panic",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"// if a non-slice is passed, make a slice",
"t",
":=",
"r",
".",
"Type",
"(",
")",
"\n",
"if",
"r",
".",
"Kind",
"(",
")",
"!=",
"reflect",
".",
"Slice",
"{",
"t",
"=",
"reflect",
".",
"SliceOf",
"(",
"t",
")",
"\n",
"}",
"\n",
"d",
":=",
"reflect",
".",
"MakeSlice",
"(",
"t",
",",
"l",
",",
"l",
")",
"\n",
"for",
"i",
":=",
"0",
";",
"i",
"<",
"l",
";",
"i",
"++",
"{",
"sv",
":=",
"Index",
"(",
"usv",
",",
"i",
")",
"\n",
"inf",
":=",
"Interface",
"(",
"sv",
")",
"\n",
"rf",
":=",
"reflect",
".",
"ValueOf",
"(",
"inf",
")",
"\n",
"// Special case for nil",
"if",
"inf",
"==",
"nil",
"{",
"d",
".",
"Index",
"(",
"i",
")",
".",
"Set",
"(",
"reflect",
".",
"ValueOf",
"(",
"\"",
"\"",
")",
")",
"\n",
"continue",
"\n",
"}",
"\n",
"d",
".",
"Index",
"(",
"i",
")",
".",
"Set",
"(",
"rf",
")",
"\n",
"}",
"\n",
"r",
".",
"Set",
"(",
"d",
")",
"\n",
"}"
] |
// Slice creates a Sass List from a Go slice. Reflection is used.
|
[
"Slice",
"creates",
"a",
"Sass",
"List",
"from",
"a",
"Go",
"slice",
".",
"Reflection",
"is",
"used",
"."
] |
f870eaa15594bb64b1908df39d0812704f0ceb8f
|
https://github.com/wellington/go-libsass/blob/f870eaa15594bb64b1908df39d0812704f0ceb8f/libs/encoding.go#L85-L115
|
15,637 |
wellington/go-libsass
|
libs/encoding.go
|
Interface
|
func Interface(usv UnionSassValue) interface{} {
switch {
case IsNil(usv):
return nil
case IsBool(usv):
return Bool(usv)
case IsString(usv):
return String(usv)
case IsColor(usv):
return Color(usv)
case IsNumber(usv):
return Number(usv)
case IsList(usv):
fallthrough
//return List(usv)
case IsMap(usv):
fallthrough
//return Map(usv)
default:
return nil
}
panic("call of interface not supported on type")
}
|
go
|
func Interface(usv UnionSassValue) interface{} {
switch {
case IsNil(usv):
return nil
case IsBool(usv):
return Bool(usv)
case IsString(usv):
return String(usv)
case IsColor(usv):
return Color(usv)
case IsNumber(usv):
return Number(usv)
case IsList(usv):
fallthrough
//return List(usv)
case IsMap(usv):
fallthrough
//return Map(usv)
default:
return nil
}
panic("call of interface not supported on type")
}
|
[
"func",
"Interface",
"(",
"usv",
"UnionSassValue",
")",
"interface",
"{",
"}",
"{",
"switch",
"{",
"case",
"IsNil",
"(",
"usv",
")",
":",
"return",
"nil",
"\n",
"case",
"IsBool",
"(",
"usv",
")",
":",
"return",
"Bool",
"(",
"usv",
")",
"\n",
"case",
"IsString",
"(",
"usv",
")",
":",
"return",
"String",
"(",
"usv",
")",
"\n",
"case",
"IsColor",
"(",
"usv",
")",
":",
"return",
"Color",
"(",
"usv",
")",
"\n",
"case",
"IsNumber",
"(",
"usv",
")",
":",
"return",
"Number",
"(",
"usv",
")",
"\n",
"case",
"IsList",
"(",
"usv",
")",
":",
"fallthrough",
"\n",
"//return List(usv)",
"case",
"IsMap",
"(",
"usv",
")",
":",
"fallthrough",
"\n",
"//return Map(usv)",
"default",
":",
"return",
"nil",
"\n",
"}",
"\n",
"panic",
"(",
"\"",
"\"",
")",
"\n",
"}"
] |
// Interface creates Go types from union sass_value
|
[
"Interface",
"creates",
"Go",
"types",
"from",
"union",
"sass_value"
] |
f870eaa15594bb64b1908df39d0812704f0ceb8f
|
https://github.com/wellington/go-libsass/blob/f870eaa15594bb64b1908df39d0812704f0ceb8f/libs/encoding.go#L150-L172
|
15,638 |
wellington/go-libsass
|
toscss.go
|
ToScss
|
func ToScss(r io.Reader, w io.Writer) error {
return libs.ToScss(r, w)
}
|
go
|
func ToScss(r io.Reader, w io.Writer) error {
return libs.ToScss(r, w)
}
|
[
"func",
"ToScss",
"(",
"r",
"io",
".",
"Reader",
",",
"w",
"io",
".",
"Writer",
")",
"error",
"{",
"return",
"libs",
".",
"ToScss",
"(",
"r",
",",
"w",
")",
"\n",
"}"
] |
// ToScss converts Sass to Scss with libsass sass2scss.h
|
[
"ToScss",
"converts",
"Sass",
"to",
"Scss",
"with",
"libsass",
"sass2scss",
".",
"h"
] |
f870eaa15594bb64b1908df39d0812704f0ceb8f
|
https://github.com/wellington/go-libsass/blob/f870eaa15594bb64b1908df39d0812704f0ceb8f/toscss.go#L10-L12
|
15,639 |
wellington/go-libsass
|
libs/func.go
|
SassMakeFunction
|
func SassMakeFunction(signature string, idx int) SassFunc {
csign := C.CString(signature)
ptr := unsafe.Pointer(uintptr(idx))
fn := C.sass_make_function(
csign,
C.Sass_Function_Fn(C.CallSassFunction),
ptr)
return (SassFunc)(fn)
}
|
go
|
func SassMakeFunction(signature string, idx int) SassFunc {
csign := C.CString(signature)
ptr := unsafe.Pointer(uintptr(idx))
fn := C.sass_make_function(
csign,
C.Sass_Function_Fn(C.CallSassFunction),
ptr)
return (SassFunc)(fn)
}
|
[
"func",
"SassMakeFunction",
"(",
"signature",
"string",
",",
"idx",
"int",
")",
"SassFunc",
"{",
"csign",
":=",
"C",
".",
"CString",
"(",
"signature",
")",
"\n",
"ptr",
":=",
"unsafe",
".",
"Pointer",
"(",
"uintptr",
"(",
"idx",
")",
")",
"\n",
"fn",
":=",
"C",
".",
"sass_make_function",
"(",
"csign",
",",
"C",
".",
"Sass_Function_Fn",
"(",
"C",
".",
"CallSassFunction",
")",
",",
"ptr",
")",
"\n\n",
"return",
"(",
"SassFunc",
")",
"(",
"fn",
")",
"\n",
"}"
] |
// SassMakeFunction binds a Go pointer to a Sass function signature
|
[
"SassMakeFunction",
"binds",
"a",
"Go",
"pointer",
"to",
"a",
"Sass",
"function",
"signature"
] |
f870eaa15594bb64b1908df39d0812704f0ceb8f
|
https://github.com/wellington/go-libsass/blob/f870eaa15594bb64b1908df39d0812704f0ceb8f/libs/func.go#L23-L32
|
15,640 |
wellington/go-libsass
|
libs/func.go
|
BindFuncs
|
func BindFuncs(opts SassOptions, cookies []Cookie) []int {
funcs := make([]SassFunc, len(cookies))
ids := make([]int, len(cookies))
for i, cookie := range cookies {
idx := globalFuncs.Set(cookies[i])
fn := SassMakeFunction(cookie.Sign, idx)
funcs[i] = fn
ids[i] = idx
}
sz := C.size_t(len(funcs))
cfuncs := C.sass_make_function_list(sz)
for i, cfn := range funcs {
C.sass_function_set_list_entry(cfuncs, C.size_t(i), C.Sass_Function_Entry(cfn))
}
C.sass_option_set_c_functions(opts, cfuncs)
return ids
}
|
go
|
func BindFuncs(opts SassOptions, cookies []Cookie) []int {
funcs := make([]SassFunc, len(cookies))
ids := make([]int, len(cookies))
for i, cookie := range cookies {
idx := globalFuncs.Set(cookies[i])
fn := SassMakeFunction(cookie.Sign, idx)
funcs[i] = fn
ids[i] = idx
}
sz := C.size_t(len(funcs))
cfuncs := C.sass_make_function_list(sz)
for i, cfn := range funcs {
C.sass_function_set_list_entry(cfuncs, C.size_t(i), C.Sass_Function_Entry(cfn))
}
C.sass_option_set_c_functions(opts, cfuncs)
return ids
}
|
[
"func",
"BindFuncs",
"(",
"opts",
"SassOptions",
",",
"cookies",
"[",
"]",
"Cookie",
")",
"[",
"]",
"int",
"{",
"funcs",
":=",
"make",
"(",
"[",
"]",
"SassFunc",
",",
"len",
"(",
"cookies",
")",
")",
"\n",
"ids",
":=",
"make",
"(",
"[",
"]",
"int",
",",
"len",
"(",
"cookies",
")",
")",
"\n",
"for",
"i",
",",
"cookie",
":=",
"range",
"cookies",
"{",
"idx",
":=",
"globalFuncs",
".",
"Set",
"(",
"cookies",
"[",
"i",
"]",
")",
"\n",
"fn",
":=",
"SassMakeFunction",
"(",
"cookie",
".",
"Sign",
",",
"idx",
")",
"\n",
"funcs",
"[",
"i",
"]",
"=",
"fn",
"\n",
"ids",
"[",
"i",
"]",
"=",
"idx",
"\n",
"}",
"\n\n",
"sz",
":=",
"C",
".",
"size_t",
"(",
"len",
"(",
"funcs",
")",
")",
"\n",
"cfuncs",
":=",
"C",
".",
"sass_make_function_list",
"(",
"sz",
")",
"\n",
"for",
"i",
",",
"cfn",
":=",
"range",
"funcs",
"{",
"C",
".",
"sass_function_set_list_entry",
"(",
"cfuncs",
",",
"C",
".",
"size_t",
"(",
"i",
")",
",",
"C",
".",
"Sass_Function_Entry",
"(",
"cfn",
")",
")",
"\n",
"}",
"\n",
"C",
".",
"sass_option_set_c_functions",
"(",
"opts",
",",
"cfuncs",
")",
"\n",
"return",
"ids",
"\n",
"}"
] |
// BindFuncs attaches a slice of Functions to a sass options. Signatures
// are already defined in the SassFunc.
|
[
"BindFuncs",
"attaches",
"a",
"slice",
"of",
"Functions",
"to",
"a",
"sass",
"options",
".",
"Signatures",
"are",
"already",
"defined",
"in",
"the",
"SassFunc",
"."
] |
f870eaa15594bb64b1908df39d0812704f0ceb8f
|
https://github.com/wellington/go-libsass/blob/f870eaa15594bb64b1908df39d0812704f0ceb8f/libs/func.go#L42-L60
|
15,641 |
wellington/go-libsass
|
func.go
|
RegisterSassFunc
|
func RegisterSassFunc(sign string, fn SassFunc) {
ghMu.Lock()
globalHandlers = append(globalHandlers, handler{
sign: sign,
callback: SassHandler(fn),
})
ghMu.Unlock()
}
|
go
|
func RegisterSassFunc(sign string, fn SassFunc) {
ghMu.Lock()
globalHandlers = append(globalHandlers, handler{
sign: sign,
callback: SassHandler(fn),
})
ghMu.Unlock()
}
|
[
"func",
"RegisterSassFunc",
"(",
"sign",
"string",
",",
"fn",
"SassFunc",
")",
"{",
"ghMu",
".",
"Lock",
"(",
")",
"\n",
"globalHandlers",
"=",
"append",
"(",
"globalHandlers",
",",
"handler",
"{",
"sign",
":",
"sign",
",",
"callback",
":",
"SassHandler",
"(",
"fn",
")",
",",
"}",
")",
"\n",
"ghMu",
".",
"Unlock",
"(",
")",
"\n",
"}"
] |
// RegisterSassFunc assigns the passed Func to the specified signature sign
|
[
"RegisterSassFunc",
"assigns",
"the",
"passed",
"Func",
"to",
"the",
"specified",
"signature",
"sign"
] |
f870eaa15594bb64b1908df39d0812704f0ceb8f
|
https://github.com/wellington/go-libsass/blob/f870eaa15594bb64b1908df39d0812704f0ceb8f/func.go#L19-L26
|
15,642 |
wellington/go-libsass
|
func.go
|
CompFromCtx
|
func CompFromCtx(ctx context.Context) (Compiler, error) {
v := ctx.Value(compkey)
comp, ok := v.(Compiler)
if !ok {
return comp, ErrCompilerNotFound
}
return comp, nil
}
|
go
|
func CompFromCtx(ctx context.Context) (Compiler, error) {
v := ctx.Value(compkey)
comp, ok := v.(Compiler)
if !ok {
return comp, ErrCompilerNotFound
}
return comp, nil
}
|
[
"func",
"CompFromCtx",
"(",
"ctx",
"context",
".",
"Context",
")",
"(",
"Compiler",
",",
"error",
")",
"{",
"v",
":=",
"ctx",
".",
"Value",
"(",
"compkey",
")",
"\n",
"comp",
",",
"ok",
":=",
"v",
".",
"(",
"Compiler",
")",
"\n",
"if",
"!",
"ok",
"{",
"return",
"comp",
",",
"ErrCompilerNotFound",
"\n",
"}",
"\n",
"return",
"comp",
",",
"nil",
"\n",
"}"
] |
// CompFromCtx retrieves a compiler from a passed context
|
[
"CompFromCtx",
"retrieves",
"a",
"compiler",
"from",
"a",
"passed",
"context"
] |
f870eaa15594bb64b1908df39d0812704f0ceb8f
|
https://github.com/wellington/go-libsass/blob/f870eaa15594bb64b1908df39d0812704f0ceb8f/func.go#L41-L48
|
15,643 |
wellington/go-libsass
|
func.go
|
SassHandler
|
func SassHandler(h SassFunc) libs.SassCallback {
return func(v interface{}, usv libs.UnionSassValue, rsv *libs.UnionSassValue) error {
if *rsv == nil {
*rsv = libs.MakeNil()
}
libCtx, ok := v.(*compctx)
if !ok {
return errors.New("libsass Context not found")
}
ctx := NewCompilerContext(libCtx.compiler)
// Cast to exported Go types
req := SassValue{value: usv}
res, err := h(ctx, req)
if err != nil {
// Returns the error to libsass Compiler
*rsv = libs.MakeError(err.Error())
// Returning an error does nothing as libsass is in charge of
// reporting error to user
return err
}
*rsv = res.Val()
return err
}
}
|
go
|
func SassHandler(h SassFunc) libs.SassCallback {
return func(v interface{}, usv libs.UnionSassValue, rsv *libs.UnionSassValue) error {
if *rsv == nil {
*rsv = libs.MakeNil()
}
libCtx, ok := v.(*compctx)
if !ok {
return errors.New("libsass Context not found")
}
ctx := NewCompilerContext(libCtx.compiler)
// Cast to exported Go types
req := SassValue{value: usv}
res, err := h(ctx, req)
if err != nil {
// Returns the error to libsass Compiler
*rsv = libs.MakeError(err.Error())
// Returning an error does nothing as libsass is in charge of
// reporting error to user
return err
}
*rsv = res.Val()
return err
}
}
|
[
"func",
"SassHandler",
"(",
"h",
"SassFunc",
")",
"libs",
".",
"SassCallback",
"{",
"return",
"func",
"(",
"v",
"interface",
"{",
"}",
",",
"usv",
"libs",
".",
"UnionSassValue",
",",
"rsv",
"*",
"libs",
".",
"UnionSassValue",
")",
"error",
"{",
"if",
"*",
"rsv",
"==",
"nil",
"{",
"*",
"rsv",
"=",
"libs",
".",
"MakeNil",
"(",
")",
"\n",
"}",
"\n\n",
"libCtx",
",",
"ok",
":=",
"v",
".",
"(",
"*",
"compctx",
")",
"\n",
"if",
"!",
"ok",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"ctx",
":=",
"NewCompilerContext",
"(",
"libCtx",
".",
"compiler",
")",
"\n\n",
"// Cast to exported Go types",
"req",
":=",
"SassValue",
"{",
"value",
":",
"usv",
"}",
"\n",
"res",
",",
"err",
":=",
"h",
"(",
"ctx",
",",
"req",
")",
"\n\n",
"if",
"err",
"!=",
"nil",
"{",
"// Returns the error to libsass Compiler",
"*",
"rsv",
"=",
"libs",
".",
"MakeError",
"(",
"err",
".",
"Error",
"(",
")",
")",
"\n",
"// Returning an error does nothing as libsass is in charge of",
"// reporting error to user",
"return",
"err",
"\n",
"}",
"\n\n",
"*",
"rsv",
"=",
"res",
".",
"Val",
"(",
")",
"\n",
"return",
"err",
"\n",
"}",
"\n",
"}"
] |
// SassHandler contains callback context for running code within
// a libsass handler
|
[
"SassHandler",
"contains",
"callback",
"context",
"for",
"running",
"code",
"within",
"a",
"libsass",
"handler"
] |
f870eaa15594bb64b1908df39d0812704f0ceb8f
|
https://github.com/wellington/go-libsass/blob/f870eaa15594bb64b1908df39d0812704f0ceb8f/func.go#L55-L83
|
15,644 |
wellington/go-libsass
|
func.go
|
RegisterHandler
|
func RegisterHandler(sign string, callback HandlerFunc) {
ghMu.Lock()
globalHandlers = append(globalHandlers, handler{
sign: sign,
callback: Handler(callback),
})
ghMu.Unlock()
}
|
go
|
func RegisterHandler(sign string, callback HandlerFunc) {
ghMu.Lock()
globalHandlers = append(globalHandlers, handler{
sign: sign,
callback: Handler(callback),
})
ghMu.Unlock()
}
|
[
"func",
"RegisterHandler",
"(",
"sign",
"string",
",",
"callback",
"HandlerFunc",
")",
"{",
"ghMu",
".",
"Lock",
"(",
")",
"\n",
"globalHandlers",
"=",
"append",
"(",
"globalHandlers",
",",
"handler",
"{",
"sign",
":",
"sign",
",",
"callback",
":",
"Handler",
"(",
"callback",
")",
",",
"}",
")",
"\n",
"ghMu",
".",
"Unlock",
"(",
")",
"\n",
"}"
] |
// RegisterHandler sets the passed signature and callback to the
// handlers array.
|
[
"RegisterHandler",
"sets",
"the",
"passed",
"signature",
"and",
"callback",
"to",
"the",
"handlers",
"array",
"."
] |
f870eaa15594bb64b1908df39d0812704f0ceb8f
|
https://github.com/wellington/go-libsass/blob/f870eaa15594bb64b1908df39d0812704f0ceb8f/func.go#L87-L94
|
15,645 |
wellington/go-libsass
|
func.go
|
Handler
|
func Handler(h HandlerFunc) libs.SassCallback {
return func(v interface{}, usv libs.UnionSassValue, rsv *libs.UnionSassValue) error {
if *rsv == nil {
*rsv = libs.MakeNil()
}
req := SassValue{value: usv}
res := SassValue{value: *rsv}
err := h(v, req, &res)
if rsv != nil {
*rsv = res.Val()
}
return err
}
}
|
go
|
func Handler(h HandlerFunc) libs.SassCallback {
return func(v interface{}, usv libs.UnionSassValue, rsv *libs.UnionSassValue) error {
if *rsv == nil {
*rsv = libs.MakeNil()
}
req := SassValue{value: usv}
res := SassValue{value: *rsv}
err := h(v, req, &res)
if rsv != nil {
*rsv = res.Val()
}
return err
}
}
|
[
"func",
"Handler",
"(",
"h",
"HandlerFunc",
")",
"libs",
".",
"SassCallback",
"{",
"return",
"func",
"(",
"v",
"interface",
"{",
"}",
",",
"usv",
"libs",
".",
"UnionSassValue",
",",
"rsv",
"*",
"libs",
".",
"UnionSassValue",
")",
"error",
"{",
"if",
"*",
"rsv",
"==",
"nil",
"{",
"*",
"rsv",
"=",
"libs",
".",
"MakeNil",
"(",
")",
"\n",
"}",
"\n",
"req",
":=",
"SassValue",
"{",
"value",
":",
"usv",
"}",
"\n",
"res",
":=",
"SassValue",
"{",
"value",
":",
"*",
"rsv",
"}",
"\n",
"err",
":=",
"h",
"(",
"v",
",",
"req",
",",
"&",
"res",
")",
"\n\n",
"if",
"rsv",
"!=",
"nil",
"{",
"*",
"rsv",
"=",
"res",
".",
"Val",
"(",
")",
"\n",
"}",
"\n\n",
"return",
"err",
"\n",
"}",
"\n",
"}"
] |
// Handler accepts a HandlerFunc and returns SassCallback for sending
// to libsass. The third argument must be a pointer and the function
// must return an error.
|
[
"Handler",
"accepts",
"a",
"HandlerFunc",
"and",
"returns",
"SassCallback",
"for",
"sending",
"to",
"libsass",
".",
"The",
"third",
"argument",
"must",
"be",
"a",
"pointer",
"and",
"the",
"function",
"must",
"return",
"an",
"error",
"."
] |
f870eaa15594bb64b1908df39d0812704f0ceb8f
|
https://github.com/wellington/go-libsass/blob/f870eaa15594bb64b1908df39d0812704f0ceb8f/func.go#L103-L118
|
15,646 |
wellington/go-libsass
|
func.go
|
Bind
|
func (fs *Funcs) Bind(goopts libs.SassOptions) {
ghMu.RLock()
cookies := make([]libs.Cookie, len(globalHandlers)+len(fs.f))
// Append registered handlers to cookie array
for i, h := range globalHandlers {
cookies[i] = libs.Cookie{
Sign: h.sign,
Fn: h.callback,
Ctx: fs.ctx,
}
}
l := len(globalHandlers)
ghMu.RUnlock()
for i, h := range fs.f {
cookies[i+l] = libs.Cookie{
Sign: h.Sign,
Fn: h.Fn,
Ctx: fs.ctx,
}
}
fs.idx = libs.BindFuncs(goopts, cookies)
}
|
go
|
func (fs *Funcs) Bind(goopts libs.SassOptions) {
ghMu.RLock()
cookies := make([]libs.Cookie, len(globalHandlers)+len(fs.f))
// Append registered handlers to cookie array
for i, h := range globalHandlers {
cookies[i] = libs.Cookie{
Sign: h.sign,
Fn: h.callback,
Ctx: fs.ctx,
}
}
l := len(globalHandlers)
ghMu.RUnlock()
for i, h := range fs.f {
cookies[i+l] = libs.Cookie{
Sign: h.Sign,
Fn: h.Fn,
Ctx: fs.ctx,
}
}
fs.idx = libs.BindFuncs(goopts, cookies)
}
|
[
"func",
"(",
"fs",
"*",
"Funcs",
")",
"Bind",
"(",
"goopts",
"libs",
".",
"SassOptions",
")",
"{",
"ghMu",
".",
"RLock",
"(",
")",
"\n",
"cookies",
":=",
"make",
"(",
"[",
"]",
"libs",
".",
"Cookie",
",",
"len",
"(",
"globalHandlers",
")",
"+",
"len",
"(",
"fs",
".",
"f",
")",
")",
"\n",
"// Append registered handlers to cookie array",
"for",
"i",
",",
"h",
":=",
"range",
"globalHandlers",
"{",
"cookies",
"[",
"i",
"]",
"=",
"libs",
".",
"Cookie",
"{",
"Sign",
":",
"h",
".",
"sign",
",",
"Fn",
":",
"h",
".",
"callback",
",",
"Ctx",
":",
"fs",
".",
"ctx",
",",
"}",
"\n",
"}",
"\n",
"l",
":=",
"len",
"(",
"globalHandlers",
")",
"\n",
"ghMu",
".",
"RUnlock",
"(",
")",
"\n\n",
"for",
"i",
",",
"h",
":=",
"range",
"fs",
".",
"f",
"{",
"cookies",
"[",
"i",
"+",
"l",
"]",
"=",
"libs",
".",
"Cookie",
"{",
"Sign",
":",
"h",
".",
"Sign",
",",
"Fn",
":",
"h",
".",
"Fn",
",",
"Ctx",
":",
"fs",
".",
"ctx",
",",
"}",
"\n",
"}",
"\n",
"fs",
".",
"idx",
"=",
"libs",
".",
"BindFuncs",
"(",
"goopts",
",",
"cookies",
")",
"\n",
"}"
] |
// SetFunc assigns the registered methods to SassOptions. Functions
// are called when the compiler encounters the registered signature.
|
[
"SetFunc",
"assigns",
"the",
"registered",
"methods",
"to",
"SassOptions",
".",
"Functions",
"are",
"called",
"when",
"the",
"compiler",
"encounters",
"the",
"registered",
"signature",
"."
] |
f870eaa15594bb64b1908df39d0812704f0ceb8f
|
https://github.com/wellington/go-libsass/blob/f870eaa15594bb64b1908df39d0812704f0ceb8f/func.go#L175-L197
|
15,647 |
wellington/go-libsass
|
context.go
|
Init
|
func (ctx *compctx) Init(goopts libs.SassOptions) libs.SassOptions {
if ctx.Precision == 0 {
ctx.Precision = 5
}
ctx.options = goopts
ctx.Headers.Bind(goopts)
ctx.Imports.Bind(goopts)
ctx.Funcs.Bind(goopts)
libs.SassOptionSetSourceComments(goopts, ctx.compiler.LineComments())
//os.PathListSeparator
incs := strings.Join(ctx.IncludePaths, string(os.PathListSeparator))
libs.SassOptionSetIncludePath(goopts, incs)
libs.SassOptionSetPrecision(goopts, ctx.Precision)
libs.SassOptionSetOutputStyle(goopts, ctx.OutputStyle)
libs.SassOptionSetSourceComments(goopts, ctx.Comments)
if ctx.includeMap {
libs.SassOptionSetSourceMapEmbed(goopts, true)
}
return goopts
}
|
go
|
func (ctx *compctx) Init(goopts libs.SassOptions) libs.SassOptions {
if ctx.Precision == 0 {
ctx.Precision = 5
}
ctx.options = goopts
ctx.Headers.Bind(goopts)
ctx.Imports.Bind(goopts)
ctx.Funcs.Bind(goopts)
libs.SassOptionSetSourceComments(goopts, ctx.compiler.LineComments())
//os.PathListSeparator
incs := strings.Join(ctx.IncludePaths, string(os.PathListSeparator))
libs.SassOptionSetIncludePath(goopts, incs)
libs.SassOptionSetPrecision(goopts, ctx.Precision)
libs.SassOptionSetOutputStyle(goopts, ctx.OutputStyle)
libs.SassOptionSetSourceComments(goopts, ctx.Comments)
if ctx.includeMap {
libs.SassOptionSetSourceMapEmbed(goopts, true)
}
return goopts
}
|
[
"func",
"(",
"ctx",
"*",
"compctx",
")",
"Init",
"(",
"goopts",
"libs",
".",
"SassOptions",
")",
"libs",
".",
"SassOptions",
"{",
"if",
"ctx",
".",
"Precision",
"==",
"0",
"{",
"ctx",
".",
"Precision",
"=",
"5",
"\n",
"}",
"\n",
"ctx",
".",
"options",
"=",
"goopts",
"\n",
"ctx",
".",
"Headers",
".",
"Bind",
"(",
"goopts",
")",
"\n",
"ctx",
".",
"Imports",
".",
"Bind",
"(",
"goopts",
")",
"\n",
"ctx",
".",
"Funcs",
".",
"Bind",
"(",
"goopts",
")",
"\n",
"libs",
".",
"SassOptionSetSourceComments",
"(",
"goopts",
",",
"ctx",
".",
"compiler",
".",
"LineComments",
"(",
")",
")",
"\n",
"//os.PathListSeparator",
"incs",
":=",
"strings",
".",
"Join",
"(",
"ctx",
".",
"IncludePaths",
",",
"string",
"(",
"os",
".",
"PathListSeparator",
")",
")",
"\n",
"libs",
".",
"SassOptionSetIncludePath",
"(",
"goopts",
",",
"incs",
")",
"\n",
"libs",
".",
"SassOptionSetPrecision",
"(",
"goopts",
",",
"ctx",
".",
"Precision",
")",
"\n",
"libs",
".",
"SassOptionSetOutputStyle",
"(",
"goopts",
",",
"ctx",
".",
"OutputStyle",
")",
"\n",
"libs",
".",
"SassOptionSetSourceComments",
"(",
"goopts",
",",
"ctx",
".",
"Comments",
")",
"\n\n",
"if",
"ctx",
".",
"includeMap",
"{",
"libs",
".",
"SassOptionSetSourceMapEmbed",
"(",
"goopts",
",",
"true",
")",
"\n",
"}",
"\n\n",
"return",
"goopts",
"\n",
"}"
] |
// Init validates options in the struct and returns a Sass Options.
|
[
"Init",
"validates",
"options",
"in",
"the",
"struct",
"and",
"returns",
"a",
"Sass",
"Options",
"."
] |
f870eaa15594bb64b1908df39d0812704f0ceb8f
|
https://github.com/wellington/go-libsass/blob/f870eaa15594bb64b1908df39d0812704f0ceb8f/context.go#L105-L126
|
15,648 |
wellington/go-libsass
|
context.go
|
compile
|
func (ctx *compctx) compile(out io.Writer, in io.Reader) error {
defer ctx.Reset()
var (
bs []byte
err error
)
// libSass will fail on Sass syntax given as non-file input
// convert the input on its behalf
if ctx.compiler.Syntax() == SassSyntax {
// this is memory intensive
var buf bytes.Buffer
err := ToScss(in, &buf)
if err != nil {
return err
}
bs = buf.Bytes()
} else {
// ScssSyntax
bs, err = ioutil.ReadAll(in)
if err != nil {
return err
}
}
if len(bs) == 0 {
return errors.New("No input provided")
}
godc := libs.SassMakeDataContext(string(bs))
goopts := libs.SassDataContextGetOptions(godc)
libs.SassOptionSetSourceComments(goopts, true)
ctx.Init(goopts)
libs.SassDataContextSetOptions(godc, goopts)
goctx := libs.SassDataContextGetContext(godc)
ctx.context = goctx
gocompiler := libs.SassMakeDataCompiler(godc)
libs.SassCompilerParse(gocompiler)
libs.SassCompilerExecute(gocompiler)
defer libs.SassDeleteCompiler(gocompiler)
goout := libs.SassContextGetOutputString(goctx)
io.WriteString(out, goout)
ctx.Status = libs.SassContextGetErrorStatus(goctx)
errJSON := libs.SassContextGetErrorJSON(goctx)
err = ctx.ProcessSassError([]byte(errJSON))
if err != nil {
return err
}
if ctx.Error() != "" {
lines := bytes.Split(bs, []byte("\n"))
var out string
for i := -7; i < 7; i++ {
if i+ctx.err.Line >= 0 && i+ctx.err.Line < len(lines) {
out += fmt.Sprintf("%s\n", string(lines[i+ctx.err.Line]))
}
}
// TODO: this is weird, make something more idiomatic
return errors.New(ctx.Error() + "\n" + out)
}
return nil
}
|
go
|
func (ctx *compctx) compile(out io.Writer, in io.Reader) error {
defer ctx.Reset()
var (
bs []byte
err error
)
// libSass will fail on Sass syntax given as non-file input
// convert the input on its behalf
if ctx.compiler.Syntax() == SassSyntax {
// this is memory intensive
var buf bytes.Buffer
err := ToScss(in, &buf)
if err != nil {
return err
}
bs = buf.Bytes()
} else {
// ScssSyntax
bs, err = ioutil.ReadAll(in)
if err != nil {
return err
}
}
if len(bs) == 0 {
return errors.New("No input provided")
}
godc := libs.SassMakeDataContext(string(bs))
goopts := libs.SassDataContextGetOptions(godc)
libs.SassOptionSetSourceComments(goopts, true)
ctx.Init(goopts)
libs.SassDataContextSetOptions(godc, goopts)
goctx := libs.SassDataContextGetContext(godc)
ctx.context = goctx
gocompiler := libs.SassMakeDataCompiler(godc)
libs.SassCompilerParse(gocompiler)
libs.SassCompilerExecute(gocompiler)
defer libs.SassDeleteCompiler(gocompiler)
goout := libs.SassContextGetOutputString(goctx)
io.WriteString(out, goout)
ctx.Status = libs.SassContextGetErrorStatus(goctx)
errJSON := libs.SassContextGetErrorJSON(goctx)
err = ctx.ProcessSassError([]byte(errJSON))
if err != nil {
return err
}
if ctx.Error() != "" {
lines := bytes.Split(bs, []byte("\n"))
var out string
for i := -7; i < 7; i++ {
if i+ctx.err.Line >= 0 && i+ctx.err.Line < len(lines) {
out += fmt.Sprintf("%s\n", string(lines[i+ctx.err.Line]))
}
}
// TODO: this is weird, make something more idiomatic
return errors.New(ctx.Error() + "\n" + out)
}
return nil
}
|
[
"func",
"(",
"ctx",
"*",
"compctx",
")",
"compile",
"(",
"out",
"io",
".",
"Writer",
",",
"in",
"io",
".",
"Reader",
")",
"error",
"{",
"defer",
"ctx",
".",
"Reset",
"(",
")",
"\n",
"var",
"(",
"bs",
"[",
"]",
"byte",
"\n",
"err",
"error",
"\n",
")",
"\n\n",
"// libSass will fail on Sass syntax given as non-file input",
"// convert the input on its behalf",
"if",
"ctx",
".",
"compiler",
".",
"Syntax",
"(",
")",
"==",
"SassSyntax",
"{",
"// this is memory intensive",
"var",
"buf",
"bytes",
".",
"Buffer",
"\n",
"err",
":=",
"ToScss",
"(",
"in",
",",
"&",
"buf",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"bs",
"=",
"buf",
".",
"Bytes",
"(",
")",
"\n",
"}",
"else",
"{",
"// ScssSyntax",
"bs",
",",
"err",
"=",
"ioutil",
".",
"ReadAll",
"(",
"in",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"}",
"\n\n",
"if",
"len",
"(",
"bs",
")",
"==",
"0",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"godc",
":=",
"libs",
".",
"SassMakeDataContext",
"(",
"string",
"(",
"bs",
")",
")",
"\n",
"goopts",
":=",
"libs",
".",
"SassDataContextGetOptions",
"(",
"godc",
")",
"\n",
"libs",
".",
"SassOptionSetSourceComments",
"(",
"goopts",
",",
"true",
")",
"\n\n",
"ctx",
".",
"Init",
"(",
"goopts",
")",
"\n\n",
"libs",
".",
"SassDataContextSetOptions",
"(",
"godc",
",",
"goopts",
")",
"\n",
"goctx",
":=",
"libs",
".",
"SassDataContextGetContext",
"(",
"godc",
")",
"\n",
"ctx",
".",
"context",
"=",
"goctx",
"\n",
"gocompiler",
":=",
"libs",
".",
"SassMakeDataCompiler",
"(",
"godc",
")",
"\n",
"libs",
".",
"SassCompilerParse",
"(",
"gocompiler",
")",
"\n",
"libs",
".",
"SassCompilerExecute",
"(",
"gocompiler",
")",
"\n",
"defer",
"libs",
".",
"SassDeleteCompiler",
"(",
"gocompiler",
")",
"\n\n",
"goout",
":=",
"libs",
".",
"SassContextGetOutputString",
"(",
"goctx",
")",
"\n",
"io",
".",
"WriteString",
"(",
"out",
",",
"goout",
")",
"\n\n",
"ctx",
".",
"Status",
"=",
"libs",
".",
"SassContextGetErrorStatus",
"(",
"goctx",
")",
"\n",
"errJSON",
":=",
"libs",
".",
"SassContextGetErrorJSON",
"(",
"goctx",
")",
"\n",
"err",
"=",
"ctx",
".",
"ProcessSassError",
"(",
"[",
"]",
"byte",
"(",
"errJSON",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"if",
"ctx",
".",
"Error",
"(",
")",
"!=",
"\"",
"\"",
"{",
"lines",
":=",
"bytes",
".",
"Split",
"(",
"bs",
",",
"[",
"]",
"byte",
"(",
"\"",
"\\n",
"\"",
")",
")",
"\n",
"var",
"out",
"string",
"\n",
"for",
"i",
":=",
"-",
"7",
";",
"i",
"<",
"7",
";",
"i",
"++",
"{",
"if",
"i",
"+",
"ctx",
".",
"err",
".",
"Line",
">=",
"0",
"&&",
"i",
"+",
"ctx",
".",
"err",
".",
"Line",
"<",
"len",
"(",
"lines",
")",
"{",
"out",
"+=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\\n",
"\"",
",",
"string",
"(",
"lines",
"[",
"i",
"+",
"ctx",
".",
"err",
".",
"Line",
"]",
")",
")",
"\n",
"}",
"\n",
"}",
"\n",
"// TODO: this is weird, make something more idiomatic",
"return",
"errors",
".",
"New",
"(",
"ctx",
".",
"Error",
"(",
")",
"+",
"\"",
"\\n",
"\"",
"+",
"out",
")",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
] |
// compile reads in and writes the libsass compiled result to out.
// Options and custom functions are applied as specified in Context.
|
[
"compile",
"reads",
"in",
"and",
"writes",
"the",
"libsass",
"compiled",
"result",
"to",
"out",
".",
"Options",
"and",
"custom",
"functions",
"are",
"applied",
"as",
"specified",
"in",
"Context",
"."
] |
f870eaa15594bb64b1908df39d0812704f0ceb8f
|
https://github.com/wellington/go-libsass/blob/f870eaa15594bb64b1908df39d0812704f0ceb8f/context.go#L201-L268
|
15,649 |
wellington/go-libsass
|
context.go
|
RelativeImage
|
func (p *compctx) RelativeImage() string {
rel, _ := filepath.Rel(p.BuildDir, p.ImageDir)
return filepath.ToSlash(filepath.Clean(rel))
}
|
go
|
func (p *compctx) RelativeImage() string {
rel, _ := filepath.Rel(p.BuildDir, p.ImageDir)
return filepath.ToSlash(filepath.Clean(rel))
}
|
[
"func",
"(",
"p",
"*",
"compctx",
")",
"RelativeImage",
"(",
")",
"string",
"{",
"rel",
",",
"_",
":=",
"filepath",
".",
"Rel",
"(",
"p",
".",
"BuildDir",
",",
"p",
".",
"ImageDir",
")",
"\n",
"return",
"filepath",
".",
"ToSlash",
"(",
"filepath",
".",
"Clean",
"(",
"rel",
")",
")",
"\n",
"}"
] |
// Rel creates relative paths between the build directory where the CSS lives
// and the image directory that is being linked. This is not compatible
// with generated images like sprites.
|
[
"Rel",
"creates",
"relative",
"paths",
"between",
"the",
"build",
"directory",
"where",
"the",
"CSS",
"lives",
"and",
"the",
"image",
"directory",
"that",
"is",
"being",
"linked",
".",
"This",
"is",
"not",
"compatible",
"with",
"generated",
"images",
"like",
"sprites",
"."
] |
f870eaa15594bb64b1908df39d0812704f0ceb8f
|
https://github.com/wellington/go-libsass/blob/f870eaa15594bb64b1908df39d0812704f0ceb8f/context.go#L273-L276
|
15,650 |
wellington/go-libsass
|
export.go
|
Error
|
func Error(err error) SassValue {
return SassValue{value: libs.MakeError(err.Error())}
}
|
go
|
func Error(err error) SassValue {
return SassValue{value: libs.MakeError(err.Error())}
}
|
[
"func",
"Error",
"(",
"err",
"error",
")",
"SassValue",
"{",
"return",
"SassValue",
"{",
"value",
":",
"libs",
".",
"MakeError",
"(",
"err",
".",
"Error",
"(",
")",
")",
"}",
"\n",
"}"
] |
// Error takes a Go error and returns a libsass Error
|
[
"Error",
"takes",
"a",
"Go",
"error",
"and",
"returns",
"a",
"libsass",
"Error"
] |
f870eaa15594bb64b1908df39d0812704f0ceb8f
|
https://github.com/wellington/go-libsass/blob/f870eaa15594bb64b1908df39d0812704f0ceb8f/export.go#L6-L8
|
15,651 |
wellington/go-libsass
|
libs/export.go
|
GoBridge
|
func GoBridge(cargs UnionSassValue, cidx C.int) UnionSassValue {
// Recover the Cookie struct passed in
idx := int(cidx)
ck, ok := globalFuncs.Get(idx).(Cookie)
if !ok {
fmt.Printf("failed to resolve Cookie %d\n", idx)
return MakeNil()
}
// ck := *(*Cookie)(ptr)
var usv UnionSassValue
err := ck.Fn(ck.Ctx, cargs, &usv)
_ = err
return usv
}
|
go
|
func GoBridge(cargs UnionSassValue, cidx C.int) UnionSassValue {
// Recover the Cookie struct passed in
idx := int(cidx)
ck, ok := globalFuncs.Get(idx).(Cookie)
if !ok {
fmt.Printf("failed to resolve Cookie %d\n", idx)
return MakeNil()
}
// ck := *(*Cookie)(ptr)
var usv UnionSassValue
err := ck.Fn(ck.Ctx, cargs, &usv)
_ = err
return usv
}
|
[
"func",
"GoBridge",
"(",
"cargs",
"UnionSassValue",
",",
"cidx",
"C",
".",
"int",
")",
"UnionSassValue",
"{",
"// Recover the Cookie struct passed in",
"idx",
":=",
"int",
"(",
"cidx",
")",
"\n",
"ck",
",",
"ok",
":=",
"globalFuncs",
".",
"Get",
"(",
"idx",
")",
".",
"(",
"Cookie",
")",
"\n",
"if",
"!",
"ok",
"{",
"fmt",
".",
"Printf",
"(",
"\"",
"\\n",
"\"",
",",
"idx",
")",
"\n",
"return",
"MakeNil",
"(",
")",
"\n",
"}",
"\n",
"// ck := *(*Cookie)(ptr)",
"var",
"usv",
"UnionSassValue",
"\n",
"err",
":=",
"ck",
".",
"Fn",
"(",
"ck",
".",
"Ctx",
",",
"cargs",
",",
"&",
"usv",
")",
"\n",
"_",
"=",
"err",
"\n",
"return",
"usv",
"\n",
"}"
] |
// GoBridge is exported to C for linking libsass to Go. This function
// adheres to the interface provided by libsass.
//
//export GoBridge
|
[
"GoBridge",
"is",
"exported",
"to",
"C",
"for",
"linking",
"libsass",
"to",
"Go",
".",
"This",
"function",
"adheres",
"to",
"the",
"interface",
"provided",
"by",
"libsass",
".",
"export",
"GoBridge"
] |
f870eaa15594bb64b1908df39d0812704f0ceb8f
|
https://github.com/wellington/go-libsass/blob/f870eaa15594bb64b1908df39d0812704f0ceb8f/libs/export.go#L31-L45
|
15,652 |
wellington/go-libsass
|
libs/header.go
|
BindHeader
|
func BindHeader(opts SassOptions, entries []ImportEntry) int {
idx := globalHeaders.Set(entries)
// ptr := unsafe.Pointer(idx)
czero := C.double(0)
imper := C.sass_make_importer(
C.Sass_Importer_Fn(C.SassHeaders),
czero,
unsafe.Pointer(uintptr(idx)),
)
impers := C.sass_make_importer_list(1)
C.sass_importer_set_list_entry(impers, 0, imper)
C.sass_option_set_c_headers(
(*C.struct_Sass_Options)(unsafe.Pointer(opts)),
impers)
return idx
}
|
go
|
func BindHeader(opts SassOptions, entries []ImportEntry) int {
idx := globalHeaders.Set(entries)
// ptr := unsafe.Pointer(idx)
czero := C.double(0)
imper := C.sass_make_importer(
C.Sass_Importer_Fn(C.SassHeaders),
czero,
unsafe.Pointer(uintptr(idx)),
)
impers := C.sass_make_importer_list(1)
C.sass_importer_set_list_entry(impers, 0, imper)
C.sass_option_set_c_headers(
(*C.struct_Sass_Options)(unsafe.Pointer(opts)),
impers)
return idx
}
|
[
"func",
"BindHeader",
"(",
"opts",
"SassOptions",
",",
"entries",
"[",
"]",
"ImportEntry",
")",
"int",
"{",
"idx",
":=",
"globalHeaders",
".",
"Set",
"(",
"entries",
")",
"\n",
"// ptr := unsafe.Pointer(idx)",
"czero",
":=",
"C",
".",
"double",
"(",
"0",
")",
"\n",
"imper",
":=",
"C",
".",
"sass_make_importer",
"(",
"C",
".",
"Sass_Importer_Fn",
"(",
"C",
".",
"SassHeaders",
")",
",",
"czero",
",",
"unsafe",
".",
"Pointer",
"(",
"uintptr",
"(",
"idx",
")",
")",
",",
")",
"\n",
"impers",
":=",
"C",
".",
"sass_make_importer_list",
"(",
"1",
")",
"\n",
"C",
".",
"sass_importer_set_list_entry",
"(",
"impers",
",",
"0",
",",
"imper",
")",
"\n\n",
"C",
".",
"sass_option_set_c_headers",
"(",
"(",
"*",
"C",
".",
"struct_Sass_Options",
")",
"(",
"unsafe",
".",
"Pointer",
"(",
"opts",
")",
")",
",",
"impers",
")",
"\n",
"return",
"idx",
"\n",
"}"
] |
// BindHeader attaches the header to a libsass context ensuring
// gc does not delete the pointers necessary to make this happen.
|
[
"BindHeader",
"attaches",
"the",
"header",
"to",
"a",
"libsass",
"context",
"ensuring",
"gc",
"does",
"not",
"delete",
"the",
"pointers",
"necessary",
"to",
"make",
"this",
"happen",
"."
] |
f870eaa15594bb64b1908df39d0812704f0ceb8f
|
https://github.com/wellington/go-libsass/blob/f870eaa15594bb64b1908df39d0812704f0ceb8f/libs/header.go#L29-L46
|
15,653 |
wellington/go-libsass
|
libs/sass_number.go
|
Add
|
func (sn SassNumber) Add(sn2 SassNumber) SassNumber {
sn1Value, sn2Value := getConvertedUnits(sn, sn2)
return SassNumber{Value: sn1Value + sn2Value, Unit: sn.Unit}
}
|
go
|
func (sn SassNumber) Add(sn2 SassNumber) SassNumber {
sn1Value, sn2Value := getConvertedUnits(sn, sn2)
return SassNumber{Value: sn1Value + sn2Value, Unit: sn.Unit}
}
|
[
"func",
"(",
"sn",
"SassNumber",
")",
"Add",
"(",
"sn2",
"SassNumber",
")",
"SassNumber",
"{",
"sn1Value",
",",
"sn2Value",
":=",
"getConvertedUnits",
"(",
"sn",
",",
"sn2",
")",
"\n",
"return",
"SassNumber",
"{",
"Value",
":",
"sn1Value",
"+",
"sn2Value",
",",
"Unit",
":",
"sn",
".",
"Unit",
"}",
"\n",
"}"
] |
// Add sums the two numbers in the first numbers units
|
[
"Add",
"sums",
"the",
"two",
"numbers",
"in",
"the",
"first",
"numbers",
"units"
] |
f870eaa15594bb64b1908df39d0812704f0ceb8f
|
https://github.com/wellington/go-libsass/blob/f870eaa15594bb64b1908df39d0812704f0ceb8f/libs/sass_number.go#L151-L154
|
15,654 |
wellington/go-libsass
|
libs/toscss.go
|
ToScss
|
func ToScss(r io.Reader, w io.Writer) error {
bs, _ := ioutil.ReadAll(r)
in := C.CString(string(bs))
defer C.free(unsafe.Pointer(in))
chars := C.sass2scss(
// FIXME: readers would be much more efficient
in,
// SASS2SCSS_PRETTIFY_1 Egyptian brackets
C.int(1),
)
_, err := io.WriteString(w, C.GoString(chars))
return err
}
|
go
|
func ToScss(r io.Reader, w io.Writer) error {
bs, _ := ioutil.ReadAll(r)
in := C.CString(string(bs))
defer C.free(unsafe.Pointer(in))
chars := C.sass2scss(
// FIXME: readers would be much more efficient
in,
// SASS2SCSS_PRETTIFY_1 Egyptian brackets
C.int(1),
)
_, err := io.WriteString(w, C.GoString(chars))
return err
}
|
[
"func",
"ToScss",
"(",
"r",
"io",
".",
"Reader",
",",
"w",
"io",
".",
"Writer",
")",
"error",
"{",
"bs",
",",
"_",
":=",
"ioutil",
".",
"ReadAll",
"(",
"r",
")",
"\n",
"in",
":=",
"C",
".",
"CString",
"(",
"string",
"(",
"bs",
")",
")",
"\n",
"defer",
"C",
".",
"free",
"(",
"unsafe",
".",
"Pointer",
"(",
"in",
")",
")",
"\n\n",
"chars",
":=",
"C",
".",
"sass2scss",
"(",
"// FIXME: readers would be much more efficient",
"in",
",",
"// SASS2SCSS_PRETTIFY_1 Egyptian brackets",
"C",
".",
"int",
"(",
"1",
")",
",",
")",
"\n",
"_",
",",
"err",
":=",
"io",
".",
"WriteString",
"(",
"w",
",",
"C",
".",
"GoString",
"(",
"chars",
")",
")",
"\n",
"return",
"err",
"\n",
"}"
] |
// ToScss converts Sass to Scss using sass2scss. Readers and Writers are
// used, but libsass does not support streaming.
|
[
"ToScss",
"converts",
"Sass",
"to",
"Scss",
"using",
"sass2scss",
".",
"Readers",
"and",
"Writers",
"are",
"used",
"but",
"libsass",
"does",
"not",
"support",
"streaming",
"."
] |
f870eaa15594bb64b1908df39d0812704f0ceb8f
|
https://github.com/wellington/go-libsass/blob/f870eaa15594bb64b1908df39d0812704f0ceb8f/libs/toscss.go#L14-L27
|
15,655 |
wellington/go-libsass
|
encoding.go
|
Unmarshal
|
func Unmarshal(arg SassValue, v ...interface{}) error {
var err error
sv := arg.Val()
var l int
if libs.IsList(sv) {
l = libs.Len(sv)
}
if arg.Val() == nil {
return errors.New("I can't work with this. arg UnionSassValue must not be nil. - Unmarshaller")
} else if len(v) == 0 {
return errors.New("Cannot Unmarshal an empty value - Michael Scott")
} else if len(v) > 1 {
if len(v) < l { //check for optional arguements that are not passed and pad with nil
return fmt.Errorf(
"Arguments mismatch %d C arguments did not match %d",
l, len(v))
}
for i := 0; i < l; i++ {
val := libs.Index(sv, i)
err = unmarshal(SassValue{value: val}, v[i])
if err != nil {
return err
}
}
return err
} else if libs.IsList(sv) &&
getKind(v[0]) != reflect.Slice &&
l == 1 { //arg is a slice of 1 but we want back a non slice
val := libs.Index(sv, 0)
return unmarshal(SassValue{value: val}, v[0])
} else if libs.IsList(sv) &&
getKind(v[0]) == reflect.Slice &&
libs.IsList(libs.Index(sv, 0)) &&
l == 1 { //arg is a list of single list and we only want back a list so we need to unwrap
val := libs.Index(sv, 0)
return unmarshal(SassValue{value: val}, v[0])
//return unmarshal(C.sass_list_get_value(arg, C.size_t(0)), v[0])
} else {
return unmarshal(arg, v[0])
}
}
|
go
|
func Unmarshal(arg SassValue, v ...interface{}) error {
var err error
sv := arg.Val()
var l int
if libs.IsList(sv) {
l = libs.Len(sv)
}
if arg.Val() == nil {
return errors.New("I can't work with this. arg UnionSassValue must not be nil. - Unmarshaller")
} else if len(v) == 0 {
return errors.New("Cannot Unmarshal an empty value - Michael Scott")
} else if len(v) > 1 {
if len(v) < l { //check for optional arguements that are not passed and pad with nil
return fmt.Errorf(
"Arguments mismatch %d C arguments did not match %d",
l, len(v))
}
for i := 0; i < l; i++ {
val := libs.Index(sv, i)
err = unmarshal(SassValue{value: val}, v[i])
if err != nil {
return err
}
}
return err
} else if libs.IsList(sv) &&
getKind(v[0]) != reflect.Slice &&
l == 1 { //arg is a slice of 1 but we want back a non slice
val := libs.Index(sv, 0)
return unmarshal(SassValue{value: val}, v[0])
} else if libs.IsList(sv) &&
getKind(v[0]) == reflect.Slice &&
libs.IsList(libs.Index(sv, 0)) &&
l == 1 { //arg is a list of single list and we only want back a list so we need to unwrap
val := libs.Index(sv, 0)
return unmarshal(SassValue{value: val}, v[0])
//return unmarshal(C.sass_list_get_value(arg, C.size_t(0)), v[0])
} else {
return unmarshal(arg, v[0])
}
}
|
[
"func",
"Unmarshal",
"(",
"arg",
"SassValue",
",",
"v",
"...",
"interface",
"{",
"}",
")",
"error",
"{",
"var",
"err",
"error",
"\n",
"sv",
":=",
"arg",
".",
"Val",
"(",
")",
"\n",
"var",
"l",
"int",
"\n",
"if",
"libs",
".",
"IsList",
"(",
"sv",
")",
"{",
"l",
"=",
"libs",
".",
"Len",
"(",
"sv",
")",
"\n",
"}",
"\n",
"if",
"arg",
".",
"Val",
"(",
")",
"==",
"nil",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"else",
"if",
"len",
"(",
"v",
")",
"==",
"0",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"else",
"if",
"len",
"(",
"v",
")",
">",
"1",
"{",
"if",
"len",
"(",
"v",
")",
"<",
"l",
"{",
"//check for optional arguements that are not passed and pad with nil",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"l",
",",
"len",
"(",
"v",
")",
")",
"\n",
"}",
"\n",
"for",
"i",
":=",
"0",
";",
"i",
"<",
"l",
";",
"i",
"++",
"{",
"val",
":=",
"libs",
".",
"Index",
"(",
"sv",
",",
"i",
")",
"\n",
"err",
"=",
"unmarshal",
"(",
"SassValue",
"{",
"value",
":",
"val",
"}",
",",
"v",
"[",
"i",
"]",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"err",
"\n",
"}",
"else",
"if",
"libs",
".",
"IsList",
"(",
"sv",
")",
"&&",
"getKind",
"(",
"v",
"[",
"0",
"]",
")",
"!=",
"reflect",
".",
"Slice",
"&&",
"l",
"==",
"1",
"{",
"//arg is a slice of 1 but we want back a non slice",
"val",
":=",
"libs",
".",
"Index",
"(",
"sv",
",",
"0",
")",
"\n",
"return",
"unmarshal",
"(",
"SassValue",
"{",
"value",
":",
"val",
"}",
",",
"v",
"[",
"0",
"]",
")",
"\n",
"}",
"else",
"if",
"libs",
".",
"IsList",
"(",
"sv",
")",
"&&",
"getKind",
"(",
"v",
"[",
"0",
"]",
")",
"==",
"reflect",
".",
"Slice",
"&&",
"libs",
".",
"IsList",
"(",
"libs",
".",
"Index",
"(",
"sv",
",",
"0",
")",
")",
"&&",
"l",
"==",
"1",
"{",
"//arg is a list of single list and we only want back a list so we need to unwrap",
"val",
":=",
"libs",
".",
"Index",
"(",
"sv",
",",
"0",
")",
"\n",
"return",
"unmarshal",
"(",
"SassValue",
"{",
"value",
":",
"val",
"}",
",",
"v",
"[",
"0",
"]",
")",
"\n",
"//return unmarshal(C.sass_list_get_value(arg, C.size_t(0)), v[0])",
"}",
"else",
"{",
"return",
"unmarshal",
"(",
"arg",
",",
"v",
"[",
"0",
"]",
")",
"\n",
"}",
"\n",
"}"
] |
// Decode converts Sass Value to Go compatible data types.
|
[
"Decode",
"converts",
"Sass",
"Value",
"to",
"Go",
"compatible",
"data",
"types",
"."
] |
f870eaa15594bb64b1908df39d0812704f0ceb8f
|
https://github.com/wellington/go-libsass/blob/f870eaa15594bb64b1908df39d0812704f0ceb8f/encoding.go#L134-L174
|
15,656 |
wellington/go-libsass
|
encoding.go
|
makevalue
|
func makevalue(v interface{}) (SassValue, error) {
f := reflect.ValueOf(v)
var err error
switch f.Kind() {
default:
return SassValue{value: libs.MakeNil()}, nil
case reflect.Bool:
b := v.(bool)
return SassValue{value: libs.MakeBool(b)}, nil
case reflect.String:
s := v.(string)
return SassValue{value: libs.MakeString(s)}, nil
case reflect.Struct: //only SassNumber and color.RGBA are supported
if sn, ok := v.(libs.SassNumber); ok {
return SassValue{
value: libs.MakeNumber(sn.Float(), sn.UnitOf()),
}, err
} else if sc, ok := v.(color.RGBA); ok {
return SassValue{value: libs.MakeColor(sc)}, nil
} else {
err = errors.New(fmt.Sprintf("The struct type %s is unsupported for marshalling", reflect.TypeOf(v).String()))
return SassValue{value: libs.MakeNil()}, err
}
case reflect.Slice:
// Initialize the list
lst := libs.MakeList(f.Len())
for i := 0; i < f.Len(); i++ {
t, er := makevalue(f.Index(i).Interface())
if err == nil && er != nil {
err = er
}
libs.SetIndex(lst, i, t.Val())
}
return SassValue{value: lst}, err
}
}
|
go
|
func makevalue(v interface{}) (SassValue, error) {
f := reflect.ValueOf(v)
var err error
switch f.Kind() {
default:
return SassValue{value: libs.MakeNil()}, nil
case reflect.Bool:
b := v.(bool)
return SassValue{value: libs.MakeBool(b)}, nil
case reflect.String:
s := v.(string)
return SassValue{value: libs.MakeString(s)}, nil
case reflect.Struct: //only SassNumber and color.RGBA are supported
if sn, ok := v.(libs.SassNumber); ok {
return SassValue{
value: libs.MakeNumber(sn.Float(), sn.UnitOf()),
}, err
} else if sc, ok := v.(color.RGBA); ok {
return SassValue{value: libs.MakeColor(sc)}, nil
} else {
err = errors.New(fmt.Sprintf("The struct type %s is unsupported for marshalling", reflect.TypeOf(v).String()))
return SassValue{value: libs.MakeNil()}, err
}
case reflect.Slice:
// Initialize the list
lst := libs.MakeList(f.Len())
for i := 0; i < f.Len(); i++ {
t, er := makevalue(f.Index(i).Interface())
if err == nil && er != nil {
err = er
}
libs.SetIndex(lst, i, t.Val())
}
return SassValue{value: lst}, err
}
}
|
[
"func",
"makevalue",
"(",
"v",
"interface",
"{",
"}",
")",
"(",
"SassValue",
",",
"error",
")",
"{",
"f",
":=",
"reflect",
".",
"ValueOf",
"(",
"v",
")",
"\n",
"var",
"err",
"error",
"\n",
"switch",
"f",
".",
"Kind",
"(",
")",
"{",
"default",
":",
"return",
"SassValue",
"{",
"value",
":",
"libs",
".",
"MakeNil",
"(",
")",
"}",
",",
"nil",
"\n",
"case",
"reflect",
".",
"Bool",
":",
"b",
":=",
"v",
".",
"(",
"bool",
")",
"\n",
"return",
"SassValue",
"{",
"value",
":",
"libs",
".",
"MakeBool",
"(",
"b",
")",
"}",
",",
"nil",
"\n",
"case",
"reflect",
".",
"String",
":",
"s",
":=",
"v",
".",
"(",
"string",
")",
"\n",
"return",
"SassValue",
"{",
"value",
":",
"libs",
".",
"MakeString",
"(",
"s",
")",
"}",
",",
"nil",
"\n",
"case",
"reflect",
".",
"Struct",
":",
"//only SassNumber and color.RGBA are supported",
"if",
"sn",
",",
"ok",
":=",
"v",
".",
"(",
"libs",
".",
"SassNumber",
")",
";",
"ok",
"{",
"return",
"SassValue",
"{",
"value",
":",
"libs",
".",
"MakeNumber",
"(",
"sn",
".",
"Float",
"(",
")",
",",
"sn",
".",
"UnitOf",
"(",
")",
")",
",",
"}",
",",
"err",
"\n",
"}",
"else",
"if",
"sc",
",",
"ok",
":=",
"v",
".",
"(",
"color",
".",
"RGBA",
")",
";",
"ok",
"{",
"return",
"SassValue",
"{",
"value",
":",
"libs",
".",
"MakeColor",
"(",
"sc",
")",
"}",
",",
"nil",
"\n",
"}",
"else",
"{",
"err",
"=",
"errors",
".",
"New",
"(",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"reflect",
".",
"TypeOf",
"(",
"v",
")",
".",
"String",
"(",
")",
")",
")",
"\n",
"return",
"SassValue",
"{",
"value",
":",
"libs",
".",
"MakeNil",
"(",
")",
"}",
",",
"err",
"\n",
"}",
"\n",
"case",
"reflect",
".",
"Slice",
":",
"// Initialize the list",
"lst",
":=",
"libs",
".",
"MakeList",
"(",
"f",
".",
"Len",
"(",
")",
")",
"\n",
"for",
"i",
":=",
"0",
";",
"i",
"<",
"f",
".",
"Len",
"(",
")",
";",
"i",
"++",
"{",
"t",
",",
"er",
":=",
"makevalue",
"(",
"f",
".",
"Index",
"(",
"i",
")",
".",
"Interface",
"(",
")",
")",
"\n",
"if",
"err",
"==",
"nil",
"&&",
"er",
"!=",
"nil",
"{",
"err",
"=",
"er",
"\n",
"}",
"\n",
"libs",
".",
"SetIndex",
"(",
"lst",
",",
"i",
",",
"t",
".",
"Val",
"(",
")",
")",
"\n",
"}",
"\n",
"return",
"SassValue",
"{",
"value",
":",
"lst",
"}",
",",
"err",
"\n",
"}",
"\n",
"}"
] |
// make is needed to create types for use by test
|
[
"make",
"is",
"needed",
"to",
"create",
"types",
"for",
"use",
"by",
"test"
] |
f870eaa15594bb64b1908df39d0812704f0ceb8f
|
https://github.com/wellington/go-libsass/blob/f870eaa15594bb64b1908df39d0812704f0ceb8f/encoding.go#L208-L243
|
15,657 |
wellington/go-libsass
|
libs/wrap.go
|
SassMakeImporterList
|
func SassMakeImporterList(gol int) SassImporterList {
l := C.size_t(gol)
cimp := C.sass_make_importer_list(l)
return (SassImporterList)(cimp)
}
|
go
|
func SassMakeImporterList(gol int) SassImporterList {
l := C.size_t(gol)
cimp := C.sass_make_importer_list(l)
return (SassImporterList)(cimp)
}
|
[
"func",
"SassMakeImporterList",
"(",
"gol",
"int",
")",
"SassImporterList",
"{",
"l",
":=",
"C",
".",
"size_t",
"(",
"gol",
")",
"\n",
"cimp",
":=",
"C",
".",
"sass_make_importer_list",
"(",
"l",
")",
"\n",
"return",
"(",
"SassImporterList",
")",
"(",
"cimp",
")",
"\n",
"}"
] |
// SassMakeImporterList maps to C.sass_make_importer_list
|
[
"SassMakeImporterList",
"maps",
"to",
"C",
".",
"sass_make_importer_list"
] |
f870eaa15594bb64b1908df39d0812704f0ceb8f
|
https://github.com/wellington/go-libsass/blob/f870eaa15594bb64b1908df39d0812704f0ceb8f/libs/wrap.go#L26-L30
|
15,658 |
wellington/go-libsass
|
libs/wrap.go
|
ImporterBridge
|
func ImporterBridge(url *C.char, prev *C.char, cidx C.uintptr_t) C.Sass_Import_List {
var importResolver ImportResolver
// Retrieve the index
idx := int(cidx)
importResolver, ok := globalImports.Get(idx).(ImportResolver)
if !ok {
fmt.Printf("failed to resolve import handler: %d\n", idx)
}
parent := C.GoString(prev)
rel := C.GoString(url)
list := C.sass_make_import_list(1)
hdr := reflect.SliceHeader{
Data: uintptr(unsafe.Pointer(list)),
Len: 1, Cap: 1,
}
golist := *(*[]C.Sass_Import_Entry)(unsafe.Pointer(&hdr))
if importResolver != nil {
newURL, body, resolved := importResolver(rel, parent)
if resolved {
// Passing a nil as body is a signal to load the import from the URL.
var bodyv *C.char
if body != "" {
bodyv = C.CString(body)
}
ent := C.sass_make_import_entry(C.CString(newURL), bodyv, nil)
cent := (C.Sass_Import_Entry)(ent)
golist[0] = cent
return list
}
}
if strings.HasPrefix(rel, "compass") {
ent := C.sass_make_import_entry(url, C.CString(""), nil)
cent := (C.Sass_Import_Entry)(ent)
golist[0] = cent
} else {
ent := C.sass_make_import_entry(url, nil, nil)
cent := (C.Sass_Import_Entry)(ent)
golist[0] = cent
}
return list
}
|
go
|
func ImporterBridge(url *C.char, prev *C.char, cidx C.uintptr_t) C.Sass_Import_List {
var importResolver ImportResolver
// Retrieve the index
idx := int(cidx)
importResolver, ok := globalImports.Get(idx).(ImportResolver)
if !ok {
fmt.Printf("failed to resolve import handler: %d\n", idx)
}
parent := C.GoString(prev)
rel := C.GoString(url)
list := C.sass_make_import_list(1)
hdr := reflect.SliceHeader{
Data: uintptr(unsafe.Pointer(list)),
Len: 1, Cap: 1,
}
golist := *(*[]C.Sass_Import_Entry)(unsafe.Pointer(&hdr))
if importResolver != nil {
newURL, body, resolved := importResolver(rel, parent)
if resolved {
// Passing a nil as body is a signal to load the import from the URL.
var bodyv *C.char
if body != "" {
bodyv = C.CString(body)
}
ent := C.sass_make_import_entry(C.CString(newURL), bodyv, nil)
cent := (C.Sass_Import_Entry)(ent)
golist[0] = cent
return list
}
}
if strings.HasPrefix(rel, "compass") {
ent := C.sass_make_import_entry(url, C.CString(""), nil)
cent := (C.Sass_Import_Entry)(ent)
golist[0] = cent
} else {
ent := C.sass_make_import_entry(url, nil, nil)
cent := (C.Sass_Import_Entry)(ent)
golist[0] = cent
}
return list
}
|
[
"func",
"ImporterBridge",
"(",
"url",
"*",
"C",
".",
"char",
",",
"prev",
"*",
"C",
".",
"char",
",",
"cidx",
"C",
".",
"uintptr_t",
")",
"C",
".",
"Sass_Import_List",
"{",
"var",
"importResolver",
"ImportResolver",
"\n\n",
"// Retrieve the index",
"idx",
":=",
"int",
"(",
"cidx",
")",
"\n",
"importResolver",
",",
"ok",
":=",
"globalImports",
".",
"Get",
"(",
"idx",
")",
".",
"(",
"ImportResolver",
")",
"\n\n",
"if",
"!",
"ok",
"{",
"fmt",
".",
"Printf",
"(",
"\"",
"\\n",
"\"",
",",
"idx",
")",
"\n",
"}",
"\n\n",
"parent",
":=",
"C",
".",
"GoString",
"(",
"prev",
")",
"\n",
"rel",
":=",
"C",
".",
"GoString",
"(",
"url",
")",
"\n",
"list",
":=",
"C",
".",
"sass_make_import_list",
"(",
"1",
")",
"\n",
"hdr",
":=",
"reflect",
".",
"SliceHeader",
"{",
"Data",
":",
"uintptr",
"(",
"unsafe",
".",
"Pointer",
"(",
"list",
")",
")",
",",
"Len",
":",
"1",
",",
"Cap",
":",
"1",
",",
"}",
"\n\n",
"golist",
":=",
"*",
"(",
"*",
"[",
"]",
"C",
".",
"Sass_Import_Entry",
")",
"(",
"unsafe",
".",
"Pointer",
"(",
"&",
"hdr",
")",
")",
"\n\n",
"if",
"importResolver",
"!=",
"nil",
"{",
"newURL",
",",
"body",
",",
"resolved",
":=",
"importResolver",
"(",
"rel",
",",
"parent",
")",
"\n",
"if",
"resolved",
"{",
"// Passing a nil as body is a signal to load the import from the URL.",
"var",
"bodyv",
"*",
"C",
".",
"char",
"\n",
"if",
"body",
"!=",
"\"",
"\"",
"{",
"bodyv",
"=",
"C",
".",
"CString",
"(",
"body",
")",
"\n",
"}",
"\n",
"ent",
":=",
"C",
".",
"sass_make_import_entry",
"(",
"C",
".",
"CString",
"(",
"newURL",
")",
",",
"bodyv",
",",
"nil",
")",
"\n",
"cent",
":=",
"(",
"C",
".",
"Sass_Import_Entry",
")",
"(",
"ent",
")",
"\n",
"golist",
"[",
"0",
"]",
"=",
"cent",
"\n\n",
"return",
"list",
"\n",
"}",
"\n",
"}",
"\n\n",
"if",
"strings",
".",
"HasPrefix",
"(",
"rel",
",",
"\"",
"\"",
")",
"{",
"ent",
":=",
"C",
".",
"sass_make_import_entry",
"(",
"url",
",",
"C",
".",
"CString",
"(",
"\"",
"\"",
")",
",",
"nil",
")",
"\n",
"cent",
":=",
"(",
"C",
".",
"Sass_Import_Entry",
")",
"(",
"ent",
")",
"\n",
"golist",
"[",
"0",
"]",
"=",
"cent",
"\n",
"}",
"else",
"{",
"ent",
":=",
"C",
".",
"sass_make_import_entry",
"(",
"url",
",",
"nil",
",",
"nil",
")",
"\n",
"cent",
":=",
"(",
"C",
".",
"Sass_Import_Entry",
")",
"(",
"ent",
")",
"\n",
"golist",
"[",
"0",
"]",
"=",
"cent",
"\n",
"}",
"\n\n",
"return",
"list",
"\n",
"}"
] |
// ImporterBridge is called by C to pass Importer arguments into Go land. A
// Sass_Import is returned for libsass to resolve.
//
//export ImporterBridge
|
[
"ImporterBridge",
"is",
"called",
"by",
"C",
"to",
"pass",
"Importer",
"arguments",
"into",
"Go",
"land",
".",
"A",
"Sass_Import",
"is",
"returned",
"for",
"libsass",
"to",
"resolve",
".",
"export",
"ImporterBridge"
] |
f870eaa15594bb64b1908df39d0812704f0ceb8f
|
https://github.com/wellington/go-libsass/blob/f870eaa15594bb64b1908df39d0812704f0ceb8f/libs/wrap.go#L84-L132
|
15,659 |
wellington/go-libsass
|
libs/wrap.go
|
SassMakeFileContext
|
func SassMakeFileContext(gos string) SassFileContext {
s := C.CString(gos)
fctx := C.sass_make_file_context(s)
return (SassFileContext)(fctx)
}
|
go
|
func SassMakeFileContext(gos string) SassFileContext {
s := C.CString(gos)
fctx := C.sass_make_file_context(s)
return (SassFileContext)(fctx)
}
|
[
"func",
"SassMakeFileContext",
"(",
"gos",
"string",
")",
"SassFileContext",
"{",
"s",
":=",
"C",
".",
"CString",
"(",
"gos",
")",
"\n",
"fctx",
":=",
"C",
".",
"sass_make_file_context",
"(",
"s",
")",
"\n",
"return",
"(",
"SassFileContext",
")",
"(",
"fctx",
")",
"\n",
"}"
] |
// SassMakeFileContext maps to C.sass_make_file_context
|
[
"SassMakeFileContext",
"maps",
"to",
"C",
".",
"sass_make_file_context"
] |
f870eaa15594bb64b1908df39d0812704f0ceb8f
|
https://github.com/wellington/go-libsass/blob/f870eaa15594bb64b1908df39d0812704f0ceb8f/libs/wrap.go#L139-L143
|
15,660 |
wellington/go-libsass
|
libs/wrap.go
|
SassMakeDataContext
|
func SassMakeDataContext(gos string) SassDataContext {
s := C.CString(gos)
dctx := C.sass_make_data_context(s)
return (SassDataContext)(dctx)
}
|
go
|
func SassMakeDataContext(gos string) SassDataContext {
s := C.CString(gos)
dctx := C.sass_make_data_context(s)
return (SassDataContext)(dctx)
}
|
[
"func",
"SassMakeDataContext",
"(",
"gos",
"string",
")",
"SassDataContext",
"{",
"s",
":=",
"C",
".",
"CString",
"(",
"gos",
")",
"\n",
"dctx",
":=",
"C",
".",
"sass_make_data_context",
"(",
"s",
")",
"\n",
"return",
"(",
"SassDataContext",
")",
"(",
"dctx",
")",
"\n",
"}"
] |
// SassMakeDataContext creates a data context from a source string
|
[
"SassMakeDataContext",
"creates",
"a",
"data",
"context",
"from",
"a",
"source",
"string"
] |
f870eaa15594bb64b1908df39d0812704f0ceb8f
|
https://github.com/wellington/go-libsass/blob/f870eaa15594bb64b1908df39d0812704f0ceb8f/libs/wrap.go#L153-L157
|
15,661 |
wellington/go-libsass
|
libs/wrap.go
|
SassDataContextGetContext
|
func SassDataContextGetContext(godc SassDataContext) SassContext {
opts := C.sass_data_context_get_context(godc)
return (SassContext)(opts)
}
|
go
|
func SassDataContextGetContext(godc SassDataContext) SassContext {
opts := C.sass_data_context_get_context(godc)
return (SassContext)(opts)
}
|
[
"func",
"SassDataContextGetContext",
"(",
"godc",
"SassDataContext",
")",
"SassContext",
"{",
"opts",
":=",
"C",
".",
"sass_data_context_get_context",
"(",
"godc",
")",
"\n",
"return",
"(",
"SassContext",
")",
"(",
"opts",
")",
"\n",
"}"
] |
// SassDataContextGetContext returns a context from a data context.
// These are useful for calling generic methods like compiling.
|
[
"SassDataContextGetContext",
"returns",
"a",
"context",
"from",
"a",
"data",
"context",
".",
"These",
"are",
"useful",
"for",
"calling",
"generic",
"methods",
"like",
"compiling",
"."
] |
f870eaa15594bb64b1908df39d0812704f0ceb8f
|
https://github.com/wellington/go-libsass/blob/f870eaa15594bb64b1908df39d0812704f0ceb8f/libs/wrap.go#L168-L171
|
15,662 |
wellington/go-libsass
|
libs/wrap.go
|
SassFileContextGetContext
|
func SassFileContextGetContext(gofc SassFileContext) SassContext {
opts := C.sass_file_context_get_context(gofc)
return (SassContext)(opts)
}
|
go
|
func SassFileContextGetContext(gofc SassFileContext) SassContext {
opts := C.sass_file_context_get_context(gofc)
return (SassContext)(opts)
}
|
[
"func",
"SassFileContextGetContext",
"(",
"gofc",
"SassFileContext",
")",
"SassContext",
"{",
"opts",
":=",
"C",
".",
"sass_file_context_get_context",
"(",
"gofc",
")",
"\n",
"return",
"(",
"SassContext",
")",
"(",
"opts",
")",
"\n",
"}"
] |
// SassFileContextGetContext returns a context from a file context.
// These are useful for calling generic methods like compiling.
|
[
"SassFileContextGetContext",
"returns",
"a",
"context",
"from",
"a",
"file",
"context",
".",
"These",
"are",
"useful",
"for",
"calling",
"generic",
"methods",
"like",
"compiling",
"."
] |
f870eaa15594bb64b1908df39d0812704f0ceb8f
|
https://github.com/wellington/go-libsass/blob/f870eaa15594bb64b1908df39d0812704f0ceb8f/libs/wrap.go#L175-L178
|
15,663 |
wellington/go-libsass
|
libs/wrap.go
|
SassFileContextGetOptions
|
func SassFileContextGetOptions(gofc SassFileContext) SassOptions {
fcopts := C.sass_file_context_get_options(gofc)
return (SassOptions)(fcopts)
}
|
go
|
func SassFileContextGetOptions(gofc SassFileContext) SassOptions {
fcopts := C.sass_file_context_get_options(gofc)
return (SassOptions)(fcopts)
}
|
[
"func",
"SassFileContextGetOptions",
"(",
"gofc",
"SassFileContext",
")",
"SassOptions",
"{",
"fcopts",
":=",
"C",
".",
"sass_file_context_get_options",
"(",
"gofc",
")",
"\n",
"return",
"(",
"SassOptions",
")",
"(",
"fcopts",
")",
"\n",
"}"
] |
// SassFileContextGetOptions returns the sass options in a file context
|
[
"SassFileContextGetOptions",
"returns",
"the",
"sass",
"options",
"in",
"a",
"file",
"context"
] |
f870eaa15594bb64b1908df39d0812704f0ceb8f
|
https://github.com/wellington/go-libsass/blob/f870eaa15594bb64b1908df39d0812704f0ceb8f/libs/wrap.go#L190-L193
|
15,664 |
wellington/go-libsass
|
libs/wrap.go
|
SassDataContextGetOptions
|
func SassDataContextGetOptions(godc SassDataContext) SassOptions {
dcopts := C.sass_data_context_get_options(godc)
return (SassOptions)(dcopts)
}
|
go
|
func SassDataContextGetOptions(godc SassDataContext) SassOptions {
dcopts := C.sass_data_context_get_options(godc)
return (SassOptions)(dcopts)
}
|
[
"func",
"SassDataContextGetOptions",
"(",
"godc",
"SassDataContext",
")",
"SassOptions",
"{",
"dcopts",
":=",
"C",
".",
"sass_data_context_get_options",
"(",
"godc",
")",
"\n",
"return",
"(",
"SassOptions",
")",
"(",
"dcopts",
")",
"\n",
"}"
] |
// SassDataContextGetOptions returns the Sass options in a data context
|
[
"SassDataContextGetOptions",
"returns",
"the",
"Sass",
"options",
"in",
"a",
"data",
"context"
] |
f870eaa15594bb64b1908df39d0812704f0ceb8f
|
https://github.com/wellington/go-libsass/blob/f870eaa15594bb64b1908df39d0812704f0ceb8f/libs/wrap.go#L201-L204
|
15,665 |
wellington/go-libsass
|
libs/wrap.go
|
SassMakeFileCompiler
|
func SassMakeFileCompiler(gofc SassFileContext) SassCompiler {
sc := C.sass_make_file_compiler(gofc)
return (SassCompiler)(sc)
}
|
go
|
func SassMakeFileCompiler(gofc SassFileContext) SassCompiler {
sc := C.sass_make_file_compiler(gofc)
return (SassCompiler)(sc)
}
|
[
"func",
"SassMakeFileCompiler",
"(",
"gofc",
"SassFileContext",
")",
"SassCompiler",
"{",
"sc",
":=",
"C",
".",
"sass_make_file_compiler",
"(",
"gofc",
")",
"\n",
"return",
"(",
"SassCompiler",
")",
"(",
"sc",
")",
"\n",
"}"
] |
// SassMakeFileCompiler returns a compiler from a file context
|
[
"SassMakeFileCompiler",
"returns",
"a",
"compiler",
"from",
"a",
"file",
"context"
] |
f870eaa15594bb64b1908df39d0812704f0ceb8f
|
https://github.com/wellington/go-libsass/blob/f870eaa15594bb64b1908df39d0812704f0ceb8f/libs/wrap.go#L214-L217
|
15,666 |
wellington/go-libsass
|
libs/wrap.go
|
SassMakeDataCompiler
|
func SassMakeDataCompiler(godc SassDataContext) SassCompiler {
dc := C.sass_make_data_compiler(godc)
return (SassCompiler)(dc)
}
|
go
|
func SassMakeDataCompiler(godc SassDataContext) SassCompiler {
dc := C.sass_make_data_compiler(godc)
return (SassCompiler)(dc)
}
|
[
"func",
"SassMakeDataCompiler",
"(",
"godc",
"SassDataContext",
")",
"SassCompiler",
"{",
"dc",
":=",
"C",
".",
"sass_make_data_compiler",
"(",
"godc",
")",
"\n",
"return",
"(",
"SassCompiler",
")",
"(",
"dc",
")",
"\n",
"}"
] |
// SassMakeDataCompiler returns a compiler from a data context
|
[
"SassMakeDataCompiler",
"returns",
"a",
"compiler",
"from",
"a",
"data",
"context"
] |
f870eaa15594bb64b1908df39d0812704f0ceb8f
|
https://github.com/wellington/go-libsass/blob/f870eaa15594bb64b1908df39d0812704f0ceb8f/libs/wrap.go#L220-L223
|
15,667 |
wellington/go-libsass
|
libs/wrap.go
|
SassCompileFileContext
|
func SassCompileFileContext(gofc SassFileContext) int {
cstatus := C.sass_compile_file_context(gofc)
return int(cstatus)
}
|
go
|
func SassCompileFileContext(gofc SassFileContext) int {
cstatus := C.sass_compile_file_context(gofc)
return int(cstatus)
}
|
[
"func",
"SassCompileFileContext",
"(",
"gofc",
"SassFileContext",
")",
"int",
"{",
"cstatus",
":=",
"C",
".",
"sass_compile_file_context",
"(",
"gofc",
")",
"\n",
"return",
"int",
"(",
"cstatus",
")",
"\n",
"}"
] |
// SassCompileFileContext compile from file context
|
[
"SassCompileFileContext",
"compile",
"from",
"file",
"context"
] |
f870eaa15594bb64b1908df39d0812704f0ceb8f
|
https://github.com/wellington/go-libsass/blob/f870eaa15594bb64b1908df39d0812704f0ceb8f/libs/wrap.go#L226-L229
|
15,668 |
wellington/go-libsass
|
libs/wrap.go
|
SassOptionSetCHeaders
|
func SassOptionSetCHeaders(gofc SassOptions, goimp SassImporterList) {
C.sass_option_set_c_headers(gofc, C.Sass_Importer_List(goimp))
}
|
go
|
func SassOptionSetCHeaders(gofc SassOptions, goimp SassImporterList) {
C.sass_option_set_c_headers(gofc, C.Sass_Importer_List(goimp))
}
|
[
"func",
"SassOptionSetCHeaders",
"(",
"gofc",
"SassOptions",
",",
"goimp",
"SassImporterList",
")",
"{",
"C",
".",
"sass_option_set_c_headers",
"(",
"gofc",
",",
"C",
".",
"Sass_Importer_List",
"(",
"goimp",
")",
")",
"\n",
"}"
] |
// SassOptionSetCHeaders adds custom C headers to a SassOptions
|
[
"SassOptionSetCHeaders",
"adds",
"custom",
"C",
"headers",
"to",
"a",
"SassOptions"
] |
f870eaa15594bb64b1908df39d0812704f0ceb8f
|
https://github.com/wellington/go-libsass/blob/f870eaa15594bb64b1908df39d0812704f0ceb8f/libs/wrap.go#L247-L249
|
15,669 |
wellington/go-libsass
|
libs/wrap.go
|
SassContextGetOutputString
|
func SassContextGetOutputString(goctx SassContext) string {
cstr := C.sass_context_get_output_string(goctx)
defer C.free(unsafe.Pointer(cstr))
return C.GoString(cstr)
}
|
go
|
func SassContextGetOutputString(goctx SassContext) string {
cstr := C.sass_context_get_output_string(goctx)
defer C.free(unsafe.Pointer(cstr))
return C.GoString(cstr)
}
|
[
"func",
"SassContextGetOutputString",
"(",
"goctx",
"SassContext",
")",
"string",
"{",
"cstr",
":=",
"C",
".",
"sass_context_get_output_string",
"(",
"goctx",
")",
"\n",
"defer",
"C",
".",
"free",
"(",
"unsafe",
".",
"Pointer",
"(",
"cstr",
")",
")",
"\n",
"return",
"C",
".",
"GoString",
"(",
"cstr",
")",
"\n",
"}"
] |
// SassContextGetOutputString retrieves the final compiled CSS after
// compiler parses and executes.
|
[
"SassContextGetOutputString",
"retrieves",
"the",
"final",
"compiled",
"CSS",
"after",
"compiler",
"parses",
"and",
"executes",
"."
] |
f870eaa15594bb64b1908df39d0812704f0ceb8f
|
https://github.com/wellington/go-libsass/blob/f870eaa15594bb64b1908df39d0812704f0ceb8f/libs/wrap.go#L253-L257
|
15,670 |
wellington/go-libsass
|
libs/wrap.go
|
SassContextGetErrorJSON
|
func SassContextGetErrorJSON(goctx SassContext) string {
cstr := C.sass_context_get_error_json(goctx)
defer C.free(unsafe.Pointer(cstr))
return C.GoString(cstr)
}
|
go
|
func SassContextGetErrorJSON(goctx SassContext) string {
cstr := C.sass_context_get_error_json(goctx)
defer C.free(unsafe.Pointer(cstr))
return C.GoString(cstr)
}
|
[
"func",
"SassContextGetErrorJSON",
"(",
"goctx",
"SassContext",
")",
"string",
"{",
"cstr",
":=",
"C",
".",
"sass_context_get_error_json",
"(",
"goctx",
")",
"\n",
"defer",
"C",
".",
"free",
"(",
"unsafe",
".",
"Pointer",
"(",
"cstr",
")",
")",
"\n",
"return",
"C",
".",
"GoString",
"(",
"cstr",
")",
"\n",
"}"
] |
// SassContextGetErrorJSON requests an error in JSON format from libsass
|
[
"SassContextGetErrorJSON",
"requests",
"an",
"error",
"in",
"JSON",
"format",
"from",
"libsass"
] |
f870eaa15594bb64b1908df39d0812704f0ceb8f
|
https://github.com/wellington/go-libsass/blob/f870eaa15594bb64b1908df39d0812704f0ceb8f/libs/wrap.go#L260-L264
|
15,671 |
wellington/go-libsass
|
libs/wrap.go
|
SassOptionGetSourceMapFile
|
func SassOptionGetSourceMapFile(goopts SassOptions) string {
p := C.sass_option_get_source_map_file(goopts)
return C.GoString(p)
}
|
go
|
func SassOptionGetSourceMapFile(goopts SassOptions) string {
p := C.sass_option_get_source_map_file(goopts)
return C.GoString(p)
}
|
[
"func",
"SassOptionGetSourceMapFile",
"(",
"goopts",
"SassOptions",
")",
"string",
"{",
"p",
":=",
"C",
".",
"sass_option_get_source_map_file",
"(",
"goopts",
")",
"\n",
"return",
"C",
".",
"GoString",
"(",
"p",
")",
"\n",
"}"
] |
// SassOptionGetSourceMapFile retrieves the source map file
|
[
"SassOptionGetSourceMapFile",
"retrieves",
"the",
"source",
"map",
"file"
] |
f870eaa15594bb64b1908df39d0812704f0ceb8f
|
https://github.com/wellington/go-libsass/blob/f870eaa15594bb64b1908df39d0812704f0ceb8f/libs/wrap.go#L272-L275
|
15,672 |
wellington/go-libsass
|
libs/wrap.go
|
SassContextGetSourceMapString
|
func SassContextGetSourceMapString(goctx SassContext) string {
s := C.sass_context_get_source_map_string(goctx)
return C.GoString(s)
}
|
go
|
func SassContextGetSourceMapString(goctx SassContext) string {
s := C.sass_context_get_source_map_string(goctx)
return C.GoString(s)
}
|
[
"func",
"SassContextGetSourceMapString",
"(",
"goctx",
"SassContext",
")",
"string",
"{",
"s",
":=",
"C",
".",
"sass_context_get_source_map_string",
"(",
"goctx",
")",
"\n",
"return",
"C",
".",
"GoString",
"(",
"s",
")",
"\n",
"}"
] |
// SassContextGetSourceMapString retrieves the contents of a
// source map
|
[
"SassContextGetSourceMapString",
"retrieves",
"the",
"contents",
"of",
"a",
"source",
"map"
] |
f870eaa15594bb64b1908df39d0812704f0ceb8f
|
https://github.com/wellington/go-libsass/blob/f870eaa15594bb64b1908df39d0812704f0ceb8f/libs/wrap.go#L279-L282
|
15,673 |
wellington/go-libsass
|
libs/wrap.go
|
SassOptionSetPrecision
|
func SassOptionSetPrecision(goopts SassOptions, i int) {
C.sass_option_set_precision(goopts, C.int(i))
}
|
go
|
func SassOptionSetPrecision(goopts SassOptions, i int) {
C.sass_option_set_precision(goopts, C.int(i))
}
|
[
"func",
"SassOptionSetPrecision",
"(",
"goopts",
"SassOptions",
",",
"i",
"int",
")",
"{",
"C",
".",
"sass_option_set_precision",
"(",
"goopts",
",",
"C",
".",
"int",
"(",
"i",
")",
")",
"\n",
"}"
] |
// SassOptionSetPrecision sets the precision of floating point math
// ie. 3.2222px. This is currently bugged and does not work.
|
[
"SassOptionSetPrecision",
"sets",
"the",
"precision",
"of",
"floating",
"point",
"math",
"ie",
".",
"3",
".",
"2222px",
".",
"This",
"is",
"currently",
"bugged",
"and",
"does",
"not",
"work",
"."
] |
f870eaa15594bb64b1908df39d0812704f0ceb8f
|
https://github.com/wellington/go-libsass/blob/f870eaa15594bb64b1908df39d0812704f0ceb8f/libs/wrap.go#L286-L288
|
15,674 |
wellington/go-libsass
|
libs/wrap.go
|
SassOptionSetSourceComments
|
func SassOptionSetSourceComments(goopts SassOptions, b bool) {
C.sass_option_set_source_comments(goopts, C.bool(b))
}
|
go
|
func SassOptionSetSourceComments(goopts SassOptions, b bool) {
C.sass_option_set_source_comments(goopts, C.bool(b))
}
|
[
"func",
"SassOptionSetSourceComments",
"(",
"goopts",
"SassOptions",
",",
"b",
"bool",
")",
"{",
"C",
".",
"sass_option_set_source_comments",
"(",
"goopts",
",",
"C",
".",
"bool",
"(",
"b",
")",
")",
"\n",
"}"
] |
// SassOptionSetSourceComments toggles the output of line comments in CSS
|
[
"SassOptionSetSourceComments",
"toggles",
"the",
"output",
"of",
"line",
"comments",
"in",
"CSS"
] |
f870eaa15594bb64b1908df39d0812704f0ceb8f
|
https://github.com/wellington/go-libsass/blob/f870eaa15594bb64b1908df39d0812704f0ceb8f/libs/wrap.go#L296-L298
|
15,675 |
wellington/go-libsass
|
libs/wrap.go
|
SassOptionSetOutputPath
|
func SassOptionSetOutputPath(goopts SassOptions, path string) {
C.sass_option_set_output_path(goopts, C.CString(path))
}
|
go
|
func SassOptionSetOutputPath(goopts SassOptions, path string) {
C.sass_option_set_output_path(goopts, C.CString(path))
}
|
[
"func",
"SassOptionSetOutputPath",
"(",
"goopts",
"SassOptions",
",",
"path",
"string",
")",
"{",
"C",
".",
"sass_option_set_output_path",
"(",
"goopts",
",",
"C",
".",
"CString",
"(",
"path",
")",
")",
"\n",
"}"
] |
// SassOptionSetOutputPath is used for output path.
// Output path is used for source map generating. LibSass will
// not write to this file, it is just used to create
// information in source-maps etc.
|
[
"SassOptionSetOutputPath",
"is",
"used",
"for",
"output",
"path",
".",
"Output",
"path",
"is",
"used",
"for",
"source",
"map",
"generating",
".",
"LibSass",
"will",
"not",
"write",
"to",
"this",
"file",
"it",
"is",
"just",
"used",
"to",
"create",
"information",
"in",
"source",
"-",
"maps",
"etc",
"."
] |
f870eaa15594bb64b1908df39d0812704f0ceb8f
|
https://github.com/wellington/go-libsass/blob/f870eaa15594bb64b1908df39d0812704f0ceb8f/libs/wrap.go#L304-L306
|
15,676 |
wellington/go-libsass
|
libs/wrap.go
|
SassOptionSetInputPath
|
func SassOptionSetInputPath(goopts SassOptions, path string) {
C.sass_option_set_input_path(goopts, C.CString(path))
}
|
go
|
func SassOptionSetInputPath(goopts SassOptions, path string) {
C.sass_option_set_input_path(goopts, C.CString(path))
}
|
[
"func",
"SassOptionSetInputPath",
"(",
"goopts",
"SassOptions",
",",
"path",
"string",
")",
"{",
"C",
".",
"sass_option_set_input_path",
"(",
"goopts",
",",
"C",
".",
"CString",
"(",
"path",
")",
")",
"\n",
"}"
] |
// SassOptionSetInputPath is used for input path.
// The input path is used for source map generating. It can be used to define
// something with string compilation or to overload the input file path. It is
// set to "stdin" for data contexts and to the input file on file contexts.
|
[
"SassOptionSetInputPath",
"is",
"used",
"for",
"input",
"path",
".",
"The",
"input",
"path",
"is",
"used",
"for",
"source",
"map",
"generating",
".",
"It",
"can",
"be",
"used",
"to",
"define",
"something",
"with",
"string",
"compilation",
"or",
"to",
"overload",
"the",
"input",
"file",
"path",
".",
"It",
"is",
"set",
"to",
"stdin",
"for",
"data",
"contexts",
"and",
"to",
"the",
"input",
"file",
"on",
"file",
"contexts",
"."
] |
f870eaa15594bb64b1908df39d0812704f0ceb8f
|
https://github.com/wellington/go-libsass/blob/f870eaa15594bb64b1908df39d0812704f0ceb8f/libs/wrap.go#L312-L314
|
15,677 |
wellington/go-libsass
|
libs/wrap.go
|
SassOptionSetIncludePath
|
func SassOptionSetIncludePath(goopts SassOptions, path string) {
C.sass_option_set_include_path(goopts, C.CString(path))
}
|
go
|
func SassOptionSetIncludePath(goopts SassOptions, path string) {
C.sass_option_set_include_path(goopts, C.CString(path))
}
|
[
"func",
"SassOptionSetIncludePath",
"(",
"goopts",
"SassOptions",
",",
"path",
"string",
")",
"{",
"C",
".",
"sass_option_set_include_path",
"(",
"goopts",
",",
"C",
".",
"CString",
"(",
"path",
")",
")",
"\n",
"}"
] |
// SassOptionSetIncludePaths adds additional paths to look for input Sass
|
[
"SassOptionSetIncludePaths",
"adds",
"additional",
"paths",
"to",
"look",
"for",
"input",
"Sass"
] |
f870eaa15594bb64b1908df39d0812704f0ceb8f
|
https://github.com/wellington/go-libsass/blob/f870eaa15594bb64b1908df39d0812704f0ceb8f/libs/wrap.go#L317-L319
|
15,678 |
wellington/go-libsass
|
libs/wrap.go
|
SassMakeImport
|
func SassMakeImport(path string, base string, source string, srcmap string) SassImportEntry {
impent := C.sass_make_import(C.CString(path), C.CString(base),
C.CString(source), C.CString(srcmap))
return (SassImportEntry)(impent)
}
|
go
|
func SassMakeImport(path string, base string, source string, srcmap string) SassImportEntry {
impent := C.sass_make_import(C.CString(path), C.CString(base),
C.CString(source), C.CString(srcmap))
return (SassImportEntry)(impent)
}
|
[
"func",
"SassMakeImport",
"(",
"path",
"string",
",",
"base",
"string",
",",
"source",
"string",
",",
"srcmap",
"string",
")",
"SassImportEntry",
"{",
"impent",
":=",
"C",
".",
"sass_make_import",
"(",
"C",
".",
"CString",
"(",
"path",
")",
",",
"C",
".",
"CString",
"(",
"base",
")",
",",
"C",
".",
"CString",
"(",
"source",
")",
",",
"C",
".",
"CString",
"(",
"srcmap",
")",
")",
"\n",
"return",
"(",
"SassImportEntry",
")",
"(",
"impent",
")",
"\n",
"}"
] |
// SassMakeImport creates an import for overriding behavior when
// certain imports are called.
|
[
"SassMakeImport",
"creates",
"an",
"import",
"for",
"overriding",
"behavior",
"when",
"certain",
"imports",
"are",
"called",
"."
] |
f870eaa15594bb64b1908df39d0812704f0ceb8f
|
https://github.com/wellington/go-libsass/blob/f870eaa15594bb64b1908df39d0812704f0ceb8f/libs/wrap.go#L348-L352
|
15,679 |
wellington/go-libsass
|
libs/wrap.go
|
SassMakeImporter
|
func SassMakeImporter(fn SassImporterFN, priority int, v interface{}) (SassImporter, error) {
vv := reflect.ValueOf(v).Elem()
if !vv.CanAddr() {
return nil, errors.New("can not take address of")
}
// TODO: this will leak memory, the interface must be freed manually
lst := C.sass_make_importer(C.Sass_Importer_Fn(fn), C.double(priority), unsafe.Pointer(vv.Addr().Pointer()))
return (SassImporter)(lst), nil
}
|
go
|
func SassMakeImporter(fn SassImporterFN, priority int, v interface{}) (SassImporter, error) {
vv := reflect.ValueOf(v).Elem()
if !vv.CanAddr() {
return nil, errors.New("can not take address of")
}
// TODO: this will leak memory, the interface must be freed manually
lst := C.sass_make_importer(C.Sass_Importer_Fn(fn), C.double(priority), unsafe.Pointer(vv.Addr().Pointer()))
return (SassImporter)(lst), nil
}
|
[
"func",
"SassMakeImporter",
"(",
"fn",
"SassImporterFN",
",",
"priority",
"int",
",",
"v",
"interface",
"{",
"}",
")",
"(",
"SassImporter",
",",
"error",
")",
"{",
"vv",
":=",
"reflect",
".",
"ValueOf",
"(",
"v",
")",
".",
"Elem",
"(",
")",
"\n",
"if",
"!",
"vv",
".",
"CanAddr",
"(",
")",
"{",
"return",
"nil",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"// TODO: this will leak memory, the interface must be freed manually",
"lst",
":=",
"C",
".",
"sass_make_importer",
"(",
"C",
".",
"Sass_Importer_Fn",
"(",
"fn",
")",
",",
"C",
".",
"double",
"(",
"priority",
")",
",",
"unsafe",
".",
"Pointer",
"(",
"vv",
".",
"Addr",
"(",
")",
".",
"Pointer",
"(",
")",
")",
")",
"\n",
"return",
"(",
"SassImporter",
")",
"(",
"lst",
")",
",",
"nil",
"\n",
"}"
] |
// SassMakeImport attaches a Go pointer to a Sass function. Go will
// eventually kill this behavior and we should find a new way to do this.
|
[
"SassMakeImport",
"attaches",
"a",
"Go",
"pointer",
"to",
"a",
"Sass",
"function",
".",
"Go",
"will",
"eventually",
"kill",
"this",
"behavior",
"and",
"we",
"should",
"find",
"a",
"new",
"way",
"to",
"do",
"this",
"."
] |
f870eaa15594bb64b1908df39d0812704f0ceb8f
|
https://github.com/wellington/go-libsass/blob/f870eaa15594bb64b1908df39d0812704f0ceb8f/libs/wrap.go#L365-L373
|
15,680 |
wellington/go-libsass
|
libs/wrap.go
|
SassImporterSetListEntry
|
func SassImporterSetListEntry(golst SassImporterList, idx int, ent SassImporter) {
C.sass_importer_set_list_entry(C.Sass_Importer_List(golst), C.size_t(idx), C.Sass_Importer_Entry(ent))
}
|
go
|
func SassImporterSetListEntry(golst SassImporterList, idx int, ent SassImporter) {
C.sass_importer_set_list_entry(C.Sass_Importer_List(golst), C.size_t(idx), C.Sass_Importer_Entry(ent))
}
|
[
"func",
"SassImporterSetListEntry",
"(",
"golst",
"SassImporterList",
",",
"idx",
"int",
",",
"ent",
"SassImporter",
")",
"{",
"C",
".",
"sass_importer_set_list_entry",
"(",
"C",
".",
"Sass_Importer_List",
"(",
"golst",
")",
",",
"C",
".",
"size_t",
"(",
"idx",
")",
",",
"C",
".",
"Sass_Importer_Entry",
"(",
"ent",
")",
")",
"\n",
"}"
] |
// SassImporterSetListEntry updates an import list with a new entry. The
// index must exist in the importer list.
|
[
"SassImporterSetListEntry",
"updates",
"an",
"import",
"list",
"with",
"a",
"new",
"entry",
".",
"The",
"index",
"must",
"exist",
"in",
"the",
"importer",
"list",
"."
] |
f870eaa15594bb64b1908df39d0812704f0ceb8f
|
https://github.com/wellington/go-libsass/blob/f870eaa15594bb64b1908df39d0812704f0ceb8f/libs/wrap.go#L377-L379
|
15,681 |
wellington/go-libsass
|
libs/importer.go
|
BindImporter
|
func BindImporter(opts SassOptions, resolver ImportResolver) int {
idx := globalImports.Set(resolver)
ptr := unsafe.Pointer(uintptr(idx))
imper := C.sass_make_importer(
C.Sass_Importer_Fn(C.SassImporterHandler),
C.double(0),
ptr,
)
impers := C.sass_make_importer_list(1)
C.sass_importer_set_list_entry(impers, 0, imper)
C.sass_option_set_c_importers(
(*C.struct_Sass_Options)(unsafe.Pointer(opts)),
impers,
)
return idx
}
|
go
|
func BindImporter(opts SassOptions, resolver ImportResolver) int {
idx := globalImports.Set(resolver)
ptr := unsafe.Pointer(uintptr(idx))
imper := C.sass_make_importer(
C.Sass_Importer_Fn(C.SassImporterHandler),
C.double(0),
ptr,
)
impers := C.sass_make_importer_list(1)
C.sass_importer_set_list_entry(impers, 0, imper)
C.sass_option_set_c_importers(
(*C.struct_Sass_Options)(unsafe.Pointer(opts)),
impers,
)
return idx
}
|
[
"func",
"BindImporter",
"(",
"opts",
"SassOptions",
",",
"resolver",
"ImportResolver",
")",
"int",
"{",
"idx",
":=",
"globalImports",
".",
"Set",
"(",
"resolver",
")",
"\n",
"ptr",
":=",
"unsafe",
".",
"Pointer",
"(",
"uintptr",
"(",
"idx",
")",
")",
"\n\n",
"imper",
":=",
"C",
".",
"sass_make_importer",
"(",
"C",
".",
"Sass_Importer_Fn",
"(",
"C",
".",
"SassImporterHandler",
")",
",",
"C",
".",
"double",
"(",
"0",
")",
",",
"ptr",
",",
")",
"\n",
"impers",
":=",
"C",
".",
"sass_make_importer_list",
"(",
"1",
")",
"\n",
"C",
".",
"sass_importer_set_list_entry",
"(",
"impers",
",",
"0",
",",
"imper",
")",
"\n\n",
"C",
".",
"sass_option_set_c_importers",
"(",
"(",
"*",
"C",
".",
"struct_Sass_Options",
")",
"(",
"unsafe",
".",
"Pointer",
"(",
"opts",
")",
")",
",",
"impers",
",",
")",
"\n",
"return",
"idx",
"\n",
"}"
] |
// BindImporter attaches a custom importer Go function to an import in Sass
|
[
"BindImporter",
"attaches",
"a",
"custom",
"importer",
"Go",
"function",
"to",
"an",
"import",
"in",
"Sass"
] |
f870eaa15594bb64b1908df39d0812704f0ceb8f
|
https://github.com/wellington/go-libsass/blob/f870eaa15594bb64b1908df39d0812704f0ceb8f/libs/importer.go#L42-L60
|
15,682 |
wellington/go-libsass
|
error.go
|
ProcessSassError
|
func (ctx *compctx) ProcessSassError(bs []byte) error {
if len(bs) == 0 {
return nil
}
err := json.Unmarshal(bs, &ctx.err)
if err != nil {
return err
}
errors := ctx.err
ctx.errorString = fmt.Sprintf("Error > %s:%d\n%s",
errors.File, errors.Line, errors.Message)
return nil
}
|
go
|
func (ctx *compctx) ProcessSassError(bs []byte) error {
if len(bs) == 0 {
return nil
}
err := json.Unmarshal(bs, &ctx.err)
if err != nil {
return err
}
errors := ctx.err
ctx.errorString = fmt.Sprintf("Error > %s:%d\n%s",
errors.File, errors.Line, errors.Message)
return nil
}
|
[
"func",
"(",
"ctx",
"*",
"compctx",
")",
"ProcessSassError",
"(",
"bs",
"[",
"]",
"byte",
")",
"error",
"{",
"if",
"len",
"(",
"bs",
")",
"==",
"0",
"{",
"return",
"nil",
"\n",
"}",
"\n\n",
"err",
":=",
"json",
".",
"Unmarshal",
"(",
"bs",
",",
"&",
"ctx",
".",
"err",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"errors",
":=",
"ctx",
".",
"err",
"\n",
"ctx",
".",
"errorString",
"=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\\n",
"\"",
",",
"errors",
".",
"File",
",",
"errors",
".",
"Line",
",",
"errors",
".",
"Message",
")",
"\n",
"return",
"nil",
"\n",
"}"
] |
// ProcessSassError reads the original libsass error and creates helpful debuggin
// information for debuggin that error.
|
[
"ProcessSassError",
"reads",
"the",
"original",
"libsass",
"error",
"and",
"creates",
"helpful",
"debuggin",
"information",
"for",
"debuggin",
"that",
"error",
"."
] |
f870eaa15594bb64b1908df39d0812704f0ceb8f
|
https://github.com/wellington/go-libsass/blob/f870eaa15594bb64b1908df39d0812704f0ceb8f/error.go#L17-L32
|
15,683 |
proullon/ramsql
|
engine/select.go
|
getSelectFunctors
|
func getSelectFunctors(attr *parser.Decl) ([]selectFunctor, error) {
var functors []selectFunctor
for i := range attr.Decl {
if attr.Decl[i].Token == parser.FromToken {
break
}
if attr.Decl[i].Token == parser.CountToken {
f := &countSelectFunction{}
functors = append(functors, f)
}
}
if len(functors) == 0 {
f := &defaultSelectFunction{}
functors = append(functors, f)
}
return functors, nil
}
|
go
|
func getSelectFunctors(attr *parser.Decl) ([]selectFunctor, error) {
var functors []selectFunctor
for i := range attr.Decl {
if attr.Decl[i].Token == parser.FromToken {
break
}
if attr.Decl[i].Token == parser.CountToken {
f := &countSelectFunction{}
functors = append(functors, f)
}
}
if len(functors) == 0 {
f := &defaultSelectFunction{}
functors = append(functors, f)
}
return functors, nil
}
|
[
"func",
"getSelectFunctors",
"(",
"attr",
"*",
"parser",
".",
"Decl",
")",
"(",
"[",
"]",
"selectFunctor",
",",
"error",
")",
"{",
"var",
"functors",
"[",
"]",
"selectFunctor",
"\n\n",
"for",
"i",
":=",
"range",
"attr",
".",
"Decl",
"{",
"if",
"attr",
".",
"Decl",
"[",
"i",
"]",
".",
"Token",
"==",
"parser",
".",
"FromToken",
"{",
"break",
"\n",
"}",
"\n\n",
"if",
"attr",
".",
"Decl",
"[",
"i",
"]",
".",
"Token",
"==",
"parser",
".",
"CountToken",
"{",
"f",
":=",
"&",
"countSelectFunction",
"{",
"}",
"\n",
"functors",
"=",
"append",
"(",
"functors",
",",
"f",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"if",
"len",
"(",
"functors",
")",
"==",
"0",
"{",
"f",
":=",
"&",
"defaultSelectFunction",
"{",
"}",
"\n",
"functors",
"=",
"append",
"(",
"functors",
",",
"f",
")",
"\n",
"}",
"\n\n",
"return",
"functors",
",",
"nil",
"\n\n",
"}"
] |
// getSelectFunctors instanciate new functors for COUNT, MAX, MIN, AVG, ... and default select functor that return rows to client
// If a functor is specified, no attribute can be selected ?
|
[
"getSelectFunctors",
"instanciate",
"new",
"functors",
"for",
"COUNT",
"MAX",
"MIN",
"AVG",
"...",
"and",
"default",
"select",
"functor",
"that",
"return",
"rows",
"to",
"client",
"If",
"a",
"functor",
"is",
"specified",
"no",
"attribute",
"can",
"be",
"selected",
"?"
] |
817cee58a24456db9e01091be07f562703408ca3
|
https://github.com/proullon/ramsql/blob/817cee58a24456db9e01091be07f562703408ca3/engine/select.go#L169-L191
|
15,684 |
proullon/ramsql
|
engine/select.go
|
selectRows
|
func selectRows(row virtualRow, predicates []PredicateLinker, functors []selectFunctor) error {
var res bool
var err error
// If the row validate all predicates, write it
for _, predicate := range predicates {
if res, err = predicate.Eval(row); err != nil {
return err
}
if res == false {
return nil
}
}
for i := range functors {
err := functors[i].FeedVirtualRow(row)
if err != nil {
return err
}
}
return nil
}
|
go
|
func selectRows(row virtualRow, predicates []PredicateLinker, functors []selectFunctor) error {
var res bool
var err error
// If the row validate all predicates, write it
for _, predicate := range predicates {
if res, err = predicate.Eval(row); err != nil {
return err
}
if res == false {
return nil
}
}
for i := range functors {
err := functors[i].FeedVirtualRow(row)
if err != nil {
return err
}
}
return nil
}
|
[
"func",
"selectRows",
"(",
"row",
"virtualRow",
",",
"predicates",
"[",
"]",
"PredicateLinker",
",",
"functors",
"[",
"]",
"selectFunctor",
")",
"error",
"{",
"var",
"res",
"bool",
"\n",
"var",
"err",
"error",
"\n\n",
"// If the row validate all predicates, write it",
"for",
"_",
",",
"predicate",
":=",
"range",
"predicates",
"{",
"if",
"res",
",",
"err",
"=",
"predicate",
".",
"Eval",
"(",
"row",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"if",
"res",
"==",
"false",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"}",
"\n\n",
"for",
"i",
":=",
"range",
"functors",
"{",
"err",
":=",
"functors",
"[",
"i",
"]",
".",
"FeedVirtualRow",
"(",
"row",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] |
// Perform actual check of predicates present in virtualrow.
|
[
"Perform",
"actual",
"check",
"of",
"predicates",
"present",
"in",
"virtualrow",
"."
] |
817cee58a24456db9e01091be07f562703408ca3
|
https://github.com/proullon/ramsql/blob/817cee58a24456db9e01091be07f562703408ca3/engine/select.go#L570-L591
|
15,685 |
proullon/ramsql
|
engine/orderby.go
|
orderbyExecutor
|
func orderbyExecutor(attr *parser.Decl, tables []*Table) (selectFunctor, error) {
f := &orderbyFunctor{}
f.buffer = make(map[int64][][]string)
// first subdecl should be attribute
if len(attr.Decl) < 1 {
return nil, fmt.Errorf("ordering attribute not provided")
}
// FIXME we should find for sure the table of the attribute
if len(tables) < 1 {
return nil, fmt.Errorf("cannot guess the table of attribute %s for order", attr.Decl[0].Lexeme)
}
if len(attr.Decl[0].Decl) > 0 {
f.orderby = attr.Decl[0].Decl[0].Lexeme + "." + attr.Decl[0].Lexeme
} else {
f.orderby = tables[0].name + "." + attr.Decl[0].Lexeme
}
// if second subdecl is present, it's either asc or desc
// default is asc anyway
if len(attr.Decl) == 2 && attr.Decl[1].Token == parser.AscToken {
f.asc = true
}
log.Debug("orderbyExecutor> you must order by '%s', asc: %v\n", f.orderby, f.asc)
return f, nil
}
|
go
|
func orderbyExecutor(attr *parser.Decl, tables []*Table) (selectFunctor, error) {
f := &orderbyFunctor{}
f.buffer = make(map[int64][][]string)
// first subdecl should be attribute
if len(attr.Decl) < 1 {
return nil, fmt.Errorf("ordering attribute not provided")
}
// FIXME we should find for sure the table of the attribute
if len(tables) < 1 {
return nil, fmt.Errorf("cannot guess the table of attribute %s for order", attr.Decl[0].Lexeme)
}
if len(attr.Decl[0].Decl) > 0 {
f.orderby = attr.Decl[0].Decl[0].Lexeme + "." + attr.Decl[0].Lexeme
} else {
f.orderby = tables[0].name + "." + attr.Decl[0].Lexeme
}
// if second subdecl is present, it's either asc or desc
// default is asc anyway
if len(attr.Decl) == 2 && attr.Decl[1].Token == parser.AscToken {
f.asc = true
}
log.Debug("orderbyExecutor> you must order by '%s', asc: %v\n", f.orderby, f.asc)
return f, nil
}
|
[
"func",
"orderbyExecutor",
"(",
"attr",
"*",
"parser",
".",
"Decl",
",",
"tables",
"[",
"]",
"*",
"Table",
")",
"(",
"selectFunctor",
",",
"error",
")",
"{",
"f",
":=",
"&",
"orderbyFunctor",
"{",
"}",
"\n",
"f",
".",
"buffer",
"=",
"make",
"(",
"map",
"[",
"int64",
"]",
"[",
"]",
"[",
"]",
"string",
")",
"\n\n",
"// first subdecl should be attribute",
"if",
"len",
"(",
"attr",
".",
"Decl",
")",
"<",
"1",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"// FIXME we should find for sure the table of the attribute",
"if",
"len",
"(",
"tables",
")",
"<",
"1",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"attr",
".",
"Decl",
"[",
"0",
"]",
".",
"Lexeme",
")",
"\n",
"}",
"\n",
"if",
"len",
"(",
"attr",
".",
"Decl",
"[",
"0",
"]",
".",
"Decl",
")",
">",
"0",
"{",
"f",
".",
"orderby",
"=",
"attr",
".",
"Decl",
"[",
"0",
"]",
".",
"Decl",
"[",
"0",
"]",
".",
"Lexeme",
"+",
"\"",
"\"",
"+",
"attr",
".",
"Decl",
"[",
"0",
"]",
".",
"Lexeme",
"\n",
"}",
"else",
"{",
"f",
".",
"orderby",
"=",
"tables",
"[",
"0",
"]",
".",
"name",
"+",
"\"",
"\"",
"+",
"attr",
".",
"Decl",
"[",
"0",
"]",
".",
"Lexeme",
"\n",
"}",
"\n",
"// if second subdecl is present, it's either asc or desc",
"// default is asc anyway",
"if",
"len",
"(",
"attr",
".",
"Decl",
")",
"==",
"2",
"&&",
"attr",
".",
"Decl",
"[",
"1",
"]",
".",
"Token",
"==",
"parser",
".",
"AscToken",
"{",
"f",
".",
"asc",
"=",
"true",
"\n",
"}",
"\n\n",
"log",
".",
"Debug",
"(",
"\"",
"\\n",
"\"",
",",
"f",
".",
"orderby",
",",
"f",
".",
"asc",
")",
"\n",
"return",
"f",
",",
"nil",
"\n",
"}"
] |
// |-> order
// |-> age
// |-> desc
|
[
"|",
"-",
">",
"order",
"|",
"-",
">",
"age",
"|",
"-",
">",
"desc"
] |
817cee58a24456db9e01091be07f562703408ca3
|
https://github.com/proullon/ramsql/blob/817cee58a24456db9e01091be07f562703408ca3/engine/orderby.go#L17-L43
|
15,686 |
proullon/ramsql
|
engine/parser/parser.go
|
Stringy
|
func (d Decl) Stringy(depth int) {
indent := ""
for i := 0; i < depth; i++ {
indent = fmt.Sprintf("%s ", indent)
}
log.Debug("%s|-> %s\n", indent, d.Lexeme)
for _, subD := range d.Decl {
subD.Stringy(depth + 1)
}
}
|
go
|
func (d Decl) Stringy(depth int) {
indent := ""
for i := 0; i < depth; i++ {
indent = fmt.Sprintf("%s ", indent)
}
log.Debug("%s|-> %s\n", indent, d.Lexeme)
for _, subD := range d.Decl {
subD.Stringy(depth + 1)
}
}
|
[
"func",
"(",
"d",
"Decl",
")",
"Stringy",
"(",
"depth",
"int",
")",
"{",
"indent",
":=",
"\"",
"\"",
"\n",
"for",
"i",
":=",
"0",
";",
"i",
"<",
"depth",
";",
"i",
"++",
"{",
"indent",
"=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"indent",
")",
"\n",
"}",
"\n\n",
"log",
".",
"Debug",
"(",
"\"",
"\\n",
"\"",
",",
"indent",
",",
"d",
".",
"Lexeme",
")",
"\n",
"for",
"_",
",",
"subD",
":=",
"range",
"d",
".",
"Decl",
"{",
"subD",
".",
"Stringy",
"(",
"depth",
"+",
"1",
")",
"\n",
"}",
"\n",
"}"
] |
// Stringy prints the declaration tree in console
|
[
"Stringy",
"prints",
"the",
"declaration",
"tree",
"in",
"console"
] |
817cee58a24456db9e01091be07f562703408ca3
|
https://github.com/proullon/ramsql/blob/817cee58a24456db9e01091be07f562703408ca3/engine/parser/parser.go#L28-L38
|
15,687 |
proullon/ramsql
|
engine/parser/parser.go
|
NewDecl
|
func NewDecl(t Token) *Decl {
return &Decl{
Token: t.Token,
Lexeme: t.Lexeme,
}
}
|
go
|
func NewDecl(t Token) *Decl {
return &Decl{
Token: t.Token,
Lexeme: t.Lexeme,
}
}
|
[
"func",
"NewDecl",
"(",
"t",
"Token",
")",
"*",
"Decl",
"{",
"return",
"&",
"Decl",
"{",
"Token",
":",
"t",
".",
"Token",
",",
"Lexeme",
":",
"t",
".",
"Lexeme",
",",
"}",
"\n",
"}"
] |
// NewDecl initialize a Decl struct from a given token
|
[
"NewDecl",
"initialize",
"a",
"Decl",
"struct",
"from",
"a",
"given",
"token"
] |
817cee58a24456db9e01091be07f562703408ca3
|
https://github.com/proullon/ramsql/blob/817cee58a24456db9e01091be07f562703408ca3/engine/parser/parser.go#L53-L58
|
15,688 |
proullon/ramsql
|
engine/parser/parser.go
|
Add
|
func (d *Decl) Add(subDecl *Decl) {
d.Decl = append(d.Decl, subDecl)
}
|
go
|
func (d *Decl) Add(subDecl *Decl) {
d.Decl = append(d.Decl, subDecl)
}
|
[
"func",
"(",
"d",
"*",
"Decl",
")",
"Add",
"(",
"subDecl",
"*",
"Decl",
")",
"{",
"d",
".",
"Decl",
"=",
"append",
"(",
"d",
".",
"Decl",
",",
"subDecl",
")",
"\n",
"}"
] |
// Add creates a new leaf with given Decl
|
[
"Add",
"creates",
"a",
"new",
"leaf",
"with",
"given",
"Decl"
] |
817cee58a24456db9e01091be07f562703408ca3
|
https://github.com/proullon/ramsql/blob/817cee58a24456db9e01091be07f562703408ca3/engine/parser/parser.go#L61-L63
|
15,689 |
proullon/ramsql
|
engine/parser/parser.go
|
parseBuiltinFunc
|
func (p *parser) parseBuiltinFunc() (*Decl, error) {
var d *Decl
var err error
// COUNT(attribute)
if p.is(CountToken) {
d, err = p.consumeToken(CountToken)
if err != nil {
return nil, err
}
// Bracket
_, err = p.consumeToken(BracketOpeningToken)
if err != nil {
return nil, err
}
// Attribute
attr, err := p.parseAttribute()
if err != nil {
return nil, err
}
d.Add(attr)
// Bracket
_, err = p.consumeToken(BracketClosingToken)
if err != nil {
return nil, err
}
}
return d, nil
}
|
go
|
func (p *parser) parseBuiltinFunc() (*Decl, error) {
var d *Decl
var err error
// COUNT(attribute)
if p.is(CountToken) {
d, err = p.consumeToken(CountToken)
if err != nil {
return nil, err
}
// Bracket
_, err = p.consumeToken(BracketOpeningToken)
if err != nil {
return nil, err
}
// Attribute
attr, err := p.parseAttribute()
if err != nil {
return nil, err
}
d.Add(attr)
// Bracket
_, err = p.consumeToken(BracketClosingToken)
if err != nil {
return nil, err
}
}
return d, nil
}
|
[
"func",
"(",
"p",
"*",
"parser",
")",
"parseBuiltinFunc",
"(",
")",
"(",
"*",
"Decl",
",",
"error",
")",
"{",
"var",
"d",
"*",
"Decl",
"\n",
"var",
"err",
"error",
"\n\n",
"// COUNT(attribute)",
"if",
"p",
".",
"is",
"(",
"CountToken",
")",
"{",
"d",
",",
"err",
"=",
"p",
".",
"consumeToken",
"(",
"CountToken",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"// Bracket",
"_",
",",
"err",
"=",
"p",
".",
"consumeToken",
"(",
"BracketOpeningToken",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"// Attribute",
"attr",
",",
"err",
":=",
"p",
".",
"parseAttribute",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"d",
".",
"Add",
"(",
"attr",
")",
"\n",
"// Bracket",
"_",
",",
"err",
"=",
"p",
".",
"consumeToken",
"(",
"BracketClosingToken",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"d",
",",
"nil",
"\n",
"}"
] |
// parseBuiltinFunc looks for COUNT,MAX,MIN
|
[
"parseBuiltinFunc",
"looks",
"for",
"COUNT",
"MAX",
"MIN"
] |
817cee58a24456db9e01091be07f562703408ca3
|
https://github.com/proullon/ramsql/blob/817cee58a24456db9e01091be07f562703408ca3/engine/parser/parser.go#L419-L448
|
15,690 |
proullon/ramsql
|
engine/parser/parser.go
|
parseQuotedToken
|
func (p *parser) parseQuotedToken() (*Decl, error) {
quoted := false
quoteToken := DoubleQuoteToken
if p.is(DoubleQuoteToken) || p.is(BacktickToken){
quoted = true
quoteToken = p.cur().Token
if err := p.next(); err != nil {
return nil, err
}
}
// shoud be a StringToken here
if !p.is(StringToken) {
return nil, p.syntaxError()
}
decl := NewDecl(p.cur())
if quoted {
// Check there is a closing quote
if _, err := p.mustHaveNext(quoteToken); err != nil {
return nil, err
}
}
p.next()
return decl, nil
}
|
go
|
func (p *parser) parseQuotedToken() (*Decl, error) {
quoted := false
quoteToken := DoubleQuoteToken
if p.is(DoubleQuoteToken) || p.is(BacktickToken){
quoted = true
quoteToken = p.cur().Token
if err := p.next(); err != nil {
return nil, err
}
}
// shoud be a StringToken here
if !p.is(StringToken) {
return nil, p.syntaxError()
}
decl := NewDecl(p.cur())
if quoted {
// Check there is a closing quote
if _, err := p.mustHaveNext(quoteToken); err != nil {
return nil, err
}
}
p.next()
return decl, nil
}
|
[
"func",
"(",
"p",
"*",
"parser",
")",
"parseQuotedToken",
"(",
")",
"(",
"*",
"Decl",
",",
"error",
")",
"{",
"quoted",
":=",
"false",
"\n",
"quoteToken",
":=",
"DoubleQuoteToken",
"\n\n",
"if",
"p",
".",
"is",
"(",
"DoubleQuoteToken",
")",
"||",
"p",
".",
"is",
"(",
"BacktickToken",
")",
"{",
"quoted",
"=",
"true",
"\n",
"quoteToken",
"=",
"p",
".",
"cur",
"(",
")",
".",
"Token",
"\n",
"if",
"err",
":=",
"p",
".",
"next",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"}",
"\n\n",
"// shoud be a StringToken here",
"if",
"!",
"p",
".",
"is",
"(",
"StringToken",
")",
"{",
"return",
"nil",
",",
"p",
".",
"syntaxError",
"(",
")",
"\n",
"}",
"\n",
"decl",
":=",
"NewDecl",
"(",
"p",
".",
"cur",
"(",
")",
")",
"\n\n",
"if",
"quoted",
"{",
"// Check there is a closing quote",
"if",
"_",
",",
"err",
":=",
"p",
".",
"mustHaveNext",
"(",
"quoteToken",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"}",
"\n\n",
"p",
".",
"next",
"(",
")",
"\n",
"return",
"decl",
",",
"nil",
"\n",
"}"
] |
// parseQuotedToken parse a token of the form
// table
// "table"
|
[
"parseQuotedToken",
"parse",
"a",
"token",
"of",
"the",
"form",
"table",
"table"
] |
817cee58a24456db9e01091be07f562703408ca3
|
https://github.com/proullon/ramsql/blob/817cee58a24456db9e01091be07f562703408ca3/engine/parser/parser.go#L509-L537
|
15,691 |
proullon/ramsql
|
engine/parser/parser.go
|
parseJoin
|
func (p *parser) parseJoin() (*Decl, error) {
joinDecl, err := p.consumeToken(JoinToken)
if err != nil {
return nil, err
}
// TABLE NAME
tableDecl, err := p.parseAttribute()
if err != nil {
return nil, err
}
joinDecl.Add(tableDecl)
// ON
onDecl, err := p.consumeToken(OnToken)
if err != nil {
return nil, err
}
// onDecl := NewDecl(t)
joinDecl.Add(onDecl)
// ATTRIBUTE
leftAttributeDecl, err := p.parseAttribute()
if err != nil {
return nil, err
}
onDecl.Add(leftAttributeDecl)
// EQUAL
equalAttr, err := p.consumeToken(EqualityToken)
if err != nil {
return nil, err
}
onDecl.Add(equalAttr)
//ATTRIBUTE
rightAttributeDecl, err := p.parseAttribute()
if err != nil {
return nil, err
}
onDecl.Add(rightAttributeDecl)
return joinDecl, nil
}
|
go
|
func (p *parser) parseJoin() (*Decl, error) {
joinDecl, err := p.consumeToken(JoinToken)
if err != nil {
return nil, err
}
// TABLE NAME
tableDecl, err := p.parseAttribute()
if err != nil {
return nil, err
}
joinDecl.Add(tableDecl)
// ON
onDecl, err := p.consumeToken(OnToken)
if err != nil {
return nil, err
}
// onDecl := NewDecl(t)
joinDecl.Add(onDecl)
// ATTRIBUTE
leftAttributeDecl, err := p.parseAttribute()
if err != nil {
return nil, err
}
onDecl.Add(leftAttributeDecl)
// EQUAL
equalAttr, err := p.consumeToken(EqualityToken)
if err != nil {
return nil, err
}
onDecl.Add(equalAttr)
//ATTRIBUTE
rightAttributeDecl, err := p.parseAttribute()
if err != nil {
return nil, err
}
onDecl.Add(rightAttributeDecl)
return joinDecl, nil
}
|
[
"func",
"(",
"p",
"*",
"parser",
")",
"parseJoin",
"(",
")",
"(",
"*",
"Decl",
",",
"error",
")",
"{",
"joinDecl",
",",
"err",
":=",
"p",
".",
"consumeToken",
"(",
"JoinToken",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"// TABLE NAME",
"tableDecl",
",",
"err",
":=",
"p",
".",
"parseAttribute",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"joinDecl",
".",
"Add",
"(",
"tableDecl",
")",
"\n\n",
"// ON",
"onDecl",
",",
"err",
":=",
"p",
".",
"consumeToken",
"(",
"OnToken",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"// onDecl := NewDecl(t)",
"joinDecl",
".",
"Add",
"(",
"onDecl",
")",
"\n\n",
"// ATTRIBUTE",
"leftAttributeDecl",
",",
"err",
":=",
"p",
".",
"parseAttribute",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"onDecl",
".",
"Add",
"(",
"leftAttributeDecl",
")",
"\n\n",
"// EQUAL",
"equalAttr",
",",
"err",
":=",
"p",
".",
"consumeToken",
"(",
"EqualityToken",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"onDecl",
".",
"Add",
"(",
"equalAttr",
")",
"\n\n",
"//ATTRIBUTE",
"rightAttributeDecl",
",",
"err",
":=",
"p",
".",
"parseAttribute",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"onDecl",
".",
"Add",
"(",
"rightAttributeDecl",
")",
"\n\n",
"return",
"joinDecl",
",",
"nil",
"\n",
"}"
] |
// parseJoin parses the JOIN keywords and all its condition
// JOIN user_addresses ON address.id=user_addresses.address_id
|
[
"parseJoin",
"parses",
"the",
"JOIN",
"keywords",
"and",
"all",
"its",
"condition",
"JOIN",
"user_addresses",
"ON",
"address",
".",
"id",
"=",
"user_addresses",
".",
"address_id"
] |
817cee58a24456db9e01091be07f562703408ca3
|
https://github.com/proullon/ramsql/blob/817cee58a24456db9e01091be07f562703408ca3/engine/parser/parser.go#L686-L729
|
15,692 |
proullon/ramsql
|
engine/engine.go
|
New
|
func New(endpoint protocol.EngineEndpoint) (e *Engine, err error) {
e = &Engine{
endpoint: endpoint,
}
e.stop = make(chan bool)
e.opsExecutors = map[int]executor{
parser.CreateToken: createExecutor,
parser.TableToken: createTableExecutor,
parser.SelectToken: selectExecutor,
parser.InsertToken: insertIntoTableExecutor,
parser.DeleteToken: deleteExecutor,
parser.UpdateToken: updateExecutor,
parser.IfToken: ifExecutor,
parser.NotToken: notExecutor,
parser.ExistsToken: existsExecutor,
parser.TruncateToken: truncateExecutor,
parser.DropToken: dropExecutor,
parser.GrantToken: grantExecutor,
}
e.relations = make(map[string]*Relation)
err = e.start()
if err != nil {
return nil, err
}
return
}
|
go
|
func New(endpoint protocol.EngineEndpoint) (e *Engine, err error) {
e = &Engine{
endpoint: endpoint,
}
e.stop = make(chan bool)
e.opsExecutors = map[int]executor{
parser.CreateToken: createExecutor,
parser.TableToken: createTableExecutor,
parser.SelectToken: selectExecutor,
parser.InsertToken: insertIntoTableExecutor,
parser.DeleteToken: deleteExecutor,
parser.UpdateToken: updateExecutor,
parser.IfToken: ifExecutor,
parser.NotToken: notExecutor,
parser.ExistsToken: existsExecutor,
parser.TruncateToken: truncateExecutor,
parser.DropToken: dropExecutor,
parser.GrantToken: grantExecutor,
}
e.relations = make(map[string]*Relation)
err = e.start()
if err != nil {
return nil, err
}
return
}
|
[
"func",
"New",
"(",
"endpoint",
"protocol",
".",
"EngineEndpoint",
")",
"(",
"e",
"*",
"Engine",
",",
"err",
"error",
")",
"{",
"e",
"=",
"&",
"Engine",
"{",
"endpoint",
":",
"endpoint",
",",
"}",
"\n\n",
"e",
".",
"stop",
"=",
"make",
"(",
"chan",
"bool",
")",
"\n\n",
"e",
".",
"opsExecutors",
"=",
"map",
"[",
"int",
"]",
"executor",
"{",
"parser",
".",
"CreateToken",
":",
"createExecutor",
",",
"parser",
".",
"TableToken",
":",
"createTableExecutor",
",",
"parser",
".",
"SelectToken",
":",
"selectExecutor",
",",
"parser",
".",
"InsertToken",
":",
"insertIntoTableExecutor",
",",
"parser",
".",
"DeleteToken",
":",
"deleteExecutor",
",",
"parser",
".",
"UpdateToken",
":",
"updateExecutor",
",",
"parser",
".",
"IfToken",
":",
"ifExecutor",
",",
"parser",
".",
"NotToken",
":",
"notExecutor",
",",
"parser",
".",
"ExistsToken",
":",
"existsExecutor",
",",
"parser",
".",
"TruncateToken",
":",
"truncateExecutor",
",",
"parser",
".",
"DropToken",
":",
"dropExecutor",
",",
"parser",
".",
"GrantToken",
":",
"grantExecutor",
",",
"}",
"\n\n",
"e",
".",
"relations",
"=",
"make",
"(",
"map",
"[",
"string",
"]",
"*",
"Relation",
")",
"\n\n",
"err",
"=",
"e",
".",
"start",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"\n",
"}"
] |
// New initialize a new RamSQL server
|
[
"New",
"initialize",
"a",
"new",
"RamSQL",
"server"
] |
817cee58a24456db9e01091be07f562703408ca3
|
https://github.com/proullon/ramsql/blob/817cee58a24456db9e01091be07f562703408ca3/engine/engine.go#L30-L61
|
15,693 |
proullon/ramsql
|
engine/engine.go
|
Stop
|
func (e *Engine) Stop() {
if e.stop == nil {
// already stopped
return
}
go func() {
e.stop <- true
close(e.stop)
e.stop = nil
}()
}
|
go
|
func (e *Engine) Stop() {
if e.stop == nil {
// already stopped
return
}
go func() {
e.stop <- true
close(e.stop)
e.stop = nil
}()
}
|
[
"func",
"(",
"e",
"*",
"Engine",
")",
"Stop",
"(",
")",
"{",
"if",
"e",
".",
"stop",
"==",
"nil",
"{",
"// already stopped",
"return",
"\n",
"}",
"\n",
"go",
"func",
"(",
")",
"{",
"e",
".",
"stop",
"<-",
"true",
"\n",
"close",
"(",
"e",
".",
"stop",
")",
"\n",
"e",
".",
"stop",
"=",
"nil",
"\n",
"}",
"(",
")",
"\n",
"}"
] |
// Stop shutdown the RamSQL server
|
[
"Stop",
"shutdown",
"the",
"RamSQL",
"server"
] |
817cee58a24456db9e01091be07f562703408ca3
|
https://github.com/proullon/ramsql/blob/817cee58a24456db9e01091be07f562703408ca3/engine/engine.go#L69-L79
|
15,694 |
proullon/ramsql
|
driver/result.go
|
LastInsertId
|
func (r *Result) LastInsertId() (int64, error) {
if r.err != nil {
return 0, r.err
}
return r.lastInsertedID, nil
}
|
go
|
func (r *Result) LastInsertId() (int64, error) {
if r.err != nil {
return 0, r.err
}
return r.lastInsertedID, nil
}
|
[
"func",
"(",
"r",
"*",
"Result",
")",
"LastInsertId",
"(",
")",
"(",
"int64",
",",
"error",
")",
"{",
"if",
"r",
".",
"err",
"!=",
"nil",
"{",
"return",
"0",
",",
"r",
".",
"err",
"\n",
"}",
"\n",
"return",
"r",
".",
"lastInsertedID",
",",
"nil",
"\n",
"}"
] |
// LastInsertId returns the database's auto-generated ID
// after, for example, an INSERT into a table with primary
// key.
|
[
"LastInsertId",
"returns",
"the",
"database",
"s",
"auto",
"-",
"generated",
"ID",
"after",
"for",
"example",
"an",
"INSERT",
"into",
"a",
"table",
"with",
"primary",
"key",
"."
] |
817cee58a24456db9e01091be07f562703408ca3
|
https://github.com/proullon/ramsql/blob/817cee58a24456db9e01091be07f562703408ca3/driver/result.go#L22-L27
|
15,695 |
proullon/ramsql
|
driver/result.go
|
RowsAffected
|
func (r *Result) RowsAffected() (int64, error) {
if r.err != nil {
return 0, r.err
}
return r.rowsAffected, nil
}
|
go
|
func (r *Result) RowsAffected() (int64, error) {
if r.err != nil {
return 0, r.err
}
return r.rowsAffected, nil
}
|
[
"func",
"(",
"r",
"*",
"Result",
")",
"RowsAffected",
"(",
")",
"(",
"int64",
",",
"error",
")",
"{",
"if",
"r",
".",
"err",
"!=",
"nil",
"{",
"return",
"0",
",",
"r",
".",
"err",
"\n",
"}",
"\n",
"return",
"r",
".",
"rowsAffected",
",",
"nil",
"\n",
"}"
] |
// RowsAffected returns the number of rows affected by the
// query.
|
[
"RowsAffected",
"returns",
"the",
"number",
"of",
"rows",
"affected",
"by",
"the",
"query",
"."
] |
817cee58a24456db9e01091be07f562703408ca3
|
https://github.com/proullon/ramsql/blob/817cee58a24456db9e01091be07f562703408ca3/driver/result.go#L31-L36
|
15,696 |
proullon/ramsql
|
engine/tuple.go
|
NewTuple
|
func NewTuple(values ...interface{}) *Tuple {
t := &Tuple{}
for _, v := range values {
t.Values = append(t.Values, v)
}
return t
}
|
go
|
func NewTuple(values ...interface{}) *Tuple {
t := &Tuple{}
for _, v := range values {
t.Values = append(t.Values, v)
}
return t
}
|
[
"func",
"NewTuple",
"(",
"values",
"...",
"interface",
"{",
"}",
")",
"*",
"Tuple",
"{",
"t",
":=",
"&",
"Tuple",
"{",
"}",
"\n\n",
"for",
"_",
",",
"v",
":=",
"range",
"values",
"{",
"t",
".",
"Values",
"=",
"append",
"(",
"t",
".",
"Values",
",",
"v",
")",
"\n",
"}",
"\n",
"return",
"t",
"\n",
"}"
] |
// NewTuple should check that value are for the right Attribute and match domain
|
[
"NewTuple",
"should",
"check",
"that",
"value",
"are",
"for",
"the",
"right",
"Attribute",
"and",
"match",
"domain"
] |
817cee58a24456db9e01091be07f562703408ca3
|
https://github.com/proullon/ramsql/blob/817cee58a24456db9e01091be07f562703408ca3/engine/tuple.go#L9-L16
|
15,697 |
proullon/ramsql
|
engine/tuple.go
|
Append
|
func (t *Tuple) Append(value interface{}) {
t.Values = append(t.Values, value)
}
|
go
|
func (t *Tuple) Append(value interface{}) {
t.Values = append(t.Values, value)
}
|
[
"func",
"(",
"t",
"*",
"Tuple",
")",
"Append",
"(",
"value",
"interface",
"{",
"}",
")",
"{",
"t",
".",
"Values",
"=",
"append",
"(",
"t",
".",
"Values",
",",
"value",
")",
"\n",
"}"
] |
// Append add a value to the tuple
|
[
"Append",
"add",
"a",
"value",
"to",
"the",
"tuple"
] |
817cee58a24456db9e01091be07f562703408ca3
|
https://github.com/proullon/ramsql/blob/817cee58a24456db9e01091be07f562703408ca3/engine/tuple.go#L19-L21
|
15,698 |
proullon/ramsql
|
engine/join.go
|
generateVirtualRows
|
func generateVirtualRows(e *Engine, attr []Attribute, conn protocol.EngineConn, t1Name string, joinPredicates []joiner, selectPredicates []PredicateLinker, functors []selectFunctor) error {
// get t1 and lock it
t1 := e.relation(t1Name)
if t1 == nil {
return fmt.Errorf("table %s not found", t1Name)
}
t1.RLock()
defer t1.RUnlock()
// all joined tables in a map of relation
relations := make(map[string]*Relation)
for _, j := range joinPredicates {
r := e.relation(j.On())
if r == nil {
return fmt.Errorf("table %s not found", j.On())
}
r.RLock()
defer r.RUnlock()
relations[j.On()] = r
}
// Write header
var header []string
var alias []string
for _, a := range attr {
alias = append(alias, a.name)
if strings.Contains(a.name, ".") == false {
a.name = t1Name + "." + a.name
}
header = append(header, a.name)
}
// Initialize functors here
for i := range functors {
if err := functors[i].Init(e, conn, header, alias); err != nil {
return err
}
}
// for each row in t1
for i := range t1.rows {
// create virtualrow
row := make(virtualRow)
for index := range t1.rows[i].Values {
v := Value{
v: t1.rows[i].Values[index],
valid: true,
lexeme: t1.table.attributes[index].name,
table: t1Name,
}
row[v.table+"."+v.lexeme] = v
}
// for first join predicates
err := join(row, relations, joinPredicates, 0, selectPredicates, functors)
if err != nil {
return err
}
}
for i := range functors {
err := functors[i].Done()
if err != nil {
return err
}
}
return nil
}
|
go
|
func generateVirtualRows(e *Engine, attr []Attribute, conn protocol.EngineConn, t1Name string, joinPredicates []joiner, selectPredicates []PredicateLinker, functors []selectFunctor) error {
// get t1 and lock it
t1 := e.relation(t1Name)
if t1 == nil {
return fmt.Errorf("table %s not found", t1Name)
}
t1.RLock()
defer t1.RUnlock()
// all joined tables in a map of relation
relations := make(map[string]*Relation)
for _, j := range joinPredicates {
r := e.relation(j.On())
if r == nil {
return fmt.Errorf("table %s not found", j.On())
}
r.RLock()
defer r.RUnlock()
relations[j.On()] = r
}
// Write header
var header []string
var alias []string
for _, a := range attr {
alias = append(alias, a.name)
if strings.Contains(a.name, ".") == false {
a.name = t1Name + "." + a.name
}
header = append(header, a.name)
}
// Initialize functors here
for i := range functors {
if err := functors[i].Init(e, conn, header, alias); err != nil {
return err
}
}
// for each row in t1
for i := range t1.rows {
// create virtualrow
row := make(virtualRow)
for index := range t1.rows[i].Values {
v := Value{
v: t1.rows[i].Values[index],
valid: true,
lexeme: t1.table.attributes[index].name,
table: t1Name,
}
row[v.table+"."+v.lexeme] = v
}
// for first join predicates
err := join(row, relations, joinPredicates, 0, selectPredicates, functors)
if err != nil {
return err
}
}
for i := range functors {
err := functors[i].Done()
if err != nil {
return err
}
}
return nil
}
|
[
"func",
"generateVirtualRows",
"(",
"e",
"*",
"Engine",
",",
"attr",
"[",
"]",
"Attribute",
",",
"conn",
"protocol",
".",
"EngineConn",
",",
"t1Name",
"string",
",",
"joinPredicates",
"[",
"]",
"joiner",
",",
"selectPredicates",
"[",
"]",
"PredicateLinker",
",",
"functors",
"[",
"]",
"selectFunctor",
")",
"error",
"{",
"// get t1 and lock it",
"t1",
":=",
"e",
".",
"relation",
"(",
"t1Name",
")",
"\n",
"if",
"t1",
"==",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"t1Name",
")",
"\n",
"}",
"\n",
"t1",
".",
"RLock",
"(",
")",
"\n",
"defer",
"t1",
".",
"RUnlock",
"(",
")",
"\n\n",
"// all joined tables in a map of relation",
"relations",
":=",
"make",
"(",
"map",
"[",
"string",
"]",
"*",
"Relation",
")",
"\n",
"for",
"_",
",",
"j",
":=",
"range",
"joinPredicates",
"{",
"r",
":=",
"e",
".",
"relation",
"(",
"j",
".",
"On",
"(",
")",
")",
"\n",
"if",
"r",
"==",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"j",
".",
"On",
"(",
")",
")",
"\n",
"}",
"\n",
"r",
".",
"RLock",
"(",
")",
"\n",
"defer",
"r",
".",
"RUnlock",
"(",
")",
"\n",
"relations",
"[",
"j",
".",
"On",
"(",
")",
"]",
"=",
"r",
"\n",
"}",
"\n\n",
"// Write header",
"var",
"header",
"[",
"]",
"string",
"\n",
"var",
"alias",
"[",
"]",
"string",
"\n",
"for",
"_",
",",
"a",
":=",
"range",
"attr",
"{",
"alias",
"=",
"append",
"(",
"alias",
",",
"a",
".",
"name",
")",
"\n",
"if",
"strings",
".",
"Contains",
"(",
"a",
".",
"name",
",",
"\"",
"\"",
")",
"==",
"false",
"{",
"a",
".",
"name",
"=",
"t1Name",
"+",
"\"",
"\"",
"+",
"a",
".",
"name",
"\n",
"}",
"\n",
"header",
"=",
"append",
"(",
"header",
",",
"a",
".",
"name",
")",
"\n",
"}",
"\n\n",
"// Initialize functors here",
"for",
"i",
":=",
"range",
"functors",
"{",
"if",
"err",
":=",
"functors",
"[",
"i",
"]",
".",
"Init",
"(",
"e",
",",
"conn",
",",
"header",
",",
"alias",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"}",
"\n\n",
"// for each row in t1",
"for",
"i",
":=",
"range",
"t1",
".",
"rows",
"{",
"// create virtualrow",
"row",
":=",
"make",
"(",
"virtualRow",
")",
"\n",
"for",
"index",
":=",
"range",
"t1",
".",
"rows",
"[",
"i",
"]",
".",
"Values",
"{",
"v",
":=",
"Value",
"{",
"v",
":",
"t1",
".",
"rows",
"[",
"i",
"]",
".",
"Values",
"[",
"index",
"]",
",",
"valid",
":",
"true",
",",
"lexeme",
":",
"t1",
".",
"table",
".",
"attributes",
"[",
"index",
"]",
".",
"name",
",",
"table",
":",
"t1Name",
",",
"}",
"\n",
"row",
"[",
"v",
".",
"table",
"+",
"\"",
"\"",
"+",
"v",
".",
"lexeme",
"]",
"=",
"v",
"\n",
"}",
"\n\n",
"// for first join predicates",
"err",
":=",
"join",
"(",
"row",
",",
"relations",
",",
"joinPredicates",
",",
"0",
",",
"selectPredicates",
",",
"functors",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"}",
"\n\n",
"for",
"i",
":=",
"range",
"functors",
"{",
"err",
":=",
"functors",
"[",
"i",
"]",
".",
"Done",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] |
// The optional WHERE, GROUP BY, and HAVING clauses in the table expression specify a pipeline of successive transformations performed on the table derived in the FROM clause.
// All these transformations produce a virtual table that provides the rows that are passed to the select list to compute the output rows of the query.
|
[
"The",
"optional",
"WHERE",
"GROUP",
"BY",
"and",
"HAVING",
"clauses",
"in",
"the",
"table",
"expression",
"specify",
"a",
"pipeline",
"of",
"successive",
"transformations",
"performed",
"on",
"the",
"table",
"derived",
"in",
"the",
"FROM",
"clause",
".",
"All",
"these",
"transformations",
"produce",
"a",
"virtual",
"table",
"that",
"provides",
"the",
"rows",
"that",
"are",
"passed",
"to",
"the",
"select",
"list",
"to",
"compute",
"the",
"output",
"rows",
"of",
"the",
"query",
"."
] |
817cee58a24456db9e01091be07f562703408ca3
|
https://github.com/proullon/ramsql/blob/817cee58a24456db9e01091be07f562703408ca3/engine/join.go#L92-L161
|
15,699 |
proullon/ramsql
|
engine/join.go
|
join
|
func join(row virtualRow, relations map[string]*Relation, predicates []joiner, predicateIndex int, selectPredicates []PredicateLinker, functors []selectFunctor) error {
// Skip directly to selectRows if there is no joiner to run
if len(predicates) == 0 {
return selectRows(row, selectPredicates, functors)
}
// get current predicates
predicate := predicates[predicateIndex]
// last := is it last join ?
last := false
if predicateIndex >= len(predicates)-1 {
last = true
}
// for each row in relations[pred.Table()]
r := relations[predicate.On()]
for i := range r.rows {
ok, err := predicate.Evaluate(row, r, i)
if err != nil {
return err
}
// if predicate not ok
if !ok {
continue
}
// combine columns to existing virtual row
for index := range r.rows[i].Values {
v := Value{
v: r.rows[i].Values[index],
valid: true,
lexeme: r.table.attributes[index].name,
table: r.table.name,
}
row[v.table+"."+v.lexeme] = v
}
// if last predicate
if last {
err = selectRows(row, selectPredicates, functors)
} else {
err = join(row, relations, predicates, predicateIndex+1, selectPredicates, functors)
}
if err != nil {
return err
}
}
return nil
}
|
go
|
func join(row virtualRow, relations map[string]*Relation, predicates []joiner, predicateIndex int, selectPredicates []PredicateLinker, functors []selectFunctor) error {
// Skip directly to selectRows if there is no joiner to run
if len(predicates) == 0 {
return selectRows(row, selectPredicates, functors)
}
// get current predicates
predicate := predicates[predicateIndex]
// last := is it last join ?
last := false
if predicateIndex >= len(predicates)-1 {
last = true
}
// for each row in relations[pred.Table()]
r := relations[predicate.On()]
for i := range r.rows {
ok, err := predicate.Evaluate(row, r, i)
if err != nil {
return err
}
// if predicate not ok
if !ok {
continue
}
// combine columns to existing virtual row
for index := range r.rows[i].Values {
v := Value{
v: r.rows[i].Values[index],
valid: true,
lexeme: r.table.attributes[index].name,
table: r.table.name,
}
row[v.table+"."+v.lexeme] = v
}
// if last predicate
if last {
err = selectRows(row, selectPredicates, functors)
} else {
err = join(row, relations, predicates, predicateIndex+1, selectPredicates, functors)
}
if err != nil {
return err
}
}
return nil
}
|
[
"func",
"join",
"(",
"row",
"virtualRow",
",",
"relations",
"map",
"[",
"string",
"]",
"*",
"Relation",
",",
"predicates",
"[",
"]",
"joiner",
",",
"predicateIndex",
"int",
",",
"selectPredicates",
"[",
"]",
"PredicateLinker",
",",
"functors",
"[",
"]",
"selectFunctor",
")",
"error",
"{",
"// Skip directly to selectRows if there is no joiner to run",
"if",
"len",
"(",
"predicates",
")",
"==",
"0",
"{",
"return",
"selectRows",
"(",
"row",
",",
"selectPredicates",
",",
"functors",
")",
"\n",
"}",
"\n\n",
"// get current predicates",
"predicate",
":=",
"predicates",
"[",
"predicateIndex",
"]",
"\n\n",
"// last := is it last join ?",
"last",
":=",
"false",
"\n",
"if",
"predicateIndex",
">=",
"len",
"(",
"predicates",
")",
"-",
"1",
"{",
"last",
"=",
"true",
"\n",
"}",
"\n\n",
"// for each row in relations[pred.Table()]",
"r",
":=",
"relations",
"[",
"predicate",
".",
"On",
"(",
")",
"]",
"\n",
"for",
"i",
":=",
"range",
"r",
".",
"rows",
"{",
"ok",
",",
"err",
":=",
"predicate",
".",
"Evaluate",
"(",
"row",
",",
"r",
",",
"i",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"// if predicate not ok",
"if",
"!",
"ok",
"{",
"continue",
"\n",
"}",
"\n\n",
"// combine columns to existing virtual row",
"for",
"index",
":=",
"range",
"r",
".",
"rows",
"[",
"i",
"]",
".",
"Values",
"{",
"v",
":=",
"Value",
"{",
"v",
":",
"r",
".",
"rows",
"[",
"i",
"]",
".",
"Values",
"[",
"index",
"]",
",",
"valid",
":",
"true",
",",
"lexeme",
":",
"r",
".",
"table",
".",
"attributes",
"[",
"index",
"]",
".",
"name",
",",
"table",
":",
"r",
".",
"table",
".",
"name",
",",
"}",
"\n",
"row",
"[",
"v",
".",
"table",
"+",
"\"",
"\"",
"+",
"v",
".",
"lexeme",
"]",
"=",
"v",
"\n",
"}",
"\n\n",
"// if last predicate",
"if",
"last",
"{",
"err",
"=",
"selectRows",
"(",
"row",
",",
"selectPredicates",
",",
"functors",
")",
"\n",
"}",
"else",
"{",
"err",
"=",
"join",
"(",
"row",
",",
"relations",
",",
"predicates",
",",
"predicateIndex",
"+",
"1",
",",
"selectPredicates",
",",
"functors",
")",
"\n",
"}",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
] |
// Recursive virtual row creation
|
[
"Recursive",
"virtual",
"row",
"creation"
] |
817cee58a24456db9e01091be07f562703408ca3
|
https://github.com/proullon/ramsql/blob/817cee58a24456db9e01091be07f562703408ca3/engine/join.go#L164-L215
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.