Skip to content

Commit 9987d66

Browse files
committed
fix variable/property/prompt
1 parent e531894 commit 9987d66

File tree

4 files changed

+14
-8
lines changed

4 files changed

+14
-8
lines changed

src/main/antlr/net/rptools/maptool/advanceddice/parser/GenesysDiceLexer.g4

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,9 @@ FUNCTION : '#' IDENTIFIER;
6868
6969
7070
// Variables
71-
VARIABLE : '${' (~[}])+ '}';
72-
PROPERTY : '${@' (~[}])+ '}';
73-
PROMPT : '${?' (~[}])+ '}';
71+
PROPERTY : LBRACE '@' (~[}])+ RBRACE;
72+
PROMPT : LBRACE '?' (~[}])+ RBRACE;
73+
VARIABLE : LBRACE (~[?@]) (~[}])+ RBRACE;
7474
7575
7676
// Dice Types
@@ -94,6 +94,8 @@ fragment WHITE_DICE_NAMES : 'w' | 'white';
9494
9595
9696
97+
fragment LBRACE : '{';
98+
fragment RBRACE : '}';
9799
98100
99101

src/main/antlr/net/rptools/maptool/advanceddice/parser/GenesysDiceParser.g4

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ genesysNumberDice : INTEGER_LITERAL
5656
| PROMPT
5757
;
5858

59+
5960
genesysFunction : func=FUNCTION LPAREN genesysFunctionParams RPAREN
6061
;
6162

src/main/java/net/rptools/maptool/advanceddice/Main.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public class Main {
2020

2121
public static void main(String[] args) {
2222
try {
23-
var res = new GenesysDiceRoller().roll("3yhs", null, null, null);
23+
var res = new GenesysDiceRoller().roll("3y{@prop}y{var}y{?prompt}s", n -> 1, n -> 2, n -> 3);
2424
System.out.println(res);
2525
} catch (Exception e) {
2626
e.printStackTrace();

src/main/java/net/rptools/maptool/advanceddice/genesys/GenesysDiceRollVisitor.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -288,13 +288,16 @@ private int getNumber(GenesysNumberDiceContext num) {
288288
if (num.INTEGER_LITERAL() != null) {
289289
return Integer.parseInt(num.INTEGER_LITERAL().getText());
290290
} else if (num.VARIABLE() != null) {
291-
return variableResolver.applyAsInt(num.VARIABLE().getText());
291+
var name = num.VARIABLE().getText().replaceAll("^\\{", "").replaceAll("}$", "");
292+
return variableResolver.applyAsInt(name);
292293
} else if (num.PROPERTY() != null) {
293-
return propertyResolver.applyAsInt(num.PROPERTY().getText());
294+
var name = num.PROPERTY().getText().replaceAll("^\\{@", "").replaceAll("}$", "");
295+
return propertyResolver.applyAsInt(name);
294296
} else if (num.PROMPT() != null) {
295-
return promptResolver.applyAsInt(num.PROMPT().getText());
297+
var name = num.PROMPT().getText().replaceAll("^\\{\\?", "").replaceAll("}$", "");
298+
return promptResolver.applyAsInt(name);
296299
} else {
297-
return 1; // TODO: CDW
300+
throw new IllegalArgumentException("Unknown number type"); // Shouldn't happen
298301
}
299302
}
300303

0 commit comments

Comments
 (0)