Skip to content

Commit 1a9451d

Browse files
committed
Object line compile and errors cleanup
1 parent 6492557 commit 1a9451d

4 files changed

Lines changed: 102 additions & 100 deletions

File tree

spin-tools/src/main/java/com/maccasoft/propeller/spin1/Spin1ExpressionBuilder.java

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ public Expression getExpression() {
219219

220220
Token token = peek();
221221
if (token != null) {
222-
throw new CompilerException("unexpected " + token.getText(), token);
222+
throw new CompilerException("unexpected '" + token.getText() + "'", token);
223223
}
224224

225225
return node;
@@ -336,7 +336,7 @@ Expression parseLevel(Expression left, int level) {
336336

337337
case "?":
338338
if (!(right instanceof IfElse)) {
339-
throw new CompilerException("invalid operator " + token.getText(), token);
339+
throw new CompilerException("invalid operator '" + token.getText() + "'", token);
340340
}
341341
left = new IfElse(left, ((IfElse) right).getTrueTerm(), ((IfElse) right).getFalseTerm());
342342
break;
@@ -345,7 +345,7 @@ Expression parseLevel(Expression left, int level) {
345345
break;
346346

347347
default:
348-
throw new CompilerException("unsupported operator " + token.getText(), token);
348+
throw new CompilerException("unsupported operator '" + token.getText() + "'", token);
349349
}
350350
}
351351
}
@@ -374,7 +374,7 @@ Expression parseAtom() {
374374
case "^^":
375375
return new Sqrt(parseAtom());
376376
default:
377-
throw new CompilerException("invalid unary operator " + token.getText(), token);
377+
throw new CompilerException("invalid unary operator '" + token.getText() + "'", token);
378378
}
379379
}
380380

@@ -388,7 +388,7 @@ Expression parseAtom() {
388388
Group expression = new Group(parseLevel(parseAtom(), 0));
389389
token = next();
390390
if (token == null || !")".equals(token.getText())) {
391-
throw new CompilerException("expecting )", token == null ? tokens.get(tokens.size() - 1) : token);
391+
throw new CompilerException("expecting ')'", token == null ? tokens.get(tokens.size() - 1) : token);
392392
}
393393
return expression;
394394
}
@@ -415,7 +415,7 @@ protected Expression compilePseudoFunction(Token token) {
415415
case "DEFINED": {
416416
token = next();
417417
if (token == null || !"(".equals(token.getText())) {
418-
throw new CompilerException("expecting (", token == null ? tokens.get(tokens.size() - 1) : token);
418+
throw new CompilerException("expecting '('", token == null ? tokens.get(tokens.size() - 1) : token);
419419
}
420420
token = next();
421421
if (token == null) {
@@ -424,43 +424,43 @@ protected Expression compilePseudoFunction(Token token) {
424424
Expression expression = new Defined(token.getText(), context);
425425
token = next();
426426
if (token == null || !")".equals(token.getText())) {
427-
throw new CompilerException("expecting )", token == null ? tokens.get(tokens.size() - 1) : token);
427+
throw new CompilerException("expecting ')'", token == null ? tokens.get(tokens.size() - 1) : token);
428428
}
429429
return expression;
430430
}
431431
case "FLOAT": {
432432
token = next();
433433
if (token == null || !"(".equals(token.getText())) {
434-
throw new CompilerException("expecting (", token == null ? tokens.get(tokens.size() - 1) : token);
434+
throw new CompilerException("expecting '('", token == null ? tokens.get(tokens.size() - 1) : token);
435435
}
436436
Expression expression = new com.maccasoft.propeller.expressions.Float(parseLevel(parseAtom(), 0));
437437
token = next();
438438
if (token == null || !")".equals(token.getText())) {
439-
throw new CompilerException("expecting )", token == null ? tokens.get(tokens.size() - 1) : token);
439+
throw new CompilerException("expecting ')'", token == null ? tokens.get(tokens.size() - 1) : token);
440440
}
441441
return expression;
442442
}
443443
case "TRUNC": {
444444
token = next();
445445
if (token == null || !"(".equals(token.getText())) {
446-
throw new CompilerException("expecting (", token == null ? tokens.get(tokens.size() - 1) : token);
446+
throw new CompilerException("expecting '('", token == null ? tokens.get(tokens.size() - 1) : token);
447447
}
448448
Expression expression = new Trunc(parseLevel(parseAtom(), 0));
449449
token = next();
450450
if (token == null || !")".equals(token.getText())) {
451-
throw new CompilerException("expecting )", token == null ? tokens.get(tokens.size() - 1) : token);
451+
throw new CompilerException("expecting ')'", token == null ? tokens.get(tokens.size() - 1) : token);
452452
}
453453
return expression;
454454
}
455455
case "ROUND": {
456456
token = next();
457457
if (token == null || !"(".equals(token.getText())) {
458-
throw new CompilerException("expecting (", token == null ? tokens.get(tokens.size() - 1) : token);
458+
throw new CompilerException("expecting '('", token == null ? tokens.get(tokens.size() - 1) : token);
459459
}
460460
Expression expression = new Round(parseLevel(parseAtom(), 0));
461461
token = next();
462462
if (token == null || !")".equals(token.getText())) {
463-
throw new CompilerException("expecting )", token == null ? tokens.get(tokens.size() - 1) : token);
463+
throw new CompilerException("expecting ')'", token == null ? tokens.get(tokens.size() - 1) : token);
464464
}
465465
return expression;
466466
}

spin-tools/src/main/java/com/maccasoft/propeller/spin1/Spin1ObjectCompiler.java

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -865,6 +865,10 @@ void compileObject(SourceLine sourceLine) {
865865
logMessage(new CompilerException("expecting identifier", nameToken));
866866
return;
867867
}
868+
if (objects.containsKey(nameToken.getText())) {
869+
logMessage(new CompilerException("expecting unique object name", nameToken));
870+
return;
871+
}
868872

869873
String name = nameToken.getText();
870874
Expression count = new NumberLiteral(1);
@@ -890,6 +894,14 @@ void compileObject(SourceLine sourceLine) {
890894
}
891895
builder.addToken(token);
892896
}
897+
if (!"]".equals(token.getText())) {
898+
logMessage(new CompilerException("expecting ']'", token));
899+
return;
900+
}
901+
if (builder.getTokenCount() == 0) {
902+
logMessage(new CompilerException("expecting expression", sourceLine.getLastToken()));
903+
return;
904+
}
893905
count = builder.getExpression();
894906
count.setData(builder.getTokens());
895907
} catch (CompilerException e) {
@@ -898,10 +910,6 @@ void compileObject(SourceLine sourceLine) {
898910
logMessage(new CompilerException(e, builder.getTokens()));
899911
}
900912

901-
if (!"]".equals(token.getText())) {
902-
logMessage(new CompilerException("expecting ']'", token));
903-
return;
904-
}
905913
if (!sourceLine.hasMoreTokens()) {
906914
logMessage(new CompilerException("expecting ':'", token.stop + 1));
907915
return;
@@ -914,7 +922,7 @@ void compileObject(SourceLine sourceLine) {
914922
return;
915923
}
916924
if (!sourceLine.hasMoreTokens()) {
917-
logMessage(new CompilerException("expecting object file name '" + token.getText() + "'", token));
925+
logMessage(new CompilerException("expecting object file name", token.stop + 1));
918926
return;
919927
}
920928
Token fileToken = sourceLine.skipCommentsAndGetNextToken();
@@ -939,14 +947,14 @@ void compileObject(SourceLine sourceLine) {
939947

940948
File file = compiler.getFile(fileName, ".spin");
941949
if (file == null) {
942-
logMessage(new CompilerException("object " + fileName + " not found", fileToken));
950+
logMessage(new CompilerException("object '" + fileName + "' not found", fileToken));
943951
return;
944952
}
945953

946954
try {
947955
ObjectInfo info = compiler.getObjectInfo(Spin1ObjectCompiler.this, file, Collections.emptyMap());
948956
if (info == null) {
949-
logMessage(new CompilerException("object " + fileName + " not found", fileToken));
957+
logMessage(new CompilerException("object '" + fileName + "' not found", fileToken));
950958
return;
951959
}
952960
objects.put(name, new ObjectInfo(info, count));
@@ -965,7 +973,7 @@ void compileObject(SourceLine sourceLine) {
965973
return;
966974
}
967975
}
968-
logMessage(new CompilerException("object " + fileName + " has errors", fileToken));
976+
logMessage(new CompilerException("object '" + fileName + "' has errors", fileToken));
969977
}
970978
} catch (CompilerException e) {
971979
logMessage(e);

spin-tools/src/main/java/com/maccasoft/propeller/spin2/Spin2ExpressionBuilder.java

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ public Expression getExpression() {
286286

287287
Token token = peek();
288288
if (token != null) {
289-
throw new CompilerException("unexpected " + token.getText(), token);
289+
throw new CompilerException("unexpected '" + token.getText() + "'", token);
290290
}
291291

292292
return node;
@@ -470,7 +470,7 @@ Expression parseLevel(Expression left, int level) {
470470

471471
case "?":
472472
if (!(right instanceof IfElse)) {
473-
throw new CompilerException("unsupported operator " + token.getText(), token);
473+
throw new CompilerException("unsupported operator '" + token.getText() + "'", token);
474474
}
475475
left = new IfElse(left, ((IfElse) right).getTrueTerm(), ((IfElse) right).getFalseTerm());
476476
break;
@@ -479,7 +479,7 @@ Expression parseLevel(Expression left, int level) {
479479
break;
480480

481481
default:
482-
throw new CompilerException("unsupported operator " + token.getText(), token);
482+
throw new CompilerException("unsupported operator '" + token.getText() + "'", token);
483483
}
484484
}
485485
}
@@ -528,7 +528,7 @@ Expression parseAtom() {
528528
case "EXP":
529529
return new Exp(parseAtom());
530530
default:
531-
throw new CompilerException("invalid unary operator " + token.getText(), token);
531+
throw new CompilerException("invalid unary operator '" + token.getText() + "'", token);
532532
}
533533
}
534534

@@ -546,7 +546,7 @@ Expression parseAtom() {
546546
Group expression = new Group(parseLevel(parseAtom(), 0));
547547
token = next();
548548
if (token == null || !")".equals(token.getText())) {
549-
throw new CompilerException("expecting )", token == null ? tokens.getLast() : token);
549+
throw new CompilerException("expecting ')'", token == null ? tokens.getLast() : token);
550550
}
551551
return expression;
552552
}
@@ -564,7 +564,7 @@ Expression parseAtom() {
564564
return compilePseudoFunction(token);
565565
}
566566

567-
throw new CompilerException("unexpected " + token.getText(), token);
567+
throw new CompilerException("unexpected '" + token.getText() + "'", token);
568568
}
569569

570570
protected Expression compilePseudoFunction(Token token) {
@@ -573,7 +573,7 @@ protected Expression compilePseudoFunction(Token token) {
573573
case "DEFINED": {
574574
token = next();
575575
if (token == null || !"(".equals(token.getText())) {
576-
throw new CompilerException("expecting (", token == null ? tokens.getLast() : token);
576+
throw new CompilerException("expecting '('", token == null ? tokens.getLast() : token);
577577
}
578578
token = next();
579579
if (token == null) {
@@ -582,88 +582,88 @@ protected Expression compilePseudoFunction(Token token) {
582582
Expression expression = new Defined(token.getText(), context);
583583
token = next();
584584
if (token == null || !")".equals(token.getText())) {
585-
throw new CompilerException("expecting )", token == null ? tokens.getLast() : token);
585+
throw new CompilerException("expecting ')'", token == null ? tokens.getLast() : token);
586586
}
587587
return expression;
588588
}
589589
case "FLOAT": {
590590
token = next();
591591
if (token == null || !"(".equals(token.getText())) {
592-
throw new CompilerException("expecting (", token == null ? tokens.getLast() : token);
592+
throw new CompilerException("expecting '('", token == null ? tokens.getLast() : token);
593593
}
594594
Expression expression = new com.maccasoft.propeller.expressions.Float(parseLevel(parseAtom(), 0));
595595
token = next();
596596
if (token == null || !")".equals(token.getText())) {
597-
throw new CompilerException("expecting )", token == null ? tokens.getLast() : token);
597+
throw new CompilerException("expecting ')'", token == null ? tokens.getLast() : token);
598598
}
599599
return expression;
600600
}
601601
case "TRUNC": {
602602
token = next();
603603
if (token == null || !"(".equals(token.getText())) {
604-
throw new CompilerException("expecting (", token == null ? tokens.getLast() : token);
604+
throw new CompilerException("expecting '('", token == null ? tokens.getLast() : token);
605605
}
606606
Expression expression = new Trunc(parseLevel(parseAtom(), 0));
607607
token = next();
608608
if (token == null || !")".equals(token.getText())) {
609-
throw new CompilerException("expecting )", token == null ? tokens.getLast() : token);
609+
throw new CompilerException("expecting ')'", token == null ? tokens.getLast() : token);
610610
}
611611
return expression;
612612
}
613613
case "ROUND": {
614614
token = next();
615615
if (token == null || !"(".equals(token.getText())) {
616-
throw new CompilerException("expecting (", token == null ? tokens.getLast() : token);
616+
throw new CompilerException("expecting '('", token == null ? tokens.getLast() : token);
617617
}
618618
Expression expression = new Round(parseLevel(parseAtom(), 0));
619619
token = next();
620620
if (token == null || !")".equals(token.getText())) {
621-
throw new CompilerException("expecting )", token == null ? tokens.getLast() : token);
621+
throw new CompilerException("expecting ')'", token == null ? tokens.getLast() : token);
622622
}
623623
return expression;
624624
}
625625
case "SQRT":
626626
case "FSQRT": {
627627
token = next();
628628
if (token == null || !"(".equals(token.getText())) {
629-
throw new CompilerException("expecting (", token == null ? tokens.getLast() : token);
629+
throw new CompilerException("expecting '('", token == null ? tokens.getLast() : token);
630630
}
631631
Expression expression = new Sqrt(parseLevel(parseAtom(), 0));
632632
token = next();
633633
if (token == null || !")".equals(token.getText())) {
634-
throw new CompilerException("expecting )", token == null ? tokens.getLast() : token);
634+
throw new CompilerException("expecting ')'", token == null ? tokens.getLast() : token);
635635
}
636636
return expression;
637637
}
638638
case "ABS":
639639
case "FABS": {
640640
token = next();
641641
if (token == null || !"(".equals(token.getText())) {
642-
throw new CompilerException("expecting (", token == null ? tokens.getLast() : token);
642+
throw new CompilerException("expecting '('", token == null ? tokens.getLast() : token);
643643
}
644644
Expression expression = new Abs(parseLevel(parseAtom(), 0));
645645
token = next();
646646
if (token == null || !")".equals(token.getText())) {
647-
throw new CompilerException("expecting )", token == null ? tokens.getLast() : token);
647+
throw new CompilerException("expecting ')", token == null ? tokens.getLast() : token);
648648
}
649649
return expression;
650650
}
651651
case "NAN": {
652652
token = next();
653653
if (token == null || !"(".equals(token.getText())) {
654-
throw new CompilerException("expecting (", token == null ? tokens.getLast() : token);
654+
throw new CompilerException("expecting '('", token == null ? tokens.getLast() : token);
655655
}
656656
Expression expression = new Nan(parseLevel(parseAtom(), 0));
657657
token = next();
658658
if (token == null || !")".equals(token.getText())) {
659-
throw new CompilerException("expecting )", token == null ? tokens.getLast() : token);
659+
throw new CompilerException("expecting ')'", token == null ? tokens.getLast() : token);
660660
}
661661
return expression;
662662
}
663663
case "SIZEOF": {
664664
token = next();
665665
if (token == null || !"(".equals(token.getText())) {
666-
throw new CompilerException("expecting (", token == null ? tokens.getLast() : token);
666+
throw new CompilerException("expecting '('", token == null ? tokens.getLast() : token);
667667
}
668668
token = next();
669669
if (token == null || token.type != Token.KEYWORD) {
@@ -672,14 +672,14 @@ protected Expression compilePseudoFunction(Token token) {
672672
Expression expression = new SizeOf(token, context);
673673
token = next();
674674
if (token == null || !")".equals(token.getText())) {
675-
throw new CompilerException("expecting )", token == null ? tokens.getLast() : token);
675+
throw new CompilerException("expecting ')'", token == null ? tokens.getLast() : token);
676676
}
677677
return expression;
678678
}
679679
case "OFFSETOF": {
680680
token = next();
681681
if (token == null || !"(".equals(token.getText())) {
682-
throw new CompilerException("expecting (", token == null ? tokens.getLast() : token);
682+
throw new CompilerException("expecting '('", token == null ? tokens.getLast() : token);
683683
}
684684
token = next();
685685
if (token == null || token.type != Token.KEYWORD) {
@@ -688,7 +688,7 @@ protected Expression compilePseudoFunction(Token token) {
688688
Expression expression = new OffsetOf(token, context);
689689
token = next();
690690
if (token == null || !")".equals(token.getText())) {
691-
throw new CompilerException("expecting )", token == null ? tokens.getLast() : token);
691+
throw new CompilerException("expecting ')'", token == null ? tokens.getLast() : token);
692692
}
693693
return expression;
694694
}

0 commit comments

Comments
 (0)