- public Element rangex(Object o, Object[] r) {
- Range.Set ret = o==null ? new Range.Set() : new Range.Set(new Range(true, true));
- if (r != null)
- for(Object aa : r) {
- Range range =
- aa instanceof Range
- ? (Range)aa
- : aa instanceof Character
- ? new Range(((Character)aa).charValue())
- : new Range(((String)aa).charAt(0));
- if (o==null) ret.add(range);
- else ret.remove(range);
- }
- return CharToken.set(ret);
- }
-
- public String sify(Object arg) {
- if (arg==null) return "";
- if (arg instanceof String) return (String)arg;
- Object[] args = (Object[])arg;
- while(true) {
- args = Reflection.lub(args);
- if (args instanceof String[]) {
- StringBuffer ret = new StringBuffer();
- for(String s : ((String[])args)) ret.append(s);
- return ret.toString();
- }
- if (args instanceof Character[]) break;
- if (!(args instanceof Object[])) break;
- args = (Object[])args[0];
- }
- if (args instanceof Character[]) {
- char[] c = new char[args.length];
- for(int i=0; i<c.length; i++) c[i] = ((Character)args[i]).charValue();
- String s = new String(c, 0, c.length);
- return s;
- }
- return (String)args[0];
- }
-
-
- ////////////////////////////////////////////////////////////////////////////////
-
- private Union g;
- private HashMap<String,Union> nt;
- private int anon = 0;
- private Element dws;
- private String startSymbol;
-
- public MetaGrammar() { this("s"); }
- public MetaGrammar(String s) { done(s); }
- public Union done() { return done("s"); }
- public Union done(String str) {
- Union ret = g;
- g = new Union(str);
- startSymbol = str;
- nt = new HashMap<String,Union>();
- dropAll = new HashSet<Element>();
- nt.put(str, g);
- this.dws = Repeat.maximal(Repeat.many0(nonTerminalY("w")));
- return ret;
- }
-
- public Union nonTerminalX(String str, PreSequence[][] s, boolean synthetic, boolean dropAll) {
- Union n = nonTerminalX(str, synthetic, dropAll);
- if (s == null || s.length==0) { n.add(Sequence.empty); return n; }
- HashSet<Sequence> seqs = new HashSet<Sequence>();
- for(int i=0; i<s.length; i++) {
- if (s[i]==null) continue;
- HashSet<Sequence> temp = new HashSet<Sequence>();
- for(PreSequence pre : s[i]) {
- pre.hatess.addAll(seqs);
- Sequence seq = pre.buildSequence(n, false, dropAll);
- temp.add(seq);
- //for(Sequence dom : seqs) seq.hates.add(dom);
- n.add(seq);
- }
- seqs.addAll(temp);
- }
- return n;
- }
-
- public String stringify(String s) { return StringUtil.unescapify(s); }
- public char unescape(char x, char c) { return unescape(c); }
- public char unescape(char c) { return StringUtil.unescapify("\\"+c).charAt(0); }
- public PreSequence sequence(Object[] o) { return new PreSequence(o, null); }