un-break reading types

This commit is contained in:
2024-07-09 21:48:40 -06:00
parent 9110dc4694
commit a2aaca9f7e
4 changed files with 10 additions and 2 deletions

View File

@@ -229,6 +229,8 @@ class Helpers {
{ {
// These could use varName() and explicitType() but so far there are no &meta annotations for function arguments // These could use varName() and explicitType() but so far there are no &meta annotations for function arguments
name: switch (funcArg.def) { name: switch (funcArg.def) {
case Symbol(name) | TypedExp(_, {pos: _, def: Symbol(name)}) if (name.endsWith(",")):
throw KissError.fromExp(funcArg, "trailing comma on function argument");
case Symbol(name) | TypedExp(_, {pos: _, def: Symbol(name)}) if (!name.contains(".")): case Symbol(name) | TypedExp(_, {pos: _, def: Symbol(name)}) if (!name.contains(".")):
name; name;
default: default:

View File

@@ -26,6 +26,7 @@ using kiss.Helpers;
using kiss.Reader; using kiss.Reader;
using tink.MacroApi; using tink.MacroApi;
using haxe.io.Path; using haxe.io.Path;
using StringTools;
typedef ExprConversion = (ReaderExp) -> Expr; typedef ExprConversion = (ReaderExp) -> Expr;
@@ -286,6 +287,8 @@ class Kiss {
printErr(); printErr();
throw EUnexpected(err); throw EUnexpected(err);
} }
} catch (err:EType) {
throw err;
} catch (err:Exception) { } catch (err:Exception) {
function printErr() { function printErr() {
Sys.stderr().writeString("Error: " + err.message + "\n"); Sys.stderr().writeString("Error: " + err.message + "\n");
@@ -698,6 +701,9 @@ class Kiss {
var substitution = k.identAliases[alias].withPosOf(exp); var substitution = k.identAliases[alias].withPosOf(exp);
if (macroExpandOnly) Left(substitution) else macroExpandAndConvert(substitution, k, false); if (macroExpandOnly) Left(substitution) else macroExpandAndConvert(substitution, k, false);
case Symbol(name) if (!macroExpandOnly): case Symbol(name) if (!macroExpandOnly):
if (name.endsWith(",")) {
throw KissError.fromExp(exp, "trailing comma on symbol");
}
try { try {
Right(Context.parse(name, exp.macroPos())); Right(Context.parse(name, exp.macroPos()));
} catch (err:haxe.Exception) { } catch (err:haxe.Exception) {

View File

@@ -251,7 +251,7 @@ class Reader {
} }
public static final whitespace = [" ", "\t", "\n"]; public static final whitespace = [" ", "\t", "\n"];
public static final terminators = [")", "]", "}", '"', "/*", ","].concat(whitespace); public static final terminators = [")", "]", "}", '"', "/*"].concat(whitespace);
public static function nextToken(stream:Stream, expect:String, allowEmptyString = false) { public static function nextToken(stream:Stream, expect:String, allowEmptyString = false) {
switch (stream.takeUntilOneOf(terminators, true)) { switch (stream.takeUntilOneOf(terminators, true)) {

View File

@@ -4,7 +4,7 @@ import utest.Test;
import utest.Assert; import utest.Assert;
import kiss.Prelude; import kiss.Prelude;
@:build(kiss.Kiss.buildExpectingError(kiss.EType.EAny)) @:build(kiss.Kiss.buildExpectingError(kiss.EType.EKiss('trailing comma on function argument')))
class CommasInArgListTestCase extends Test { class CommasInArgListTestCase extends Test {
function testExpectedError() { function testExpectedError() {
_testExpectedError(); _testExpectedError();