loreline 0.9.0 → 0.9.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -29,6 +29,7 @@ npm install # Install Node.js dependencies (esbuild, tsx, etc.)
29
29
  node ./setup --js # Build JavaScript library (js/loreline.js)
30
30
  node ./setup --cs # Export C# source files (cs/Loreline/)
31
31
  node ./setup --cs --cs-dll # Export C# + build Loreline.dll
32
+ node ./setup --cs-generics # Export C# test runner without erase-generics (see CS_COMPATIBILITY.md)
32
33
  node ./setup --py # Build Python package (py/loreline/)
33
34
  node ./setup --lua # Build Lua module (lua/loreline/)
34
35
  node ./setup --cpp # Build native CLI (loreline / loreline.exe)
@@ -62,7 +63,7 @@ python3 py/test-runner.py ./test # Run Python tests only
62
63
  lua5.4 lua/test-runner.lua ./test # Run Lua tests only
63
64
  npx tsx js/test-runner.ts ./test # Run JS tests only
64
65
  java -cp jvm/loreline.jar:build/jvm/test TestRunner ./test # Run JVM tests only
65
- node ./setup --test # Build and run all test suites (Neko + C# + C# AOT + JS + C++ lib + Python + Lua + JVM)
66
+ node ./setup --test # Build and run all test suites (Neko + C# + C# AOT + C# (with generics) + JS + C++ lib + Python + Lua + JVM)
66
67
  ```
67
68
 
68
69
  ## License
package/js/loreline.js CHANGED
@@ -5484,8 +5484,8 @@ class loreline_Functions {
5484
5484
  if(typeof(value) == "string") {
5485
5485
  return value.length > 0;
5486
5486
  }
5487
- if(((value) instanceof Array)) {
5488
- return value.length > 0;
5487
+ if(loreline_Arrays.isArray(value)) {
5488
+ return loreline_Arrays.arrayLength(value) > 0;
5489
5489
  }
5490
5490
  if(typeof(value) == "number" && ((value | 0) === value)) {
5491
5491
  return value != 0;
@@ -7711,7 +7711,7 @@ class loreline_Interpreter {
7711
7711
  let optionsDone = _gthis.wrapNext(function() {
7712
7712
  _gthis.presentChoice(choice,options,next);
7713
7713
  });
7714
- _gthis.evalChoiceOptionsAndInsertions(parentBeat,choice,options,optionsDone.cb,nextIndex);
7714
+ _gthis.evalChoiceOptionsAndInsertions(parentBeat,choice,options,optionsDone.cb,nextIndex,true);
7715
7715
  optionsDone.sync = false;
7716
7716
  });
7717
7717
  } else {
@@ -8081,7 +8081,7 @@ class loreline_Interpreter {
8081
8081
  let _g_key = key;
8082
8082
  let key1 = _g_key;
8083
8083
  let func = _g_value;
8084
- this.topLevelFunctions.h[key1] = func;
8084
+ this.registerTopLevelFunction(key1,func);
8085
8085
  }
8086
8086
  }
8087
8087
  let h = this.topLevelFunctions.h;
@@ -8106,6 +8106,15 @@ class loreline_Interpreter {
8106
8106
  }
8107
8107
  }
8108
8108
  }
8109
+ registerTopLevelFunction(key,func) {
8110
+ let userFunc = func;
8111
+ let _gthis = this;
8112
+ let this1 = this.topLevelFunctions;
8113
+ let value = Reflect.makeVarArgs(function(args) {
8114
+ return userFunc.apply(null,[_gthis,args]);
8115
+ });
8116
+ this1.h[key] = value;
8117
+ }
8109
8118
  initializeStringLiteralProcessors(processors) {
8110
8119
  let _gthis = this;
8111
8120
  this.stringLiteralProcessors.push(function(str) {
@@ -8412,7 +8421,7 @@ class loreline_Interpreter {
8412
8421
  let optionsDone = this.wrapNext(function() {
8413
8422
  _gthis.presentChoice(choice,options,next);
8414
8423
  });
8415
- this.evalChoiceOptionsAndInsertions(this.get_currentScope().beat,choice,options,optionsDone.cb);
8424
+ this.evalChoiceOptionsAndInsertions(this.get_currentScope().beat,choice,options,optionsDone.cb,null,this.get_currentInsertion() == null);
8416
8425
  optionsDone.sync = false;
8417
8426
  }
8418
8427
  presentChoice(choice,options,next) {
@@ -8480,10 +8489,22 @@ class loreline_Interpreter {
8480
8489
  });
8481
8490
  choiceCallback.sync = false;
8482
8491
  }
8483
- evalChoiceOptionsAndInsertions(beat,choice,result,next,startIndex) {
8492
+ evalChoiceOptionsAndInsertions(beat,choice,result,next,startIndex,isChoiceRoot) {
8493
+ if(isChoiceRoot == null) {
8494
+ isChoiceRoot = true;
8495
+ }
8484
8496
  let options = choice.options;
8485
- this._choiceEvalTexts.length = 0;
8486
- this._choiceEvalEnabled.length = 0;
8497
+ if(isChoiceRoot) {
8498
+ this._choiceEvalTexts.length = 0;
8499
+ this._choiceEvalEnabled.length = 0;
8500
+ let _g = 0;
8501
+ while(_g < result.length) {
8502
+ let opt = result[_g];
8503
+ ++_g;
8504
+ this._choiceEvalTexts.push(opt.text);
8505
+ this._choiceEvalEnabled.push(opt.enabled);
8506
+ }
8507
+ }
8487
8508
  let index = startIndex != null ? startIndex : 0;
8488
8509
  let moveNext = null;
8489
8510
  let insertion = null;
@@ -8496,8 +8517,10 @@ class loreline_Interpreter {
8496
8517
  let i = _g++;
8497
8518
  let opt = insertion.options[i];
8498
8519
  result.push(opt);
8499
- _gthis._choiceEvalTexts.push(opt.text);
8500
- _gthis._choiceEvalEnabled.push(opt.enabled);
8520
+ if(isChoiceRoot) {
8521
+ _gthis._choiceEvalTexts.push(opt.text);
8522
+ _gthis._choiceEvalEnabled.push(opt.enabled);
8523
+ }
8501
8524
  }
8502
8525
  insertion = null;
8503
8526
  }
@@ -8511,8 +8534,10 @@ class loreline_Interpreter {
8511
8534
  let str = _gthis.getTranslatedString(option,option.text);
8512
8535
  let content = _gthis.evaluateString(str);
8513
8536
  result.push(new loreline_ChoiceOption(content.text,content.tags,enabled,option,_gthis.get_currentInsertion()));
8514
- _gthis._choiceEvalTexts.push(content.text);
8515
- _gthis._choiceEvalEnabled.push(enabled);
8537
+ if(isChoiceRoot) {
8538
+ _gthis._choiceEvalTexts.push(content.text);
8539
+ _gthis._choiceEvalEnabled.push(enabled);
8540
+ }
8516
8541
  done.cb();
8517
8542
  done.sync = false;
8518
8543
  } else if(option.insertion != null) {
@@ -9373,8 +9398,8 @@ class loreline_Interpreter {
9373
9398
  return value == true;
9374
9399
  } else if(typeof(value) == "string") {
9375
9400
  return value.length > 0;
9376
- } else if(((value) instanceof Array)) {
9377
- return value.length > 0;
9401
+ } else if(loreline_Arrays.isArray(value)) {
9402
+ return loreline_Arrays.arrayLength(value) > 0;
9378
9403
  } else if(typeof(value) == "number" && ((value | 0) === value)) {
9379
9404
  return value != 0;
9380
9405
  } else if(typeof(value) == "number") {
@@ -9612,13 +9637,8 @@ class loreline_Interpreter {
9612
9637
  } else {
9613
9638
  return true;
9614
9639
  }
9615
- } else if(((operand) instanceof Array)) {
9616
- let v = operand;
9617
- if(v != null) {
9618
- return v.length == 0;
9619
- } else {
9620
- return true;
9621
- }
9640
+ } else if(loreline_Arrays.isArray(operand)) {
9641
+ return loreline_Arrays.arrayLength(operand) == 0;
9622
9642
  } else if(typeof(operand) == "number" && ((operand | 0) === operand)) {
9623
9643
  let v = operand;
9624
9644
  return v == 0;
@@ -15523,7 +15543,13 @@ class loreline_Lexer {
15523
15543
  if(pos == startPos && startPos < this.length) {
15524
15544
  let c = HxOverrides.cca(this.input,startPos);
15525
15545
  let c1 = c == null ? -1 : c;
15526
- tmp1 = c1 >= 97 && c1 <= 122 || c1 >= 65 && c1 <= 90 || c1 == 95;
15546
+ if(!(c1 >= 97 && c1 <= 122 || c1 >= 65 && c1 <= 90 || c1 == 95)) {
15547
+ let c = HxOverrides.cca(this.input,startPos);
15548
+ let c1 = c == null ? -1 : c;
15549
+ tmp1 = c1 >= 48 && c1 <= 57;
15550
+ } else {
15551
+ tmp1 = true;
15552
+ }
15527
15553
  } else {
15528
15554
  tmp1 = false;
15529
15555
  }
@@ -15534,7 +15560,13 @@ class loreline_Lexer {
15534
15560
  if(pos < this.length) {
15535
15561
  let c = HxOverrides.cca(this.input,pos);
15536
15562
  let c1 = c == null ? -1 : c;
15537
- tmp2 = !(c1 >= 97 && c1 <= 122 || c1 >= 65 && c1 <= 90 || c1 == 95);
15563
+ if(!(c1 >= 97 && c1 <= 122 || c1 >= 65 && c1 <= 90 || c1 == 95)) {
15564
+ let c = HxOverrides.cca(this.input,pos);
15565
+ let c1 = c == null ? -1 : c;
15566
+ tmp2 = !(c1 >= 48 && c1 <= 57);
15567
+ } else {
15568
+ tmp2 = false;
15569
+ }
15538
15570
  } else {
15539
15571
  tmp2 = true;
15540
15572
  }
@@ -15547,65 +15579,52 @@ class loreline_Lexer {
15547
15579
  if((c == null ? -1 : c) == 40) {
15548
15580
  return true;
15549
15581
  } else {
15550
- let result = true;
15551
- let len = _gthis.length;
15552
- if(pos >= len) {
15553
- result = false;
15554
- } else {
15555
- let tmp;
15556
- let tmp1;
15557
- let tmp2;
15558
- if(pos + 1 < len) {
15559
- let c = HxOverrides.cca(_gthis.input,pos);
15560
- tmp2 = (c == null ? -1 : c) == 111;
15561
- } else {
15562
- tmp2 = false;
15563
- }
15564
- if(tmp2) {
15565
- let c = HxOverrides.cca(_gthis.input,pos + 1);
15566
- tmp1 = (c == null ? -1 : c) == 114;
15567
- } else {
15568
- tmp1 = false;
15569
- }
15570
- if(tmp1) {
15571
- if(pos + 2 < len) {
15572
- let c = HxOverrides.cca(_gthis.input,pos + 2);
15582
+ let c = HxOverrides.cca(this.input,pos);
15583
+ let c1 = c == null ? -1 : c;
15584
+ if(c1 >= 48 && c1 <= 57) {
15585
+ while(true) {
15586
+ let tmp;
15587
+ if(pos < this.length) {
15588
+ let c = HxOverrides.cca(this.input,pos);
15573
15589
  let c1 = c == null ? -1 : c;
15574
- tmp = !(c1 >= 97 && c1 <= 122 || c1 >= 65 && c1 <= 90 || c1 == 95);
15590
+ if(!(c1 >= 48 && c1 <= 57)) {
15591
+ let c = HxOverrides.cca(this.input,pos);
15592
+ tmp = (c == null ? -1 : c) == 46;
15593
+ } else {
15594
+ tmp = true;
15595
+ }
15575
15596
  } else {
15576
- tmp = true;
15597
+ tmp = false;
15577
15598
  }
15578
- } else {
15579
- tmp = false;
15599
+ if(!tmp) {
15600
+ break;
15601
+ }
15602
+ ++pos;
15580
15603
  }
15581
- if(tmp) {
15604
+ } else {
15605
+ let result = true;
15606
+ let len = _gthis.length;
15607
+ if(pos >= len) {
15582
15608
  result = false;
15583
15609
  } else {
15584
15610
  let tmp;
15585
15611
  let tmp1;
15586
15612
  let tmp2;
15587
- let tmp3;
15588
- if(pos + 2 < len) {
15613
+ if(pos + 1 < len) {
15589
15614
  let c = HxOverrides.cca(_gthis.input,pos);
15590
- tmp3 = (c == null ? -1 : c) == 97;
15591
- } else {
15592
- tmp3 = false;
15593
- }
15594
- if(tmp3) {
15595
- let c = HxOverrides.cca(_gthis.input,pos + 1);
15596
- tmp2 = (c == null ? -1 : c) == 110;
15615
+ tmp2 = (c == null ? -1 : c) == 111;
15597
15616
  } else {
15598
15617
  tmp2 = false;
15599
15618
  }
15600
15619
  if(tmp2) {
15601
- let c = HxOverrides.cca(_gthis.input,pos + 2);
15602
- tmp1 = (c == null ? -1 : c) == 100;
15620
+ let c = HxOverrides.cca(_gthis.input,pos + 1);
15621
+ tmp1 = (c == null ? -1 : c) == 114;
15603
15622
  } else {
15604
15623
  tmp1 = false;
15605
15624
  }
15606
15625
  if(tmp1) {
15607
- if(pos + 3 < len) {
15608
- let c = HxOverrides.cca(_gthis.input,pos + 3);
15626
+ if(pos + 2 < len) {
15627
+ let c = HxOverrides.cca(_gthis.input,pos + 2);
15609
15628
  let c1 = c == null ? -1 : c;
15610
15629
  tmp = !(c1 >= 97 && c1 <= 122 || c1 >= 65 && c1 <= 90 || c1 == 95);
15611
15630
  } else {
@@ -15617,26 +15636,63 @@ class loreline_Lexer {
15617
15636
  if(tmp) {
15618
15637
  result = false;
15619
15638
  } else {
15620
- let c = HxOverrides.cca(_gthis.input,pos);
15621
- let c1 = c == null ? -1 : c;
15622
- if(!(c1 >= 97 && c1 <= 122 || c1 >= 65 && c1 <= 90 || c1 == 95)) {
15639
+ let tmp;
15640
+ let tmp1;
15641
+ let tmp2;
15642
+ let tmp3;
15643
+ if(pos + 2 < len) {
15644
+ let c = HxOverrides.cca(_gthis.input,pos);
15645
+ tmp3 = (c == null ? -1 : c) == 97;
15646
+ } else {
15647
+ tmp3 = false;
15648
+ }
15649
+ if(tmp3) {
15650
+ let c = HxOverrides.cca(_gthis.input,pos + 1);
15651
+ tmp2 = (c == null ? -1 : c) == 110;
15652
+ } else {
15653
+ tmp2 = false;
15654
+ }
15655
+ if(tmp2) {
15656
+ let c = HxOverrides.cca(_gthis.input,pos + 2);
15657
+ tmp1 = (c == null ? -1 : c) == 100;
15658
+ } else {
15659
+ tmp1 = false;
15660
+ }
15661
+ if(tmp1) {
15662
+ if(pos + 3 < len) {
15663
+ let c = HxOverrides.cca(_gthis.input,pos + 3);
15664
+ let c1 = c == null ? -1 : c;
15665
+ tmp = !(c1 >= 97 && c1 <= 122 || c1 >= 65 && c1 <= 90 || c1 == 95);
15666
+ } else {
15667
+ tmp = true;
15668
+ }
15669
+ } else {
15670
+ tmp = false;
15671
+ }
15672
+ if(tmp) {
15623
15673
  result = false;
15624
15674
  } else {
15625
- ++pos;
15626
- while(pos < _gthis.length) {
15627
- let c = HxOverrides.cca(_gthis.input,pos);
15628
- c1 = c == null ? -1 : c;
15629
- if(!(c1 >= 97 && c1 <= 122 || c1 >= 65 && c1 <= 90 || c1 == 95 || c1 >= 48 && c1 <= 57)) {
15630
- break;
15631
- }
15675
+ let c = HxOverrides.cca(_gthis.input,pos);
15676
+ let c1 = c == null ? -1 : c;
15677
+ if(!(c1 >= 97 && c1 <= 122 || c1 >= 65 && c1 <= 90 || c1 == 95)) {
15678
+ result = false;
15679
+ } else {
15632
15680
  ++pos;
15681
+ while(pos < _gthis.length) {
15682
+ let c = HxOverrides.cca(_gthis.input,pos);
15683
+ c1 = c == null ? -1 : c;
15684
+ if(!(c1 >= 97 && c1 <= 122 || c1 >= 65 && c1 <= 90 || c1 == 95 || c1 >= 48 && c1 <= 57)) {
15685
+ break;
15686
+ }
15687
+ ++pos;
15688
+ }
15633
15689
  }
15634
15690
  }
15635
15691
  }
15636
15692
  }
15637
- }
15638
- if(!result) {
15639
- return false;
15693
+ if(!result) {
15694
+ return false;
15695
+ }
15640
15696
  }
15641
15697
  }
15642
15698
  pos = this._skipWhitespaceAndComments(pos,false);
@@ -16919,7 +16975,13 @@ class loreline_Lexer {
16919
16975
  if(loreline_TokenTypeHelpers.isComment(token.type) || token.type == loreline_TokenType.Indent || token.type == loreline_TokenType.Unindent) {
16920
16976
  --i;
16921
16977
  } else if(token.type == loreline_TokenType.OpMinus) {
16922
- return true;
16978
+ --i;
16979
+ while(i >= 0 && (loreline_TokenTypeHelpers.isComment(this.tokenized[i].type) || this.tokenized[i].type == loreline_TokenType.Indent || this.tokenized[i].type == loreline_TokenType.Unindent)) --i;
16980
+ if(i >= 0) {
16981
+ return this.tokenized[i].type == loreline_TokenType.LineBreak;
16982
+ } else {
16983
+ return true;
16984
+ }
16923
16985
  } else {
16924
16986
  return false;
16925
16987
  }
@@ -22968,6 +23030,7 @@ Object.assign(loreline_ParserContext.prototype, {
22968
23030
  });
22969
23031
  class loreline_Parser {
22970
23032
  constructor(tokens,context) {
23033
+ this.parsingCondition = false;
22971
23034
  this.tokens = tokens;
22972
23035
  this.current = 0;
22973
23036
  this.errors = null;
@@ -23061,6 +23124,9 @@ class loreline_Parser {
23061
23124
  if(advanceLineBreaks == null) {
23062
23125
  advanceLineBreaks = true;
23063
23126
  }
23127
+ if(this.parsingCondition) {
23128
+ advanceLineBreaks = false;
23129
+ }
23064
23130
  let prev = this.tokens[this.current];
23065
23131
  if(!this.isAtEnd()) {
23066
23132
  this.lastTokenEnd = prev.pos;
@@ -24872,7 +24938,7 @@ class loreline_Parser {
24872
24938
  elements.push(this.parseExpression());
24873
24939
  }
24874
24940
  let prev = this.previous();
24875
- needsSeparator = prev.type != loreline_TokenType.Colon && prev.type != loreline_TokenType.LineBreak;
24941
+ needsSeparator = prev.type != loreline_TokenType.Colon && prev.type != loreline_TokenType.LineBreak && prev.type != loreline_TokenType.Unindent;
24876
24942
  }
24877
24943
  while(this.match(loreline_TokenType.LineBreak) || this.match(loreline_TokenType.Indent) || this.match(loreline_TokenType.Unindent)) {
24878
24944
  }
@@ -24905,7 +24971,7 @@ class loreline_Parser {
24905
24971
  fields.push(this.parseObjectField());
24906
24972
  }
24907
24973
  let prev = this.previous();
24908
- needsSeparator = prev.type != loreline_TokenType.Colon && prev.type != loreline_TokenType.LineBreak;
24974
+ needsSeparator = prev.type != loreline_TokenType.Colon && prev.type != loreline_TokenType.LineBreak && prev.type != loreline_TokenType.Unindent;
24909
24975
  }
24910
24976
  while(this.match(loreline_TokenType.LineBreak) || blockEnd != loreline_TokenType.Unindent && this.match(loreline_TokenType.Unindent)) {
24911
24977
  }
@@ -24928,6 +24994,8 @@ class loreline_Parser {
24928
24994
  return args;
24929
24995
  }
24930
24996
  parseConditionExpression() {
24997
+ let prevParsingCondition = this.parsingCondition;
24998
+ this.parsingCondition = true;
24931
24999
  let hasParen = this.match(loreline_TokenType.LParen);
24932
25000
  let expr = null;
24933
25001
  try {
@@ -24947,6 +25015,7 @@ class loreline_Parser {
24947
25015
  throw _g;
24948
25016
  }
24949
25017
  }
25018
+ this.parsingCondition = prevParsingCondition;
24950
25019
  if(hasParen) {
24951
25020
  this.expect(loreline_TokenType.RParen);
24952
25021
  }