changeset 1822:aeaf2b65c005

better parse tables
author Franklin Schmidt <fschmidt@gmail.com>
date Tue, 09 Jul 2024 12:46:27 -0600
parents d28f5ed56454
children 36dfc31fd607
files src/luan/modules/parsers/LuanParser.java
diffstat 1 files changed, 10 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
diff -r d28f5ed56454 -r aeaf2b65c005 src/luan/modules/parsers/LuanParser.java
--- a/src/luan/modules/parsers/LuanParser.java	Tue Jul 09 07:17:41 2024 -0600
+++ b/src/luan/modules/parsers/LuanParser.java	Tue Jul 09 12:46:27 2024 -0600
@@ -259,16 +259,18 @@
 		if( !parser.match('{') )
 			return parser.failure(null);
 		LuanTable tbl = new LuanTable();
+		int i = 0;
 		do {
 			spaces();
 			Object obj = value();
 			if( obj != null ) {
-				if( obj != NULL ) {
-					try {
-						tbl.rawAdd(obj);
-					} catch(LuanException e) {
-						throw new RuntimeException(e);
-					}
+				if( obj == NULL )
+					obj = null;
+				try {
+					if( tbl.rawPut(++i,obj) != null )
+						throw new LuanException("duplicate key in table: "+i);
+				} catch(LuanException e) {
+					throw new RuntimeException(e);
 				}
 				spaces();
 				continue;
@@ -281,7 +283,8 @@
 				Object value = requiredValue();
 				spaces();
 				try {
-					tbl.rawPut(key,value);
+					if( tbl.rawPut(key,value) != null )
+						throw new LuanException("duplicate key in table: "+key);
 				} catch(LuanException e) {
 					throw new RuntimeException(e);
 				}