changeset 1681:6061be2cd84b

minor
author Franklin Schmidt <fschmidt@gmail.com>
date Fri, 03 Jun 2022 09:17:21 -0600
parents 9ef19f5ea973
children 97cc73664ca8
files src/luan/impl/LuanParser.java
diffstat 1 files changed, 17 insertions(+), 40 deletions(-) [+]
line wrap: on
line diff
--- a/src/luan/impl/LuanParser.java	Thu Jun 02 22:34:55 2022 -0600
+++ b/src/luan/impl/LuanParser.java	Fri Jun 03 09:17:21 2022 -0600
@@ -1012,6 +1012,19 @@
 		return parser.match('-') && !parser.match('-') ? parser.success() : parser.failure();
 	}
 
+	private Expr TermExpr(Expr exp,String op) throws ParseException {
+		Spaces();
+		exp = exp.single();
+		Expr exp2 = required(UnaryExpr()).single();
+		Expr newExp = new Expr(Val.SINGLE,false);
+		newExp.add( "LuanImpl." + op + "(luan," );
+		newExp.addAll( exp );
+		newExp.add( "," );
+		newExp.addAll( exp2 );
+		newExp.add( ")" );
+		return newExp;
+	}
+
 	private Expr TermExpr() throws ParseException {
 		parser.begin();
 		Expr exp = UnaryExpr();
@@ -1019,51 +1032,15 @@
 			return parser.failure(null);
 		while(true) {
 			if( parser.match('*') ) {
-				Spaces();
-				exp = exp.single();
-				Expr exp2 = required(UnaryExpr()).single();
-				Expr newExp = new Expr(Val.SINGLE,false);
-				newExp.add( "LuanImpl.mul(luan," );
-				newExp.addAll( exp );
-				newExp.add( "," );
-				newExp.addAll( exp2 );
-				newExp.add( ")" );
-				exp = newExp;
+				exp = TermExpr(exp,"mul");
 			} else if( parser.match('/') ) {
 				if( parser.match('/') ) {
-					Spaces();
-					exp = exp.single();
-					Expr exp2 = required(UnaryExpr()).single();
-					Expr newExp = new Expr(Val.SINGLE,false);
-					newExp.add( "LuanImpl.idiv(luan," );
-					newExp.addAll( exp );
-					newExp.add( "," );
-					newExp.addAll( exp2 );
-					newExp.add( ")" );
-					exp = newExp;
+					exp = TermExpr(exp,"idiv");
 				} else {
-					Spaces();
-					exp = exp.single();
-					Expr exp2 = required(UnaryExpr()).single();
-					Expr newExp = new Expr(Val.SINGLE,false);
-					newExp.add( "LuanImpl.div(luan," );
-					newExp.addAll( exp );
-					newExp.add( "," );
-					newExp.addAll( exp2 );
-					newExp.add( ")" );
-					exp = newExp;
+					exp = TermExpr(exp,"div");
 				}
 			} else if( Mod() ) {
-				Spaces();
-				exp = exp.single();
-				Expr exp2 = required(UnaryExpr()).single();
-				Expr newExp = new Expr(Val.SINGLE,false);
-				newExp.add( "LuanImpl.mod(luan," );
-				newExp.addAll( exp );
-				newExp.add( "," );
-				newExp.addAll( exp2 );
-				newExp.add( ")" );
-				exp = newExp;
+				exp = TermExpr(exp,"mod");
 			} else
 				break;
 		}