@@ -28,6 +28,7 @@ class CodeRay::Scanners::Lua < CodeRay::Scanners::Scanner
28
28
]
29
29
30
30
SCANNER = /
31
+ (?<space>\s *) # eat leading whitespace, just to make iteration of fluff easier
31
32
(?<fluff>[\d \D ]*?) # eat content up until something we want
32
33
(?:
33
34
\b (?<keyword>#{ KEYWORDS . join ( '|' ) } )\b
@@ -48,19 +49,25 @@ class CodeRay::Scanners::Lua < CodeRay::Scanners::Scanner
48
49
--(?!\[ ).+
49
50
)
50
51
|
51
- (?<number>
52
+ \b (?<number>
52
53
-? # Allows -2 to be properly highlighted, but makes 10-5 show -5 as a single number
53
54
(?:
54
- 0[xX][\d a-fA-F]+
55
+ 0[xX]
56
+ (?:
57
+ [\d a-fA-F]+\. ?[\d a-fA-F]*
58
+ |
59
+ [\d a-fA-F]*\. [\d a-fA-F]+
60
+ )
61
+ (?:[pP][-+]?\d +)?
55
62
|
56
63
(?:
57
64
\d +\. ?\d *
58
65
|
59
- \d *\. ? \d +
66
+ \d *\. \d +
60
67
)
61
68
(?:[eE][-+]?\d +)?
62
69
)
63
- )
70
+ )\b
64
71
|
65
72
\b (?<constant>#{ PREDEFINED_CONSTANTS . join ( '|' ) } )\b
66
73
|
@@ -77,7 +84,6 @@ class CodeRay::Scanners::Lua < CodeRay::Scanners::Scanner
77
84
/x
78
85
79
86
CAPTURE_KINDS = {
80
- fluff : :content ,
81
87
reserved : :reserved ,
82
88
comment : :comment ,
83
89
blockcomment : :comment ,
@@ -101,8 +107,17 @@ class CodeRay::Scanners::Lua < CodeRay::Scanners::Scanner
101
107
102
108
def scan_tokens ( tokens , options )
103
109
string . gsub ( SCANNER ) do
110
+ match = $~
111
+ tokens . text_token ( match [ :space ] , :space ) unless match [ :space ] . empty?
112
+ unless match [ :fluff ] . empty?
113
+ space = false
114
+ match [ :fluff ] . split ( /(\s +)/ ) . each do |piece |
115
+ tokens . text_token ( piece , space ? :space : :content )
116
+ space = !space
117
+ end
118
+ end
104
119
CAPTURE_KINDS . each do |capture , kind |
105
- tokens . text_token ( $~ [ capture ] , kind ) if $~ [ capture ] && !$~ [ capture ] . empty?
120
+ tokens . text_token ( match [ capture ] , kind ) if match [ capture ] && !match [ capture ] . empty?
106
121
end
107
122
end
108
123
tokens
0 commit comments