LoadCustomTokenizer reads and loads a custom tokenizer from the given file.
(soFile string)
| 133 | |
| 134 | // LoadCustomTokenizer reads and loads a custom tokenizer from the given file. |
| 135 | func LoadCustomTokenizer(soFile string) { |
| 136 | glog.Infof("Loading custom tokenizer from %q", soFile) |
| 137 | pl, err := plugin.Open(soFile) |
| 138 | x.Checkf(err, "could not open custom tokenizer plugin file") |
| 139 | symb, err := pl.Lookup("Tokenizer") |
| 140 | x.Checkf(err, `could not find symbol "Tokenizer" while loading custom tokenizer: %v`, err) |
| 141 | |
| 142 | // Let any type assertion panics occur, since they will contain a message |
| 143 | // telling the user what went wrong. Otherwise it's hard to capture this |
| 144 | // information to pass on to the user. |
| 145 | tokenizer := symb.(func() interface{})().(PluginTokenizer) |
| 146 | |
| 147 | id := tokenizer.Identifier() |
| 148 | x.AssertTruef(id >= IdentCustom, |
| 149 | "custom tokenizer identifier byte must be >= 0x80, but was %#x", id) |
| 150 | registerTokenizer(CustomTokenizer{PluginTokenizer: tokenizer}) |
| 151 | } |
| 152 | |
| 153 | // GetTokenizerByID tries to find a tokenizer by id in the registered list. |
| 154 | // Returns the tokenizer and true if found, otherwise nil and false. |
no test coverage detected