diff --git a/ftb_snbt_lib/parse.py b/ftb_snbt_lib/parse.py index 0d0df75..eebb14f 100644 --- a/ftb_snbt_lib/parse.py +++ b/ftb_snbt_lib/parse.py @@ -35,6 +35,7 @@ def p_key_value_pair(p): def p_value(p): """value : compound | list + | array | BOOL | BYTE | SHORT @@ -52,6 +53,14 @@ def p_list(p): else: p[0] = List(p[2]) +def p_array(p): + """array : LBRACKET NAME SEMICOLON values RBRACKET + | LBRACKET NAME SEMICOLON RBRACKET""" + if len(p) == 4: + p[0] = Array(p[2], []) + else: + p[0] = Array(p[2], p[4]) + def p_values(p): """values : values value | values COMMA value diff --git a/ftb_snbt_lib/parser.out b/ftb_snbt_lib/parser.out index 0ea39cd..00d4ab8 100644 --- a/ftb_snbt_lib/parser.out +++ b/ftb_snbt_lib/parser.out @@ -13,46 +13,51 @@ Rule 7 key_value_pair -> NAME COLON value Rule 8 key_value_pair -> STRING COLON value Rule 9 value -> compound Rule 10 value -> list -Rule 11 value -> BOOL -Rule 12 value -> BYTE -Rule 13 value -> SHORT -Rule 14 value -> DOUBLE -Rule 15 value -> LONG -Rule 16 value -> INTEGER -Rule 17 value -> STRING -Rule 18 list -> LBRACKET values RBRACKET -Rule 19 list -> LBRACKET RBRACKET -Rule 20 values -> values value -Rule 21 values -> values COMMA value -Rule 22 values -> value +Rule 11 value -> array +Rule 12 value -> BOOL +Rule 13 value -> BYTE +Rule 14 value -> SHORT +Rule 15 value -> DOUBLE +Rule 16 value -> LONG +Rule 17 value -> INTEGER +Rule 18 value -> STRING +Rule 19 list -> LBRACKET values RBRACKET +Rule 20 list -> LBRACKET RBRACKET +Rule 21 array -> LBRACKET NAME SEMICOLON values RBRACKET +Rule 22 array -> LBRACKET NAME SEMICOLON RBRACKET +Rule 23 values -> values value +Rule 24 values -> values COMMA value +Rule 25 values -> value Terminals, with rules where they appear -BOOL : 11 -BYTE : 12 +BOOL : 12 +BYTE : 13 COLON : 7 8 -COMMA : 5 21 -DOUBLE : 14 -INTEGER : 16 +COMMA : 5 24 +DOUBLE : 15 +INTEGER : 17 LBRACE : 2 3 -LBRACKET : 18 19 -LONG : 15 -NAME : 7 +LBRACKET : 19 20 21 22 +LONG : 16 +NAME : 7 21 22 RBRACE : 2 3 -RBRACKET : 18 19 -SHORT : 13 -STRING : 8 17 +RBRACKET : 19 20 21 22 +SEMICOLON : 21 22 +SHORT : 14 +STRING : 8 18 error : Nonterminals, with rules where they appear +array : 11 compound : 1 9 key_value_pair : 4 5 6 key_value_pairs : 2 4 5 list : 10 snbt : 0 -value : 7 8 20 21 22 -values : 18 20 21 +value : 7 8 23 24 25 +values : 19 21 23 24 Parsing method: LALR @@ -203,62 +208,70 @@ state 12 (7) key_value_pair -> NAME COLON . value (9) value -> . compound (10) value -> . list - (11) value -> . BOOL - (12) value -> . BYTE - (13) value -> . SHORT - (14) value -> . DOUBLE - (15) value -> . LONG - (16) value -> . INTEGER - (17) value -> . STRING + (11) value -> . array + (12) value -> . BOOL + (13) value -> . BYTE + (14) value -> . SHORT + (15) value -> . DOUBLE + (16) value -> . LONG + (17) value -> . INTEGER + (18) value -> . STRING (2) compound -> . LBRACE key_value_pairs RBRACE (3) compound -> . LBRACE RBRACE - (18) list -> . LBRACKET values RBRACKET - (19) list -> . LBRACKET RBRACKET - - BOOL shift and go to state 18 - BYTE shift and go to state 19 - SHORT shift and go to state 20 - DOUBLE shift and go to state 21 - LONG shift and go to state 22 - INTEGER shift and go to state 23 - STRING shift and go to state 24 + (19) list -> . LBRACKET values RBRACKET + (20) list -> . LBRACKET RBRACKET + (21) array -> . LBRACKET NAME SEMICOLON values RBRACKET + (22) array -> . LBRACKET NAME SEMICOLON RBRACKET + + BOOL shift and go to state 19 + BYTE shift and go to state 20 + SHORT shift and go to state 21 + DOUBLE shift and go to state 22 + LONG shift and go to state 23 + INTEGER shift and go to state 24 + STRING shift and go to state 25 LBRACE shift and go to state 3 - LBRACKET shift and go to state 25 + LBRACKET shift and go to state 26 value shift and go to state 15 compound shift and go to state 16 list shift and go to state 17 + array shift and go to state 18 state 13 (8) key_value_pair -> STRING COLON . value (9) value -> . compound (10) value -> . list - (11) value -> . BOOL - (12) value -> . BYTE - (13) value -> . SHORT - (14) value -> . DOUBLE - (15) value -> . LONG - (16) value -> . INTEGER - (17) value -> . STRING + (11) value -> . array + (12) value -> . BOOL + (13) value -> . BYTE + (14) value -> . SHORT + (15) value -> . DOUBLE + (16) value -> . LONG + (17) value -> . INTEGER + (18) value -> . STRING (2) compound -> . LBRACE key_value_pairs RBRACE (3) compound -> . LBRACE RBRACE - (18) list -> . LBRACKET values RBRACKET - (19) list -> . LBRACKET RBRACKET - - BOOL shift and go to state 18 - BYTE shift and go to state 19 - SHORT shift and go to state 20 - DOUBLE shift and go to state 21 - LONG shift and go to state 22 - INTEGER shift and go to state 23 - STRING shift and go to state 24 + (19) list -> . LBRACKET values RBRACKET + (20) list -> . LBRACKET RBRACKET + (21) array -> . LBRACKET NAME SEMICOLON values RBRACKET + (22) array -> . LBRACKET NAME SEMICOLON RBRACKET + + BOOL shift and go to state 19 + BYTE shift and go to state 20 + SHORT shift and go to state 21 + DOUBLE shift and go to state 22 + LONG shift and go to state 23 + INTEGER shift and go to state 24 + STRING shift and go to state 25 LBRACE shift and go to state 3 - LBRACKET shift and go to state 25 + LBRACKET shift and go to state 26 - value shift and go to state 26 + value shift and go to state 27 compound shift and go to state 16 list shift and go to state 17 + array shift and go to state 18 state 14 @@ -320,175 +333,201 @@ state 17 state 18 - (11) value -> BOOL . + (11) value -> array . - RBRACE reduce using rule 11 (value -> BOOL .) - COMMA reduce using rule 11 (value -> BOOL .) - NAME reduce using rule 11 (value -> BOOL .) - STRING reduce using rule 11 (value -> BOOL .) - RBRACKET reduce using rule 11 (value -> BOOL .) - BOOL reduce using rule 11 (value -> BOOL .) - BYTE reduce using rule 11 (value -> BOOL .) - SHORT reduce using rule 11 (value -> BOOL .) - DOUBLE reduce using rule 11 (value -> BOOL .) - LONG reduce using rule 11 (value -> BOOL .) - INTEGER reduce using rule 11 (value -> BOOL .) - LBRACE reduce using rule 11 (value -> BOOL .) - LBRACKET reduce using rule 11 (value -> BOOL .) + RBRACE reduce using rule 11 (value -> array .) + COMMA reduce using rule 11 (value -> array .) + NAME reduce using rule 11 (value -> array .) + STRING reduce using rule 11 (value -> array .) + RBRACKET reduce using rule 11 (value -> array .) + BOOL reduce using rule 11 (value -> array .) + BYTE reduce using rule 11 (value -> array .) + SHORT reduce using rule 11 (value -> array .) + DOUBLE reduce using rule 11 (value -> array .) + LONG reduce using rule 11 (value -> array .) + INTEGER reduce using rule 11 (value -> array .) + LBRACE reduce using rule 11 (value -> array .) + LBRACKET reduce using rule 11 (value -> array .) state 19 - (12) value -> BYTE . + (12) value -> BOOL . - RBRACE reduce using rule 12 (value -> BYTE .) - COMMA reduce using rule 12 (value -> BYTE .) - NAME reduce using rule 12 (value -> BYTE .) - STRING reduce using rule 12 (value -> BYTE .) - RBRACKET reduce using rule 12 (value -> BYTE .) - BOOL reduce using rule 12 (value -> BYTE .) - BYTE reduce using rule 12 (value -> BYTE .) - SHORT reduce using rule 12 (value -> BYTE .) - DOUBLE reduce using rule 12 (value -> BYTE .) - LONG reduce using rule 12 (value -> BYTE .) - INTEGER reduce using rule 12 (value -> BYTE .) - LBRACE reduce using rule 12 (value -> BYTE .) - LBRACKET reduce using rule 12 (value -> BYTE .) + RBRACE reduce using rule 12 (value -> BOOL .) + COMMA reduce using rule 12 (value -> BOOL .) + NAME reduce using rule 12 (value -> BOOL .) + STRING reduce using rule 12 (value -> BOOL .) + RBRACKET reduce using rule 12 (value -> BOOL .) + BOOL reduce using rule 12 (value -> BOOL .) + BYTE reduce using rule 12 (value -> BOOL .) + SHORT reduce using rule 12 (value -> BOOL .) + DOUBLE reduce using rule 12 (value -> BOOL .) + LONG reduce using rule 12 (value -> BOOL .) + INTEGER reduce using rule 12 (value -> BOOL .) + LBRACE reduce using rule 12 (value -> BOOL .) + LBRACKET reduce using rule 12 (value -> BOOL .) state 20 - (13) value -> SHORT . + (13) value -> BYTE . - RBRACE reduce using rule 13 (value -> SHORT .) - COMMA reduce using rule 13 (value -> SHORT .) - NAME reduce using rule 13 (value -> SHORT .) - STRING reduce using rule 13 (value -> SHORT .) - RBRACKET reduce using rule 13 (value -> SHORT .) - BOOL reduce using rule 13 (value -> SHORT .) - BYTE reduce using rule 13 (value -> SHORT .) - SHORT reduce using rule 13 (value -> SHORT .) - DOUBLE reduce using rule 13 (value -> SHORT .) - LONG reduce using rule 13 (value -> SHORT .) - INTEGER reduce using rule 13 (value -> SHORT .) - LBRACE reduce using rule 13 (value -> SHORT .) - LBRACKET reduce using rule 13 (value -> SHORT .) + RBRACE reduce using rule 13 (value -> BYTE .) + COMMA reduce using rule 13 (value -> BYTE .) + NAME reduce using rule 13 (value -> BYTE .) + STRING reduce using rule 13 (value -> BYTE .) + RBRACKET reduce using rule 13 (value -> BYTE .) + BOOL reduce using rule 13 (value -> BYTE .) + BYTE reduce using rule 13 (value -> BYTE .) + SHORT reduce using rule 13 (value -> BYTE .) + DOUBLE reduce using rule 13 (value -> BYTE .) + LONG reduce using rule 13 (value -> BYTE .) + INTEGER reduce using rule 13 (value -> BYTE .) + LBRACE reduce using rule 13 (value -> BYTE .) + LBRACKET reduce using rule 13 (value -> BYTE .) state 21 - (14) value -> DOUBLE . + (14) value -> SHORT . - RBRACE reduce using rule 14 (value -> DOUBLE .) - COMMA reduce using rule 14 (value -> DOUBLE .) - NAME reduce using rule 14 (value -> DOUBLE .) - STRING reduce using rule 14 (value -> DOUBLE .) - RBRACKET reduce using rule 14 (value -> DOUBLE .) - BOOL reduce using rule 14 (value -> DOUBLE .) - BYTE reduce using rule 14 (value -> DOUBLE .) - SHORT reduce using rule 14 (value -> DOUBLE .) - DOUBLE reduce using rule 14 (value -> DOUBLE .) - LONG reduce using rule 14 (value -> DOUBLE .) - INTEGER reduce using rule 14 (value -> DOUBLE .) - LBRACE reduce using rule 14 (value -> DOUBLE .) - LBRACKET reduce using rule 14 (value -> DOUBLE .) + RBRACE reduce using rule 14 (value -> SHORT .) + COMMA reduce using rule 14 (value -> SHORT .) + NAME reduce using rule 14 (value -> SHORT .) + STRING reduce using rule 14 (value -> SHORT .) + RBRACKET reduce using rule 14 (value -> SHORT .) + BOOL reduce using rule 14 (value -> SHORT .) + BYTE reduce using rule 14 (value -> SHORT .) + SHORT reduce using rule 14 (value -> SHORT .) + DOUBLE reduce using rule 14 (value -> SHORT .) + LONG reduce using rule 14 (value -> SHORT .) + INTEGER reduce using rule 14 (value -> SHORT .) + LBRACE reduce using rule 14 (value -> SHORT .) + LBRACKET reduce using rule 14 (value -> SHORT .) state 22 - (15) value -> LONG . + (15) value -> DOUBLE . - RBRACE reduce using rule 15 (value -> LONG .) - COMMA reduce using rule 15 (value -> LONG .) - NAME reduce using rule 15 (value -> LONG .) - STRING reduce using rule 15 (value -> LONG .) - RBRACKET reduce using rule 15 (value -> LONG .) - BOOL reduce using rule 15 (value -> LONG .) - BYTE reduce using rule 15 (value -> LONG .) - SHORT reduce using rule 15 (value -> LONG .) - DOUBLE reduce using rule 15 (value -> LONG .) - LONG reduce using rule 15 (value -> LONG .) - INTEGER reduce using rule 15 (value -> LONG .) - LBRACE reduce using rule 15 (value -> LONG .) - LBRACKET reduce using rule 15 (value -> LONG .) + RBRACE reduce using rule 15 (value -> DOUBLE .) + COMMA reduce using rule 15 (value -> DOUBLE .) + NAME reduce using rule 15 (value -> DOUBLE .) + STRING reduce using rule 15 (value -> DOUBLE .) + RBRACKET reduce using rule 15 (value -> DOUBLE .) + BOOL reduce using rule 15 (value -> DOUBLE .) + BYTE reduce using rule 15 (value -> DOUBLE .) + SHORT reduce using rule 15 (value -> DOUBLE .) + DOUBLE reduce using rule 15 (value -> DOUBLE .) + LONG reduce using rule 15 (value -> DOUBLE .) + INTEGER reduce using rule 15 (value -> DOUBLE .) + LBRACE reduce using rule 15 (value -> DOUBLE .) + LBRACKET reduce using rule 15 (value -> DOUBLE .) state 23 - (16) value -> INTEGER . + (16) value -> LONG . - RBRACE reduce using rule 16 (value -> INTEGER .) - COMMA reduce using rule 16 (value -> INTEGER .) - NAME reduce using rule 16 (value -> INTEGER .) - STRING reduce using rule 16 (value -> INTEGER .) - RBRACKET reduce using rule 16 (value -> INTEGER .) - BOOL reduce using rule 16 (value -> INTEGER .) - BYTE reduce using rule 16 (value -> INTEGER .) - SHORT reduce using rule 16 (value -> INTEGER .) - DOUBLE reduce using rule 16 (value -> INTEGER .) - LONG reduce using rule 16 (value -> INTEGER .) - INTEGER reduce using rule 16 (value -> INTEGER .) - LBRACE reduce using rule 16 (value -> INTEGER .) - LBRACKET reduce using rule 16 (value -> INTEGER .) + RBRACE reduce using rule 16 (value -> LONG .) + COMMA reduce using rule 16 (value -> LONG .) + NAME reduce using rule 16 (value -> LONG .) + STRING reduce using rule 16 (value -> LONG .) + RBRACKET reduce using rule 16 (value -> LONG .) + BOOL reduce using rule 16 (value -> LONG .) + BYTE reduce using rule 16 (value -> LONG .) + SHORT reduce using rule 16 (value -> LONG .) + DOUBLE reduce using rule 16 (value -> LONG .) + LONG reduce using rule 16 (value -> LONG .) + INTEGER reduce using rule 16 (value -> LONG .) + LBRACE reduce using rule 16 (value -> LONG .) + LBRACKET reduce using rule 16 (value -> LONG .) state 24 - (17) value -> STRING . + (17) value -> INTEGER . - RBRACE reduce using rule 17 (value -> STRING .) - COMMA reduce using rule 17 (value -> STRING .) - NAME reduce using rule 17 (value -> STRING .) - STRING reduce using rule 17 (value -> STRING .) - RBRACKET reduce using rule 17 (value -> STRING .) - BOOL reduce using rule 17 (value -> STRING .) - BYTE reduce using rule 17 (value -> STRING .) - SHORT reduce using rule 17 (value -> STRING .) - DOUBLE reduce using rule 17 (value -> STRING .) - LONG reduce using rule 17 (value -> STRING .) - INTEGER reduce using rule 17 (value -> STRING .) - LBRACE reduce using rule 17 (value -> STRING .) - LBRACKET reduce using rule 17 (value -> STRING .) + RBRACE reduce using rule 17 (value -> INTEGER .) + COMMA reduce using rule 17 (value -> INTEGER .) + NAME reduce using rule 17 (value -> INTEGER .) + STRING reduce using rule 17 (value -> INTEGER .) + RBRACKET reduce using rule 17 (value -> INTEGER .) + BOOL reduce using rule 17 (value -> INTEGER .) + BYTE reduce using rule 17 (value -> INTEGER .) + SHORT reduce using rule 17 (value -> INTEGER .) + DOUBLE reduce using rule 17 (value -> INTEGER .) + LONG reduce using rule 17 (value -> INTEGER .) + INTEGER reduce using rule 17 (value -> INTEGER .) + LBRACE reduce using rule 17 (value -> INTEGER .) + LBRACKET reduce using rule 17 (value -> INTEGER .) state 25 - (18) list -> LBRACKET . values RBRACKET - (19) list -> LBRACKET . RBRACKET - (20) values -> . values value - (21) values -> . values COMMA value - (22) values -> . value + (18) value -> STRING . + + RBRACE reduce using rule 18 (value -> STRING .) + COMMA reduce using rule 18 (value -> STRING .) + NAME reduce using rule 18 (value -> STRING .) + STRING reduce using rule 18 (value -> STRING .) + RBRACKET reduce using rule 18 (value -> STRING .) + BOOL reduce using rule 18 (value -> STRING .) + BYTE reduce using rule 18 (value -> STRING .) + SHORT reduce using rule 18 (value -> STRING .) + DOUBLE reduce using rule 18 (value -> STRING .) + LONG reduce using rule 18 (value -> STRING .) + INTEGER reduce using rule 18 (value -> STRING .) + LBRACE reduce using rule 18 (value -> STRING .) + LBRACKET reduce using rule 18 (value -> STRING .) + + +state 26 + + (19) list -> LBRACKET . values RBRACKET + (20) list -> LBRACKET . RBRACKET + (21) array -> LBRACKET . NAME SEMICOLON values RBRACKET + (22) array -> LBRACKET . NAME SEMICOLON RBRACKET + (23) values -> . values value + (24) values -> . values COMMA value + (25) values -> . value (9) value -> . compound (10) value -> . list - (11) value -> . BOOL - (12) value -> . BYTE - (13) value -> . SHORT - (14) value -> . DOUBLE - (15) value -> . LONG - (16) value -> . INTEGER - (17) value -> . STRING + (11) value -> . array + (12) value -> . BOOL + (13) value -> . BYTE + (14) value -> . SHORT + (15) value -> . DOUBLE + (16) value -> . LONG + (17) value -> . INTEGER + (18) value -> . STRING (2) compound -> . LBRACE key_value_pairs RBRACE (3) compound -> . LBRACE RBRACE - (18) list -> . LBRACKET values RBRACKET - (19) list -> . LBRACKET RBRACKET - - RBRACKET shift and go to state 28 - BOOL shift and go to state 18 - BYTE shift and go to state 19 - SHORT shift and go to state 20 - DOUBLE shift and go to state 21 - LONG shift and go to state 22 - INTEGER shift and go to state 23 - STRING shift and go to state 24 + (19) list -> . LBRACKET values RBRACKET + (20) list -> . LBRACKET RBRACKET + (21) array -> . LBRACKET NAME SEMICOLON values RBRACKET + (22) array -> . LBRACKET NAME SEMICOLON RBRACKET + + RBRACKET shift and go to state 29 + NAME shift and go to state 30 + BOOL shift and go to state 19 + BYTE shift and go to state 20 + SHORT shift and go to state 21 + DOUBLE shift and go to state 22 + LONG shift and go to state 23 + INTEGER shift and go to state 24 + STRING shift and go to state 25 LBRACE shift and go to state 3 - LBRACKET shift and go to state 25 + LBRACKET shift and go to state 26 - values shift and go to state 27 - value shift and go to state 29 + values shift and go to state 28 + value shift and go to state 31 compound shift and go to state 16 list shift and go to state 17 + array shift and go to state 18 -state 26 +state 27 (8) key_value_pair -> STRING COLON value . @@ -498,157 +537,291 @@ state 26 STRING reduce using rule 8 (key_value_pair -> STRING COLON value .) -state 27 +state 28 - (18) list -> LBRACKET values . RBRACKET - (20) values -> values . value - (21) values -> values . COMMA value + (19) list -> LBRACKET values . RBRACKET + (23) values -> values . value + (24) values -> values . COMMA value (9) value -> . compound (10) value -> . list - (11) value -> . BOOL - (12) value -> . BYTE - (13) value -> . SHORT - (14) value -> . DOUBLE - (15) value -> . LONG - (16) value -> . INTEGER - (17) value -> . STRING + (11) value -> . array + (12) value -> . BOOL + (13) value -> . BYTE + (14) value -> . SHORT + (15) value -> . DOUBLE + (16) value -> . LONG + (17) value -> . INTEGER + (18) value -> . STRING (2) compound -> . LBRACE key_value_pairs RBRACE (3) compound -> . LBRACE RBRACE - (18) list -> . LBRACKET values RBRACKET - (19) list -> . LBRACKET RBRACKET - - RBRACKET shift and go to state 30 - COMMA shift and go to state 32 - BOOL shift and go to state 18 - BYTE shift and go to state 19 - SHORT shift and go to state 20 - DOUBLE shift and go to state 21 - LONG shift and go to state 22 - INTEGER shift and go to state 23 - STRING shift and go to state 24 + (19) list -> . LBRACKET values RBRACKET + (20) list -> . LBRACKET RBRACKET + (21) array -> . LBRACKET NAME SEMICOLON values RBRACKET + (22) array -> . LBRACKET NAME SEMICOLON RBRACKET + + RBRACKET shift and go to state 32 + COMMA shift and go to state 34 + BOOL shift and go to state 19 + BYTE shift and go to state 20 + SHORT shift and go to state 21 + DOUBLE shift and go to state 22 + LONG shift and go to state 23 + INTEGER shift and go to state 24 + STRING shift and go to state 25 LBRACE shift and go to state 3 - LBRACKET shift and go to state 25 + LBRACKET shift and go to state 26 - value shift and go to state 31 + value shift and go to state 33 compound shift and go to state 16 list shift and go to state 17 - -state 28 - - (19) list -> LBRACKET RBRACKET . - - RBRACE reduce using rule 19 (list -> LBRACKET RBRACKET .) - COMMA reduce using rule 19 (list -> LBRACKET RBRACKET .) - NAME reduce using rule 19 (list -> LBRACKET RBRACKET .) - STRING reduce using rule 19 (list -> LBRACKET RBRACKET .) - RBRACKET reduce using rule 19 (list -> LBRACKET RBRACKET .) - BOOL reduce using rule 19 (list -> LBRACKET RBRACKET .) - BYTE reduce using rule 19 (list -> LBRACKET RBRACKET .) - SHORT reduce using rule 19 (list -> LBRACKET RBRACKET .) - DOUBLE reduce using rule 19 (list -> LBRACKET RBRACKET .) - LONG reduce using rule 19 (list -> LBRACKET RBRACKET .) - INTEGER reduce using rule 19 (list -> LBRACKET RBRACKET .) - LBRACE reduce using rule 19 (list -> LBRACKET RBRACKET .) - LBRACKET reduce using rule 19 (list -> LBRACKET RBRACKET .) - + array shift and go to state 18 state 29 - (22) values -> value . + (20) list -> LBRACKET RBRACKET . - RBRACKET reduce using rule 22 (values -> value .) - COMMA reduce using rule 22 (values -> value .) - BOOL reduce using rule 22 (values -> value .) - BYTE reduce using rule 22 (values -> value .) - SHORT reduce using rule 22 (values -> value .) - DOUBLE reduce using rule 22 (values -> value .) - LONG reduce using rule 22 (values -> value .) - INTEGER reduce using rule 22 (values -> value .) - STRING reduce using rule 22 (values -> value .) - LBRACE reduce using rule 22 (values -> value .) - LBRACKET reduce using rule 22 (values -> value .) + RBRACE reduce using rule 20 (list -> LBRACKET RBRACKET .) + COMMA reduce using rule 20 (list -> LBRACKET RBRACKET .) + NAME reduce using rule 20 (list -> LBRACKET RBRACKET .) + STRING reduce using rule 20 (list -> LBRACKET RBRACKET .) + RBRACKET reduce using rule 20 (list -> LBRACKET RBRACKET .) + BOOL reduce using rule 20 (list -> LBRACKET RBRACKET .) + BYTE reduce using rule 20 (list -> LBRACKET RBRACKET .) + SHORT reduce using rule 20 (list -> LBRACKET RBRACKET .) + DOUBLE reduce using rule 20 (list -> LBRACKET RBRACKET .) + LONG reduce using rule 20 (list -> LBRACKET RBRACKET .) + INTEGER reduce using rule 20 (list -> LBRACKET RBRACKET .) + LBRACE reduce using rule 20 (list -> LBRACKET RBRACKET .) + LBRACKET reduce using rule 20 (list -> LBRACKET RBRACKET .) state 30 - (18) list -> LBRACKET values RBRACKET . + (21) array -> LBRACKET NAME . SEMICOLON values RBRACKET + (22) array -> LBRACKET NAME . SEMICOLON RBRACKET - RBRACE reduce using rule 18 (list -> LBRACKET values RBRACKET .) - COMMA reduce using rule 18 (list -> LBRACKET values RBRACKET .) - NAME reduce using rule 18 (list -> LBRACKET values RBRACKET .) - STRING reduce using rule 18 (list -> LBRACKET values RBRACKET .) - RBRACKET reduce using rule 18 (list -> LBRACKET values RBRACKET .) - BOOL reduce using rule 18 (list -> LBRACKET values RBRACKET .) - BYTE reduce using rule 18 (list -> LBRACKET values RBRACKET .) - SHORT reduce using rule 18 (list -> LBRACKET values RBRACKET .) - DOUBLE reduce using rule 18 (list -> LBRACKET values RBRACKET .) - LONG reduce using rule 18 (list -> LBRACKET values RBRACKET .) - INTEGER reduce using rule 18 (list -> LBRACKET values RBRACKET .) - LBRACE reduce using rule 18 (list -> LBRACKET values RBRACKET .) - LBRACKET reduce using rule 18 (list -> LBRACKET values RBRACKET .) + SEMICOLON shift and go to state 35 state 31 - (20) values -> values value . + (25) values -> value . - RBRACKET reduce using rule 20 (values -> values value .) - COMMA reduce using rule 20 (values -> values value .) - BOOL reduce using rule 20 (values -> values value .) - BYTE reduce using rule 20 (values -> values value .) - SHORT reduce using rule 20 (values -> values value .) - DOUBLE reduce using rule 20 (values -> values value .) - LONG reduce using rule 20 (values -> values value .) - INTEGER reduce using rule 20 (values -> values value .) - STRING reduce using rule 20 (values -> values value .) - LBRACE reduce using rule 20 (values -> values value .) - LBRACKET reduce using rule 20 (values -> values value .) + RBRACKET reduce using rule 25 (values -> value .) + COMMA reduce using rule 25 (values -> value .) + BOOL reduce using rule 25 (values -> value .) + BYTE reduce using rule 25 (values -> value .) + SHORT reduce using rule 25 (values -> value .) + DOUBLE reduce using rule 25 (values -> value .) + LONG reduce using rule 25 (values -> value .) + INTEGER reduce using rule 25 (values -> value .) + STRING reduce using rule 25 (values -> value .) + LBRACE reduce using rule 25 (values -> value .) + LBRACKET reduce using rule 25 (values -> value .) state 32 - (21) values -> values COMMA . value + (19) list -> LBRACKET values RBRACKET . + + RBRACE reduce using rule 19 (list -> LBRACKET values RBRACKET .) + COMMA reduce using rule 19 (list -> LBRACKET values RBRACKET .) + NAME reduce using rule 19 (list -> LBRACKET values RBRACKET .) + STRING reduce using rule 19 (list -> LBRACKET values RBRACKET .) + RBRACKET reduce using rule 19 (list -> LBRACKET values RBRACKET .) + BOOL reduce using rule 19 (list -> LBRACKET values RBRACKET .) + BYTE reduce using rule 19 (list -> LBRACKET values RBRACKET .) + SHORT reduce using rule 19 (list -> LBRACKET values RBRACKET .) + DOUBLE reduce using rule 19 (list -> LBRACKET values RBRACKET .) + LONG reduce using rule 19 (list -> LBRACKET values RBRACKET .) + INTEGER reduce using rule 19 (list -> LBRACKET values RBRACKET .) + LBRACE reduce using rule 19 (list -> LBRACKET values RBRACKET .) + LBRACKET reduce using rule 19 (list -> LBRACKET values RBRACKET .) + + +state 33 + + (23) values -> values value . + + RBRACKET reduce using rule 23 (values -> values value .) + COMMA reduce using rule 23 (values -> values value .) + BOOL reduce using rule 23 (values -> values value .) + BYTE reduce using rule 23 (values -> values value .) + SHORT reduce using rule 23 (values -> values value .) + DOUBLE reduce using rule 23 (values -> values value .) + LONG reduce using rule 23 (values -> values value .) + INTEGER reduce using rule 23 (values -> values value .) + STRING reduce using rule 23 (values -> values value .) + LBRACE reduce using rule 23 (values -> values value .) + LBRACKET reduce using rule 23 (values -> values value .) + + +state 34 + + (24) values -> values COMMA . value (9) value -> . compound (10) value -> . list - (11) value -> . BOOL - (12) value -> . BYTE - (13) value -> . SHORT - (14) value -> . DOUBLE - (15) value -> . LONG - (16) value -> . INTEGER - (17) value -> . STRING + (11) value -> . array + (12) value -> . BOOL + (13) value -> . BYTE + (14) value -> . SHORT + (15) value -> . DOUBLE + (16) value -> . LONG + (17) value -> . INTEGER + (18) value -> . STRING (2) compound -> . LBRACE key_value_pairs RBRACE (3) compound -> . LBRACE RBRACE - (18) list -> . LBRACKET values RBRACKET - (19) list -> . LBRACKET RBRACKET - - BOOL shift and go to state 18 - BYTE shift and go to state 19 - SHORT shift and go to state 20 - DOUBLE shift and go to state 21 - LONG shift and go to state 22 - INTEGER shift and go to state 23 - STRING shift and go to state 24 + (19) list -> . LBRACKET values RBRACKET + (20) list -> . LBRACKET RBRACKET + (21) array -> . LBRACKET NAME SEMICOLON values RBRACKET + (22) array -> . LBRACKET NAME SEMICOLON RBRACKET + + BOOL shift and go to state 19 + BYTE shift and go to state 20 + SHORT shift and go to state 21 + DOUBLE shift and go to state 22 + LONG shift and go to state 23 + INTEGER shift and go to state 24 + STRING shift and go to state 25 LBRACE shift and go to state 3 - LBRACKET shift and go to state 25 + LBRACKET shift and go to state 26 - value shift and go to state 33 + value shift and go to state 36 compound shift and go to state 16 list shift and go to state 17 + array shift and go to state 18 -state 33 +state 35 + + (21) array -> LBRACKET NAME SEMICOLON . values RBRACKET + (22) array -> LBRACKET NAME SEMICOLON . RBRACKET + (23) values -> . values value + (24) values -> . values COMMA value + (25) values -> . value + (9) value -> . compound + (10) value -> . list + (11) value -> . array + (12) value -> . BOOL + (13) value -> . BYTE + (14) value -> . SHORT + (15) value -> . DOUBLE + (16) value -> . LONG + (17) value -> . INTEGER + (18) value -> . STRING + (2) compound -> . LBRACE key_value_pairs RBRACE + (3) compound -> . LBRACE RBRACE + (19) list -> . LBRACKET values RBRACKET + (20) list -> . LBRACKET RBRACKET + (21) array -> . LBRACKET NAME SEMICOLON values RBRACKET + (22) array -> . LBRACKET NAME SEMICOLON RBRACKET + + RBRACKET shift and go to state 38 + BOOL shift and go to state 19 + BYTE shift and go to state 20 + SHORT shift and go to state 21 + DOUBLE shift and go to state 22 + LONG shift and go to state 23 + INTEGER shift and go to state 24 + STRING shift and go to state 25 + LBRACE shift and go to state 3 + LBRACKET shift and go to state 26 + + values shift and go to state 37 + value shift and go to state 31 + compound shift and go to state 16 + list shift and go to state 17 + array shift and go to state 18 + +state 36 - (21) values -> values COMMA value . - - RBRACKET reduce using rule 21 (values -> values COMMA value .) - COMMA reduce using rule 21 (values -> values COMMA value .) - BOOL reduce using rule 21 (values -> values COMMA value .) - BYTE reduce using rule 21 (values -> values COMMA value .) - SHORT reduce using rule 21 (values -> values COMMA value .) - DOUBLE reduce using rule 21 (values -> values COMMA value .) - LONG reduce using rule 21 (values -> values COMMA value .) - INTEGER reduce using rule 21 (values -> values COMMA value .) - STRING reduce using rule 21 (values -> values COMMA value .) - LBRACE reduce using rule 21 (values -> values COMMA value .) - LBRACKET reduce using rule 21 (values -> values COMMA value .) + (24) values -> values COMMA value . + + RBRACKET reduce using rule 24 (values -> values COMMA value .) + COMMA reduce using rule 24 (values -> values COMMA value .) + BOOL reduce using rule 24 (values -> values COMMA value .) + BYTE reduce using rule 24 (values -> values COMMA value .) + SHORT reduce using rule 24 (values -> values COMMA value .) + DOUBLE reduce using rule 24 (values -> values COMMA value .) + LONG reduce using rule 24 (values -> values COMMA value .) + INTEGER reduce using rule 24 (values -> values COMMA value .) + STRING reduce using rule 24 (values -> values COMMA value .) + LBRACE reduce using rule 24 (values -> values COMMA value .) + LBRACKET reduce using rule 24 (values -> values COMMA value .) + + +state 37 + + (21) array -> LBRACKET NAME SEMICOLON values . RBRACKET + (23) values -> values . value + (24) values -> values . COMMA value + (9) value -> . compound + (10) value -> . list + (11) value -> . array + (12) value -> . BOOL + (13) value -> . BYTE + (14) value -> . SHORT + (15) value -> . DOUBLE + (16) value -> . LONG + (17) value -> . INTEGER + (18) value -> . STRING + (2) compound -> . LBRACE key_value_pairs RBRACE + (3) compound -> . LBRACE RBRACE + (19) list -> . LBRACKET values RBRACKET + (20) list -> . LBRACKET RBRACKET + (21) array -> . LBRACKET NAME SEMICOLON values RBRACKET + (22) array -> . LBRACKET NAME SEMICOLON RBRACKET + + RBRACKET shift and go to state 39 + COMMA shift and go to state 34 + BOOL shift and go to state 19 + BYTE shift and go to state 20 + SHORT shift and go to state 21 + DOUBLE shift and go to state 22 + LONG shift and go to state 23 + INTEGER shift and go to state 24 + STRING shift and go to state 25 + LBRACE shift and go to state 3 + LBRACKET shift and go to state 26 + + value shift and go to state 33 + compound shift and go to state 16 + list shift and go to state 17 + array shift and go to state 18 + +state 38 + + (22) array -> LBRACKET NAME SEMICOLON RBRACKET . + + RBRACE reduce using rule 22 (array -> LBRACKET NAME SEMICOLON RBRACKET .) + COMMA reduce using rule 22 (array -> LBRACKET NAME SEMICOLON RBRACKET .) + NAME reduce using rule 22 (array -> LBRACKET NAME SEMICOLON RBRACKET .) + STRING reduce using rule 22 (array -> LBRACKET NAME SEMICOLON RBRACKET .) + RBRACKET reduce using rule 22 (array -> LBRACKET NAME SEMICOLON RBRACKET .) + BOOL reduce using rule 22 (array -> LBRACKET NAME SEMICOLON RBRACKET .) + BYTE reduce using rule 22 (array -> LBRACKET NAME SEMICOLON RBRACKET .) + SHORT reduce using rule 22 (array -> LBRACKET NAME SEMICOLON RBRACKET .) + DOUBLE reduce using rule 22 (array -> LBRACKET NAME SEMICOLON RBRACKET .) + LONG reduce using rule 22 (array -> LBRACKET NAME SEMICOLON RBRACKET .) + INTEGER reduce using rule 22 (array -> LBRACKET NAME SEMICOLON RBRACKET .) + LBRACE reduce using rule 22 (array -> LBRACKET NAME SEMICOLON RBRACKET .) + LBRACKET reduce using rule 22 (array -> LBRACKET NAME SEMICOLON RBRACKET .) + + +state 39 + + (21) array -> LBRACKET NAME SEMICOLON values RBRACKET . + + RBRACE reduce using rule 21 (array -> LBRACKET NAME SEMICOLON values RBRACKET .) + COMMA reduce using rule 21 (array -> LBRACKET NAME SEMICOLON values RBRACKET .) + NAME reduce using rule 21 (array -> LBRACKET NAME SEMICOLON values RBRACKET .) + STRING reduce using rule 21 (array -> LBRACKET NAME SEMICOLON values RBRACKET .) + RBRACKET reduce using rule 21 (array -> LBRACKET NAME SEMICOLON values RBRACKET .) + BOOL reduce using rule 21 (array -> LBRACKET NAME SEMICOLON values RBRACKET .) + BYTE reduce using rule 21 (array -> LBRACKET NAME SEMICOLON values RBRACKET .) + SHORT reduce using rule 21 (array -> LBRACKET NAME SEMICOLON values RBRACKET .) + DOUBLE reduce using rule 21 (array -> LBRACKET NAME SEMICOLON values RBRACKET .) + LONG reduce using rule 21 (array -> LBRACKET NAME SEMICOLON values RBRACKET .) + INTEGER reduce using rule 21 (array -> LBRACKET NAME SEMICOLON values RBRACKET .) + LBRACE reduce using rule 21 (array -> LBRACKET NAME SEMICOLON values RBRACKET .) + LBRACKET reduce using rule 21 (array -> LBRACKET NAME SEMICOLON values RBRACKET .) diff --git a/ftb_snbt_lib/parsetab.py b/ftb_snbt_lib/parsetab.py index 30fc1df..758d7a4 100644 --- a/ftb_snbt_lib/parsetab.py +++ b/ftb_snbt_lib/parsetab.py @@ -6,9 +6,9 @@ _lr_method = 'LALR' -_lr_signature = 'BOOL BYTE COLON COMMA DOUBLE INTEGER LBRACE LBRACKET LONG NAME RBRACE RBRACKET SHORT STRINGsnbt : compoundcompound : LBRACE key_value_pairs RBRACE\n | LBRACE RBRACEkey_value_pairs : key_value_pairs key_value_pair\n | key_value_pairs COMMA key_value_pair\n | key_value_pairkey_value_pair : NAME COLON value\n | STRING COLON valuevalue : compound\n | list\n | BOOL\n | BYTE\n | SHORT\n | DOUBLE\n | LONG\n | INTEGER\n | STRINGlist : LBRACKET values RBRACKET\n | LBRACKET RBRACKETvalues : values value\n | values COMMA value\n | value' +_lr_signature = 'BOOL BYTE COLON COMMA DOUBLE INTEGER LBRACE LBRACKET LONG NAME RBRACE RBRACKET SEMICOLON SHORT STRINGsnbt : compoundcompound : LBRACE key_value_pairs RBRACE\n | LBRACE RBRACEkey_value_pairs : key_value_pairs key_value_pair\n | key_value_pairs COMMA key_value_pair\n | key_value_pairkey_value_pair : NAME COLON value\n | STRING COLON valuevalue : compound\n | list\n | array\n | BOOL\n | BYTE\n | SHORT\n | DOUBLE\n | LONG\n | INTEGER\n | STRINGlist : LBRACKET values RBRACKET\n | LBRACKET RBRACKETarray : LBRACKET NAME SEMICOLON values RBRACKET\n | LBRACKET NAME SEMICOLON RBRACKETvalues : values value\n | values COMMA value\n | value' -_lr_action_items = {'LBRACE':([0,5,9,12,13,16,17,18,19,20,21,22,23,24,25,27,28,29,30,31,32,33,],[3,-3,-2,3,3,-9,-10,-11,-12,-13,-14,-15,-16,-17,3,3,-19,-22,-18,-20,3,-21,]),'$end':([1,2,5,9,],[0,-1,-3,-2,]),'RBRACE':([3,4,5,6,9,10,14,15,16,17,18,19,20,21,22,23,24,26,28,30,],[5,9,-3,-6,-2,-4,-5,-7,-9,-10,-11,-12,-13,-14,-15,-16,-17,-8,-19,-18,]),'NAME':([3,4,5,6,9,10,11,14,15,16,17,18,19,20,21,22,23,24,26,28,30,],[7,7,-3,-6,-2,-4,7,-5,-7,-9,-10,-11,-12,-13,-14,-15,-16,-17,-8,-19,-18,]),'STRING':([3,4,5,6,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,],[8,8,-3,-6,-2,-4,8,24,24,-5,-7,-9,-10,-11,-12,-13,-14,-15,-16,-17,24,-8,24,-19,-22,-18,-20,24,-21,]),'COMMA':([4,5,6,9,10,14,15,16,17,18,19,20,21,22,23,24,26,27,28,29,30,31,33,],[11,-3,-6,-2,-4,-5,-7,-9,-10,-11,-12,-13,-14,-15,-16,-17,-8,32,-19,-22,-18,-20,-21,]),'RBRACKET':([5,9,16,17,18,19,20,21,22,23,24,25,27,28,29,30,31,33,],[-3,-2,-9,-10,-11,-12,-13,-14,-15,-16,-17,28,30,-19,-22,-18,-20,-21,]),'BOOL':([5,9,12,13,16,17,18,19,20,21,22,23,24,25,27,28,29,30,31,32,33,],[-3,-2,18,18,-9,-10,-11,-12,-13,-14,-15,-16,-17,18,18,-19,-22,-18,-20,18,-21,]),'BYTE':([5,9,12,13,16,17,18,19,20,21,22,23,24,25,27,28,29,30,31,32,33,],[-3,-2,19,19,-9,-10,-11,-12,-13,-14,-15,-16,-17,19,19,-19,-22,-18,-20,19,-21,]),'SHORT':([5,9,12,13,16,17,18,19,20,21,22,23,24,25,27,28,29,30,31,32,33,],[-3,-2,20,20,-9,-10,-11,-12,-13,-14,-15,-16,-17,20,20,-19,-22,-18,-20,20,-21,]),'DOUBLE':([5,9,12,13,16,17,18,19,20,21,22,23,24,25,27,28,29,30,31,32,33,],[-3,-2,21,21,-9,-10,-11,-12,-13,-14,-15,-16,-17,21,21,-19,-22,-18,-20,21,-21,]),'LONG':([5,9,12,13,16,17,18,19,20,21,22,23,24,25,27,28,29,30,31,32,33,],[-3,-2,22,22,-9,-10,-11,-12,-13,-14,-15,-16,-17,22,22,-19,-22,-18,-20,22,-21,]),'INTEGER':([5,9,12,13,16,17,18,19,20,21,22,23,24,25,27,28,29,30,31,32,33,],[-3,-2,23,23,-9,-10,-11,-12,-13,-14,-15,-16,-17,23,23,-19,-22,-18,-20,23,-21,]),'LBRACKET':([5,9,12,13,16,17,18,19,20,21,22,23,24,25,27,28,29,30,31,32,33,],[-3,-2,25,25,-9,-10,-11,-12,-13,-14,-15,-16,-17,25,25,-19,-22,-18,-20,25,-21,]),'COLON':([7,8,],[12,13,]),} +_lr_action_items = {'LBRACE':([0,5,9,12,13,16,17,18,19,20,21,22,23,24,25,26,28,29,31,32,33,34,35,36,37,38,39,],[3,-3,-2,3,3,-9,-10,-11,-12,-13,-14,-15,-16,-17,-18,3,3,-20,-25,-19,-23,3,3,-24,3,-22,-21,]),'$end':([1,2,5,9,],[0,-1,-3,-2,]),'RBRACE':([3,4,5,6,9,10,14,15,16,17,18,19,20,21,22,23,24,25,27,29,32,38,39,],[5,9,-3,-6,-2,-4,-5,-7,-9,-10,-11,-12,-13,-14,-15,-16,-17,-18,-8,-20,-19,-22,-21,]),'NAME':([3,4,5,6,9,10,11,14,15,16,17,18,19,20,21,22,23,24,25,26,27,29,32,38,39,],[7,7,-3,-6,-2,-4,7,-5,-7,-9,-10,-11,-12,-13,-14,-15,-16,-17,-18,30,-8,-20,-19,-22,-21,]),'STRING':([3,4,5,6,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,31,32,33,34,35,36,37,38,39,],[8,8,-3,-6,-2,-4,8,25,25,-5,-7,-9,-10,-11,-12,-13,-14,-15,-16,-17,-18,25,-8,25,-20,-25,-19,-23,25,25,-24,25,-22,-21,]),'COMMA':([4,5,6,9,10,14,15,16,17,18,19,20,21,22,23,24,25,27,28,29,31,32,33,36,37,38,39,],[11,-3,-6,-2,-4,-5,-7,-9,-10,-11,-12,-13,-14,-15,-16,-17,-18,-8,34,-20,-25,-19,-23,-24,34,-22,-21,]),'RBRACKET':([5,9,16,17,18,19,20,21,22,23,24,25,26,28,29,31,32,33,35,36,37,38,39,],[-3,-2,-9,-10,-11,-12,-13,-14,-15,-16,-17,-18,29,32,-20,-25,-19,-23,38,-24,39,-22,-21,]),'BOOL':([5,9,12,13,16,17,18,19,20,21,22,23,24,25,26,28,29,31,32,33,34,35,36,37,38,39,],[-3,-2,19,19,-9,-10,-11,-12,-13,-14,-15,-16,-17,-18,19,19,-20,-25,-19,-23,19,19,-24,19,-22,-21,]),'BYTE':([5,9,12,13,16,17,18,19,20,21,22,23,24,25,26,28,29,31,32,33,34,35,36,37,38,39,],[-3,-2,20,20,-9,-10,-11,-12,-13,-14,-15,-16,-17,-18,20,20,-20,-25,-19,-23,20,20,-24,20,-22,-21,]),'SHORT':([5,9,12,13,16,17,18,19,20,21,22,23,24,25,26,28,29,31,32,33,34,35,36,37,38,39,],[-3,-2,21,21,-9,-10,-11,-12,-13,-14,-15,-16,-17,-18,21,21,-20,-25,-19,-23,21,21,-24,21,-22,-21,]),'DOUBLE':([5,9,12,13,16,17,18,19,20,21,22,23,24,25,26,28,29,31,32,33,34,35,36,37,38,39,],[-3,-2,22,22,-9,-10,-11,-12,-13,-14,-15,-16,-17,-18,22,22,-20,-25,-19,-23,22,22,-24,22,-22,-21,]),'LONG':([5,9,12,13,16,17,18,19,20,21,22,23,24,25,26,28,29,31,32,33,34,35,36,37,38,39,],[-3,-2,23,23,-9,-10,-11,-12,-13,-14,-15,-16,-17,-18,23,23,-20,-25,-19,-23,23,23,-24,23,-22,-21,]),'INTEGER':([5,9,12,13,16,17,18,19,20,21,22,23,24,25,26,28,29,31,32,33,34,35,36,37,38,39,],[-3,-2,24,24,-9,-10,-11,-12,-13,-14,-15,-16,-17,-18,24,24,-20,-25,-19,-23,24,24,-24,24,-22,-21,]),'LBRACKET':([5,9,12,13,16,17,18,19,20,21,22,23,24,25,26,28,29,31,32,33,34,35,36,37,38,39,],[-3,-2,26,26,-9,-10,-11,-12,-13,-14,-15,-16,-17,-18,26,26,-20,-25,-19,-23,26,26,-24,26,-22,-21,]),'COLON':([7,8,],[12,13,]),'SEMICOLON':([30,],[35,]),} _lr_action = {} for _k, _v in _lr_action_items.items(): @@ -17,7 +17,7 @@ _lr_action[_x][_k] = _y del _lr_action_items -_lr_goto_items = {'snbt':([0,],[1,]),'compound':([0,12,13,25,27,32,],[2,16,16,16,16,16,]),'key_value_pairs':([3,],[4,]),'key_value_pair':([3,4,11,],[6,10,14,]),'value':([12,13,25,27,32,],[15,26,29,31,33,]),'list':([12,13,25,27,32,],[17,17,17,17,17,]),'values':([25,],[27,]),} +_lr_goto_items = {'snbt':([0,],[1,]),'compound':([0,12,13,26,28,34,35,37,],[2,16,16,16,16,16,16,16,]),'key_value_pairs':([3,],[4,]),'key_value_pair':([3,4,11,],[6,10,14,]),'value':([12,13,26,28,34,35,37,],[15,27,31,33,36,31,33,]),'list':([12,13,26,28,34,35,37,],[17,17,17,17,17,17,17,]),'array':([12,13,26,28,34,35,37,],[18,18,18,18,18,18,18,]),'values':([26,35,],[28,37,]),} _lr_goto = {} for _k, _v in _lr_goto_items.items(): @@ -37,16 +37,19 @@ ('key_value_pair -> STRING COLON value','key_value_pair',3,'p_key_value_pair','parse.py',32), ('value -> compound','value',1,'p_value','parse.py',36), ('value -> list','value',1,'p_value','parse.py',37), - ('value -> BOOL','value',1,'p_value','parse.py',38), - ('value -> BYTE','value',1,'p_value','parse.py',39), - ('value -> SHORT','value',1,'p_value','parse.py',40), - ('value -> DOUBLE','value',1,'p_value','parse.py',41), - ('value -> LONG','value',1,'p_value','parse.py',42), - ('value -> INTEGER','value',1,'p_value','parse.py',43), - ('value -> STRING','value',1,'p_value','parse.py',44), - ('list -> LBRACKET values RBRACKET','list',3,'p_list','parse.py',48), - ('list -> LBRACKET RBRACKET','list',2,'p_list','parse.py',49), - ('values -> values value','values',2,'p_values','parse.py',56), - ('values -> values COMMA value','values',3,'p_values','parse.py',57), - ('values -> value','values',1,'p_values','parse.py',58), + ('value -> array','value',1,'p_value','parse.py',38), + ('value -> BOOL','value',1,'p_value','parse.py',39), + ('value -> BYTE','value',1,'p_value','parse.py',40), + ('value -> SHORT','value',1,'p_value','parse.py',41), + ('value -> DOUBLE','value',1,'p_value','parse.py',42), + ('value -> LONG','value',1,'p_value','parse.py',43), + ('value -> INTEGER','value',1,'p_value','parse.py',44), + ('value -> STRING','value',1,'p_value','parse.py',45), + ('list -> LBRACKET values RBRACKET','list',3,'p_list','parse.py',49), + ('list -> LBRACKET RBRACKET','list',2,'p_list','parse.py',50), + ('array -> LBRACKET NAME SEMICOLON values RBRACKET','array',5,'p_array','parse.py',57), + ('array -> LBRACKET NAME SEMICOLON RBRACKET','array',4,'p_array','parse.py',58), + ('values -> values value','values',2,'p_values','parse.py',65), + ('values -> values COMMA value','values',3,'p_values','parse.py',66), + ('values -> value','values',1,'p_values','parse.py',67), ] diff --git a/ftb_snbt_lib/tag.py b/ftb_snbt_lib/tag.py index 1626cf9..9dd8d89 100644 --- a/ftb_snbt_lib/tag.py +++ b/ftb_snbt_lib/tag.py @@ -1,4 +1,4 @@ -__all__ = ["Base", "Numeric", "NumericInteger", "Byte", "Short", "Integer", "Long", "Double", "Bool", "String", "List", "Compound"] +__all__ = ["Base", "Numeric", "NumericInteger", "Byte", "Short", "Integer", "Long", "Double", "Bool", "String", "List", "Array", "Compound"] class InvalidTypeError(ValueError): def __init__(self, item, cls): @@ -152,6 +152,74 @@ def cast_item(cls, item): raise CastError(item, cls.subtype) from e return item + +class Array(Base, list): + __slots__ = () + write_func = "array" + subtype = None + array_prefix = None + + def __new__(cls, subtype, iterable=()): + if cls.subtype is None: + cls = cls[subtype] + return super().__new__(cls, subtype, iterable) + + def __init__(self, subtype, iterable=()): + super().__init__(map(self.cast_item, iterable)) + + def __class_getitem__(cls, subtype): + if subtype == "B": + return ByteArray + if subtype == "I": + return IntArray + if subtype == "L": + return LongArray + raise TypeError(f"Array type must be specified with 'B', 'I', or 'L'") + + def __setitem__(self, index, value): + if isinstance(index, int): + super().__setitem__(index, self.cast_item(value)) + elif isinstance(index, slice): + super().__setitem__(index, map(self.cast_item, value)) + else: + raise TypeError(f"Array indices must be integers or slices, not {index.__class__.__name__}") + + def append(self, value): + super().append(self.cast_item(value)) + + def extend(self, iterable): + super().extend(map(self.cast_item, iterable)) + + def insert(self, index, value): + super().insert(index, self.cast_item(value)) + + @classmethod + def cast_item(cls, item): + if cls.subtype is None: + raise InvalidTypeError(item, cls) + + if not isinstance(item, cls.subtype): + try: + return cls.subtype(item) + except Exception as e: + raise CastError(item, cls.subtype) from e + + return item + +class ByteArray(Array): + __slots__ = () + subtype = Byte + array_prefix = "B" + +class IntArray(Array): + __slots__ = () + subtype = Integer + array_prefix = "I" + +class LongArray(Array): + __slots__ = () + subtype = Long + array_prefix = "L" class Compound(Base, dict): __slots__ = () diff --git a/ftb_snbt_lib/token.py b/ftb_snbt_lib/token.py index 3d21260..c7eccf2 100644 --- a/ftb_snbt_lib/token.py +++ b/ftb_snbt_lib/token.py @@ -15,6 +15,7 @@ "STRING", "NAME", "COLON", + "SEMICOLON", "COMMA", ) @@ -87,6 +88,10 @@ def t_COLON(t): r'\:' return t +def t_SEMICOLON(t): + r'\;' + return t + def t_COMMA(t): r'\,' return t diff --git a/ftb_snbt_lib/write.py b/ftb_snbt_lib/write.py index 4ef2fd9..f4bd215 100644 --- a/ftb_snbt_lib/write.py +++ b/ftb_snbt_lib/write.py @@ -97,12 +97,12 @@ def depth(self): self.indent = self.prev_indent self.prev_indent = prev - def should_expand(self, tag: List | Compound) -> bool: + def should_expand(self, tag: List | Array | Compound) -> bool: return ( self.indentation is not None and ( not self.prev_indent - or isinstance(tag, (List, Compound)) + or isinstance(tag, (List, Array, Compound)) ) ) @@ -141,6 +141,20 @@ def write_list(self, tag: List) -> str: separator, fmt = self.expand(fmt) return fmt.format(separator.join(map(self.write, tag))) + + def write_array(self, tag: Array) -> str: + separator, fmt = "\n", f"[{tag.array_prefix};{{}}]" + + if len(tag) == 0: + return fmt.format(" ") + if len(tag) == 1: + return fmt.format(self.write(tag[0])) + + with self.depth(): + if self.should_expand(tag): + separator, fmt = self.expand(fmt) + + return fmt.format(separator.join(map(self.write, tag))) def write_compound(self, tag: Compound) -> str: separator, fmt = "\n", "{{{}}}"