From 3339b939c3e93d7900be54bcb537f017388d8e28 Mon Sep 17 00:00:00 2001 From: peunsu Date: Sun, 12 May 2024 18:39:48 +0900 Subject: [PATCH] Changed some tokens and precedence rules to avoid conflicts of the parser. --- ftb_snbt_lib/__init__.py | 2 +- ftb_snbt_lib/parse.py | 4 +- ftb_snbt_lib/parser.out | 113 ++++++++++++++++++++------------------- ftb_snbt_lib/parsetab.py | 8 +-- ftb_snbt_lib/token.py | 61 +++++++++++---------- 5 files changed, 97 insertions(+), 91 deletions(-) diff --git a/ftb_snbt_lib/__init__.py b/ftb_snbt_lib/__init__.py index faa469b..d7519b8 100644 --- a/ftb_snbt_lib/__init__.py +++ b/ftb_snbt_lib/__init__.py @@ -2,5 +2,5 @@ from .tag import * from .write import * -__version__ = '0.2.3' +__version__ = '0.3.0' __all__ = ['parse', 'tag', 'write'] \ No newline at end of file diff --git a/ftb_snbt_lib/parse.py b/ftb_snbt_lib/parse.py index 8be710f..1e055bb 100644 --- a/ftb_snbt_lib/parse.py +++ b/ftb_snbt_lib/parse.py @@ -55,8 +55,8 @@ def p_list(p): p[0] = List(p[2]) def p_array(p): - """array : LBRACKET NAME SEMICOLON values RBRACKET - | LBRACKET NAME SEMICOLON RBRACKET""" + """array : LBRACKET TYPE SEMICOLON values RBRACKET + | LBRACKET TYPE SEMICOLON RBRACKET""" if len(p) == 4: p[0] = Array(p[2], []) else: diff --git a/ftb_snbt_lib/parser.out b/ftb_snbt_lib/parser.out index 0f30200..b6e87f4 100644 --- a/ftb_snbt_lib/parser.out +++ b/ftb_snbt_lib/parser.out @@ -24,8 +24,8 @@ Rule 18 value -> INTEGER Rule 19 value -> STRING Rule 20 list -> LBRACKET values RBRACKET Rule 21 list -> LBRACKET RBRACKET -Rule 22 array -> LBRACKET NAME SEMICOLON values RBRACKET -Rule 23 array -> LBRACKET NAME SEMICOLON RBRACKET +Rule 22 array -> LBRACKET TYPE SEMICOLON values RBRACKET +Rule 23 array -> LBRACKET TYPE SEMICOLON RBRACKET Rule 24 values -> values value Rule 25 values -> values COMMA value Rule 26 values -> value @@ -42,12 +42,13 @@ INTEGER : 18 LBRACE : 2 3 LBRACKET : 20 21 22 23 LONG : 17 -NAME : 7 22 23 +NAME : 7 RBRACE : 2 3 RBRACKET : 20 21 22 23 SEMICOLON : 22 23 SHORT : 14 STRING : 8 19 +TYPE : 22 23 error : Nonterminals, with rules where they appear @@ -225,8 +226,8 @@ state 12 (3) compound -> . LBRACE RBRACE (20) list -> . LBRACKET values RBRACKET (21) list -> . LBRACKET RBRACKET - (22) array -> . LBRACKET NAME SEMICOLON values RBRACKET - (23) array -> . LBRACKET NAME SEMICOLON RBRACKET + (22) array -> . LBRACKET TYPE SEMICOLON values RBRACKET + (23) array -> . LBRACKET TYPE SEMICOLON RBRACKET BOOL shift and go to state 19 BYTE shift and go to state 20 @@ -262,8 +263,8 @@ state 13 (3) compound -> . LBRACE RBRACE (20) list -> . LBRACKET values RBRACKET (21) list -> . LBRACKET RBRACKET - (22) array -> . LBRACKET NAME SEMICOLON values RBRACKET - (23) array -> . LBRACKET NAME SEMICOLON RBRACKET + (22) array -> . LBRACKET TYPE SEMICOLON values RBRACKET + (23) array -> . LBRACKET TYPE SEMICOLON RBRACKET BOOL shift and go to state 19 BYTE shift and go to state 20 @@ -525,8 +526,8 @@ state 27 (20) list -> LBRACKET . values RBRACKET (21) list -> LBRACKET . RBRACKET - (22) array -> LBRACKET . NAME SEMICOLON values RBRACKET - (23) array -> LBRACKET . NAME SEMICOLON RBRACKET + (22) array -> LBRACKET . TYPE SEMICOLON values RBRACKET + (23) array -> LBRACKET . TYPE SEMICOLON RBRACKET (24) values -> . values value (25) values -> . values COMMA value (26) values -> . value @@ -545,11 +546,11 @@ state 27 (3) compound -> . LBRACE RBRACE (20) list -> . LBRACKET values RBRACKET (21) list -> . LBRACKET RBRACKET - (22) array -> . LBRACKET NAME SEMICOLON values RBRACKET - (23) array -> . LBRACKET NAME SEMICOLON RBRACKET + (22) array -> . LBRACKET TYPE SEMICOLON values RBRACKET + (23) array -> . LBRACKET TYPE SEMICOLON RBRACKET RBRACKET shift and go to state 30 - NAME shift and go to state 31 + TYPE shift and go to state 31 BOOL shift and go to state 19 BYTE shift and go to state 20 SHORT shift and go to state 21 @@ -597,8 +598,8 @@ state 29 (3) compound -> . LBRACE RBRACE (20) list -> . LBRACKET values RBRACKET (21) list -> . LBRACKET RBRACKET - (22) array -> . LBRACKET NAME SEMICOLON values RBRACKET - (23) array -> . LBRACKET NAME SEMICOLON RBRACKET + (22) array -> . LBRACKET TYPE SEMICOLON values RBRACKET + (23) array -> . LBRACKET TYPE SEMICOLON RBRACKET RBRACKET shift and go to state 33 COMMA shift and go to state 35 @@ -640,8 +641,8 @@ state 30 state 31 - (22) array -> LBRACKET NAME . SEMICOLON values RBRACKET - (23) array -> LBRACKET NAME . SEMICOLON RBRACKET + (22) array -> LBRACKET TYPE . SEMICOLON values RBRACKET + (23) array -> LBRACKET TYPE . SEMICOLON RBRACKET SEMICOLON shift and go to state 36 @@ -720,8 +721,8 @@ state 35 (3) compound -> . LBRACE RBRACE (20) list -> . LBRACKET values RBRACKET (21) list -> . LBRACKET RBRACKET - (22) array -> . LBRACKET NAME SEMICOLON values RBRACKET - (23) array -> . LBRACKET NAME SEMICOLON RBRACKET + (22) array -> . LBRACKET TYPE SEMICOLON values RBRACKET + (23) array -> . LBRACKET TYPE SEMICOLON RBRACKET BOOL shift and go to state 19 BYTE shift and go to state 20 @@ -741,8 +742,8 @@ state 35 state 36 - (22) array -> LBRACKET NAME SEMICOLON . values RBRACKET - (23) array -> LBRACKET NAME SEMICOLON . RBRACKET + (22) array -> LBRACKET TYPE SEMICOLON . values RBRACKET + (23) array -> LBRACKET TYPE SEMICOLON . RBRACKET (24) values -> . values value (25) values -> . values COMMA value (26) values -> . value @@ -761,8 +762,8 @@ state 36 (3) compound -> . LBRACE RBRACE (20) list -> . LBRACKET values RBRACKET (21) list -> . LBRACKET RBRACKET - (22) array -> . LBRACKET NAME SEMICOLON values RBRACKET - (23) array -> . LBRACKET NAME SEMICOLON RBRACKET + (22) array -> . LBRACKET TYPE SEMICOLON values RBRACKET + (23) array -> . LBRACKET TYPE SEMICOLON RBRACKET RBRACKET shift and go to state 39 BOOL shift and go to state 19 @@ -802,7 +803,7 @@ state 37 state 38 - (22) array -> LBRACKET NAME SEMICOLON values . RBRACKET + (22) array -> LBRACKET TYPE SEMICOLON values . RBRACKET (24) values -> values . value (25) values -> values . COMMA value (9) value -> . compound @@ -820,8 +821,8 @@ state 38 (3) compound -> . LBRACE RBRACE (20) list -> . LBRACKET values RBRACKET (21) list -> . LBRACKET RBRACKET - (22) array -> . LBRACKET NAME SEMICOLON values RBRACKET - (23) array -> . LBRACKET NAME SEMICOLON RBRACKET + (22) array -> . LBRACKET TYPE SEMICOLON values RBRACKET + (23) array -> . LBRACKET TYPE SEMICOLON RBRACKET RBRACKET shift and go to state 40 COMMA shift and go to state 35 @@ -843,40 +844,40 @@ state 38 state 39 - (23) array -> LBRACKET NAME SEMICOLON RBRACKET . + (23) array -> LBRACKET TYPE SEMICOLON RBRACKET . - RBRACE reduce using rule 23 (array -> LBRACKET NAME SEMICOLON RBRACKET .) - COMMA reduce using rule 23 (array -> LBRACKET NAME SEMICOLON RBRACKET .) - NAME reduce using rule 23 (array -> LBRACKET NAME SEMICOLON RBRACKET .) - STRING reduce using rule 23 (array -> LBRACKET NAME SEMICOLON RBRACKET .) - RBRACKET reduce using rule 23 (array -> LBRACKET NAME SEMICOLON RBRACKET .) - BOOL reduce using rule 23 (array -> LBRACKET NAME SEMICOLON RBRACKET .) - BYTE reduce using rule 23 (array -> LBRACKET NAME SEMICOLON RBRACKET .) - SHORT reduce using rule 23 (array -> LBRACKET NAME SEMICOLON RBRACKET .) - FLOAT reduce using rule 23 (array -> LBRACKET NAME SEMICOLON RBRACKET .) - DOUBLE reduce using rule 23 (array -> LBRACKET NAME SEMICOLON RBRACKET .) - LONG reduce using rule 23 (array -> LBRACKET NAME SEMICOLON RBRACKET .) - INTEGER reduce using rule 23 (array -> LBRACKET NAME SEMICOLON RBRACKET .) - LBRACE reduce using rule 23 (array -> LBRACKET NAME SEMICOLON RBRACKET .) - LBRACKET reduce using rule 23 (array -> LBRACKET NAME SEMICOLON RBRACKET .) + RBRACE reduce using rule 23 (array -> LBRACKET TYPE SEMICOLON RBRACKET .) + COMMA reduce using rule 23 (array -> LBRACKET TYPE SEMICOLON RBRACKET .) + NAME reduce using rule 23 (array -> LBRACKET TYPE SEMICOLON RBRACKET .) + STRING reduce using rule 23 (array -> LBRACKET TYPE SEMICOLON RBRACKET .) + RBRACKET reduce using rule 23 (array -> LBRACKET TYPE SEMICOLON RBRACKET .) + BOOL reduce using rule 23 (array -> LBRACKET TYPE SEMICOLON RBRACKET .) + BYTE reduce using rule 23 (array -> LBRACKET TYPE SEMICOLON RBRACKET .) + SHORT reduce using rule 23 (array -> LBRACKET TYPE SEMICOLON RBRACKET .) + FLOAT reduce using rule 23 (array -> LBRACKET TYPE SEMICOLON RBRACKET .) + DOUBLE reduce using rule 23 (array -> LBRACKET TYPE SEMICOLON RBRACKET .) + LONG reduce using rule 23 (array -> LBRACKET TYPE SEMICOLON RBRACKET .) + INTEGER reduce using rule 23 (array -> LBRACKET TYPE SEMICOLON RBRACKET .) + LBRACE reduce using rule 23 (array -> LBRACKET TYPE SEMICOLON RBRACKET .) + LBRACKET reduce using rule 23 (array -> LBRACKET TYPE SEMICOLON RBRACKET .) state 40 - (22) array -> LBRACKET NAME SEMICOLON values RBRACKET . - - RBRACE reduce using rule 22 (array -> LBRACKET NAME SEMICOLON values RBRACKET .) - COMMA reduce using rule 22 (array -> LBRACKET NAME SEMICOLON values RBRACKET .) - NAME reduce using rule 22 (array -> LBRACKET NAME SEMICOLON values RBRACKET .) - STRING reduce using rule 22 (array -> LBRACKET NAME SEMICOLON values RBRACKET .) - RBRACKET reduce using rule 22 (array -> LBRACKET NAME SEMICOLON values RBRACKET .) - BOOL reduce using rule 22 (array -> LBRACKET NAME SEMICOLON values RBRACKET .) - BYTE reduce using rule 22 (array -> LBRACKET NAME SEMICOLON values RBRACKET .) - SHORT reduce using rule 22 (array -> LBRACKET NAME SEMICOLON values RBRACKET .) - FLOAT reduce using rule 22 (array -> LBRACKET NAME SEMICOLON values RBRACKET .) - DOUBLE reduce using rule 22 (array -> LBRACKET NAME SEMICOLON values RBRACKET .) - LONG reduce using rule 22 (array -> LBRACKET NAME SEMICOLON values RBRACKET .) - INTEGER reduce using rule 22 (array -> LBRACKET NAME SEMICOLON values RBRACKET .) - LBRACE reduce using rule 22 (array -> LBRACKET NAME SEMICOLON values RBRACKET .) - LBRACKET reduce using rule 22 (array -> LBRACKET NAME SEMICOLON values RBRACKET .) + (22) array -> LBRACKET TYPE SEMICOLON values RBRACKET . + + RBRACE reduce using rule 22 (array -> LBRACKET TYPE SEMICOLON values RBRACKET .) + COMMA reduce using rule 22 (array -> LBRACKET TYPE SEMICOLON values RBRACKET .) + NAME reduce using rule 22 (array -> LBRACKET TYPE SEMICOLON values RBRACKET .) + STRING reduce using rule 22 (array -> LBRACKET TYPE SEMICOLON values RBRACKET .) + RBRACKET reduce using rule 22 (array -> LBRACKET TYPE SEMICOLON values RBRACKET .) + BOOL reduce using rule 22 (array -> LBRACKET TYPE SEMICOLON values RBRACKET .) + BYTE reduce using rule 22 (array -> LBRACKET TYPE SEMICOLON values RBRACKET .) + SHORT reduce using rule 22 (array -> LBRACKET TYPE SEMICOLON values RBRACKET .) + FLOAT reduce using rule 22 (array -> LBRACKET TYPE SEMICOLON values RBRACKET .) + DOUBLE reduce using rule 22 (array -> LBRACKET TYPE SEMICOLON values RBRACKET .) + LONG reduce using rule 22 (array -> LBRACKET TYPE SEMICOLON values RBRACKET .) + INTEGER reduce using rule 22 (array -> LBRACKET TYPE SEMICOLON values RBRACKET .) + LBRACE reduce using rule 22 (array -> LBRACKET TYPE SEMICOLON values RBRACKET .) + LBRACKET reduce using rule 22 (array -> LBRACKET TYPE SEMICOLON values RBRACKET .) diff --git a/ftb_snbt_lib/parsetab.py b/ftb_snbt_lib/parsetab.py index 0c9f1fc..35499ed 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 FLOAT 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 | FLOAT\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_signature = 'BOOL BYTE COLON COMMA DOUBLE FLOAT INTEGER LBRACE LBRACKET LONG NAME RBRACE RBRACKET SEMICOLON SHORT STRING TYPEsnbt : 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 | FLOAT\n | DOUBLE\n | LONG\n | INTEGER\n | STRINGlist : LBRACKET values RBRACKET\n | LBRACKET RBRACKETarray : LBRACKET TYPE SEMICOLON values RBRACKET\n | LBRACKET TYPE 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,26,27,29,30,32,33,34,35,36,37,38,39,40,],[3,-3,-2,3,3,-9,-10,-11,-12,-13,-14,-15,-16,-17,-18,-19,3,3,-21,-26,-20,-24,3,3,-25,3,-23,-22,]),'$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,26,28,30,33,39,40,],[5,9,-3,-6,-2,-4,-5,-7,-9,-10,-11,-12,-13,-14,-15,-16,-17,-18,-19,-8,-21,-20,-23,-22,]),'NAME':([3,4,5,6,9,10,11,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,30,33,39,40,],[7,7,-3,-6,-2,-4,7,-5,-7,-9,-10,-11,-12,-13,-14,-15,-16,-17,-18,-19,31,-8,-21,-20,-23,-22,]),'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,32,33,34,35,36,37,38,39,40,],[8,8,-3,-6,-2,-4,8,26,26,-5,-7,-9,-10,-11,-12,-13,-14,-15,-16,-17,-18,-19,26,-8,26,-21,-26,-20,-24,26,26,-25,26,-23,-22,]),'COMMA':([4,5,6,9,10,14,15,16,17,18,19,20,21,22,23,24,25,26,28,29,30,32,33,34,37,38,39,40,],[11,-3,-6,-2,-4,-5,-7,-9,-10,-11,-12,-13,-14,-15,-16,-17,-18,-19,-8,35,-21,-26,-20,-24,-25,35,-23,-22,]),'RBRACKET':([5,9,16,17,18,19,20,21,22,23,24,25,26,27,29,30,32,33,34,36,37,38,39,40,],[-3,-2,-9,-10,-11,-12,-13,-14,-15,-16,-17,-18,-19,30,33,-21,-26,-20,-24,39,-25,40,-23,-22,]),'BOOL':([5,9,12,13,16,17,18,19,20,21,22,23,24,25,26,27,29,30,32,33,34,35,36,37,38,39,40,],[-3,-2,19,19,-9,-10,-11,-12,-13,-14,-15,-16,-17,-18,-19,19,19,-21,-26,-20,-24,19,19,-25,19,-23,-22,]),'BYTE':([5,9,12,13,16,17,18,19,20,21,22,23,24,25,26,27,29,30,32,33,34,35,36,37,38,39,40,],[-3,-2,20,20,-9,-10,-11,-12,-13,-14,-15,-16,-17,-18,-19,20,20,-21,-26,-20,-24,20,20,-25,20,-23,-22,]),'SHORT':([5,9,12,13,16,17,18,19,20,21,22,23,24,25,26,27,29,30,32,33,34,35,36,37,38,39,40,],[-3,-2,21,21,-9,-10,-11,-12,-13,-14,-15,-16,-17,-18,-19,21,21,-21,-26,-20,-24,21,21,-25,21,-23,-22,]),'FLOAT':([5,9,12,13,16,17,18,19,20,21,22,23,24,25,26,27,29,30,32,33,34,35,36,37,38,39,40,],[-3,-2,22,22,-9,-10,-11,-12,-13,-14,-15,-16,-17,-18,-19,22,22,-21,-26,-20,-24,22,22,-25,22,-23,-22,]),'DOUBLE':([5,9,12,13,16,17,18,19,20,21,22,23,24,25,26,27,29,30,32,33,34,35,36,37,38,39,40,],[-3,-2,23,23,-9,-10,-11,-12,-13,-14,-15,-16,-17,-18,-19,23,23,-21,-26,-20,-24,23,23,-25,23,-23,-22,]),'LONG':([5,9,12,13,16,17,18,19,20,21,22,23,24,25,26,27,29,30,32,33,34,35,36,37,38,39,40,],[-3,-2,24,24,-9,-10,-11,-12,-13,-14,-15,-16,-17,-18,-19,24,24,-21,-26,-20,-24,24,24,-25,24,-23,-22,]),'INTEGER':([5,9,12,13,16,17,18,19,20,21,22,23,24,25,26,27,29,30,32,33,34,35,36,37,38,39,40,],[-3,-2,25,25,-9,-10,-11,-12,-13,-14,-15,-16,-17,-18,-19,25,25,-21,-26,-20,-24,25,25,-25,25,-23,-22,]),'LBRACKET':([5,9,12,13,16,17,18,19,20,21,22,23,24,25,26,27,29,30,32,33,34,35,36,37,38,39,40,],[-3,-2,27,27,-9,-10,-11,-12,-13,-14,-15,-16,-17,-18,-19,27,27,-21,-26,-20,-24,27,27,-25,27,-23,-22,]),'COLON':([7,8,],[12,13,]),'SEMICOLON':([31,],[36,]),} +_lr_action_items = {'LBRACE':([0,5,9,12,13,16,17,18,19,20,21,22,23,24,25,26,27,29,30,32,33,34,35,36,37,38,39,40,],[3,-3,-2,3,3,-9,-10,-11,-12,-13,-14,-15,-16,-17,-18,-19,3,3,-21,-26,-20,-24,3,3,-25,3,-23,-22,]),'$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,26,28,30,33,39,40,],[5,9,-3,-6,-2,-4,-5,-7,-9,-10,-11,-12,-13,-14,-15,-16,-17,-18,-19,-8,-21,-20,-23,-22,]),'NAME':([3,4,5,6,9,10,11,14,15,16,17,18,19,20,21,22,23,24,25,26,28,30,33,39,40,],[7,7,-3,-6,-2,-4,7,-5,-7,-9,-10,-11,-12,-13,-14,-15,-16,-17,-18,-19,-8,-21,-20,-23,-22,]),'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,32,33,34,35,36,37,38,39,40,],[8,8,-3,-6,-2,-4,8,26,26,-5,-7,-9,-10,-11,-12,-13,-14,-15,-16,-17,-18,-19,26,-8,26,-21,-26,-20,-24,26,26,-25,26,-23,-22,]),'COMMA':([4,5,6,9,10,14,15,16,17,18,19,20,21,22,23,24,25,26,28,29,30,32,33,34,37,38,39,40,],[11,-3,-6,-2,-4,-5,-7,-9,-10,-11,-12,-13,-14,-15,-16,-17,-18,-19,-8,35,-21,-26,-20,-24,-25,35,-23,-22,]),'RBRACKET':([5,9,16,17,18,19,20,21,22,23,24,25,26,27,29,30,32,33,34,36,37,38,39,40,],[-3,-2,-9,-10,-11,-12,-13,-14,-15,-16,-17,-18,-19,30,33,-21,-26,-20,-24,39,-25,40,-23,-22,]),'BOOL':([5,9,12,13,16,17,18,19,20,21,22,23,24,25,26,27,29,30,32,33,34,35,36,37,38,39,40,],[-3,-2,19,19,-9,-10,-11,-12,-13,-14,-15,-16,-17,-18,-19,19,19,-21,-26,-20,-24,19,19,-25,19,-23,-22,]),'BYTE':([5,9,12,13,16,17,18,19,20,21,22,23,24,25,26,27,29,30,32,33,34,35,36,37,38,39,40,],[-3,-2,20,20,-9,-10,-11,-12,-13,-14,-15,-16,-17,-18,-19,20,20,-21,-26,-20,-24,20,20,-25,20,-23,-22,]),'SHORT':([5,9,12,13,16,17,18,19,20,21,22,23,24,25,26,27,29,30,32,33,34,35,36,37,38,39,40,],[-3,-2,21,21,-9,-10,-11,-12,-13,-14,-15,-16,-17,-18,-19,21,21,-21,-26,-20,-24,21,21,-25,21,-23,-22,]),'FLOAT':([5,9,12,13,16,17,18,19,20,21,22,23,24,25,26,27,29,30,32,33,34,35,36,37,38,39,40,],[-3,-2,22,22,-9,-10,-11,-12,-13,-14,-15,-16,-17,-18,-19,22,22,-21,-26,-20,-24,22,22,-25,22,-23,-22,]),'DOUBLE':([5,9,12,13,16,17,18,19,20,21,22,23,24,25,26,27,29,30,32,33,34,35,36,37,38,39,40,],[-3,-2,23,23,-9,-10,-11,-12,-13,-14,-15,-16,-17,-18,-19,23,23,-21,-26,-20,-24,23,23,-25,23,-23,-22,]),'LONG':([5,9,12,13,16,17,18,19,20,21,22,23,24,25,26,27,29,30,32,33,34,35,36,37,38,39,40,],[-3,-2,24,24,-9,-10,-11,-12,-13,-14,-15,-16,-17,-18,-19,24,24,-21,-26,-20,-24,24,24,-25,24,-23,-22,]),'INTEGER':([5,9,12,13,16,17,18,19,20,21,22,23,24,25,26,27,29,30,32,33,34,35,36,37,38,39,40,],[-3,-2,25,25,-9,-10,-11,-12,-13,-14,-15,-16,-17,-18,-19,25,25,-21,-26,-20,-24,25,25,-25,25,-23,-22,]),'LBRACKET':([5,9,12,13,16,17,18,19,20,21,22,23,24,25,26,27,29,30,32,33,34,35,36,37,38,39,40,],[-3,-2,27,27,-9,-10,-11,-12,-13,-14,-15,-16,-17,-18,-19,27,27,-21,-26,-20,-24,27,27,-25,27,-23,-22,]),'COLON':([7,8,],[12,13,]),'TYPE':([27,],[31,]),'SEMICOLON':([31,],[36,]),} _lr_action = {} for _k, _v in _lr_action_items.items(): @@ -48,8 +48,8 @@ ('value -> STRING','value',1,'p_value','parse.py',46), ('list -> LBRACKET values RBRACKET','list',3,'p_list','parse.py',50), ('list -> LBRACKET RBRACKET','list',2,'p_list','parse.py',51), - ('array -> LBRACKET NAME SEMICOLON values RBRACKET','array',5,'p_array','parse.py',58), - ('array -> LBRACKET NAME SEMICOLON RBRACKET','array',4,'p_array','parse.py',59), + ('array -> LBRACKET TYPE SEMICOLON values RBRACKET','array',5,'p_array','parse.py',58), + ('array -> LBRACKET TYPE SEMICOLON RBRACKET','array',4,'p_array','parse.py',59), ('values -> values value','values',2,'p_values','parse.py',66), ('values -> values COMMA value','values',3,'p_values','parse.py',67), ('values -> value','values',1,'p_values','parse.py',68), diff --git a/ftb_snbt_lib/token.py b/ftb_snbt_lib/token.py index f09723d..e6c95e7 100644 --- a/ftb_snbt_lib/token.py +++ b/ftb_snbt_lib/token.py @@ -15,6 +15,7 @@ "INTEGER", "STRING", "NAME", + "TYPE", "COLON", "SEMICOLON", "COMMA", @@ -22,33 +23,18 @@ t_ignore = ' \t\r' -def t_newline(t): - r'\n' - t.lexer.lineno += 1 - -def t_LBRACE(t): - r'\{' - t.lexer.level += 1 - return t - -def t_RBRACE(t): - r'\}' - t.lexer.level -= 1 - return t - -def t_LBRACKET(t): - r'\[' - t.lexer.level += 1 +def t_BOOL(t): + r'true|false' + t.value = Bool(t.value == "true") return t -def t_RBRACKET(t): - r'\]' - t.lexer.level -= 1 +def t_NAME(t): + r'[a-zA-Z0-9._+-]+(?=:)' return t -def t_BOOL(t): - r'true|false' - t.value = Bool(t.value == "true") +def t_STRING(t): + r'\"[^\"\\]*(?:\\.[^\"\\]*)*\"' + t.value = String(t.value[1:-1].replace(r'\"', '"').replace(r'\\', '\\')) return t def t_BYTE(t): @@ -81,13 +67,32 @@ def t_INTEGER(t): t.value = Integer(t.value) return t -def t_STRING(t): - r'\"[^\"\\]*(?:\\.[^\"\\]*)*\"' - t.value = String(t.value[1:-1].replace(r'\"', '"').replace(r'\\', '\\')) +def t_TYPE(t): + r'[BIL]+(?=;)' return t -def t_NAME(t): - r'[a-zA-Z0-9._+-]+' +def t_newline(t): + r'\n' + t.lexer.lineno += 1 + +def t_LBRACE(t): + r'\{' + t.lexer.level += 1 + return t + +def t_RBRACE(t): + r'\}' + t.lexer.level -= 1 + return t + +def t_LBRACKET(t): + r'\[' + t.lexer.level += 1 + return t + +def t_RBRACKET(t): + r'\]' + t.lexer.level -= 1 return t def t_COLON(t):