|
@@ -14,17 +14,16 @@ private enum Token {
|
|
TEof;
|
|
TEof;
|
|
}
|
|
}
|
|
|
|
|
|
-@:nodebug
|
|
|
|
class Parser {
|
|
class Parser {
|
|
|
|
|
|
var line : Int;
|
|
var line : Int;
|
|
var buf : String;
|
|
var buf : String;
|
|
var pos : Int;
|
|
var pos : Int;
|
|
var token : Null<Token>;
|
|
var token : Null<Token>;
|
|
-
|
|
|
|
|
|
+
|
|
function new() {
|
|
function new() {
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
function parseText( str ) {
|
|
function parseText( str ) {
|
|
this.buf = str;
|
|
this.buf = str;
|
|
this.pos = 0;
|
|
this.pos = 0;
|
|
@@ -32,7 +31,7 @@ class Parser {
|
|
token = null;
|
|
token = null;
|
|
return parseNodes();
|
|
return parseNodes();
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
function parseNodes() {
|
|
function parseNodes() {
|
|
var nodes = [];
|
|
var nodes = [];
|
|
while( true ) {
|
|
while( true ) {
|
|
@@ -45,7 +44,7 @@ class Parser {
|
|
}
|
|
}
|
|
return nodes;
|
|
return nodes;
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
function parseNode() : FbxNode {
|
|
function parseNode() : FbxNode {
|
|
var t = next();
|
|
var t = next();
|
|
var name = switch( t ) {
|
|
var name = switch( t ) {
|
|
@@ -120,19 +119,19 @@ class Parser {
|
|
if( childs == null ) childs = [];
|
|
if( childs == null ) childs = [];
|
|
return { name : name, props : props, childs : childs };
|
|
return { name : name, props : props, childs : childs };
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
function except( except : Token ) {
|
|
function except( except : Token ) {
|
|
var t = next();
|
|
var t = next();
|
|
if( !Type.enumEq(t, except) )
|
|
if( !Type.enumEq(t, except) )
|
|
error("Unexpected '" + tokenStr(t) + "' (" + tokenStr(except) + " expected)");
|
|
error("Unexpected '" + tokenStr(t) + "' (" + tokenStr(except) + " expected)");
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
function peek() {
|
|
function peek() {
|
|
if( token == null )
|
|
if( token == null )
|
|
token = nextToken();
|
|
token = nextToken();
|
|
return token;
|
|
return token;
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
function next() {
|
|
function next() {
|
|
if( token == null )
|
|
if( token == null )
|
|
return nextToken();
|
|
return nextToken();
|
|
@@ -140,16 +139,16 @@ class Parser {
|
|
token = null;
|
|
token = null;
|
|
return tmp;
|
|
return tmp;
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
function error( msg : String ) : Dynamic {
|
|
function error( msg : String ) : Dynamic {
|
|
throw msg + " (line " + line + ")";
|
|
throw msg + " (line " + line + ")";
|
|
return null;
|
|
return null;
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
function unexpected( t : Token ) : Dynamic {
|
|
function unexpected( t : Token ) : Dynamic {
|
|
return error("Unexpected "+tokenStr(t));
|
|
return error("Unexpected "+tokenStr(t));
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
function tokenStr( t : Token ) {
|
|
function tokenStr( t : Token ) {
|
|
return switch( t ) {
|
|
return switch( t ) {
|
|
case TEof: "<eof>";
|
|
case TEof: "<eof>";
|
|
@@ -164,19 +163,20 @@ class Parser {
|
|
case TLength(l): '*' + l;
|
|
case TLength(l): '*' + l;
|
|
};
|
|
};
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
inline function nextChar() {
|
|
inline function nextChar() {
|
|
return StringTools.fastCodeAt(buf, pos++);
|
|
return StringTools.fastCodeAt(buf, pos++);
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
inline function getBuf( pos : Int, len : Int ) {
|
|
inline function getBuf( pos : Int, len : Int ) {
|
|
return buf.substr(pos, len);
|
|
return buf.substr(pos, len);
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
inline function isIdentChar(c) {
|
|
inline function isIdentChar(c) {
|
|
return (c >= 'a'.code && c <= 'z'.code) || (c >= 'A'.code && c <= 'Z'.code) || (c >= '0'.code && c <= '9'.code) || c == '_'.code || c == '-'.code;
|
|
return (c >= 'a'.code && c <= 'z'.code) || (c >= 'A'.code && c <= 'Z'.code) || (c >= '0'.code && c <= '9'.code) || c == '_'.code || c == '-'.code;
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
|
|
+ @:noDebug
|
|
function nextToken() {
|
|
function nextToken() {
|
|
var start = pos;
|
|
var start = pos;
|
|
while( true ) {
|
|
while( true ) {
|
|
@@ -261,7 +261,7 @@ class Parser {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
public static function parse( text : String ) {
|
|
public static function parse( text : String ) {
|
|
return new Parser().parseText(text);
|
|
return new Parser().parseText(text);
|
|
}
|
|
}
|