From 08ceeffa73652857f989d893ae56cf8f6a61d9be Mon Sep 17 00:00:00 2001 From: cornelk Date: Tue, 12 May 2020 01:34:31 +0300 Subject: [PATCH] cgo: add support for negative numeric constants in tokenizer --- cgo/const.go | 4 ++-- cgo/const_test.go | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/cgo/const.go b/cgo/const.go index c2451bc0bb..dcd9b7354a 100644 --- a/cgo/const.go +++ b/cgo/const.go @@ -131,7 +131,7 @@ func (t *tokenizer) Next() { t.value = t.buf[:1] t.buf = t.buf[1:] return - case c >= '0' && c <= '9': + case (c >= '0' && c <= '9') || c == '-': // Numeric constant (int, float, etc.). // Find the last non-numeric character. tokenLen := len(t.buf) @@ -140,7 +140,7 @@ func (t *tokenizer) Next() { if c == '.' { hasDot = true } - if c >= '0' && c <= '9' || c == '.' || c == '_' || c >= 'a' && c <= 'z' || c >= 'A' && c <= 'Z' { + if c >= '0' && c <= '9' || c == '-' || c == '.' || c == '_' || c >= 'a' && c <= 'z' || c >= 'A' && c <= 'Z' { tokenLen = i + 1 } else { break diff --git a/cgo/const_test.go b/cgo/const_test.go index cfba45079f..43f9bb708f 100644 --- a/cgo/const_test.go +++ b/cgo/const_test.go @@ -15,6 +15,7 @@ func TestParseConst(t *testing.T) { Go string }{ {`5`, `5`}, + {`-5`, `-5`}, {`(5)`, `(5)`}, {`(((5)))`, `(5)`}, {`)`, `error: 1:1: unexpected token )`},