private void JsonPair(TerminalSet _TS, out BaseTerm t) { BaseTerm t0, t1; GetSymbol(new TerminalSet(terminalCount, StringLiteral), true, true); t0 = new StringTerm(symbol.ToString().Dequoted()); GetSymbol(new TerminalSet(terminalCount, Colon), true, true); JsonValue(_TS, out t1); t = new OperatorTerm(opTable, PrologParser.COLON, t0, t1); }
void JsonPair(TerminalSet _TS, out BaseTerm t) { #if LL1_tracing ReportParserProcEntry("JsonPair"); #endif BaseTerm t0, t1; GetSymbol(new TerminalSet(terminalCount, StringLiteral), true, true); t0 = new StringTerm(symbol.ToString().Dequoted()); GetSymbol(new TerminalSet(terminalCount, Colon), true, true); JsonValue(_TS, out t1); t = new OperatorTerm(opTable, PrologParser.COLON, t0, t1); #if LL1_tracing ReportParserProcExit("JsonPair"); #endif }
void JsonLiteral(TerminalSet _TS, out BaseTerm t) { #if LL1_tracing ReportParserProcEntry("JsonLiteral"); #endif GetSymbol(new TerminalSet(terminalCount, IntLiteral, RealLiteral, StringLiteral, TrueSym, FalseSym, NullSym), false, true); if (symbol.IsMemberOf(IntLiteral, RealLiteral)) { GetSymbol(new TerminalSet(terminalCount, IntLiteral, RealLiteral), false, true); if (symbol.Terminal == IntLiteral) { symbol.SetProcessed(); } else { symbol.SetProcessed(); } t = new DecimalTerm(symbol.ToDecimal()); } else if (symbol.Terminal == StringLiteral) { symbol.SetProcessed(); t = new StringTerm(symbol.ToString().Dequoted()); } else if (symbol.Terminal == TrueSym) { symbol.SetProcessed(); t = new AtomTerm("true"); } else if (symbol.Terminal == FalseSym) { symbol.SetProcessed(); t = new AtomTerm("false"); } else { symbol.SetProcessed(); t = new AtomTerm("null"); } #if LL1_tracing ReportParserProcExit("JsonLiteral"); #endif }
public static BaseTerm MakeMatchTerm(Match m, bool asAtom) { BaseTerm[] args = new BaseTerm[4]; if (asAtom) { args[0] = new AtomTerm(m.Value.ToAtom()); } else { args[0] = new StringTerm(m.Value.ToString()); } args[1] = new DecimalTerm(m.Index); args[2] = new DecimalTerm(m.Length); args[3] = new AtomTerm("m.Groups"); return(new CompoundTerm("match", args)); }
private void JsonLiteral(TerminalSet _TS, out BaseTerm t) { GetSymbol(new TerminalSet(terminalCount, IntLiteral, RealLiteral, StringLiteral, TrueSym, FalseSym, NullSym), false, true); if (symbol.IsMemberOf(IntLiteral, RealLiteral)) { GetSymbol(new TerminalSet(terminalCount, IntLiteral, RealLiteral), false, true); if (symbol.TerminalId == IntLiteral) { symbol.SetProcessed(); } else { symbol.SetProcessed(); } t = new DecimalTerm(symbol.ToDecimal()); } else if (symbol.TerminalId == StringLiteral) { symbol.SetProcessed(); t = new StringTerm(symbol.ToString().Dequoted()); } else if (symbol.TerminalId == TrueSym) { symbol.SetProcessed(); t = new AtomTerm("true"); } else if (symbol.TerminalId == FalseSym) { symbol.SetProcessed(); t = new AtomTerm("false"); } else { symbol.SetProcessed(); t = new AtomTerm("null"); } }
/// <summary> /// Initializes a new instance of the <see cref="Sum"/> class. /// </summary> /// <param name="matchPredicate">The match predicate.</param> /// <param name="alias">The alias.</param> public Sum(Term matchPredicate, StringTerm alias) : base(matchPredicate, alias) { }
/// <summary> /// Determines whether this object is equal to another object. /// </summary> /// <param name="other">The other object.</param> /// <returns><see langword="true"/> when the objects are equal; /// otherwise, <see langword="false"/>.</returns> private bool Equals(StringTerm other) { return base.Equals(other) && this.Value == other.Value; }
static BaseTerm ToTermEx(Node root) { BaseTerm [] args = new BaseTerm [3]; string tagName = root.TagName.ToAtom(); args [1] = ListTerm.EMPTYLIST; Decimal d; foreach (KeyValuePair <string, string> kv in root.Attributes) // XML Declaration { BaseTerm pair; if (Decimal.TryParse(kv.Value, styleAllowDecPnt, CIC, out d)) { pair = new OperatorTerm(EqualOpDescr, new AtomTerm(kv.Key), new DecimalTerm(d)); } else { pair = new OperatorTerm(EqualOpDescr, new AtomTerm(kv.Key), new StringTerm(kv.Value)); } args [1] = new ListTerm(pair, args [1]); } args [2] = ListTerm.EMPTYLIST; if (root.ChildNodes.Count > 0) { foreach (Node n in root.ChildNodes) { BaseTerm e; e = null; switch (n.type) { case XmlNodeType.Element: e = ToTermEx(n); break; case XmlNodeType.Comment: e = new CompoundTerm(COMMENT, new StringTerm(n.text.Trim().EscapeDoubleQuotes())); break; case XmlNodeType.Text: if (Decimal.TryParse(n.text, styleAllowDecPnt, CIC, out d)) { e = new DecimalTerm(d); } else if (n.text.HasAtomFormat()) { e = new AtomTerm(n.text); } else { e = new StringTerm(n.text.EscapeDoubleQuotes()); } break; case XmlNodeType.SignificantWhitespace: case XmlNodeType.Whitespace: e = new StringTerm(n.text); break; case XmlNodeType.CDATA: e = new CompoundTerm(CDATA, new StringTerm(n.text.Trim().EscapeDoubleQuotes())); break; case XmlNodeType.ProcessingInstruction: e = new CompoundTerm("processing_instruction", new AtomTerm(n.name.ToAtom()), new StringTerm(n.text.Trim().EscapeDoubleQuotes())); break; default: break; } if (e != null) { args [2] = new ListTerm(e, args [2]); } } } if (args [1].IsEmptyList) { return(new CompoundTerm(tagName, args [2])); } else { return(new CompoundTerm(tagName, args [1], args [2])); } }
static BaseTerm ToTermEx(Node root) { BaseTerm [] args = new BaseTerm [3]; #if fullyTagged args [0] = new AtomTerm(root.TagName.ToAtom()); #else string tagName = root.TagName.ToAtom(); #endif args [1] = ListTerm.EMPTYLIST; Decimal d; foreach (KeyValuePair <string, string> kv in root.Attributes) // XML Declaration { BaseTerm pair; if (Decimal.TryParse(kv.Value, styleAllowDecPnt, Utils.CIC, out d)) { pair = new OperatorTerm(EqualOpDescr, new AtomTerm(kv.Key), new DecimalTerm(d)); } else { pair = new OperatorTerm(EqualOpDescr, new AtomTerm(kv.Key), new StringTerm(kv.Value)); } args [1] = new ListTerm(pair, args [1]); } args [2] = ListTerm.EMPTYLIST; if (root.ChildNodes.Count > 0) { foreach (Node n in root.ChildNodes) { BaseTerm e; e = null; switch (n.type) { case XmlNodeType.Element: e = ToTermEx(n); break; case XmlNodeType.Comment: e = new CompoundTerm(COMMENT, new StringTerm(n.text.Trim().EscapeDoubleQuotes())); break; case XmlNodeType.Text: if (Decimal.TryParse(n.text, styleAllowDecPnt, Utils.CIC, out d)) #if fullyTagged { e = new CompoundTerm(TEXT, new DecimalTerm(d)); } else { e = new CompoundTerm(TEXT, new StringTerm(n.text.Trim().EscapeDoubleQuotes())); } #else { e = new DecimalTerm(d); } else { e = new StringTerm(n.text.Trim().EscapeDoubleQuotes()); } #endif break;
/// <summary> /// Initializes a new instance of the <see cref="SetCondition"/> class. /// </summary> /// <param name="id">The id.</param> /// <param name="attribute">The attribute.</param> /// <param name="value">The value.</param> public SetCondition(Term id, StringTerm attribute, Term value) : base("SetCondition", ConditionType.Set, id, attribute, value) { }
/// <summary> /// Initializes a new instance of the <see cref="InvokeCondition"/> class. /// </summary> /// <param name="label">The label.</param> /// <param name="id">The id.</param> /// <param name="attribute">The attribute.</param> /// <param name="value">The value.</param> public InvokeCondition(string label, Term id, StringTerm attribute, Term value) : base(label, ConditionType.Invoke, id, attribute, value) { }
/// <summary> /// Initializes a new instance of the <see cref="INVOKE"/> class. /// </summary> /// <param name="id">The id.</param> /// <param name="attribute">The attribute.</param> /// <param name="value">The value.</param> public INVOKE(Term id, StringTerm attribute, Term value) : base("InvokeCondition", id, attribute, value) { }
/// <summary> /// Initializes a new instance of the <see cref="SetCondition"/> class. /// </summary> /// <param name="label">The label.</param> /// <param name="id">The id.</param> /// <param name="attribute">The attribute.</param> /// <param name="value">The value.</param> public SetCondition(string label, Term id, StringTerm attribute, Term value) : base(label, ConditionType.Set, id, attribute, value) { }
/// <summary> /// Initializes a new instance of the <see cref="InvokeCondition"/> class. /// </summary> /// <param name="id">The id.</param> /// <param name="attribute">The attribute.</param> /// <param name="value">The value.</param> public InvokeCondition(Term id, StringTerm attribute, Term value) : base("InvokeCondition", ConditionType.Invoke, id, attribute, value) { }
/// <summary> /// Initializes a new instance of the <see cref="SET"/> class. /// </summary> /// <param name="id">The id.</param> /// <param name="attribute">The attribute.</param> /// <param name="value">The value.</param> public SET(Term id, StringTerm attribute, Term value) : base("SetCondition", id, attribute, value) { }
/// <summary> /// Determines whether this object is equal to another object. /// </summary> /// <param name="other">The other object.</param> /// <returns><see langword="true"/> when the objects are equal; /// otherwise, <see langword="false"/>.</returns> private bool Equals(StringTerm other) { return(base.Equals(other) && this.Value == other.Value); }
/// <summary> /// Initializes a new instance of the <see cref="Count"/> class. /// </summary> /// <param name="matchPredicate">The match predicate.</param> /// <param name="alias">The alias.</param> public BaseAggregator(Term matchPredicate, StringTerm alias) { _matchPredicate = matchPredicate; _alias = alias; }
/// <summary> /// Initializes a new instance of the <see cref="Sum"/> class. /// </summary> /// <param name="matchPredicate">The match predicate.</param> /// <param name="alias">The alias.</param> public Average(Term matchPredicate, StringTerm alias) : base(matchPredicate, alias) { }
static BaseTerm ToTermEx(Node root) { BaseTerm [] args = new BaseTerm [3]; #if fullyTagged args [0] = new AtomTerm (root.TagName.ToAtom ()); #else string tagName = root.TagName.ToAtom (); #endif args [1] = ListTerm.EMPTYLIST; Decimal d; foreach (KeyValuePair<string, string> kv in root.Attributes) // XML Declaration { BaseTerm pair; if (Decimal.TryParse (kv.Value, styleAllowDecPnt, Utils.CIC, out d)) pair = new OperatorTerm (EqualOpDescr, new AtomTerm (kv.Key), new DecimalTerm (d)); else pair = new OperatorTerm (EqualOpDescr, new AtomTerm (kv.Key), new StringTerm (kv.Value)); args [1] = new ListTerm (pair, args [1]); } args [2] = ListTerm.EMPTYLIST; if (root.ChildNodes.Count > 0) { foreach (Node n in root.ChildNodes) { BaseTerm e; e = null; switch (n.type) { case XmlNodeType.Element: e = ToTermEx (n); break; case XmlNodeType.Comment: e = new CompoundTerm (COMMENT, new StringTerm (n.text.Trim ().EscapeDoubleQuotes ())); break; case XmlNodeType.Text: if (Decimal.TryParse (n.text, styleAllowDecPnt, Utils.CIC, out d)) #if fullyTagged e = new CompoundTerm (TEXT, new DecimalTerm (d)); else e = new CompoundTerm (TEXT, new StringTerm (n.text.Trim ().EscapeDoubleQuotes ())); #else e = new DecimalTerm (d); else e = new StringTerm (n.text.Trim ().EscapeDoubleQuotes ()); #endif break; case XmlNodeType.CDATA: e = new CompoundTerm (CDATA, new StringTerm (n.text.Trim ().EscapeDoubleQuotes ())); break; case XmlNodeType.ProcessingInstruction: e = new CompoundTerm ("processing_instruction", new AtomTerm (n.name.ToAtom ()), new StringTerm (n.text.Trim ().EscapeDoubleQuotes ())); break; case XmlNodeType.SignificantWhitespace: case XmlNodeType.Whitespace: break;
/// <summary> /// Initializes a new instance of the <see cref="SET"/> class. /// </summary> /// <param name="label">The label.</param> /// <param name="id">The id.</param> /// <param name="attribute">The attribute.</param> /// <param name="value">The value.</param> public SET(string label, Term id, StringTerm attribute, Term value) : base(label, id, attribute, value) { }
public static BaseTerm FindRegexMatches( OperatorTable opTable, string source, string matchPattern, string[] options) { Regex re = null; RegexOptions reOptions = RegexOptions.None; if (options != null) { foreach (string o in options) { switch (o.ToLower()) { case "ignorecase": reOptions |= RegexOptions.IgnoreCase; break; case "multiline": reOptions |= RegexOptions.Multiline; break; case "singleline": reOptions |= RegexOptions.Singleline; break; case "explicitcapture": reOptions |= RegexOptions.ExplicitCapture; break; case "cultureinvariant": reOptions |= RegexOptions.CultureInvariant; break; default: IO.Error("match_regex -- unsupported option '{0}'", o); break; } } ; } try { re = new Regex(matchPattern, reOptions); //, RegexOptions.Multiline); } catch (Exception x) { IO.Error("Error in regular expression '{0}'\r\nMessage: {1}", matchPattern, x.Message); } Match m = re.Match(source); if (!m.Success) { return(null); } int[] gnums = re.GetGroupNumbers(); BaseTerm groups = new ListTerm(); while (m.Success) { for (int i = 1; i < gnums.Length; i++) // start at group 1 (0 is the fully captured match string) { Group g = m.Groups[gnums[i]]; BaseTerm captures = new ListTerm(); string groupId = re.GetGroupNames()[i]; int groupNo; BaseTerm groupIdTerm; foreach (Capture c in g.Captures) { captures = ((ListTerm)captures).AppendElement(new StringTerm(c.ToString())); } if (int.TryParse(groupId, out groupNo)) { groupIdTerm = new DecimalTerm(groupNo); } else { groupIdTerm = new StringTerm(re.GetGroupNames()[i]); } groups = ((ListTerm)groups).AppendElement( new OperatorTerm(opTable, ":", groupIdTerm, captures)); } m = m.NextMatch(); } if (((ListTerm)groups).ProperLength == 1) { groups = groups.Arg(0); // groups is <groupname>:[<captures>] if (groups.Arg(0) is DecimalTerm) { groups = groups.Arg(1); // anonymous group, just return the list of captures } } return(groups); }