<commit_before>﻿/* 
 * Copyright (c) 2015, Furore (<EMAIL>) and contributors
 * See the file CONTRIBUTORS for details.
 * 
 * This file is licensed under the BSD 3-Clause license
 * available at https://raw.githubusercontent.com/ewoutkramer/fhir-net-api/master/LICENSE
 */

using Hl7.FluentPath;
using System;
using System.Linq;
using System.Collections.Generic;
using Hl7.FluentPath.Support;
using Hl7.FluentPath.Functions;
using System.Text.RegularExpressions;
using Hl7.ElementModel;

namespace Hl7.FluentPath.Expressions
{

    public class SymbolTable
    {
        public SymbolTable()
        {

        }

        public SymbolTable(SymbolTable parent)
        {
            Parent = parent;
        }

        public int Count()
        {
            var cnt = _entries.Count();
            if (Parent != null) cnt += Parent.Count();

            return cnt;
        }

        internal Invokee First()
        {
            if (_entries.Any())
                return _entries.First().Body;
            else
            {
                if (Parent != null)
                    return Parent.First();
                else
                    return null;
            }
        }

        public SymbolTable Parent { get; private set; }

        private class TableEntry
        {
            public CallSignature Signature { get; private set; }
            public Invokee Body { get; private set; }

            public TableEntry(CallSignature signature, Invokee body)
            {
                Signature = signature;
                Body = body;
            }
        }

        private List<TableEntry> _entries = new List<TableEntry>();

        internal void Add(CallSignature signature, Invokee body)
        {
            _entries.Add(new TableEntry(signature, body));
        }

        public SymbolTable Filter(string name, int argCount)
        {
            var result = new SymbolTable();
            result._entries = new List<TableEntry>(_entries.Where(e => e.Signature.Matches(name, argCount)));

            if (Parent != null)
                result.Parent = Parent.Filter(name, argCount);
<commit_msg>SymbolTable Entry debugger visualizer<commit_after>﻿/* 
 * Copyright (c) 2015, Furore (<EMAIL>) and contributors
 * See the file CONTRIBUTORS for details.
 * 
 * This file is licensed under the BSD 3-Clause license
 * available at https://raw.githubusercontent.com/ewoutkramer/fhir-net-api/master/LICENSE
 */

using Hl7.FluentPath;
using System;
using System.Linq;
using System.Collections.Generic;
using Hl7.FluentPath.Support;
using Hl7.FluentPath.Functions;
using System.Text.RegularExpressions;
using Hl7.ElementModel;
using System.Text;

namespace Hl7.FluentPath.Expressions
{

    public class SymbolTable
    {
        public SymbolTable()
        {

        }

        public SymbolTable(SymbolTable parent)
        {
            Parent = parent;
        }

        public int Count()
        {
            var cnt = _entries.Count();
            if (Parent != null) cnt += Parent.Count();

            return cnt;
        }

        internal Invokee First()
        {
            if (_entries.Any())
                return _entries.First().Body;
            else
            {
                if (Parent != null)
                    return Parent.First();
                else
                    return null;
            }
        }

        public SymbolTable Parent { get; private set; }

        [System.Diagnostics.DebuggerDisplay(@"\{{DebuggerDisplayValue()}}")]
        private class TableEntry
        {
            public string DebuggerDisplayValue()
            {
                if (Signature != null)
                {
                    StringBuilder sb = new StringBuilder();
                    sb.Append(Signature.ReturnType.Name);
                    sb.Append(" ");
                    sb.Append(Signature.Name);
                    sb.Append(" (");
                    bool b = false;
                    foreach (var item in Signature.ArgumentTypes)
                    {
                        if (b)
                            sb.Append(", ");
                        sb.Append(item.Name);
                        b = true;
                    }
                    sb.Append(")");
                    return sb.ToString();
                }
                return null;
            }

            public CallSignature Signature { get; private set; }
            public Invokee Body { get; private set; }

            public TableEntry(CallSignature signature, Invokee body)
            {
                Signature = signature;
                Body = body;
            }
        }

        private List<TableEntry> _entries = new List<TableEntry>();

        internal void Add(CallSignature signature, Invokee body)
        {
            _entries.Add(new TableEntry(signature, body));
        }

        public SymbolTable Filter(string name, int argCount)
        {
            var result = new SymbolTable();
            result._entries = new List<TableEntry>(_entries.Where(e => e.Signature.Matches(name, argCount)));

            if (Parent != null)
                result.Parent = Parent.Filter(name, argCount);

{'fraction_non_alphanumeric': 0.09085648148148148, 'fraction_numerical': 0.0038580246913580245, 'mean_word_length': 1.5206611570247934, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 13, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6436690', 'n_tokens_mistral': 1342, 'n_tokens_neox': 1267, 'n_words': 335}