File: gentextiter.rb

package info (click to toggle)
golang-github-twstrike-gotk3adapter 0.0~git20170505.0.901a95d%2Bds-3
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 1,232 kB
  • sloc: ruby: 478; makefile: 4
file content (171 lines) | stat: -rwxr-xr-x 3,552 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
#!/usr/bin/env ruby

all = [
	"BackwardChar() bool",
	"BackwardChars(int) bool",
    "BackwardCursorPosition() bool",
	"BackwardCursorPositions(int) bool",
    "BackwardLine() bool",
	"BackwardLines(int) bool",
    "BackwardToTagToggle(TextTag) bool",
	"BackwardVisibleCursorPosition() bool",
    "BackwardVisibleCursorPositions(int) bool",
	"BackwardVisibleLine() bool",
    "BackwardVisibleLines(int) bool",
	"BeginsTag(TextTag) bool",
    "CanInsert(bool) bool",
	"Compare(TextIter) int",
    "Editable(bool) bool",
	"EndsLine() bool",
    "EndsSentence() bool",
	"EndsTag(TextTag) bool",
    "EndsWord() bool",
	"Equal(TextIter) bool",
    "ForwardChar() bool",
	"ForwardChars(int) bool",
    "ForwardCursorPosition() bool",
	"ForwardCursorPositions(int) bool",
    "ForwardLine() bool",
	"ForwardLines(int) bool",
    "ForwardSentenceEnd() bool",
	"ForwardSentenceEnds(int) bool",
    "ForwardToEnd()",
	"ForwardToLineEnd() bool",
    "ForwardToTagToggle(TextTag) bool",
	"ForwardVisibleCursorPosition() bool",
    "ForwardVisibleCursorPositions(int) bool",
	"ForwardVisibleLine() bool",
    "ForwardVisibleLines(int) bool",
	"ForwardVisibleWordEnd() bool",
    "ForwardVisibleWordEnds(int) bool",
	"ForwardWordEnd() bool",
    "ForwardWordEnds(int) bool",
	"GetBuffer() TextBuffer",
    "GetBytesInLine() int",
	"GetChar() rune",
    "GetCharsInLine() int",
	"GetLine() int",
    "GetLineIndex() int",
	"GetLineOffset() int",
    "GetOffset() int",
	"GetSlice(TextIter) string",
    "GetText(TextIter) string",
	"GetVisibleLineIndex() int",
    "GetVisibleLineOffset() int",
	"GetVisibleSlice(TextIter) string",
    "GetVisibleText(TextIter) string",
	"HasTag(TextTag) bool",
    "InRange(TextIter, TextIter) bool",
	"InsideSentence() bool",
    "InsideWord() bool",
	"IsCursorPosition() bool",
    "IsEnd() bool",
	"IsStart() bool",
    "SetLine(int)",
	"SetLineIndex(int)",
    "SetLineOffset(int)",
	"SetOffset(int)",
    "SetVisibleLineIndex(int)",
	"SetVisibleLineOffset(int)",
    "StartsLine() bool",
	"StartsSentence() bool",
    "StartsWord() bool",
	"TogglesTag(TextTag) bool"
]

$PRIMITIVES = {
  "bool" => true,
  "int" => true,
  "string" => true,
  "rune" => true,
}

def parse(s)
  name, args, rets = /^(.*?)\((.*?)\)(?: ?(.*?))$/.match(s).captures
  {
    name: name,
    args: args.split(", "),
    rets: rets
  }
end

def mapType(tt)
  if $PRIMITIVES[tt]
    tt
  else
    "gtki.#{tt}"
  end
end

def singleArgList(arg, ix)
  argName = "v#{ix+1}"
  argType = mapType(arg)
  "#{argName} #{argType}"
end

def unwrapType(type, name)
  "unwrap#{type}(#{name})"
end

def singleCallList(arg, ix)
  argName = "v#{ix+1}"
  if $PRIMITIVES[arg]
    "#{argName}"
  else
    unwrapType(arg, argName)
  end
end

def argList(args)
  args.map.with_index { |x, ix|
    singleArgList(x, ix)
  }.join(", ")
end

def returnList(rets)
  if rets == ""
    ""
  else
    " #{mapType(rets)}"
  end
end

def callList(args)
  args.map.with_index { |x, ix|
    singleCallList(x, ix)
  }.join(", ")
end

def potentialReturnStart(rets)
  if rets == ""
    ""
  else
    if $PRIMITIVES[rets]
      "return "
    else
      "return wrap#{rets}("
    end
  end
end

def potentialReturnEnd(rets)
  if rets == ""
    ""
  else
    if $PRIMITIVES[rets]
      ""
    else
      ")"
    end
  end
end

all.each do |xx|
  res = parse(xx)
  puts <<END
func (v *textIter) #{res[:name]}(#{argList(res[:args])})#{returnList(res[:rets])} {
	#{potentialReturnStart(res[:rets])}v.internal.#{res[:name]}(#{callList(res[:args])})#{potentialReturnEnd(res[:rets])}
}

END
end