internal ScannerEnumerator(Scanner scanner, ILogging logging) { this.scanner = scanner; this.document = scanner.document; this.textSource = scanner.textSource; this.termFactory = scanner.scanAction; this.logging = logging; this.cursor = new ScanCursor { RootContext = scanner.context, CurrentMode = scanner.startMode, Buffer = new char[Scanner.BufferSize], Cursor = 0, Limit = 0, Marker = -1, Start = 0, InnerState = 0, Actions = new int[scanner.MaxActionCount], ActionCount = 0, }; cursor.Buffer[0] = Scanner.Sentinel; this.priorPosition = 0; this.priorLine = 1; this.priorColumn = 1; InitContext(); }
public Scanner( Scan1Delegate startMode, TextReader textSource, string document, object rootContext, ScanActionDelegate scanAction, int maxActionCount, ILogging logging) { this.startMode = startMode; this.textSource = textSource; this.context = rootContext; this.document = document; this.scanAction = scanAction; this.MaxActionCount = maxActionCount; this.logging = logging; }
public void Test() { const string document = "number.list"; string[] expectedTokens = new string[] { " ", "123", " ", "0" }; int[] expectedTokenIds = new int[] { SpaceTokenId, NumberTokenId, SpaceTokenId, NumberTokenId }; Loc[] expectedLocations = new Loc[] { new Loc(document, 0, 1), new Loc(document, 1, 4), new Loc(document, 4, 7), new Loc(document, 7, 8) }; var input = new StringReader(string.Join("", expectedTokens)); ScanActionDelegate scanAction = (ScanCursor cursor, out object value) => { value = new string(cursor.Buffer, cursor.Start, cursor.Marker - cursor.Start); return(cursor.Actions[0]); }; var logging = ExceptionLogging.Instance; var allTokens = new Scanner(Scan1, input, document, null, scanAction, 10, logging).ToArray(); Assert.AreEqual(expectedTokens, TokenTexts(allTokens)); Assert.AreEqual(expectedTokenIds, TokenIds(allTokens)); Assert.AreEqual(expectedLocations, Locations(allTokens)); var scanner = new Scanner(Scan1, new StringReader(" a11"), Loc.MemoryString, null, scanAction, 10, logging); Assert.Throws <SyntaxException>( () => { scanner.ToArray(); }); }