public IListSource<LNode> Parse(IListSource<Token> input, ISourceFile file, IMessageSink msgs, ParsingMode inputType = null) { // For efficiency we'd prefer to re-use our _parser object, but // when parsing lazily, we can't re-use it because another parsing // operation could start before this one is finished. To force // greedy parsing, we can call ParseStmtsGreedy(), but the caller may // prefer lazy parsing, especially if the input is large. As a // compromise I'll check if the source file is larger than a // certain arbitrary size. Also, ParseExprs() is always greedy // so we can always re-use _parser in that case. bool exprMode = inputType == ParsingMode.Expressions; char _ = '\0'; if (inputType == ParsingMode.Expressions || file.Text.TryGet(255, ref _)) { Les2Parser parser = _parser; if (parser == null) _parser = parser = new Les2Parser(input, file, msgs); else { parser.ErrorSink = msgs; parser.Reset(input.AsList(), file); } if (inputType == ParsingMode.Expressions) return parser.ExprList(); else return parser.Start(new Holder<TokenType>(TokenType.Semicolon)).Buffered(); } else { var parser = new Les2Parser(input, file, msgs); return parser.Start(new Holder<TokenType>(TokenType.Semicolon)).Buffered(); } }
public RDMain(string fileContents) { lines = fileContents.Split('\n'); tokenDefinitions = new Dictionary<string, Graph>(); parseOrder = new List<string>(); tokenBuffer = ""; inIdent = false; tokenPosition = 0; charRanges = new List<Tuple<char, char>>(); StringBuilder allChar = new StringBuilder(); for (int i = 32; i <= 126; i++) { allChar.Append((char)i); } allChar.Remove(allChar.ToString().IndexOf('\\'), 1); allChar.Remove(allChar.ToString().IndexOf('^'), 1); allChar.Remove(allChar.ToString().IndexOf('-'), 1); allChar.Remove(allChar.ToString().IndexOf('['), 1); allChar.Remove(allChar.ToString().IndexOf(']'), 1); this.CLS_CHAR_NO_SPECIALS = allChar.ToString(); this.doDelaySet = false; charSetString = ""; characterClasses = new Dictionary<string, Graph>(); parsingMode = ParsingMode.None; this.parenCounter = 0; }
public IListSource<LNode> Parse(ILexer<Token> input, IMessageSink msgs, ParsingMode inputType = null, bool preserveComments = true) { if (preserveComments) { var saver = new TriviaSaver(input, (int)TokenType.Newline); var results = Parse(saver.Buffered(), input.SourceFile, msgs, inputType); var injector = new StandardTriviaInjector(saver.TriviaList, saver.SourceFile, (int)TokenType.Newline, "/*", "*/", "//"); return injector.Run(results.GetEnumerator()).Buffered(); } else { var lexer = new WhitespaceFilter(input); return Parse(lexer.Buffered(), input.SourceFile, msgs, inputType); } }
public MultipartFormDataReader(string contentType, Encoding contentEncoding, Stream inputStream, int bufferSize) { this.contentType = contentType; this.contentEncoding = contentEncoding; this.inputStream = inputStream; mode = ParsingMode.Headers; ParseContentType(); mem = new MemoryStream(bufferSize); text = new char[ contentEncoding.GetMaxCharCount(mem.Capacity) ]; }
internal void DtdParserProxy_ParsePI( BufferBuilder sb ) { if ( sb == null ) { ParsingMode pm = parsingMode; parsingMode = ParsingMode.SkipNode; ParsePI( null ); parsingMode = pm; } else { ParsePI( sb ); } }
public IDictionary<string, string> ReadHeaders() { IDictionary<string, string> headers = new Dictionary<string, string>(); Decoder decoder = contentEncoding.GetDecoder(); byte[] buffer = new byte[ Math.Max(mem.Length, 32) ]; int count = mem.Read(buffer, 0, (int)mem.Length); int crlfMatch = 0; do { Console.WriteLine("Read {0} bytes", count); int bufferPos = 0; while(bufferPos < count) { int startBufferPos = bufferPos; int deltaMatch = crlfMatch; MatchByteSeq(buffer, ref bufferPos, count, crlf, ref crlfMatch); deltaMatch = Math.Max(0, (crlfMatch - deltaMatch)); int dataByteCount = (bufferPos - startBufferPos - deltaMatch); mem.Write(buffer, startBufferPos, dataByteCount); if(crlfMatch == crlf.Length) // line terminator { if(mem.Length == 0) // empty line { mode = ParsingMode.Data; ResetMemStream(); int unprocByteCount = Math.Max(0, (count - bufferPos - deltaMatch)); Console.WriteLine("Empty line, terminating ReadHeaders. Bytes {0}+{1} unprocessed in buffer.", bufferPos, unprocByteCount); mem.Write(buffer, bufferPos, unprocByteCount); mem.Seek(0, SeekOrigin.Begin); return headers; } byte[] textByteData = mem.GetBuffer(); int lineChars = decoder.GetCharCount(textByteData, 0, (int)mem.Length); if(text.Length < lineChars) // make sure we have enough space text = new char[lineChars]; int textLength = decoder.GetChars(textByteData, 0, (int)mem.Length, text, 0); // TODO: Parse line contents. //Content-Disposition: file; filename="file2.gif" //Content-Type: image/gif //Content-Transfer-Encoding: binary Console.WriteLine("Read line of text ({0} bytes counted):", mem.Length); Console.Write('"'); Console.Write(text, 0, lineChars); Console.WriteLine('"'); if(!ParseHeaderLine(headers, text, textLength)) { Console.WriteLine("Unable to parse header."); } ResetMemStream(); crlfMatch = 0; } } Console.ReadKey(true); } while((count = inputStream.Read(buffer, 0, buffer.Length)) != 0); mode = ParsingMode.EndOfStream; return headers; }
public IListSource<LNode> Parse(ICharSource text, string fileName, IMessageSink msgs, ParsingMode inputType = null, bool preserveComments = true) { var lexer = Tokenize(text, fileName, msgs); return Parse(lexer, msgs, inputType, preserveComments); }
public void Print(ILNode node, StringBuilder target, IMessageSink sink = null, ParsingMode mode = null, ILNodePrinterOptions options = null) { Les2Printer.Print(node, target, sink, mode, options); }
private void AreaTransformer_StringToDigitMakeCompactWithSpecialRange09( ParsingMode ParsingMode) { List<string> AreaList = AreaTransformer.GetAreasFromString<string>("0-9", ';', '-', ParsingMode); Assert.AreEqual<string>("0", AreaList.First()); }
private void AreaTransformer_StringToDigitMakeCompact(ParsingMode ParsingMode) { bool bExpectedEatingUpChildren = (ParsingMode == ParsingMode.EatChildReturnRanges || ParsingMode == ParsingMode.EatChildReturnSingleDigits); List<string> AreaList = AreaTransformer.GetAreasFromString<string>("10-19", ';', '-', ParsingMode); Assert.IsTrue(AreaList.Contains("1")); AreaList = AreaTransformer.GetAreasFromString<string>("11;110-117", ';', '-', ParsingMode); Assert.IsTrue(AreaList.Contains("11")); Assert.AreNotEqual<bool>(bExpectedEatingUpChildren, AreaList.Any(x => x.StartsWith("110")), "Child areas expected to be handled correctly"); AreaList = AreaTransformer.GetAreasFromString<string>("5;510-517", ';', '-', ParsingMode); int iExpectedCount = bExpectedEatingUpChildren ? 1 : ParsingMode == ParsingMode.PreserveChildReturnSingleDigits ? 9 : 2; Assert.AreEqual<int>(iExpectedCount, AreaList.Count, "Child areas expected to be handled correctly"); Assert.AreEqual<string>("5", AreaList.First(), "Parent digit expected to be at first place"); }
/// <summary> /// Creates a Client or Server HTTP module. /// </summary> /// <param name="mode"></param> public HttpSockNetChannelModule(ParsingMode mode) { this.Mode = mode; }
public HtmlTree(ITextProvider text, IHtmlScriptTypeResolutionService scriptTypeResolution, IHtmlScriptOrStyleTagNamesService scriptOrStyleTagNameService, ParsingMode parsingMode) { Text = text; ScriptTypeResolution = scriptTypeResolution; ScriptOrStyleTagNameService = (scriptOrStyleTagNameService ?? new DefaultScriptOrStyleTagNameService()); ParsingMode = parsingMode; HtmlClosureProvider = new HtmlClosureProvider(); CommentCollection = new CommentCollection(); // Create root node last when all fields are intialized RootNode = new RootNode(this); }
protected LNode ParseHostBraces(Token p, int endIndex, ParsingMode mode) { return(F.Braces(ParseHostCode(p, mode), p.StartIndex, endIndex)); }
/// <summary> /// Creates HTML parser. /// </summary> /// <param name="parsingMode"> /// Parsing mode (HTML, XHTML or XML). HTML and XHTML differ in element /// and attribute name case-sensitity while XML mode treats <script> /// and <style elements as regular elements. /// </param> public HtmlParser(ParsingMode parsingMode) : this(parsingMode, null, null) { }
/// <summary> /// Creates HTML parser /// </summary> /// <param name="parsingMode"> /// Parsing mode (HTML, XHTML or XML). HTML and XHTML differ in element /// and attribute name case-sensitity while XML mode treats <script> /// and <style elements as regular elements. /// </param> /// <param name="scriptTypeResolution"> /// A service that helps parser to detemine if content of a <script> /// block should be skipped over (normal behavior) or should parser /// continue parsing inside the block since block content is actually /// a markup, like in <script type="text/x-handlebars-template">. /// </param> public HtmlParser(ParsingMode parsingMode, IHtmlScriptTypeResolutionService scriptTypeResolution, IHtmlScriptOrStyleTagNamesService scriptOrStyleTagNameService) { ParsingMode = parsingMode; ScriptTypeResolution = scriptTypeResolution; ScriptOrStyleTagNameService = (scriptOrStyleTagNameService ?? new DefaultScriptOrStyleTagNameService()); Stats = new HtmlParserStatistic(); }
public void Work(string _command) { if (_command.Contains("setphrase")) { string pattern = @"setphrase\s*(?<phrase>.*)"; Regex rgx = new Regex(pattern); Phrase = rgx.Match(_command).Groups["phrase"].Value; Console.WriteLine("Set phrase \"" + Phrase + "\"."); } else if (_command.Contains("getphrase")) { Console.WriteLine("Current phrase: \"" + Phrase + "\"."); } else if (_command.Contains("setoptions")) { string pattern = @"setoptions\s*(?<options>.*)"; Regex rgx = new Regex(pattern); string result = rgx.Match(_command).Groups["options"].Value; foreach (RegexOptions rgxvalue in Enum.GetValues(typeof(RegexOptions))) { if (result.Contains(rgxvalue.ToString())) { Options = Options | rgxvalue; } } } else if (_command.Contains("setmode")) { string pattern = @"setmode\s*(?<mode>.*)"; Regex rgx = new Regex(pattern); string result = rgx.Match(_command).Groups["mode"].Value; foreach (ParsingMode rgxvalue in Enum.GetValues(typeof(ParsingMode))) { if (result.Contains(rgxvalue.ToString())) { Mode = Mode | rgxvalue; } } } else if (_command.Contains("getmode")) { Console.WriteLine(Mode.ToString()); } else if (_command.Contains("getoptions")) { Console.WriteLine(Options.ToString()); } else if (_command.Contains("removeoption")) { string pattern = @"removeoption\s*(?<option>.*)"; Regex rgx = new Regex(pattern); string result = rgx.Match(_command).Groups["option"].Value; RegexOptions _tmp = RegexOptions.None; foreach (RegexOptions opt in Enum.GetValues(typeof(RegexOptions))) { if (result != opt.ToString()) { string used = Options.ToString(); //Console.WriteLine(used + ";" + opt.ToString()); if (used.Contains(opt.ToString())) { _tmp = _tmp | opt; } } } Options = _tmp; } else if (_command.Contains("removemode")) { string pattern = @"removemode\s*(?<option>.*)"; Regex rgx = new Regex(pattern); string result = rgx.Match(_command).Groups["option"].Value; // Options = Options & (RegexOptions)Enum.Parse(typeof(RegexOptions),result); ParsingMode _tmp = ParsingMode.All; foreach (ParsingMode opt in Enum.GetValues(typeof(ParsingMode))) { if (result != opt.ToString()) { string used = Mode.ToString(); //Console.WriteLine(used + ";" + opt.ToString()); if (used.Contains(opt.ToString())) { _tmp = _tmp | opt; } } } Mode = _tmp; } else if (_command.Contains("setdata")) { string pattern = @"setdata\s*(?<data>.*)"; Regex rgx = new Regex(pattern); string result = rgx.Match(_command).Groups["data"].Value; if (System.IO.File.Exists(result)) { Data = System.IO.File.ReadAllText(result, System.Text.Encoding.Default); } else { Data = result; } } else if (_command.Contains("getdata")) { Console.WriteLine("----------------------------DATA--------------------------"); Console.WriteLine(Data); Console.WriteLine("----------------------------DATA--------------------------"); } else if (_command.Contains("listmodes")) { foreach (ParsingMode opt in Enum.GetValues(typeof(ParsingMode))) { Console.WriteLine(opt.ToString()); } } else if (_command.Contains("listoptions")) { foreach (RegexOptions opt in Enum.GetValues(typeof(RegexOptions))) { Console.WriteLine(opt.ToString()); } } else if (_command.Contains("parse")) { Regex neu = new Regex(Phrase, Options); if (neu.IsMatch(Data) == false) { Console.WriteLine("No Matches!"); } else { int count = 0; string result = ""; foreach (Match mt in neu.Matches(Data)) { result += "[" + count + "] " + mt.Value + "\n"; count++; for (int i = 0; i < mt.Groups.Count; i++) { if (result.Contains("[" + neu.GetGroupNames() [i] + "] " + mt.Groups [i].Value) == false) { result += "-> [" + neu.GetGroupNames() [i] + "] " + mt.Groups [i].Value + "\n"; } } } Console.WriteLine(result); } } else if (_command.Contains("help")) { Console.WriteLine(cTerminus.g_programName + " help"); Console.WriteLine("setphrase - set the regular expression to parse"); Console.WriteLine("getphrase - print the regular expression to parse"); Console.WriteLine("setoptions - set the RegexOptions - enumeration values"); Console.WriteLine("setmode - set the ParsingMode - enumeration values"); Console.WriteLine("getmode - list the currently used values for parsing modes"); Console.WriteLine("getoptions - list the currently used values for regex options"); Console.WriteLine("removeoption - remove a >single< option"); Console.WriteLine("removemode - removes a mode"); Console.WriteLine("setdata - set the data for parsing, if the file does exist, the content of the file is used"); Console.WriteLine("getdata - print the data"); Console.WriteLine("listmodes - list the avaiable modes"); Console.WriteLine("listoptions - list the avaiable regex options"); Console.WriteLine("parse - run the Parser"); } }
// Skips the current node. If on element, skips to the end tag of the element. public override void Skip() { if (_readState != ReadState.Interactive) return; if (InAttributeValueIterator) { FinishAttributeValueIterator(); _curNode = _nodes[_index]; } else { switch (_parsingFunction) { case ParsingFunction.InReadAttributeValue: Debug.Assert(false); break; case ParsingFunction.InIncrementalRead: FinishIncrementalRead(); break; case ParsingFunction.PartialTextValue: SkipPartialTextValue(); break; case ParsingFunction.InReadValueChunk: FinishReadValueChunk(); break; case ParsingFunction.InReadContentAsBinary: FinishReadContentAsBinary(); break; case ParsingFunction.InReadElementContentAsBinary: FinishReadElementContentAsBinary(); break; } } switch (_curNode.type) { // skip subtree case XmlNodeType.Element: if (_curNode.IsEmptyElement) { break; } int initialDepth = _index; _parsingMode = ParsingMode.SkipContent; // skip content while (_outerReader.Read() && _index > initialDepth) ; Debug.Assert(_curNode.type == XmlNodeType.EndElement); Debug.Assert(_parsingFunction != ParsingFunction.Eof); _parsingMode = ParsingMode.Full; break; case XmlNodeType.Attribute: _outerReader.MoveToElement(); goto case XmlNodeType.Element; } // move to following sibling node _outerReader.Read(); return; }
/// <summary> /// Creates parser for configuration at given path. /// </summary> /// <param name="mode">Desired Configuration Parsing mode</param> private ConfigParser(ParsingMode mode) { _mode = mode; }
internal void DtdParserProxy_ParseComment(StringBuilder sb) { Debug.Assert(_parsingMode == ParsingMode.Full); try { if (sb == null) { ParsingMode savedParsingMode = _parsingMode; _parsingMode = ParsingMode.SkipNode; ParseCDataOrComment(XmlNodeType.Comment); _parsingMode = savedParsingMode; } else { NodeData originalCurNode = _curNode; _curNode = AddNode(_index + _attrCount + 1, _index); ParseCDataOrComment(XmlNodeType.Comment); _curNode.CopyTo(0, sb); _curNode = originalCurNode; } } catch (XmlException e) { if (e.ResString == SR.Xml_UnexpectedEOF && _ps.entity != null) { SendValidationEvent(XmlSeverityType.Error, SR.Sch_ParEntityRefNesting, null, _ps.LineNo, _ps.LinePos); } else { throw; } } }
public abstract ParsingMode SwitchMode(ParsingMode mode, char character);
private void AreaTransformer_StringToDigitLongAreaCodes(ParsingMode ParsingMode) { List<string> AreaList = AreaTransformer.GetAreasFromString<string>("123456, 21234556", ',', '-', ParsingMode); Assert.IsTrue(AreaList.Contains("123456"), "123456"); }
public abstract (string, INonTerminalExpression) ParseString(ParsingMode mode, INonTerminalExpression parrentNode, string text, char character);
private void AreaTransformer_StringToDigitMakeCompactWithHeadingZeroes(ParsingMode ParsingMode) { bool bPrintRanges = (ParsingMode == ParsingMode.EatChildReturnRanges || ParsingMode == ParsingMode.PreserveChildReturnRanges); List<string> AreaList = AreaTransformer.GetAreasFromString<string>("00000000001-3;0000000000000000005;6", ';', '-', ParsingMode); string[] ExpectedSequence = (bPrintRanges ? new string[] { "1-3", "5-6" } : new string[] { "1", "2", "3", "5", "6" }); if (ParsingMode == ParsingMode.PreserveChildReturnRanges) { ExpectedSequence = new string[] { "1-3", "5", "6" }; } Assert.IsTrue(ExpectedSequence.SequenceEqual(AreaList)); }
private static object RunCSharpCodeWithRoslyn(LNode parent, LNodeList code, IMacroContext context, ParsingMode printMode = null) { // Note: when using compileTimeAndRuntime, the transforms here affect the version // sent to Roslyn, but not the runtime version placed in the output file. code = code.SmartSelectMany(stmt => { // Ensure #r gets an absolute path; I don't know what Roslyn does with a // relative path (maybe WithMetadataResolver would let me control this, // but it's easier not to) if ((stmt.Calls(S.CsiReference, 1) || stmt.Calls(S.CsiLoad, 1)) && stmt[0].Value is string fileName) { fileName = fileName.Trim().WithoutPrefix("\"").WithoutSuffix("\""); var inputFolder = context.ScopedProperties.TryGetValue((Symbol)"#inputFolder", "").ToString(); var fullPath = Path.Combine(inputFolder, fileName); return(LNode.List(stmt.WithArgChanged(0, stmt[0].WithValue("\"" + fullPath + "\"")))); } // For each (top-level) LexicalMacro method, call #macro_context.RegisterMacro(). LNode attribute = null; if ((attribute = stmt.Attrs.FirstOrDefault( attr => AppearsToCall(attr, "LeMP", nameof(LexicalMacroAttribute).WithoutSuffix("Attribute")) || AppearsToCall(attr, "LeMP", nameof(LexicalMacroAttribute)))) != null && EcsValidators.MethodDefinitionKind(stmt, out _, out var macroName, out _, out _) == S.Fn) { var setters = SeparateAttributeSetters(ref attribute); attribute = attribute.WithTarget((Symbol)nameof(LexicalMacroAttribute)); setters.Insert(0, attribute); var newAttribute = F.Call(S.New, setters); var registrationCommand = F.Call(F.Dot(__macro_context, nameof(IMacroContext.RegisterMacro)), F.Call(S.New, F.Call(nameof(MacroInfo), F.Null, newAttribute, macroName))); return(LNode.List(stmt, registrationCommand)); } return(LNode.List(stmt)); }); var outputLocationMapper = new LNodeRangeMapper(); var options = new LNodePrinterOptions { IndentString = " ", SaveRange = outputLocationMapper.SaveRange }; string codeText = EcsLanguageService.WithPlainCSharpPrinter.Print(code, context.Sink, printMode, options); _roslynSessionLog?.WriteLine(codeText); _roslynSessionLog?.Flush(); _roslynScriptState.GetVariable(__macro_context_sanitized).Value = context; try { // Allow users to write messages via MessageSink.Default using (MessageSink.SetDefault(new MessageSinkFromDelegate((sev, ctx, msg, args) => { _roslynSessionLog?.Write("{0} from user ({1}): ", sev, MessageSink.GetLocationString(ctx)); _roslynSessionLog?.WriteLine(msg, args); context.Sink.Write(sev, ctx, msg, args); }))) { _roslynScriptState = _roslynScriptState.ContinueWithAsync(codeText).Result; } return(_roslynScriptState.ReturnValue); } catch (CompilationErrorException e) when(e.Diagnostics.Length > 0 && e.Diagnostics[0].Location.IsInSource) { // Determine the best location in the source code at which to report the error. // Keep in mind that the error may have occurred in a synthetic location not // found in the original code, and we cannot report such a location. Microsoft.CodeAnalysis.Text.TextSpan range = e.Diagnostics[0].Location.SourceSpan; var errorLocation = new IndexRange(range.Start, range.Length); var mappedErrorLocation = outputLocationMapper.FindRelatedNodes(errorLocation, 10) .FirstOrDefault(p => !p.A.Range.Source.Text.IsEmpty); string locationCaveat = ""; if (mappedErrorLocation.A != null) { bool mappedIsEarly = mappedErrorLocation.B.EndIndex <= errorLocation.StartIndex; if (mappedIsEarly || mappedErrorLocation.B.StartIndex >= errorLocation.EndIndex) { locationCaveat = "; " + "The error occurred at a location ({0}) that doesn't seem to exist in the original code.".Localized( mappedIsEarly ? "after the location indicated".Localized() : "before the location indicated".Localized()); } } // Extract the line where the error occurred, for inclusion in the error message int column = e.Diagnostics[0].Location.GetLineSpan().StartLinePosition.Character; int lineStart = range.Start - column; int lineEnd = codeText.IndexOf('\n', lineStart); if (lineEnd < lineStart) { lineEnd = codeText.Length; } string line = codeText.Substring(lineStart, lineEnd - lineStart); string errorMsg = e.Message + " - in «{0}»{1}".Localized(line, locationCaveat); context.Sink.Error(mappedErrorLocation.A ?? parent, errorMsg); LogRoslynError(e, context.Sink, parent, compiling: true); } catch (Exception e) { while (e is AggregateException ae && ae.InnerExceptions.Count == 1) { e = ae.InnerExceptions[0]; } context.Sink.Error(parent, "An exception was thrown from your code:".Localized() + " " + e.ExceptionMessageAndType()); LogRoslynError(e, context.Sink, parent, compiling: false); } return(NoValue.Value); }
void ILNodePrinter.Print(LNode node, StringBuilder target, IMessageSink sink, ParsingMode mode, ILNodePrinterOptions options) { Print((ILNode)node, target, sink, mode, options); }
public CommandTreeParser(CommandModel configuration, ParsingMode?parsingMode = null) { _configuration = configuration; _parsingMode = parsingMode ?? _configuration.ParsingMode; _help = new CommandOptionAttribute("-h|--help"); }
public void Print(IEnumerable<LNode> nodes, StringBuilder target, IMessageSink msgs = null, ParsingMode mode = null, ILNodePrinterOptions options = null) { LNodePrinter.PrintMultiple(this, nodes, target, msgs, mode, options); }
internal void DtdParserProxy_ParseComment(BufferBuilder sb) { Debug.Assert(_parsingMode == ParsingMode.Full); try { if (sb == null) { ParsingMode savedParsingMode = _parsingMode; _parsingMode = ParsingMode.SkipNode; ParseCDataOrComment(XmlNodeType.Comment); _parsingMode = savedParsingMode; } else { NodeData originalCurNode = _curNode; _curNode = AddNode(_index + _attrCount + 1, _index); ParseCDataOrComment(XmlNodeType.Comment); _curNode.CopyTo(0, sb); _curNode = originalCurNode; } } catch (XmlException e) { throw e; } }
public void CopyData(Stream outputStream) { if(mode != ParsingMode.Data) throw new InvalidOperationException( "MultipartFormReader is not at a data segment." ); byte[] buffer = mem.GetBuffer(); int count = (int)mem.Length; Console.WriteLine("Mem is at {1} and has {0} bytes.", count, mem.Position); int boundMatch = 0; do { Console.WriteLine("Read {0} bytes.", count); int bufferPos = 0; while(bufferPos < count) { int startBufferPos = bufferPos; int deltaMatch = boundMatch; MatchByteSeq(buffer, ref bufferPos, count, boundary, ref boundMatch); deltaMatch = Math.Max(0, (boundMatch - deltaMatch)); int dataByteCount = (bufferPos - startBufferPos - deltaMatch); Console.Write("startBufferPos={0}; bufferPos={1}; boundMatch={2}; dataByteCount={3}; ", startBufferPos, bufferPos, boundMatch, dataByteCount); outputStream.Write(buffer, startBufferPos, dataByteCount); Console.WriteLine("Copied {0} bytes.", dataByteCount); if(boundMatch == boundary.Length) { mode = ParsingMode.Epilogue; return; } } Console.ReadKey(true); } while((count = inputStream.Read(buffer, 0, buffer.Length)) > 0); mode = ParsingMode.EndOfStream; Console.WriteLine("End of input stream."); }
// Skips the current node. If on element, skips to the end tag of the element. public override void Skip() { if (readState != ReadState.Interactive) return; switch (parsingFunction) { case ParsingFunction.InReadAttributeValue: FinishAttributeValueIterator(); curNode = nodes[index]; break; case ParsingFunction.InIncrementalRead: FinishIncrementalRead(); break; case ParsingFunction.PartialTextValue: SkipPartialTextValue(); break; case ParsingFunction.InReadValueChunk: FinishReadValueChunk(); break; } switch (curNode.type) { // skip subtree case XmlNodeType.Element: if (curNode.IsEmptyElement) { break; } int initialDepth = index; parsingMode = ParsingMode.SkipContent; // skip content while (Read() && index > initialDepth) ; Debug.Assert(curNode.type == XmlNodeType.EndElement); Debug.Assert(parsingFunction != ParsingFunction.Eof); parsingMode = ParsingMode.Full; break; case XmlNodeType.Attribute: MoveToElement(); goto case XmlNodeType.Element; } // move to following sibling node Read(); return; }
void ILNodePrinter.Print(IEnumerable <LNode> nodes, StringBuilder target, IMessageSink sink, ParsingMode mode, ILNodePrinterOptions options) { Print(nodes, target, sink, mode, options); }
// Skips the current node. If on element, skips to the end tag of the element. public override void Skip() { if ( readState != ReadState.Interactive ) return; if ( InAttributeValueIterator ) { FinishAttributeValueIterator(); curNode = nodes[index]; } else { switch ( parsingFunction ) { case ParsingFunction.InReadAttributeValue: Debug.Assert( false ); break; #if !SILVERLIGHT // Needed only for XmlTextReader (ReadChars, ReadBase64, ReadBinHex) case ParsingFunction.InIncrementalRead: FinishIncrementalRead(); break; #endif case ParsingFunction.PartialTextValue: SkipPartialTextValue(); break; case ParsingFunction.InReadValueChunk: FinishReadValueChunk(); break; case ParsingFunction.InReadContentAsBinary: FinishReadContentAsBinary(); break; case ParsingFunction.InReadElementContentAsBinary: FinishReadElementContentAsBinary(); break; } } switch ( curNode.type ) { // skip subtree case XmlNodeType.Element: if ( curNode.IsEmptyElement ) { break; } int initialDepth = index; parsingMode = ParsingMode.SkipContent; // skip content while ( outerReader.Read() && index > initialDepth ) ; Debug.Assert( curNode.type == XmlNodeType.EndElement ); Debug.Assert( parsingFunction != ParsingFunction.Eof ); parsingMode = ParsingMode.Full; break; case XmlNodeType.Attribute: outerReader.MoveToElement(); goto case XmlNodeType.Element; } // move to following sibling node outerReader.Read(); return; }
public void Print(ILNode node, StringBuilder target, IMessageSink sink = null, ParsingMode mode = null, ILNodePrinterOptions options = null) { CheckParam.IsNotNull("target", target); var p = new Les3Printer(target, sink, options); p.Print(node); }
internal void DtdParserProxy_ParseComment( BufferBuilder sb ) { Debug.Assert( parsingMode == ParsingMode.Full ); try { if ( sb == null ) { ParsingMode savedParsingMode = parsingMode; parsingMode = ParsingMode.SkipNode; ParseCDataOrComment( XmlNodeType.Comment ); parsingMode = savedParsingMode; } else { NodeData originalCurNode = curNode; curNode = AddNode( index + attrCount + 1, index ); ParseCDataOrComment( XmlNodeType.Comment ); curNode.CopyTo( 0, sb ); curNode = originalCurNode; } } catch ( XmlException e ) { #if !SILVERLIGHT if ( e.ResString == Res.Xml_UnexpectedEOF && ps.entity != null ) { SendValidationEvent( XmlSeverityType.Error, Res.Sch_ParEntityRefNesting, null, ps.LineNo, ps.LinePos ); } else { throw; } #else throw e; #endif } }
/// <summary> /// Parse a line in the character class definition and token definition file /// </summary> /// <param name="line"></param> private Tuple<String, Graph> parseLine(string line) { line = line.Trim(); if (line.Length == 0) return null; //switch parsing modes when we find a header for a new section if (line.Substring(0, 2) == "%%") { if (parsingMode == ParsingMode.None) parsingMode = ParsingMode.CharacterClasses; else if (parsingMode == ParsingMode.CharacterClasses) parsingMode = ParsingMode.TokenDefinitions; //skip to next line after getting rid of the comment line return null; } if(line.Substring(0,1) == "$") { //get char class name int index = 1; while(line[index] != ' ' && line[index] != '\t') { index++; } string charClassName = line.Substring(1, index-1); //get char class definition text String charClassDef = line.Substring(index).Trim(); //try parsing character class definition lineGraph = new Graph(); tokenBuffer = charClassDef; tokenPosition = 0; Regexp(); //insert name/NFA into the correct dictionary depending on if we are parsing character classes or token definitions if(parsingMode == ParsingMode.CharacterClasses) { characterClasses.Add(charClassName, lineGraph); } else if(parsingMode == ParsingMode.TokenDefinitions) { tokenDefinitions.Add(charClassName, lineGraph); } return new Tuple<string, Graph>(charClassName, lineGraph); } return null; }
internal void DtdParserProxy_ParsePI(StringBuilder sb) { if (sb == null) { ParsingMode pm = _parsingMode; _parsingMode = ParsingMode.SkipNode; ParsePI(null); _parsingMode = pm; } else { ParsePI(sb); } }
private void AreaTransformer_CanConvertInBothDirectionCorrectly( ParsingMode ParsingMode) { char chSep = '+'; char chDel = '&'; //first conversion, from digits to string string sExpectedAreaString = "110&117+ 22"; string sActualAreaString = AreaTransformer.TransformAreaDigitsToString((new int[] { 220, 221, 222, 223, 224, 225, 226, 227, 228, 229, 110, 111, 112, 113, 114, 115, 116, 117 }) .Select(x => x.ToString()).ToList(), chSep, chDel, Compression.Full); Assert.AreEqual<string>(sExpectedAreaString, sActualAreaString); //second conversion, back to digits List<string> AreaList = AreaTransformer.GetAreasFromString<string>(sActualAreaString, chSep, chDel, ParsingMode); List<string> ExpectedSequence = null; switch (ParsingMode) { case ParsingMode.EatChildReturnRanges: case ParsingMode.PreserveChildReturnRanges: ExpectedSequence = new List<string>(new string[] { "110&117", "22" }); Assert.IsTrue(ExpectedSequence.SequenceEqual(AreaList)); break; default: ExpectedSequence = new List<string>(new string[] { "110", "111", "112", "113", "114", "115", "116", "117", "22" }); Assert.IsTrue(ExpectedSequence.SequenceEqual(AreaList)); break; } }
private bool ParseComment() { if (_ignoreComments) { ParsingMode oldParsingMode = _parsingMode; _parsingMode = ParsingMode.SkipNode; ParseCDataOrComment(XmlNodeType.Comment); _parsingMode = oldParsingMode; return false; } else { ParseCDataOrComment(XmlNodeType.Comment); return true; } }
public void Print(IEnumerable<ILNode> nodes, StringBuilder target, IMessageSink sink = null, ParsingMode mode = null, ILNodePrinterOptions options = null) { CheckParam.IsNotNull("target", target); var p = new Les3Printer(target, sink, options); p.Print(nodes); }