functions are now case sensitive. Modules are still case insensitive.
This commit is contained in:
1 parent
7a1e05cfa1
commit
2c7c7d9bc6
3 files changed
+7
-10
No files matched your search
@@ -210,7 +210,7 @@ public class CarpetScriptHost extends ScriptHost
|
|||||||
switch (tok.type)
|
switch (tok.type)
|
||||||
{
|
{
|
||||||
case VARIABLE:
|
case VARIABLE:
|
||||||
LazyValue var = getGlobalVariable(tok.surface.toLowerCase(Locale.ROOT));
|
LazyValue var = getGlobalVariable(tok.surface);
|
||||||
if (var != null)
|
if (var != null)
|
||||||
{
|
{
|
||||||
argv.add(var);
|
argv.add(var);
|
||||||
|
|||||||
@@ -321,7 +321,6 @@ public class Expression
|
|||||||
|
|
||||||
public void addUnaryFunction(String name, Function<Value, Value> fun)
|
public void addUnaryFunction(String name, Function<Value, Value> fun)
|
||||||
{
|
{
|
||||||
name = name.toLowerCase(Locale.ROOT);
|
|
||||||
functions.put(name, new AbstractFunction(1)
|
functions.put(name, new AbstractFunction(1)
|
||||||
{
|
{
|
||||||
@Override
|
@Override
|
||||||
@@ -334,7 +333,6 @@ public class Expression
|
|||||||
|
|
||||||
public void addBinaryFunction(String name, BiFunction<Value, Value, Value> fun)
|
public void addBinaryFunction(String name, BiFunction<Value, Value, Value> fun)
|
||||||
{
|
{
|
||||||
name = name.toLowerCase(Locale.ROOT);
|
|
||||||
functions.put(name, new AbstractFunction(2)
|
functions.put(name, new AbstractFunction(2)
|
||||||
{
|
{
|
||||||
@Override
|
@Override
|
||||||
@@ -350,7 +348,6 @@ public class Expression
|
|||||||
|
|
||||||
public void addFunction(String name, Function<List<Value>, Value> fun)
|
public void addFunction(String name, Function<List<Value>, Value> fun)
|
||||||
{
|
{
|
||||||
name = name.toLowerCase(Locale.ROOT);
|
|
||||||
functions.put(name, new AbstractFunction(-1)
|
functions.put(name, new AbstractFunction(-1)
|
||||||
{
|
{
|
||||||
@Override
|
@Override
|
||||||
@@ -377,7 +374,6 @@ public class Expression
|
|||||||
|
|
||||||
public void addLazyFunction(String name, int num_params, TriFunction<Context, Integer, List<LazyValue>, LazyValue> fun)
|
public void addLazyFunction(String name, int num_params, TriFunction<Context, Integer, List<LazyValue>, LazyValue> fun)
|
||||||
{
|
{
|
||||||
name = name.toLowerCase(Locale.ROOT);
|
|
||||||
functions.put(name, new AbstractLazyFunction(num_params)
|
functions.put(name, new AbstractLazyFunction(num_params)
|
||||||
{
|
{
|
||||||
@Override
|
@Override
|
||||||
@@ -396,7 +392,6 @@ public class Expression
|
|||||||
}
|
}
|
||||||
public FunctionValue addContextFunction(Context context, String name, Expression expr, Tokenizer.Token token, List<String> arguments, List<String> outers, LazyValue code)
|
public FunctionValue addContextFunction(Context context, String name, Expression expr, Tokenizer.Token token, List<String> arguments, List<String> outers, LazyValue code)
|
||||||
{
|
{
|
||||||
name = name.toLowerCase(Locale.ROOT);
|
|
||||||
if (functions.containsKey(name))
|
if (functions.containsKey(name))
|
||||||
throw new ExpressionException(context, expr, token, "Function "+name+" would mask a built-in function");
|
throw new ExpressionException(context, expr, token, "Function "+name+" would mask a built-in function");
|
||||||
Map<String, LazyValue> contextValues = new HashMap<>();
|
Map<String, LazyValue> contextValues = new HashMap<>();
|
||||||
@@ -434,6 +429,7 @@ public class Expression
|
|||||||
if (lv.size() < 1) throw new InternalExpressionException("'import' needs at least a module name to import, and list of values to import");
|
if (lv.size() < 1) throw new InternalExpressionException("'import' needs at least a module name to import, and list of values to import");
|
||||||
String moduleName = lv.get(0).evalValue(c).getString();
|
String moduleName = lv.get(0).evalValue(c).getString();
|
||||||
c.host.importModule(c, moduleName);
|
c.host.importModule(c, moduleName);
|
||||||
|
moduleName = moduleName.toLowerCase(Locale.ROOT);
|
||||||
if (lv.size() > 1)
|
if (lv.size() > 1)
|
||||||
c.host.importNames(c, module, moduleName, lv.subList(1, lv.size()).stream().map((l) -> l.evalValue(c).getString()).collect(Collectors.toList()));
|
c.host.importNames(c, module, moduleName, lv.subList(1, lv.size()).stream().map((l) -> l.evalValue(c).getString()).collect(Collectors.toList()));
|
||||||
if (t == Context.VOID)
|
if (t == Context.VOID)
|
||||||
@@ -2289,7 +2285,7 @@ public class Expression
|
|||||||
stack.push((c, t) -> getOrSetAnyVariable(c, token.surface).evalValue(c));
|
stack.push((c, t) -> getOrSetAnyVariable(c, token.surface).evalValue(c));
|
||||||
break;
|
break;
|
||||||
case FUNCTION:
|
case FUNCTION:
|
||||||
String name = token.surface.toLowerCase(Locale.ROOT);
|
String name = token.surface;
|
||||||
ILazyFunction f;
|
ILazyFunction f;
|
||||||
ArrayList<LazyValue> p;
|
ArrayList<LazyValue> p;
|
||||||
boolean isKnown = functions.containsKey(name); // globals will be evaluated lazily, not at compile time via .
|
boolean isKnown = functions.containsKey(name); // globals will be evaluated lazily, not at compile time via .
|
||||||
@@ -2376,7 +2372,7 @@ public class Expression
|
|||||||
case OPERATOR:
|
case OPERATOR:
|
||||||
if (stack.peek() < 2)
|
if (stack.peek() < 2)
|
||||||
{
|
{
|
||||||
if (token.surface.equalsIgnoreCase(";"))
|
if (token.surface.equals(";"))
|
||||||
{
|
{
|
||||||
throw new ExpressionException(c, this, token, "Unnecessary semicolon");
|
throw new ExpressionException(c, this, token, "Unnecessary semicolon");
|
||||||
}
|
}
|
||||||
@@ -2386,7 +2382,7 @@ public class Expression
|
|||||||
stack.set(stack.size() - 1, stack.peek() - 2 + 1);
|
stack.set(stack.size() - 1, stack.peek() - 2 + 1);
|
||||||
break;
|
break;
|
||||||
case FUNCTION:
|
case FUNCTION:
|
||||||
ILazyFunction f = functions.get(token.surface.toLowerCase(Locale.ROOT));// don't validate global - userdef functions
|
ILazyFunction f = functions.get(token.surface);// don't validate global - userdef functions
|
||||||
int numParams = stack.pop();
|
int numParams = stack.pop();
|
||||||
if (f != null && !f.numParamsVaries() && numParams != f.getNumParams())
|
if (f != null && !f.numParamsVaries() && numParams != f.getNumParams())
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap;
|
|||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Locale;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
@@ -107,7 +108,7 @@ public abstract class ScriptHost
|
|||||||
|
|
||||||
public void importModule(Context c, String moduleName)
|
public void importModule(Context c, String moduleName)
|
||||||
{
|
{
|
||||||
if (modules.containsKey(moduleName)) return; // aready imported
|
if (modules.containsKey(moduleName.toLowerCase(Locale.ROOT))) return; // aready imported
|
||||||
Module module = getModuleOrLibraryByName(moduleName);
|
Module module = getModuleOrLibraryByName(moduleName);
|
||||||
if (modules.containsKey(module.getName())) return; // aready imported, once again, in case some discrepancies in names?
|
if (modules.containsKey(module.getName())) return; // aready imported, once again, in case some discrepancies in names?
|
||||||
modules.put(module.getName(), module);
|
modules.put(module.getName(), module);
|
||||||
|
|||||||
Reference in new issue
Block a user