diff Implab/Formats/JSON/JSONGrammar.cs @ 180:c32688129f14 ref20160224

refactoring complete, JSONParser rewritten
author cin
date Thu, 24 Mar 2016 02:30:46 +0300
parents d5c5db0335ee
children b2b6a6640aa3
line wrap: on
line diff
--- a/Implab/Formats/JSON/JSONGrammar.cs	Wed Mar 23 19:52:08 2016 +0300
+++ b/Implab/Formats/JSON/JSONGrammar.cs	Thu Mar 24 02:30:46 2016 +0300
@@ -2,6 +2,7 @@
 using Implab.Automaton.RegularExpressions;
 using System;
 using Implab.Automaton;
+using Implab.Components;
 
 namespace Implab.Formats.JSON {
     class JSONGrammar : Grammar<char> {
@@ -23,7 +24,7 @@
             EscapedUnicode
         }
 
-        static Lazy<JSONGrammar> _instance = new Lazy<JSONGrammar>();
+        static LazyAndWeak<JSONGrammar> _instance = new LazyAndWeak<JSONGrammar>(() => new JSONGrammar());
 
         public static JSONGrammar Instance {
             get { return _instance.Value; }
@@ -31,6 +32,7 @@
 
         readonly ScannerContext<TokenType> m_jsonExpression;
         readonly ScannerContext<TokenType> m_stringExpression;
+        readonly CharAlphabet m_defaultAlphabet = new CharAlphabet();
 
         public JSONGrammar() {
             DefineAlphabet(Enumerable.Range(0, 0x20).Select(x => (char)x));
@@ -87,6 +89,12 @@
 
         }
 
+        protected override IAlphabetBuilder<char> AlphabetBuilder {
+            get {
+                return m_defaultAlphabet;
+            }
+        }
+
         public ScannerContext<TokenType> JsonExpression {
             get {
                 return m_jsonExpression;
@@ -103,7 +111,7 @@
             return SymbolToken(Enumerable.Range(start,stop - start).Cast<char>());
         }
 
-        protected override IAlphabetBuilder<char> CreateAlphabet() {
+        protected override IndexedAlphabetBase<char> CreateAlphabet() {
             return new CharAlphabet();
         }