internal static Token?TryMatch(LookaheadBuffer <char> cs) { if (cs.TryExpect('[')) { return(new Token(TokenType.LBrac, new string(cs.Consume(), 1))); } else if (cs.TryExpect(']')) { return(new Token(TokenType.RBrac, new string(cs.Consume(), 1))); } else if (cs.TryExpect('=')) { return(new Token(TokenType.Assign, new string(cs.Consume(), 1))); } else if (cs.TryExpect(',')) { return(new Token(TokenType.Comma, new string(cs.Consume(), 1))); } else if (cs.TryExpect('.')) { return(new Token(TokenType.Dot, new string(cs.Consume(), 1))); } else if (cs.TryExpect('{')) { return(new Token(TokenType.LCurly, new string(cs.Consume(), 1))); } else if (cs.TryExpect('}')) { return(new Token(TokenType.RCurly, new string(cs.Consume(), 1))); } return(null); }
private static TomlString ParseLiteralString(ITomlRoot root, LookaheadBuffer <Token> tokens) { var t = tokens.Consume(); Debug.Assert(t.type == TokenType.LiteralString); return(new TomlString(root, t.value, TomlString.TypeOfString.Literal)); }
public void LookAheadTestStartZero() { var instructions = new List<Instruction>(); var enumerator = instructions.GetEnumerator(); enumerator.MoveNext(); var count = LookaheadBuffer.GetUntilEndOfRoot(enumerator).Count(); Assert.Equal(0, count); }
private static TomlString ParseLiteralString(ITomlRoot root, LookaheadBuffer<Token> tokens) { var t = tokens.Consume(); Debug.Assert(t.type == TokenType.LiteralString); var s = t.value.TrimNChars(1); return new TomlString(root, s, TomlString.TypeOfString.Literal); }
private static TomlInt ParseTomlInt(ITomlRoot root, LookaheadBuffer <Token> tokens) { var token = tokens.Consume(); if (token.value.Length > 1 && token.value[0] == '0') { throw new Exception($"Failed to parse TOML int with '{token.value}' because it has a leading '0' which is not allowed by the TOML specification."); } return(new TomlInt(root, long.Parse(token.value.Replace("_", string.Empty)))); }
private static TomlInt ParseTomlInt(ITomlRoot root, LookaheadBuffer <Token> tokens, ParseIntDelegate parseDelegate) { var token = tokens.Consume(); if (!parseDelegate(token.value.Replace("_", string.Empty), out long value)) { throw new Exception($"Failed to parse TOML int with '{token.value}'."); } return(new TomlInt(root, value)); }
internal static Token? TryMatch(LookaheadBuffer<char> cs) { if (cs.TryExpect('[')) { return new Token(TokenType.LBrac, new string(cs.Consume(), 1)); } else if (cs.TryExpect(']')) { return new Token(TokenType.RBrac, new string(cs.Consume(), 1)); } else if (cs.TryExpect('=')) { return new Token(TokenType.Assign, new string(cs.Consume(), 1)); } else if (cs.TryExpect(',')) { return new Token(TokenType.Comma, new string(cs.Consume(), 1)); } else if (cs.TryExpect('.')) { return new Token(TokenType.Dot, new string(cs.Consume(), 1)); } else if (cs.TryExpect('{')) { return new Token(TokenType.LCurly, new string(cs.Consume(), 1)); } else if (cs.TryExpect('}')) { return new Token(TokenType.RCurly, new string(cs.Consume(), 1)); } return null; }
public void LookAheadTestStartMiniumLength() { var look = new List<Instruction> { X.StartObject<Style>(), X.EndObject() }; var enumerator = look.GetEnumerator(); enumerator.MoveNext(); var count = LookaheadBuffer.GetUntilEndOfRoot(enumerator).Count(); Assert.Equal(2, count); }
private static TomlFloat ParseTomlFloat(ITomlRoot root, LookaheadBuffer <Token> tokens) { var floatToken = tokens.Consume(); var check = floatToken.value; int startToCheckForZeros = check[0] == '+' || check[0] == '-' ? 1 : 0; if (check[startToCheckForZeros] == '0' && check[startToCheckForZeros + 1] != '.') { throw new Exception($"Failed to parse TOML float with '{floatToken.value}' because it has a leading '0' which is not allowed by the TOML specification."); } return(new TomlFloat(root, double.Parse(floatToken.value.Replace("_", string.Empty), CultureInfo.InvariantCulture))); }
public static Token? TryMatch(LookaheadBuffer<char> chars) { if (!chars.TryExpect('#')) { return null; } else { chars.Consume(); StringBuilder sb = new StringBuilder(64); while (!chars.End && !chars.TryExpect('\r') && !chars.TryExpect('\n')) { sb.Append(chars.Consume()); } return new Token(TokenType.Comment, sb.ToString()); } }
private static TomlString ParseStringValue(ITomlRoot root, LookaheadBuffer <Token> tokens) { var t = tokens.Consume(); Debug.Assert(t.type == TokenType.String); if (t.value.Contains("\n")) { throw Parser.CreateParseError(t, $"String '{t.value}' is invalid because it contains newlines."); } var s = t.value.Unescape(t); return(new TomlString(root, s, TomlString.TypeOfString.Normal)); }
public void LookAheadTestWithGetObjectAndCollection() { var look = resources.ComboBoxUnsorted; var expectedCount = look.Count; for (var t = 0; t < 4; t++) { look.Add(new Instruction(InstructionType.Value, "Noise")); } var enumerator = look.GetEnumerator(); enumerator.MoveNext(); var count = LookaheadBuffer.GetUntilEndOfRoot(enumerator).Count(); Assert.Equal(expectedCount, count); }
public static Token?TryMatch(LookaheadBuffer <char> chars) { if (!chars.TryExpect('#')) { return(null); } else { chars.Consume(); StringBuilder sb = new StringBuilder(Constants.MatcherBufferSize); while (!chars.End && !chars.TryExpect('\r') && !chars.TryExpect('\n')) { sb.Append(chars.Consume()); } return(new Token(TokenType.Comment, sb.ToString())); } }
public void LookAheadTest() { var look = new List<Instruction> { X.StartObject<Style>(), X.StartMember<Setter>(c => c.Value), X.Value("Value"), X.EndMember(), X.StartMember<Setter>(c => c.Property), X.Value("Property"), X.EndMember(), X.EndObject(), }; var enumerator = look.GetEnumerator(); enumerator.MoveNext(); var count = LookaheadBuffer.GetUntilEndOfRoot(enumerator).Count(); Assert.Equal(8, count); }
private static TomlString ParseMultilineLiteralString(ITomlRoot root, LookaheadBuffer <Token> tokens) { var t = tokens.Consume(); Debug.Assert(t.type == TokenType.MultilineLiteralString); string s = t.value; // Trim newline following the """ tag immediately if (s.Length > 0 && s[0] == '\r') { s = s.Substring(1); } if (s.Length > 0 && s[0] == '\n') { s = s.Substring(1); } return(new TomlString(root, t.value, TomlString.TypeOfString.MultilineLiteral)); }
public void LookAheadTest10() { var look = new List<Instruction> { X.StartObject<Setter>(), X.StartObject<Setter>(), X.StartObject<Setter>(), X.StartObject<Setter>(), X.StartObject<Setter>(), X.EndObject(), X.EndObject(), X.EndObject(), X.EndObject(), X.EndObject(), }; var enumerator = look.GetEnumerator(); enumerator.MoveNext(); var count = LookaheadBuffer.GetUntilEndOfRoot(enumerator).Count(); Assert.Equal(10, count); }
private static TomlString ParseMultilineString(ITomlRoot root, LookaheadBuffer <Token> tokens) { var t = tokens.Consume(); Debug.Assert(t.type == TokenType.MultilineString); var s = t.value; // Trim newline following the """ tag immediate if (s.Length > 0 && s[0] == '\r') { s = s.Substring(1); } if (s.Length > 0 && s[0] == '\n') { s = s.Substring(1); } s = ReplaceDelimeterBackslash(s); return(new TomlString(root, s, TomlString.TypeOfString.Multiline)); }
private static TomlFloat ParseTomlFloat(ITomlRoot root, LookaheadBuffer <Token> tokens) { var floatToken = tokens.Consume(); switch (floatToken.value) { case "nan": case "+nan": return(new TomlFloat(root, double.NaN)); case "-nan": return(new TomlFloat(root, -double.NaN)); case "inf": case "+inf": return(new TomlFloat(root, double.PositiveInfinity)); case "-inf": return(new TomlFloat(root, double.NegativeInfinity)); default: return(new TomlFloat( root, double.Parse(floatToken.value.Replace("_", string.Empty), CultureInfo.InvariantCulture))); } }
private static TomlInt ParseTomlInt(ITomlRoot root, LookaheadBuffer<Token> tokens) { var token = tokens.Consume(); if (token.value.Length > 1 && token.value[0] == '0') { throw new Exception($"Failed to parse TOML int with '{token.value}' because it has a leading '0' which is not allowed by the TOML specification."); } return new TomlInt(root, long.Parse(token.value.Replace("_", string.Empty))); }
private static TomlString ParseStringValue(ITomlRoot root, LookaheadBuffer<Token> tokens) { var t = tokens.Consume(); Debug.Assert(t.type == TokenType.String); if (t.value.Contains("\n")) { throw Parser.CreateParseError(t, $"String '{t.value}' is invalid because it contains newlines."); } var s = t.value.TrimNChars(1).Unescape(t); return new TomlString(root, s, TomlString.TypeOfString.Normal); }
private static TomlFloat ParseTomlFloat(ITomlRoot root, LookaheadBuffer<Token> tokens) { var floatToken = tokens.Consume(); var check = floatToken.value; int startToCheckForZeros = check[0] == '+' || check[0] == '-' ? 1 : 0; if (check[startToCheckForZeros] == '0' && check[startToCheckForZeros + 1] != '.') { throw new Exception($"Failed to parse TOML float with '{floatToken.value}' because it has a leading '0' which is not allowed by the TOML specification."); } return new TomlFloat(root, double.Parse(floatToken.value.Replace("_", string.Empty), CultureInfo.InvariantCulture)); }
private static TomlString ParseMultilineLiteralString(ITomlRoot root, LookaheadBuffer<Token> tokens) { var t = tokens.Consume(); Debug.Assert(t.type == TokenType.MultilineLiteralString); var s = t.value.TrimNChars(3); // Trim newline following the """ tag immediate if (s.Length > 0 && s[0] == '\r') { s = s.Substring(1); } if (s.Length > 0 && s[0] == '\n') { s = s.Substring(1); } return new TomlString(root, s, TomlString.TypeOfString.MultilineLiteral); }