private void ParseGlobalScope(ParseCursor cursor, ModuleNode result) { var currToken = cursor.Current; switch (currToken.Text) { case "package": SetPackageName(cursor, result); break; case "func": SetFunctionDeclaration(cursor, result); break; default: throw new InvalidDataException("Unexpected reserved word: " + currToken); } }
public FunctionDeclaration(ParseCursor cursor) { if (cursor.Current.Kind == TokenKind.Identifier) { Name = cursor.Current.Text; cursor.Advance(); } cursor.Advance("("); if (cursor.Current.Text == ")") { cursor.Advance(); } if (cursor.Current.Text == "{") { return; } throw new System.NotImplementedException(); }
public ModuleNode ParseModule(Token[] tokens) { ParseCursor _cursor = new ParseCursor(tokens); var result = new ModuleNode(); do { switch (_cursor.Current.Kind) { case TokenKind.Reserved: ParseGlobalScope(_cursor, result); continue; default: throw new DataException("Unexpected token: " + _cursor.Current); } _cursor.Advance(); } while (true); return(result); }
private void SetPackageName(ParseCursor cursor, ModuleNode result) { cursor.Advance(); result.Name = cursor.AdvanceToken().Text; cursor.Advance(TokenKind.Eoln); }
private void SetFunctionDeclaration(ParseCursor cursor, ModuleNode result) { var functionDeclaration = new FunctionDeclaration(cursor.ReadRow()); throw new System.NotImplementedException(); }