public string ToString(StringRep <SYMBOL_ENUM> symbolsRep, StringRep <STATE_ENUM> statesRep) { string result = "states: " + StateTransStr(statesRep); result += Environment.NewLine; if (Text == null) { result += "EOF " + Position.XYString() + Environment.NewLine; } else { result += "text " + Position.XYString() + ": " + Text.PrintableString() + Environment.NewLine; } if (Rule == null) { result += "UNRECOGNIZED TEXT" + Environment.NewLine; } else if (!Rule.IsEofRule) { result += "rule [" + Rule.PatternId + "]: " + Rule.ToString(statesRep) + Environment.NewLine; } string indent = ""; if (tokens.Count > 1) { result += "multiple tokens {" + Environment.NewLine; indent = " "; } foreach (TokenMatch <SYMBOL_ENUM> token in Tokens) { result += indent + "token [" + token.ID + "]: "; if (!token.HasToken) { result += "*none*"; } else { result += symbolsRep.Get(token.Token) + Environment.NewLine; result += indent + "value assigned: " + (token.Value == null ? "null" : (Rule == null ? token.Value : token.Value.ToString().PrintableString())); } result += Environment.NewLine; } if (tokens.Count > 1) { result += "}" + Environment.NewLine; } return(result); }
// multiple entities repeated are created not as list of tuples, but tuple of the lists // e.g. (a b)+ translates into Tuple<List(a),List(b)> private CodeBody makeTupleListCode(SymbolPosition position, IEnumerable <string> elementTypeNames) { if (elementTypeNames.Any()) { return(makeTupleListCode(elementTypeNames)); } else { reportError(position.XYString() + " Cannot infer which elements have to be aggregated with repetition"); return(new CodeBody()); } }
public AltRule(SymbolPosition pos, string markWith, IEnumerable <RhsGroup> groups, CodeMix gen) { this.Position = pos; this.MarkWith = markWith; // [@PARSER_USER_ACTION] // here we swap the notion of user action // if in grammar user didn't pass ANY code -- it means identity function // if the grammar user pass empty code -- it means passing null value, so as shorcut set null as entire user action if (gen == null) // if there was no code at all, we infer the end object { CodeMix mix = null; if (inferEndObject(groups, ref mix)) { this.Code = mix; } else { throw ParseControlException.NewAndRun("Couldn't infer which object to pass at " + pos.XYString()); } } // if there was an empty code, such code does not produce anything (i.e. null) // thus we set entire action as null -- it is a shortcut else if (gen.IsEmpty) { this.Code = null; } else { this.Code = gen; } SetGroups(groups); }