Skip to content

Commit

Permalink
Use strongly typed CharRange (#56)
Browse files Browse the repository at this point in the history
  • Loading branch information
hughsando authored and Simn committed Jul 7, 2019
1 parent 53b7917 commit f61faa2
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions src/hxparse/LexEngine.hx
Original file line number Diff line number Diff line change
Expand Up @@ -208,8 +208,8 @@ class LexEngine {
// ----------------------- PATTERN PARSING ---------------------------

static inline var MAX_CODE = 255;
static var EMPTY = [];
static var ALL_CHARS = [ { min : 0, max : MAX_CODE } ];
static var EMPTY:Charset = [];
static var ALL_CHARS = [ new CharRange( 0, MAX_CODE ) ];

static inline function single( c : Int ) : Charset {
return [ { min : c, max : c } ];
Expand Down Expand Up @@ -278,7 +278,7 @@ class LexEngine {
static function ccomplement( c : Charset ) {
var first = c[0];
var start = first != null && first.min == -1 ? c.shift().max + 1 : -1;
var out = [];
var out: Charset = [];
for( k in c ) {
out.push( { min : start, max : k.min - 1 } );
start = k.max + 1;
Expand Down Expand Up @@ -380,7 +380,7 @@ class LexEngine {
return { pattern: Group(r), pos: i};
case '['.code if (pattern.length > 1):
var range = 0;
var acc = [];
var acc:Charset = [];
var not = pattern.readByte(i) == '^'.code;
if( not ) i++;
while( true ) {
Expand Down Expand Up @@ -409,7 +409,7 @@ class LexEngine {
}
}
}
var g = [];
var g:Charset = [];
for( k in acc )
g = cunion(g, [k]);
if( not )
Expand Down Expand Up @@ -437,7 +437,15 @@ private enum Pattern {
Group ( p : Pattern );
}

private typedef Charset = Array<{ min : Int, max : Int }>;
@:structInit private class CharRange {
public var min:Int;
public var max:Int;
public function new(min,max) {
this.min = min;
this.max = max;
}
}
private typedef Charset = Array<CharRange>;

private class Node {
public var id : Int;
Expand Down

0 comments on commit f61faa2

Please sign in to comment.