Add the golang keywords to the set of identifier checks. · aeron-io/simple-binary-encoding@1e9a3e5 (original) (raw)

`@@ -198,4 +198,97 @@ private static boolean isJavaIdentifier(final String token)

`

198

198

``

199

199

`return true;

`

200

200

` }

`

``

201

+

``

202

`+

private static final Set GOLANG_KEYWORDS = new HashSet<>(

`

``

203

`+

Arrays.asList(new String[]

`

``

204

`+

{

`

``

205

`+

/* https://golang.org/ref/spec#Keywords */

`

``

206

`+

"break", "default", "func", "interface", "select",

`

``

207

`+

"case", "defer", "go", "map", "struct",

`

``

208

`+

"chan", "else", "goto", "package", "switch",

`

``

209

`+

"const", "fallthrough", "if", "range", "type",

`

``

210

`+

"continue", "for", "import", "return", "var",

`

``

211

+

``

212

`+

/* https://golang.org/ref/spec#Predeclared_identifiers */

`

``

213

`+

/* types */

`

``

214

`+

"bool", "byte", "complex64", "complex128", "error", "float32", "float64",

`

``

215

`+

"int", "int8", "int16", "int32", "int64", "rune", "string",

`

``

216

`+

"uint", "uint8", "uint16", "uint32", "uint64", "uintptr",

`

``

217

`+

/* constants */

`

``

218

`+

"true", "false", "iota",

`

``

219

`+

/* zero value */

`

``

220

`+

"nil",

`

``

221

`+

/* functions */

`

``

222

`+

"append", "cap", "close", "complex", "copy", "delete", "imag", "len",

`

``

223

`+

"make", "new", "panic", "print", "println", "real", "recover"

`

``

224

`+

}));

`

``

225

+

``

226

`+

/**

`

``

227

`+

`

``

228

`+

`

``

229

`+

`

``

230

`+

`

``

231

`+

`

``

232

`+

`

``

233

`+

`

``

234

`+

`

``

235

`+

`

``

236

`+

`

``

237

`+

`

``

238

`+

`

``

239

`+

*/

`

``

240

`+

public static boolean isSbeGolangName(final String value)

`

``

241

`+

{

`

``

242

`+

if (possibleGolangKeyword(value))

`

``

243

`+

{

`

``

244

`+

if (isGolangKeyword(value))

`

``

245

`+

{

`

``

246

`+

return false;

`

``

247

`+

}

`

``

248

`+

}

`

``

249

`+

else

`

``

250

`+

{

`

``

251

`+

return false;

`

``

252

`+

}

`

``

253

+

``

254

`+

return true;

`

``

255

`+

}

`

``

256

+

``

257

`+

public static boolean isGolangKeyword(final String token)

`

``

258

`+

{

`

``

259

`+

return GOLANG_KEYWORDS.contains(token);

`

``

260

`+

}

`

``

261

+

``

262

`+

private static boolean possibleGolangKeyword(final String value)

`

``

263

`+

{

`

``

264

`+

for (int i = 0, size = value.length(); i < size; i++)

`

``

265

`+

{

`

``

266

`+

final char c = value.charAt(i);

`

``

267

+

``

268

`+

if (i == 0 && isSbeGolangIdentifierStart(c))

`

``

269

`+

{

`

``

270

`+

continue;

`

``

271

`+

}

`

``

272

+

``

273

`+

if (isSbeGolangIdentifierPart(c))

`

``

274

`+

{

`

``

275

`+

continue;

`

``

276

`+

}

`

``

277

+

``

278

`+

return false;

`

``

279

`+

}

`

``

280

+

``

281

`+

return true;

`

``

282

`+

}

`

``

283

+

``

284

`+

private static boolean isSbeGolangIdentifierStart(final char c)

`

``

285

`+

{

`

``

286

`+

return Character.isLetter(c) || c == '_';

`

``

287

`+

}

`

``

288

+

``

289

`+

private static boolean isSbeGolangIdentifierPart(final char c)

`

``

290

`+

{

`

``

291

`+

return Character.isLetterOrDigit(c) || c == '_';

`

``

292

`+

}

`

``

293

+

201

294

`}

`