Skip to content

Commit f61faa2

Browse files
hughsandoSimn
authored andcommitted
Use strongly typed CharRange (#56)
1 parent 53b7917 commit f61faa2

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

src/hxparse/LexEngine.hx

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -208,8 +208,8 @@ class LexEngine {
208208
// ----------------------- PATTERN PARSING ---------------------------
209209

210210
static inline var MAX_CODE = 255;
211-
static var EMPTY = [];
212-
static var ALL_CHARS = [ { min : 0, max : MAX_CODE } ];
211+
static var EMPTY:Charset = [];
212+
static var ALL_CHARS = [ new CharRange( 0, MAX_CODE ) ];
213213

214214
static inline function single( c : Int ) : Charset {
215215
return [ { min : c, max : c } ];
@@ -278,7 +278,7 @@ class LexEngine {
278278
static function ccomplement( c : Charset ) {
279279
var first = c[0];
280280
var start = first != null && first.min == -1 ? c.shift().max + 1 : -1;
281-
var out = [];
281+
var out: Charset = [];
282282
for( k in c ) {
283283
out.push( { min : start, max : k.min - 1 } );
284284
start = k.max + 1;
@@ -380,7 +380,7 @@ class LexEngine {
380380
return { pattern: Group(r), pos: i};
381381
case '['.code if (pattern.length > 1):
382382
var range = 0;
383-
var acc = [];
383+
var acc:Charset = [];
384384
var not = pattern.readByte(i) == '^'.code;
385385
if( not ) i++;
386386
while( true ) {
@@ -409,7 +409,7 @@ class LexEngine {
409409
}
410410
}
411411
}
412-
var g = [];
412+
var g:Charset = [];
413413
for( k in acc )
414414
g = cunion(g, [k]);
415415
if( not )
@@ -437,7 +437,15 @@ private enum Pattern {
437437
Group ( p : Pattern );
438438
}
439439

440-
private typedef Charset = Array<{ min : Int, max : Int }>;
440+
@:structInit private class CharRange {
441+
public var min:Int;
442+
public var max:Int;
443+
public function new(min,max) {
444+
this.min = min;
445+
this.max = max;
446+
}
447+
}
448+
private typedef Charset = Array<CharRange>;
441449

442450
private class Node {
443451
public var id : Int;

0 commit comments

Comments
 (0)