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
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(".")):
name;
default:

View File

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

View File

@@ -251,7 +251,7 @@ class Reader {
}
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) {
switch (stream.takeUntilOneOf(terminators, true)) {

View File

@@ -4,7 +4,7 @@ import utest.Test;
import utest.Assert;
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 {
function testExpectedError() {
_testExpectedError();