Ejemplo n.º 1
0
        public BootstrapScanner(
            TextReader textSource,
            string document,
            ScannerDescriptor descriptor,
            object rootContext,
            ILogging logging)
        {
            this.descriptor  = descriptor;
            this.rootContext = rootContext;
            this.logging     = logging;

            var pattern = @"\G(?:" + string.Join("|", descriptor.Matchers.Select(scanProd => "(" + GetPattern(scanProd) + ")")) + ")";

            this.regex = new Regex(pattern, RegexOptions.IgnorePatternWhitespace);
            this.text  = textSource.ReadToEnd();

            int count = descriptor.Matchers.Count;

            this.tokenFactories = new TokenFactoryDelegate[count];

            for (int i = 0; i != count; ++i)
            {
                if (descriptor.Matchers[i].Outcome != null)
                {
                    tokenFactories[i] = BuildTokenFactory(descriptor.Matchers[i]);
                }
            }
        }
Ejemplo n.º 2
0
 public BootstrapScanner(
     string input,
     ScannerDescriptor descriptor,
     object rootContext,
     ILogging logging)
     : this(new StringReader(input), Loc.MemoryString, descriptor, rootContext, logging)
 {
 }
Ejemplo n.º 3
0
 public IScanner CreateScanner(object context, TextReader input, string document, ILogging logging)
 {
     return(new BootstrapScanner(
                input,
                document,
                ScannerDescriptor.FromScanRules(data.Grammar.Conditions[0].Matchers, ExceptionLogging.Instance),
                context,
                logging));
 }
Ejemplo n.º 4
0
        public static ScannerDescriptor FromScanRules(IEnumerable<Matcher> matchers, ILogging logging)
        {
            CheckAllRulesHaveIndex(matchers);

            var result = new ScannerDescriptor(logging);
            foreach (var matcher in matchers)
            {
                result.AddRule(matcher);
            }

            return result;
        }
Ejemplo n.º 5
0
        public static ScannerDescriptor FromScanRules(IEnumerable <Matcher> matchers, ILogging logging)
        {
            CheckAllRulesHaveIndex(matchers);

            var result = new ScannerDescriptor(logging);

            foreach (var matcher in matchers)
            {
                result.AddRule(matcher);
            }

            return(result);
        }
Ejemplo n.º 6
0
        private static bool CompileTdfa(ILogging logging, Condition condition, out ITdfaData outcome)
        {
            var descr = ScannerDescriptor.FromScanRules(condition.Matchers, logging);

            var literalToAction = new Dictionary <string, int>();
            var ast             = descr.MakeAst(literalToAction);

            if (ast == null)
            {
                outcome = null;
                return(false);
            }

            var regTree = new RegularTree(ast);

            outcome = new RegularToTdfaAlgorithm(regTree, literalToAction).Data;
            condition.Joint.Add(outcome);

            return(true);
        }