public SExprAtomic(SToken tok) { Token = tok; }
public VMException(string msg, SToken t) : base(String.Format("'{0}': {1}, File:{2}, Line:{3}:{4}", (string)t.TValue, msg, t.Source, t.LineIndex?.Item1 + 1, t.LineIndex?.Item2 + 1)) { }
public SExprComp Parse(string text, string path, string source) { if (text.Length < 2) { throw new VMException("Invalid code"); } basePath = path; List <SToken> tokens = new List <SToken>(); var m = reString.Match(text); var finder = new LineFinder(text); while (m.Success) { SToken tok = new SToken(); tok.Source = source; if (m.Groups["str"].Success) { tok.LineIndex = finder.FindIndexAtLineIndex(m.Groups["str"].Index); tok.TType = SToken.TokenType.STRING; tok.TValue = Regex.Unescape(m.Groups["str"].Value).Replace(@"\""", "\""); } else if (m.Groups["rawstr"].Success) { tok.LineIndex = finder.FindIndexAtLineIndex(m.Groups["rawstr"].Index); tok.TType = SToken.TokenType.STRING; tok.TValue = m.Groups["rawstr"].Value.Replace("\"\"", "\""); //.Replace("}}", "}"); } else if (m.Groups["paren"].Success) { tok.LineIndex = finder.FindIndexAtLineIndex(m.Groups["paren"].Index); tok.TValue = m.Groups["paren"].Value; tok.TType = SExpr.Lookup[(string)tok.TValue]; } else if (m.Groups["atom"].Success) { string v = m.Groups["atom"].Value; decimal dum; tok.LineIndex = finder.FindIndexAtLineIndex(m.Groups["atom"].Index); if (Decimal.TryParse(v, out dum)) { tok.TType = SToken.TokenType.NUMBER; tok.TValue = dum; } else { tok.TType = SToken.TokenType.ATOMIC; tok.TValue = v; } } else { m = m.NextMatch(); continue; } tokens.Add(tok); m = m.NextMatch(); } SExprComp chain = new SExprComp(); chain.Atomics.Add(new SExprAtomic(new SToken(SToken.TokenType.ATOMIC, "chain"))); while (tokens.Count > 0) { chain.Atomics.Add(ParseNext(tokens)); } return(chain); }