public List<Lexeme> lex(String input) { List<Lexeme> output = new List<Lexeme>(); StringSource source = new StringSource(input); while (!source.EOF) { bool validLex = false; foreach (Rule rule in rules) { Lexeme lexeme = rule.Match(source); if (lexeme != null) { output.Add(lexeme); validLex = true; break; } } if (!validLex) { throw new LexException(); } } return output; }
/// <summary> /// Incrementally lexes and parses the specified string. /// </summary> /// <param name="input">The <see cref="StringSource"/> to parse.</param> /// <param name="start">The index of the first character that was changed.</param> /// <param name="count">The number of characters that were changed.</param> /// <param name="output">The parsed token stream.</param> /// <param name="options">A set of <see cref="TextParserOptions"/> values that specify how the text should be parsed.</param> /// <returns>An <see cref="IncrementalResult"/> structure that represents the result of the operation.</returns> /// <remarks>Incremental parsing provides a performance benefit when relatively small changes are being made /// to a large source text. Only tokens which are potentially influenced by changes within the specified substring /// of the source text are re-parsed by this operation.</remarks> private IncrementalResult ParseIncremental(StringSource input, Int32 start, Int32 count, TextParserTokenStream output, TextParserOptions options = TextParserOptions.None) { var inputLengthOld = output.SourceText.Length; var inputLengthNew = input.Length; var inputLengthDiff = inputLengthNew - inputLengthOld; Int32 ix1, ix2; FindTokensInfluencedBySubstring(output, start, count - inputLengthDiff, out ix1, out ix2); var token1 = output[ix1]; var token2 = output[ix2]; var invalidatedTokenCount = 1 + (ix2 - ix1); output.RemoveRange(ix1, invalidatedTokenCount); var lexStart = token1.SourceOffset; var lexCount = inputLengthDiff + (token2.SourceOffset + token2.SourceLength) - lexStart; var parserBuffer = incrementalParserBuffer.Value; Parse(input, parserBuffer, lexStart, lexCount); output.SourceText = input.CreateStringSegment(); output.InsertRange(ix1, parserBuffer); var affectedOffset = ix1; var affectedCount = parserBuffer.Count; parserBuffer.Clear(); return new IncrementalResult(affectedOffset, affectedCount); }
public override bool Execute() { var isbs = base.Execute(); if (!isbs) { return(false); } int id = 0; using (var services = new BankServiceClient()) { id = LastElement == null ? 0 : LastElement.CardAccountID; if (!IsUpdate) { if (IsNext) { CurrentList = services.GetNextCardAccounts(id, AmountElements).ToList(); } else { if (FirstElement == null) { id = int.MaxValue; } else { id = FirstElement.CardAccountID; } CurrentList = services.GetPrevCardAccounts(id, AmountElements).ToList(); } } else { CurrentList = services.GetNextCardAccounts(id - 1, AmountElements).ToList(); } } if (CurrentList != null && CurrentList.Count > 0) { FirstElement = CurrentList.First(); LastElement = CurrentList.Last(); } else { FirstElement = null; LastElement = null; Information = StringSource.EndList(); return(false); } Customer cust = null; using (var localrepos = new DAL.Repositories()) { Customers = localrepos.Customers.GetAll(); foreach (var el in CurrentList) { if (Customers.Count() > 0) { cust = Customers.FirstOrDefault(cs => cs.CustomerID == el.CustomerID); } EntitiesInformation.Add(StringSource.CardAccountAndClientShortInfo(el, cust)); IdsEntities.Add(el.CardAccountID); } } Information = StringSource.Successfully(); return(true); }
public StringSource TryGetValue(UInt64 key, StringSource source, out string value) { StubbleEntry entry; StringSource ret = TryGetValue(key, source, out entry); if (ret != StringSource.None) { value = entry.Value; return ret; } value = null; return ret; }
public bool LangHasData(Languages lang, StringSource source) { if (source == StringSource.Display) source = mCurrentSource; if ((source & StringSource.Modified) != 0) { Dictionary<UInt64, StubbleEntry> entrylist; if (mModifiedEntries.TryGetValue(lang, out entrylist) && entrylist.Count > 0) return true; } if ((source & StringSource.Loaded) != 0) { Dictionary<UInt64, StubbleEntry> entrylist; if (mLoadedEntries.TryGetValue(lang, out entrylist) && entrylist.Count > 0) return true; } return false; }
/// <summary> /// Gets a value indicating whether the specified character is the end of a command token. /// </summary> /// <param name="input">The input string.</param> /// <param name="ix">The index of the character to evaluate.</param> /// <returns><c>true</c> if the specified character is the end of a command token; otherwise, <c>false</c>.</returns> private static Boolean IsEndOfCommand(StringSource input, Int32 ix) { return input[ix] == '|'; }
/// <summary> /// Retrieves a command token from the input stream, beginning at the specified character. /// </summary> /// <param name="input">The input string.</param> /// <param name="options">The parser options.</param> /// <param name="ix">The index at which to begin consuming token characters.</param> /// <returns>The token that was created.</returns> private static TextParserToken ConsumeCommandToken(StringSource input, TextParserOptions options, ref Int32 ix) { var valid = false; var start = ix++; while (ix < input.Length) { if (Char.IsWhiteSpace(input[ix])) break; if (IsEndOfCommand(input, ix++)) { valid = true; break; } } var sourceOffset = start; var sourceLength = ix - start; var segment = input.CreateStringSegmentFromSameSource(sourceOffset, sourceLength); return ParseLexerToken(valid ? LexedTokenType.Command : LexedTokenType.Word, segment, sourceOffset, sourceLength, options); }
private static ICssGradientFunctionValue ParseRepeatingRadialGradient(StringSource source) { return(ParseRadialGradient(source, true)); }
public override bool Execute() { foreach (var el in CurrenciesNames) { if (!Verifier.CheckName(el)) { Information = StringSource.NameStructureError(); return(false); } } foreach (var el in CurrenciesShortNames) { if (!Verifier.CheckName(el)) { Information = StringSource.NameStructureError(); return(false); } } foreach (var el in CurrenciesRates) { if (!Verifier.CheckCurrencyCoef(el)) { Information = StringSource.CurrencyCoefStructureError(); return(false); } } var currencies = new List <Currency>(); int idd = -1; for (int i = 0; i < CurrenciesRates.Count; i++, idd = -1) { if (!int.TryParse(CurrenciesId.ElementAt(i), out idd)) { idd = -1; } currencies.Add(new Currency { CurrencyID = idd, Name = CurrenciesNames.ElementAt(i), ShortName = CurrenciesShortNames.ElementAt(i), Rate = double.Parse(CurrenciesRates.ElementAt(i)), }); } using (var bankaccoun = new BankServiceClient()) { //bankaccoun.RemoveAllCurrency(); var oldcurr = bankaccoun.GetAllCurrency(); foreach (var el in oldcurr) { if (currencies.Where(vl => vl.CurrencyID == el.CurrencyID).Count() <= 0) { bankaccoun.RemoveCurrency(el); } } foreach (var el in currencies) { if (el.CurrencyID == -1) { bankaccoun.AddCurrency(el); } else { bankaccoun.UpdateCurrency(el); } } } Information = StringSource.EditedIsTrue(); return(true); }
private static RadialOptions?ParseRadialOptions(StringSource source) { var circle = false; var center = Point.Center; var width = default(ICssValue); var height = default(ICssValue); var size = CssRadialGradientValue.SizeMode.None; var redo = false; var ident = source.ParseIdent(); if (ident != null) { if (ident.Isi(CssKeywords.Circle)) { circle = true; source.SkipSpacesAndComments(); var radius = source.ParseLengthOrCalc(); if (radius != null) { width = height = radius; } else { size = ToSizeMode(source) ?? CssRadialGradientValue.SizeMode.None; } redo = true; } else if (ident.Isi(CssKeywords.Ellipse)) { circle = false; source.SkipSpacesAndComments(); var el = source.ParseDistanceOrCalc(); source.SkipSpacesAndComments(); var es = source.ParseDistanceOrCalc(); if (el != null && es != null) { width = el; height = es; } else if (el == null && es == null) { size = ToSizeMode(source) ?? CssRadialGradientValue.SizeMode.None; } else { return(null); } redo = true; } else if (Map.RadialGradientSizeModes.ContainsKey(ident)) { size = Map.RadialGradientSizeModes[ident]; source.SkipSpacesAndComments(); ident = source.ParseIdent(); if (ident != null) { if (ident.Isi(CssKeywords.Circle)) { circle = true; redo = true; } else if (ident.Isi(CssKeywords.Ellipse)) { circle = false; redo = true; } } } } else { var el = source.ParseDistanceOrCalc(); source.SkipSpacesAndComments(); var es = source.ParseDistanceOrCalc(); if (el != null && es != null) { circle = false; width = el; height = es; } else if (el != null) { circle = true; width = el; } else { return(null); } redo = true; } if (redo) { source.SkipSpacesAndComments(); ident = source.ParseIdent(); } if (ident != null) { if (!ident.Isi(CssKeywords.At)) { return(null); } source.SkipSpacesAndComments(); var pt = source.ParsePoint(); if (!pt.HasValue) { return(null); } center = pt.Value; } return(new RadialOptions { Circle = circle, Center = center, Width = width, Height = height, Size = size }); }
private static ICssGradientFunctionValue ParseLinearGradient(StringSource source) { return(ParseLinearGradient(source, false)); }
public override bool Execute() { if (!Verifier.CheckName(Country)) { Information = StringSource.NameStructureError(); return(false); } if (!Verifier.CheckAddress(Address)) { Information = StringSource.AddressStructureError(); return(false); } if (!Verifier.CheckPassportNumber(PassportNumber)) { Information = StringSource.PassportNumberStructureError(); return(false); } if (!Verifier.CheckName(FirstName)) { Information = StringSource.NameStructureError(); return(false); } if (!Verifier.CheckName(LastName)) { Information = StringSource.NameStructureError(); return(false); } if (!Verifier.CheckName(MiddleName)) { Information = StringSource.NameStructureError(); return(false); } if (!Verifier.CheckEMail(EMail)) { Information = StringSource.EMailStructureError(); return(false); } Client = new Customer { FirstName = FirstName, LastName = LastName, MiddleName = MiddleName, PassportNumber = PassportNumber, Country = Country, Address = Address, Email = EMail, Login = LoginGeneration(), Passoword = PasswordGeneration(), IsLocked = false, }; var gen = new Generator { NumberCount = DataSource.LengthCode }; using (var localrepos = new Repositories()) { var all = localrepos.Customers.GetAll(); if (all.Where(el => el.PassportNumber == PassportNumber).Count() > 0) { Information = StringSource.ClientPassportNumberIsContains(); return(false); } localrepos.Customers.Add(Client); localrepos.SaveChanges(); //////////////////////////////////////////////////////////////////// new Supporting().RemoveClientInformationById(Client.CustomerID); //////////////////////////////////////////////////////////////////// if (all.Count() > 0) { var cl = all.Where(el => el.Login == Client.Login).ToList(); if (cl.Count() > 0) { var cc = (Customer)cl.ElementAt(0); IdClient = cc.CustomerID; } else { Information = StringSource.ClientRegistredError(); return(false); } } else { Information = StringSource.ClientRegistredError(); return(false); } // зарегаем карту доступа AccessCard = new AccessCard { //Customer=Client, CustomerID = Client.CustomerID, EnteredCodeFail = 0, IsBlocked = false, //AccessCodes=, }; localrepos.AccessCards.Add(AccessCard); localrepos.SaveChanges(); var acs = localrepos.AccessCards.GetAll(); if (acs.Count() > 0) { var acs2 = acs.Where(el => el.CustomerID == Client.CustomerID).ToArray(); if (acs2.Count() > 0) { AccessCard = acs2[0]; } else { Information = StringSource.ClientRegistredError(); return(false); } } else { Information = StringSource.ClientRegistredError(); return(false); } for (int i = 0; i < 40; i++) { localrepos.AccessCodes.Add(new AccessCode { //AccessCard=ac, AccessCardID = AccessCard.AccessCardID, Code = gen.NumberGenerate().ToString(), Number = i + 1, }); } ; localrepos.SaveChanges(); } Login = Client.Login; Information = StringSource.ClientRegistred(Client.Login); return(true); }
public override bool Execute() { if (IdClient <= 0) { Information = StringSource.ClientNotFound(); return(false); } if (!Verifier.CheckPassword(Password)) { Information = StringSource.PasswordStructureError(); return(false); } if (!Verifier.CheckName(Country)) { Information = StringSource.NameStructureError(); return(false); } if (!Verifier.CheckAddress(Address)) { Information = StringSource.AddressStructureError(); return(false); } if (!Verifier.CheckPassportNumber(PassportNumber)) { Information = StringSource.PassportNumberStructureError(); return(false); } if (!Verifier.CheckName(FirstName)) { Information = StringSource.NameStructureError(); return(false); } if (!Verifier.CheckName(LastName)) { Information = StringSource.NameStructureError(); return(false); } if (!Verifier.CheckName(MiddleName)) { Information = StringSource.NameStructureError(); return(false); } if (!Verifier.CheckEMail(EMail)) { Information = StringSource.EMailStructureError(); return(false); } using (var localrepos = new Repositories()) { if (localrepos.Customers.GetAll(el => el.PassportNumber == PassportNumber && el.CustomerID != IdClient).Count() > 0) { Information = StringSource.ClientPassportNumberIsContains(); return(false); } Client = localrepos.Customers.GetSingle(IdClient); if (Client == null) { Information = StringSource.ClientNotFound(); return(false); } Client.FirstName = FirstName; Client.LastName = LastName; Client.MiddleName = MiddleName; Client.PassportNumber = PassportNumber; Client.Country = Country; Client.Address = Address; Client.Email = EMail; Client.Login = Login; Client.Passoword = Password; Client.IsLocked = IsLocked; //Client.CustomerID= localrepos.Customers.Update(Client); localrepos.SaveChanges(); } Information = StringSource.ClientEdited(); return(true); }
public void TrailingComma_Object_4() { var json = @"{ a: [1,-2,], b: [{f: true},{f: false},{f: null},] , /* comment: comment */ , }"; var src = new StringSource(json); var got = JazonParser.Parse(src, true) as JsonDataMap; }
/// <summary> /// Gets a value indicating whether the specified character is the end of a non-breaking white space token. /// </summary> /// <param name="input">The input string.</param> /// <param name="ix">The index of the character to evaluate.</param> /// <returns><c>true</c> if the specified character is the end of a non-breaking white space token; otherwise, <c>false</c>.</returns> private static Boolean IsEndOfNonBreakingSpace(StringSource input, Int32 ix) { return input[ix] != '\u00A0'; }
public ICssValue Convert(StringSource source) { return(BorderSideConverter.Convert(source)); }
/// <summary> /// Gets a value indicating whether the specified character is the end of a breaking white space token. /// </summary> /// <param name="input">The input string.</param> /// <param name="ix">The index of the character to evaluate.</param> /// <returns><c>true</c> if the specified character is the end of a breaking white space token; otherwise, <c>false</c>.</returns> private static Boolean IsEndOfBreakingSpace(StringSource input, Int32 ix) { return input[ix] == '\u00A0' || !Char.IsWhiteSpace(input[ix]) || IsStartOfNewline(input, ix); }
public ICssValue Convert(StringSource source) => converter.Convert(source);
/// <summary> /// Retrieves a newline token from the input stream, beginning at the specified character. /// </summary> /// <param name="input">The input string.</param> /// <param name="options">The parser options.</param> /// <param name="ix">The index at which to begin consuming token characters.</param> /// <returns>The token that was created.</returns> private static TextParserToken ConsumeNewlineToken(StringSource input, TextParserOptions options, ref Int32 ix) { var sourceLength = 1; if (input[ix] == '\r' && ix + 1 < input.Length && input[ix + 1] == '\n') sourceLength = 2; var sourceOffset = ix; ix += sourceLength; var segment = input.CreateStringSegmentFromSameSource(sourceOffset, sourceLength); return ParseLexerToken(LexedTokenType.NewLine, segment, sourceOffset, sourceLength, options); }
private void parse() { var source = new StringSource(m_Pattern); var lexer = new CSLexer(source, throwErrors: true); var tokens = lexer.ToList(); m_Chunks = new List <chunk>(); var wasWildcard = false; var buf = string.Empty; var portion = chunkPortion.Path; var capture = false; Action flushBuf = () => { buf = buf.Trim(); if (buf.Length == 0) { return; } if (wasWildcard) { throw new WaveException(StringConsts.URI_WILDCARD_PARSE_ERROR); } if (capture) { //reparse buf var wildcard = buf.StartsWith("*"); if (wildcard) { buf = buf.Remove(0, 1).Trim(); if (buf.Length == 0) { buf = "ALL"; } } var segs = buf.Split('='); if (segs.Length == 2) { m_Chunks.Add(new chunk { Name = segs[0], DefaultValue = segs[1], Portion = portion, IsVar = true, IsWildcard = wildcard }); } else { m_Chunks.Add(new chunk { Name = buf, Portion = portion, IsVar = true, IsWildcard = wildcard }); } if (wildcard) { wasWildcard = true; } } else { m_Chunks.Add(new chunk { Name = Uri.UnescapeDataString(buf), Portion = portion }); } buf = string.Empty; }; for (var i = 0; i < tokens.Count; i++) { var token = tokens[i]; if (!token.IsPrimary) { continue; //skip comments etc. } if (!capture && token.Type == CSTokenType.tBraceOpen) { flushBuf(); capture = true; continue; } if (capture && token.Type == CSTokenType.tBraceClose) { flushBuf(); capture = false; continue; } if (capture) { buf += token.Text; continue; } if (token.Type == CSTokenType.tDiv) { flushBuf(); m_Chunks.Add(new chunk { IsPathDiv = true, Name = "/", Portion = portion }); continue; } if (token.Type == CSTokenType.tTernaryIf) { flushBuf(); portion = chunkPortion.Query; continue; } buf += token.Text; } flushBuf(); }
/// <summary> /// Lexes and parses the specified string. /// </summary> /// <param name="input">The <see cref="StringSource"/> to parse.</param> /// <param name="output">The parsed token stream.</param> /// <param name="index">The index at which to begin parsing the input string.</param> /// <param name="count">the number of characters to parse.</param> /// <param name="options">A set of <see cref="TextParserOptions"/> values that specify how the text should be parsed.</param> private void Parse(StringSource input, TextParserTokenStream output, Int32 index, Int32 count, TextParserOptions options = TextParserOptions.None) { var bound = index + count; while (index < bound) { if (IsStartOfNewline(input, index)) { output.Add(ConsumeNewlineToken(input, options, ref index)); continue; } if (IsStartOfNonBreakingSpace(input, index)) { output.Add(ConsumeNonBreakingSpaceToken(input, options, ref index)); continue; } if (IsStartOfBreakingSpace(input, index)) { output.Add(ConsumeBreakingSpaceToken(input, options, ref index)); continue; } if (IsEscapedPipe(input, index, options)) { output.Add(ConsumeEscapedPipeToken(input, options, ref index)); continue; } if (IsStartOfCommand(input, index)) { output.Add(ConsumeCommandToken(input, options, ref index)); continue; } if (IsStartOfWord(input, index)) { output.Add(ConsumeWordToken(input, options, ref index)); continue; } index++; } output.SourceText = input.CreateStringSegment(); output.ParserOptions = options; }
private static object read(string data, bool caseSensitiveMaps) { var source = new StringSource(data, JSONLanguage.Instance); return(read(source, caseSensitiveMaps)); }
public UInt32 GetHighestPriorityString(StringSource source, Languages lang) { UInt32 ret = UInt32.MaxValue; if ((source & StringSource.Modified) != 0) ret = Math.Min(ret, GetHighestPriorityString(mModifiedEntries, lang)); if ((source & StringSource.Loaded) != 0) ret = Math.Min(ret, GetHighestPriorityString(mLoadedEntries, lang)); if ((source & StringSource.Game) != 0) ret = Math.Min(ret, GetHighestPriorityString(mModifiedEntries, lang)); return ret; }
public static ICssValue ParsePointY(this StringSource source) { return(source.ParsePointDir(IsVertical)); }
public void RemoveEntry(UInt64 key, StringSource source, bool justone) { if (source == StringSource.Display) source = mCurrentSource; Dictionary<UInt64, StubbleEntry> entrylist; if ((source & StringSource.Modified) != 0) { if (mModifiedEntries.TryGetValue(CurrentLanguage, out entrylist) && entrylist.ContainsKey(key)) { entrylist.Remove(key); if (entrylist.Count == 0) mModifiedEntries.Remove(CurrentLanguage); if (justone) return; } } if ((source & StringSource.Loaded) != 0) { if (mLoadedEntries.TryGetValue(CurrentLanguage, out entrylist) && entrylist.ContainsKey(key)) { entrylist.Remove(key); if (entrylist.Count == 0) mLoadedEntries.Remove(CurrentLanguage); } } }
public static Point?ParsePoint(this StringSource source) { var pos = source.Index; var x = new Length(50f, Length.Unit.Percent); var y = new Length(50f, Length.Unit.Percent); var l = source.ParseIdent(); source.SkipSpacesAndComments(); var r = source.ParseIdent(); if (r != null) { if (IsHorizontal(r) && IsVertical(l)) { var t = l; l = r; r = t; } if (IsHorizontal(l) && IsVertical(r)) { x = KeywordToLength(l).Value; y = KeywordToLength(r).Value; return(new Point(x, y)); } } else if (l != null) { var s = source.ParseDistanceOrCalc(); if (IsHorizontal(l)) { x = KeywordToLength(l).Value; return(new Point(x, s ?? y)); } else if (IsVertical(l)) { y = KeywordToLength(l).Value; return(new Point(s ?? x, y)); } } else { var f = source.ParseDistanceOrCalc(); source.SkipSpacesAndComments(); var s = source.ParseDistanceOrCalc(); if (s != null) { return(new Point(f ?? x, s ?? y)); } else if (f != null) { pos = source.Index; r = source.ParseIdent(); if (r == null) { return(new Point(f, y)); } else if (IsVertical(r)) { y = KeywordToLength(r).Value; return(new Point(f ?? x, y)); } else if (IsHorizontal(r)) { x = KeywordToLength(r).Value; return(new Point(x, f ?? y)); } else { source.BackTo(pos); return(new Point(f ?? x, y)); } } } source.BackTo(pos); return(null); }
public void TrailingComma_Array_4() { var json = @"{ a: [1,-2,], b: [{f: true},{f: false},{f: null}, ,]}"; var src = new StringSource(json); var got = JazonParser.Parse(src, true) as JsonDataMap; }
public static ICssValue ParsePointX(this StringSource source) { return(source.ParsePointDir(IsHorizontal)); }
public ICssValue Convert(StringSource source) { return(converter.Convert(source)); }
/// <summary> /// Gets a value indicating whether the specified character is the start of a newline token. /// </summary> /// <param name="input">The input string.</param> /// <param name="ix">The index of the character to evaluate.</param> /// <returns><see langword="true"/> if the specified character is the start of a newline token; otherwise, <see langword="false"/>.</returns> private static Boolean IsStartOfNewline(StringSource input, Int32 ix) { return(input[ix] == '\n' || input[ix] == '\r'); }
/// <summary> /// Gets a value indicating whether the specified character is the start of a newline token. /// </summary> /// <param name="input">The input string.</param> /// <param name="ix">The index of the character to evaluate.</param> /// <returns><c>true</c> if the specified character is the start of a newline token; otherwise, <c>false</c>.</returns> private static Boolean IsStartOfNewline(StringSource input, Int32 ix) { return input[ix] == '\n' || input[ix] == '\r'; }
/// <summary> /// Gets a value indicating whether the specified character is the end of a non-breaking white space token. /// </summary> /// <param name="input">The input string.</param> /// <param name="ix">The index of the character to evaluate.</param> /// <returns><see langword="true"/> if the specified character is the end of a non-breaking white space token; otherwise, <see langword="false"/>.</returns> private static Boolean IsEndOfNonBreakingSpace(StringSource input, Int32 ix) { return(input[ix] != '\u00A0'); }
/// <summary> /// Gets a value indicating whether the specified character is the start of a breaking white space token. /// </summary> /// <param name="input">The input string.</param> /// <param name="ix">The index of the character to evaluate.</param> /// <returns><c>true</c> if the specified character is the start of a breaking white space token; otherwise, <c>false</c>.</returns> private static Boolean IsStartOfBreakingSpace(StringSource input, Int32 ix) { return input[ix] != '\u00A0' && Char.IsWhiteSpace(input[ix]) && !IsStartOfNewline(input, ix); }
/// <summary> /// Gets a value indicating whether the specified character is the start of a breaking white space token. /// </summary> /// <param name="input">The input string.</param> /// <param name="ix">The index of the character to evaluate.</param> /// <returns><see langword="true"/> if the specified character is the start of a breaking white space token; otherwise, <see langword="false"/>.</returns> private static Boolean IsStartOfBreakingSpace(StringSource input, Int32 ix) { return(input[ix] != '\u00A0' && Char.IsWhiteSpace(input[ix]) && !IsStartOfNewline(input, ix)); }
/// <summary> /// Gets a value indicating whether the specified character is an escaped pipe. /// </summary> /// <param name="input">The input string.</param> /// <param name="ix">The index of the character to evaluate.</param> /// <param name="options">A set of <see cref="TextParserOptions"/> values that specify how the text should be parsed.</param> /// <returns><c>true</c> if the specified character is an escaped pipe; otherwise, <c>false</c>.</returns> private static Boolean IsEscapedPipe(StringSource input, Int32 ix, TextParserOptions options) { if ((options & TextParserOptions.IgnoreCommandCodes) == TextParserOptions.IgnoreCommandCodes) return false; return input[ix] == '|' && (ix + 1 >= input.Length || input[ix + 1] == '|' || Char.IsWhiteSpace(input[ix + 1])); }
/// <summary> /// Gets a value indicating whether the specified character is the end of a breaking white space token. /// </summary> /// <param name="input">The input string.</param> /// <param name="ix">The index of the character to evaluate.</param> /// <returns><see langword="true"/> if the specified character is the end of a breaking white space token; otherwise, <see langword="false"/>.</returns> private static Boolean IsEndOfBreakingSpace(StringSource input, Int32 ix) { return(input[ix] == '\u00A0' || !Char.IsWhiteSpace(input[ix]) || IsStartOfNewline(input, ix)); }
/// <summary> /// Gets a value indicating whether the specified character is the end of a word token. /// </summary> /// <param name="input">The input string.</param> /// <param name="ix">The index of the character to evaluate.</param> /// <returns><c>true</c> if the specified character is the end of a word token; otherwise, <c>false</c>.</returns> private static Boolean IsEndOfWord(StringSource input, Int32 ix) { return Char.IsWhiteSpace(input[ix]) || IsStartOfCommand(input, ix); }
/// <summary> /// Gets a value indicating whether the specified character is the end of a command token. /// </summary> /// <param name="input">The input string.</param> /// <param name="ix">The index of the character to evaluate.</param> /// <returns><see langword="true"/> if the specified character is the end of a command token; otherwise, <see langword="false"/>.</returns> private static Boolean IsEndOfCommand(StringSource input, Int32 ix) { return(input[ix] == '|'); }
/// <summary> /// Retrieves an escaped pipe token from the input stream, beginning at the specified character. /// </summary> /// <param name="input">The input string.</param> /// <param name="options">The parser options.</param> /// <param name="ix">The index at which to begin consuming token characters.</param> /// <returns>The token that was created.</returns> private static TextParserToken ConsumeEscapedPipeToken(StringSource input, TextParserOptions options, ref Int32 ix) { var start = ix++; if (ix < input.Length && input[ix] == '|') ix++; var sourceOffset = start; var sourceLength = 1; return ParseLexerToken(LexedTokenType.Pipe, "|", sourceOffset, sourceLength, options); }
/// <summary> /// Gets a value indicating whether the specified character is the end of a word token. /// </summary> /// <param name="input">The input string.</param> /// <param name="ix">The index of the character to evaluate.</param> /// <returns><see langword="true"/> if the specified character is the end of a word token; otherwise, <see langword="false"/>.</returns> private static Boolean IsEndOfWord(StringSource input, Int32 ix) { return(Char.IsWhiteSpace(input[ix]) || IsStartOfCommand(input, ix)); }
/// <summary> /// Retrieves a word token from the input stream, beginning at the specified character. /// </summary> /// <param name="input">The input string.</param> /// <param name="options">The parser options.</param> /// <param name="ix">The index at which to begin consuming token characters.</param> /// <returns>The token that was created.</returns> private static TextParserToken ConsumeWordToken(StringSource input, TextParserOptions options, ref Int32 ix) { var start = ix++; while (ix < input.Length && !IsEndOfWord(input, ix)) ix++; var sourceOffset = start; var sourceLength = ix - start; var segment = input.CreateStringSegmentFromSameSource(sourceOffset, sourceLength); return ParseLexerToken(LexedTokenType.Word, segment, sourceOffset, sourceLength, options); }
/// <summary> /// Write header to result file /// </summary> private void WriteHeadersToResult() { _taskQueue.AddNotBufferedTask(TaskWriteObjectToFile.GetInstance(StringSource.GetInstance($"Calc SHA256 for each block of file: {_fileSource.Name}"))); _taskQueue.AddNotBufferedTask(TaskWriteObjectToFile.GetInstance(StringSource.GetInstance(string.Empty))); }
public Lexeme Match(StringSource source) { Position pos = source.SourcePos; Match match = source.TryExtract(regex); if (!match.Success) { return null; } return producer(match.Value, pos); }
public static Char SkipCurrentAndSpaces(this StringSource source) { source.Next(); return(source.SkipSpacesAndComments()); }
public IEnumerable<KeyValuePair<UInt64, StubbleEntry>> GetEntriesWithSourceForLanguage(Languages lang, StringSource source) { if (source == StringSource.Display) source = mCurrentSource; Dictionary<UInt64, StubbleEntry> modentrylist = null; if ((source & StringSource.Modified) != 0) { if (mModifiedEntries.TryGetValue(lang, out modentrylist)) { foreach (KeyValuePair<UInt64, StubbleEntry> entry in modentrylist) { yield return entry; } } } Dictionary<UInt64, StubbleEntry> loadentrylist = null; if ((source & StringSource.Loaded) != 0) { if (mLoadedEntries.TryGetValue(lang, out loadentrylist)) { foreach (KeyValuePair<UInt64, StubbleEntry> entry in loadentrylist) { if (modentrylist != null && modentrylist.ContainsKey(entry.Key)) continue; yield return entry; } } } if ((source & StringSource.Game) != 0) { foreach (KeyValuePair<UInt64, StubbleEntry> entry in GlobalEntries) { if (modentrylist != null && modentrylist.ContainsKey(entry.Key)) continue; if (loadentrylist != null && loadentrylist.ContainsKey(entry.Key)) continue; yield return entry; } } }
/// <summary> /// Sets the transformation matrix explicitly. /// http://www.w3.org/TR/css3-transforms/#funcdef-matrix3d /// </summary> private static MatrixTransform ParseMatrix3d(StringSource source) { return(ParseMatrix(source, 16)); }
public bool HasEntriesForLanguage(Languages lang, StringSource source) { if ((source & StringSource.Game) != 0) throw new InvalidOperationException(); if (source == StringSource.Display) source = mCurrentSource; Dictionary<UInt64, StubbleEntry> entrylist = null; if ((source & StringSource.Modified) != 0) { if (mModifiedEntries.TryGetValue(lang, out entrylist) && entrylist.Count > 0) return true; } if ((source & StringSource.Loaded) != 0) { if (mLoadedEntries.TryGetValue(lang, out entrylist) && entrylist.Count > 0) return true; } return false; }
/// <summary> /// A broad variety of rotate transforms. /// http://www.w3.org/TR/css3-transforms/#funcdef-rotate3d /// </summary> private static RotateTransform ParseRotate2d(StringSource source) { return(ParseRotate(source, Double.NaN, Double.NaN, Double.NaN)); }
public int LoadEntries(StringSource target, StubbleSource source, Languages lang, OverwriteMode overwrite, IEnumerable<KeyValuePair<UInt64, string>> entries) { if (source.SourceTable == DBPFReference.MinValue && overwrite != OverwriteMode.All && overwrite != OverwriteMode.None) throw new InvalidOperationException(); Dictionary<UInt64, StubbleEntry> targetlist; if (target == StringSource.Modified) { if (!mModifiedEntries.TryGetValue(lang, out targetlist)) { targetlist = new Dictionary<ulong, StubbleEntry>(); mModifiedEntries[lang] = targetlist; } } else if (target == StringSource.Loaded) { if (!mLoadedEntries.TryGetValue(lang, out targetlist)) { targetlist = new Dictionary<ulong, StubbleEntry>(); mLoadedEntries[lang] = targetlist; } } else { throw new InvalidOperationException(); } int added = 0; foreach (KeyValuePair<UInt64, string> entry in entries) { if (overwrite != OverwriteMode.All) { StubbleEntry oldentry; if (targetlist.TryGetValue(entry.Key, out oldentry)) { if (overwrite == OverwriteMode.None) continue; if (overwrite == OverwriteMode.Priority) { if ((UInt32)source.SourceTable.Instance >= (UInt32)oldentry.Source.SourceTable.Instance) continue; } else { if (source.SourceTable != oldentry.Source.SourceTable && (UInt32)source.SourceTable.Instance >= (UInt32)oldentry.Source.SourceTable.Instance) continue; } } } StubbleEntry newentry = new StubbleEntry(); newentry.Value = entry.Value; newentry.Source = source; targetlist[entry.Key] = newentry; added++; } return added; }
/// <summary> /// A broad variety of rotate transforms. /// http://www.w3.org/TR/css3-transforms/#funcdef-rotate3d /// </summary> private static RotateTransform ParseRotateZ(StringSource source) { return(ParseRotate(source, 0f, 0f, 1f)); }
public StringSource TryGetValue(UInt64 key, StringSource source, out StubbleEntry value) { if (source == StringSource.Display) source = mCurrentSource; if ((source & StringSource.Modified) != 0 && TryGetValue(mModifiedEntries, key, out value)) return StringSource.Modified; if ((source & StringSource.Loaded) != 0 && TryGetValue(mLoadedEntries, key, out value)) return StringSource.Loaded; if ((source & StringSource.Game) != 0 && GlobalEntries.TryGetValue(key, out value)) return StringSource.Game; value = null; return StringSource.None; }
public void substring_outofrange() { var spanner = new StringSource("hey there"); new Action(() => spanner.Substring(new Range(4, 9))).Should().ThrowExactly <ArgumentOutOfRangeException>(); }
private void parse() { var source = new StringSource(m_Pattern); var lexer = new CSLexer(source, throwErrors: true); var tokens = lexer.ToList(); m_Chunks = new List<chunk>(); var wasWildcard = false; var buf = string.Empty; var portion = chunkPortion.Path; var capture = false; Action flushBuf = () => { buf = buf.Trim(); if (buf.Length==0) return; if (wasWildcard) throw new WaveException(StringConsts.URI_WILDCARD_PARSE_ERROR); if (capture) { //reparse buf var wildcard = buf.StartsWith("*"); if (wildcard) { buf = buf.Remove(0,1).Trim(); if (buf.Length==0) buf = "ALL"; } var segs = buf.Split('='); if (segs.Length==2) m_Chunks.Add( new chunk{ Name = segs[0], DefaultValue = segs[1], Portion = portion, IsVar = true, IsWildcard = wildcard}); else m_Chunks.Add( new chunk{ Name = buf, Portion = portion, IsVar = true, IsWildcard = wildcard}); if (wildcard) wasWildcard = true; } else m_Chunks.Add( new chunk{ Name = Uri.UnescapeDataString(buf), Portion = portion}); buf = string.Empty; }; for(var i=0; i<tokens.Count; i++) { var token = tokens[i]; if (!token.IsPrimary) continue;//skip comments etc. if (!capture && token.Type==CSTokenType.tBraceOpen) { flushBuf(); capture = true; continue; } if (capture && token.Type==CSTokenType.tBraceClose) { flushBuf(); capture = false; continue; } if (capture) { buf+=token.Text; continue; } if (token.Type==CSTokenType.tDiv) { flushBuf(); m_Chunks.Add( new chunk{ IsPathDiv=true, Name = "/", Portion = portion}); continue; } if (token.Type==CSTokenType.tTernaryIf) { flushBuf(); portion = chunkPortion.Query; continue; } buf+=token.Text; } flushBuf(); }
public void Depth_5() { var json = @"{ v: {v2: 'abc'}}"; var src = new StringSource(json); var got = JazonParser.Parse(src, true, 1) as JsonDataMap; }