diff Implab/Formats/JSON/JSONScanner.cs @ 177:a0ff6a0e9c44 ref20160224

refactoring
author cin
date Wed, 23 Mar 2016 01:42:00 +0300
parents 0c3c69fe225b
children 478ef706906a
line wrap: on
line diff
--- a/Implab/Formats/JSON/JSONScanner.cs	Tue Mar 22 18:58:40 2016 +0300
+++ b/Implab/Formats/JSON/JSONScanner.cs	Wed Mar 23 01:42:00 2016 +0300
@@ -4,7 +4,6 @@
 using System.Text;
 using Implab.Components;
 using System.IO;
-using Implab.Automaton.RegularExpressions;
 
 namespace Implab.Formats.JSON {
     /// <summary>
@@ -13,8 +12,8 @@
     public class JSONScanner : Disposable {
         readonly StringBuilder m_builder = new StringBuilder();
 
-        readonly ScannerContext<JSONGrammar.TokenType> m_jsonScanner = JSONGrammar.Instance.JsonDFA;
-        readonly ScannerContext<JSONGrammar.TokenType> m_stringScanner = JSONGrammar.Instance.JsonStringDFA;
+        readonly ScannerContext<JSONGrammar.TokenType> m_jsonContext = JSONGrammar.Instance.JsonDFA;
+        readonly ScannerContext<JSONGrammar.TokenType> m_stringContext = JSONGrammar.Instance.JsonStringDFA;
 
 
         readonly TextScanner m_scanner;
@@ -31,7 +30,7 @@
         public JSONScanner(TextReader reader, int bufferMax, int chunkSize) {
             Safe.ArgumentNotNull(reader, "reader");
 
-            m_scanner = new ReaderScanner(reader);
+            m_scanner = new ReaderScanner(reader, bufferMax, chunkSize);
         }
 
         /// <summary>
@@ -44,7 +43,7 @@
         /// в строках обрабатываются экранированные символы, числа становтся типа double.</remarks>
         public bool ReadToken(out object tokenValue, out JsonTokenType tokenType) {
             JSONGrammar.TokenType[] tag;
-            if (m_jsonScanner.Execute(m_scanner, out tag)) {
+            if (m_jsonContext.Execute(m_scanner, out tag)) {
                 switch (tag[0]) {
                     case JSONGrammar.TokenType.StringBound:
                         tokenValue = ReadString();
@@ -68,12 +67,12 @@
 
         string ReadString() {
             int pos = 0;
-            char[] buf = new char[6]; // the buffer for unescaping chars
+            var buf = new char[6]; // the buffer for unescaping chars
 
             JSONGrammar.TokenType[] tag;
             m_builder.Clear();
 
-            while (m_stringScanner.Execute(m_scanner, out tag)) {
+            while (m_stringContext.Execute(m_scanner, out tag)) {
                 switch (tag[0]) {
                     case JSONGrammar.TokenType.StringBound:
                         return m_builder.ToString();
@@ -89,13 +88,17 @@
                         m_scanner.CopyTokenTo(buf, 0);
                         m_builder.Append(StringTranslator.TranslateEscapedChar(buf[1]));
                         break;
-                    default:
-                        break;
                 }
 
             }
 
             throw new ParserException("Unexpected end of data");
         }
+
+        protected override void Dispose(bool disposing) {
+            if (disposing)
+                Safe.Dispose(m_scanner);
+            base.Dispose(disposing);
+        }
     }
 }