Skip to content

Commit

Permalink
Revert float pattern for C++.
Browse files Browse the repository at this point in the history
Fixes #290.
  • Loading branch information
alecthomas committed Oct 5, 2019
1 parent 6acfa13 commit 20b4f5f
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lexers/c/cpp.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ var CPP = internal.Register(MustNewLexer(
{`(u8|u|U)(")`, ByGroups(LiteralStringAffix, LiteralString), Push("string")},
{`(L?)(")`, ByGroups(LiteralStringAffix, LiteralString), Push("string")},
{`(L?)(')(\\.|\\[0-7]{1,3}|\\x[a-fA-F0-9]{1,2}|[^\\\'\n])(')`, ByGroups(LiteralStringAffix, LiteralStringChar, LiteralStringChar, LiteralStringChar), nil},
{`(\.([0-9](?:'?[0-9]+)*)([eE][+-]?([0-9]('?[0-9]+)*))?|([0-9]('?[0-9]+)*)(([eE][+-]?([0-9]('?[0-9]+)*))|\.([0-9]('?[0-9]+)*)?([eE][+-]?([0-9]('?[0-9]+)*))?)|0[xX](\.([0-9A-Fa-f]('?[0-9A-Fa-f]+)*)([pP][-+]?([0-9]('?[0-9]+)*))?|([0-9A-Fa-f]('?[0-9A-Fa-f]+)*)(([pP][-+]?([0-9]('?[0-9]+)*))|\.([0-9A-Fa-f]('?[0-9A-Fa-f]+)*)?([pP][-+]?([0-9]('?[0-9]+)*))?)))[fFLlUu]*`, LiteralNumberFloat, nil},
{`(\d+\.\d*|\.\d+|\d+)[eE][+-]?\d+[LlUu]*`, LiteralNumberFloat, nil},
{`(\d+\.\d*|\.\d+|\d+[fF])[fF]?`, LiteralNumberFloat, nil},
{`0[xX]([0-9A-Fa-f]('?[0-9A-Fa-f]+)*)[LlUu]*`, LiteralNumberHex, nil},
{`0('?[0-7]+)+[LlUu]*`, LiteralNumberOct, nil},
{`0[Bb][01]('?[01]+)*[LlUu]*`, LiteralNumberBin, nil},
Expand Down
27 changes: 27 additions & 0 deletions lexers/c/cpp_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package c_test

import (
"testing"

"github.com/stretchr/testify/require"

"github.com/alecthomas/chroma"
"github.com/alecthomas/chroma/lexers/c"
)

func TestIssue290(t *testing.T) {
input := `// 64-bit floats have 53 digits of precision, including the whole-number-part.
double a = 0011111110111001100110011001100110011001100110011001100110011010; // imperfect representation of 0.1
double b = 0011111111001001100110011001100110011001100110011001100110011010; // imperfect representation of 0.2
double c = 0011111111010011001100110011001100110011001100110011001100110011; // imperfect representation of 0.3
double a + b = 0011111111010011001100110011001100110011001100110011001100110100; // Note that this is not quite equal to the "canonical" 0.3!a
`
it, err := c.CPP.Tokenise(nil, input)
require.NoError(t, err)
for {
token := it()
if token == chroma.EOF {
break
}
}
}

0 comments on commit 20b4f5f

Please sign in to comment.