/* L1 - General-Purpose Programming Language
Copyright (C) 2014 Danny Milosavljevic
This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License (in "COPYING") for more details.
If you have not received a copy of the GNU General Public License along with this program, see . */
// ... or: make the entire parser&formatter a shared object and load it.
// TODO I("|-") for inference.
// This module doesn't work since gdc apparently can't make shared objects. Sigh...
import std.typecons : tuple, Tuple;
import OPLs.OPL : Assoc, Operatorprecedencetable;
//extern (C) export __gshared void* _Dmodule_ref = null; // FIXME remove
// TypeInfo_Struct6
static pure auto I(string value, size_t arity) nothrow {
return tuple(value, arity);
}
alias L = Assoc.Infixl;
alias R = Assoc.Infixr;
alias N = Assoc.Infixn;
alias P = Assoc.Prefix;
alias S = Assoc.Suffix;
Operatorprecedencetable operatorprecedencetable = [
tuple(S,[I("", 0)]),
tuple(S,[I(")", 0), I("]", 0), I("}", 0), I("", 0)]),
tuple(R,[I("in", 2)]),
tuple(N,[I("let", 1)]),
tuple(N,[I(":=", 2)]),
tuple(N,[I("from", 2), I("by", 2)]),
tuple(R,[I(":", 2)]),
tuple(R,[I(";", 2), I("?;", 2)]),
tuple(R,[I("=>", 2)]),
tuple(L,[I("|", 2)]),
tuple(R,[I("elif", 2), I("else", 1)]),
tuple(R,[I("$", 2)]),
tuple(R,[I(",", 2)]),
tuple(L,[I("||", 2), I("∨", 2)]),
tuple(L,[I("&&", 2), I("∧", 2)]),
tuple(N,[I("<", 2), I("<=", 2), I(">", 2), I(">=", 2), I("≤", 2), I("≥", 2)]),
tuple(N,[I("=", 2), I("≟", 2), I("/=", 2)]),
tuple(N,[I("∈", 2), I("⊂", 2), I("⊃", 2), I("⊆", 2), I("⊇", 2)]),
tuple(L,[I("∪", 2)]),
tuple(L,[I("∩", 2)]),
tuple(L,[I("%", 2)]), // TODO remove?
tuple(L,[I("+", 2), I("-", 2)]),
tuple(P,[I("#exports", 1)]),
tuple(P,[I("∫", 1)]),
tuple(R,[I("⨯", 2)]), // TODO maybe move that one down.
tuple(L,[I(" ", 2), I("*", 2), I("⋅", 2), I("/", 2), I("&", 2), I("<<", 2), I(">>", 2), I("~", 2)]), // TODO remove un-math-like operators
tuple(P,[I("∂", 1), I("∇", 1), I("∇⋅", 1), I("∇⨯", 1), I("d", 1), I("D", 1)]), // TODO the latter are kinda weird.
tuple(N,[I("::", 2)]), // TODO move these up?
tuple(R,[I("->", 2)]), // TODO move these up?
tuple(R,[I("**", 2)]),
tuple(S,[I("!", 1), I("!!", 1)]),
tuple(L,[I("", 2)]), // at this level so that f(x)**2 = (f(x))**2
tuple(L,[I(".", 2)]),
tuple(P,[I("(", 0), I("[", 0), I("{", 0), I("", 0), I("`", 0), I("'", 0), I("if", 3), I("import", 3), I("∀", 2), I("∃", 2), I("not", 1), I("rem", 1)]),
];
// FIXME this must be able to replace the builder midway in. So more like (val, fn) buildNumber(val, input)
void* buildNumber(void* accu, char input) { /* or first convert the numeral into a list (or Name), then pass that. */
return accu;
}