Exemple #1
0
 public UniqueSymbolOrArities(int arity, TSymbol uniqueSymbol)
 {
     _uniqueSymbolOrArities       = uniqueSymbol;
     _arityBitVectorOrUniqueArity = arity;
     //if there's no unique symbol, how can there be an arity?
     Debug.Assert((uniqueSymbol != null) || (arity == 0));
 }
            public TreeNode(TreeNode parent, TSymbol c)
            {
                this.Char    = c;
                this.Parent  = parent;
                this.results = new List <TSymbol[]>();

                hash = new Dictionary <TSymbol, TreeNode>();
            }
Exemple #3
0
        public TPlayer(string name, TSymbol symbol)
        {
            if (string.IsNullOrWhiteSpace(name)) throw new ArgumentException(nameof(name));
            if (symbol == TSymbol.Empty) throw new ArgumentException(nameof(symbol));

            Name = name;
            Symbol = symbol;
        }
            public TreeNode(TreeNode parent, TSymbol c)
            {
                _char      = c; _parent = parent;
                _results   = new List <TSymbol[]>();
                _resultsAr = new TSymbol[][] { };

                _transitionsAr = new TreeNode[] { };
                _transHash     = new Hashtable();
            }
Exemple #5
0
            public void SyntaxError(TextWriter output, IRecognizer recognizer, TSymbol offendingSymbol, int line, int charPositionInLine, string msg, RecognitionException e)
            {
                var source = offendingSymbol is IToken t?
                             SourceRange.FromTokens(t, null) :
                                 new SourceRange(new SourceLocation(line, charPositionInLine),
                                                 new SourceLocation(line, charPositionInLine));

                mod.Diagnostics.AddError(msg, source);
            }
Exemple #6
0
 public void GetUniqueSymbolOrArities(out IArityEnumerable arities, out TSymbol uniqueSymbol)
 {
     if (this.HasUniqueSymbol)
     {
         arities      = null;
         uniqueSymbol = (TSymbol)_uniqueSymbolOrArities;
     }
     else
     {
         arities      = (_uniqueSymbolOrArities == null && _arityBitVectorOrUniqueArity == 0) ? null : (IArityEnumerable)this;
         uniqueSymbol = null;
     }
 }
            public TreeNode GetTransition(TSymbol c)
            {
                TreeNode t;

                if (hash.TryGetValue(c, out t))
                {
                    return(t);
                }
                else
                {
                    return(null);
                }
            }
Exemple #8
0
        internal static TSymbol FindSymbol(string name, TSymbol gSymbol)
        {
            TSymbol temp = gSymbol;

            while (temp != null)
            {
                if (temp.Name.ToLower() == name.ToLower())
                {
                    return(temp);
                }
                temp = temp.Next;
            }

            return(null);
        }
            public void AddSymbol(TSymbol symbol, string multiName)
            {
                if (symbol != null && symbol == _uniqueSymbolOrMultiNames)
                {
                    return;
                }

                if (this.HasUniqueSymbol)
                {
                    // The symbol is no longer unique. So clear the
                    // UniqueSymbol field and record the unique name
                    // before adding the new name value.
                    var(uniqueName, _) = (Tuple <string, TSymbol>)_uniqueSymbolOrMultiNames;
                    Debug.Assert(_uniqueSymbolOrMultiNames is TSymbol);
                    _uniqueSymbolOrMultiNames = new ConsList <string>(uniqueName, ConsList <string> .Empty);
                }
                AddMultiName(multiName);
            }
Exemple #10
0
        public void Bind <TSymbol, TCodeCommand>()
            where TSymbol : Symbol, new()
            where TCodeCommand : CodeCommand, new()
        {
            var symbol = new TSymbol();

            if (symbol is IScope scope)
            {
                var openSymbol = scope.GetOpenSymbol();
                symbolToCommand.Add(openSymbol.GetType(), () => new TCodeCommand());
                symbols.Add(openSymbol);
                symbols.Add(scope.GetCloseSymbol());
            }
            else
            {
                symbols.Add(symbol);
                symbolToCommand.Add(typeof(TSymbol), () => new TCodeCommand());
            }
        }
Exemple #11
0
            public void AddSymbol(TSymbol symbol, int arity)
            {
                if (symbol != null && symbol == _uniqueSymbolOrArities)
                {
                    Debug.Assert(arity == _arityBitVectorOrUniqueArity);
                    return;
                }

                if (this.HasUniqueSymbol)
                {
                    // The symbol is no longer unique. So clear the
                    // UniqueSymbol field and record the unique arity
                    // before adding the new arity value.
                    Debug.Assert(_uniqueSymbolOrArities is TSymbol);
                    _uniqueSymbolOrArities = null;

                    int uniqueArity = _arityBitVectorOrUniqueArity;
                    _arityBitVectorOrUniqueArity = 0;
                    AddArity(uniqueArity);
                }

                AddArity(arity);
            }
Exemple #12
0
 public void Execute(GeneratorExecutionContext context)
 {
     //if (!Debugger.IsAttached) Debugger.Launch();
     context.AddSource("g2", SourceText.From(AttrCode, new UTF8Encoding(false)));
     if (context.SyntaxReceiver is RegisterReceiver Receiver)
     {
         CSharpParseOptions Options  = (context.Compilation as CSharpCompilation).SyntaxTrees[0].Options as CSharpParseOptions;
         var           AttributeTree = CSharpSyntaxTree.ParseText(SourceText.From(AttrCode, new UTF8Encoding(false)), Options);
         var           Compilation   = context.Compilation.AddSyntaxTrees(AttributeTree);
         var           Symbol        = Compilation.GetTypeByMetadataName("CodeGed.AutoRegisterAttribute");
         List <string> RegCalls      = new List <string>();
         foreach (var C in Receiver.Classes)
         {
             SemanticModel Model = Compilation.GetSemanticModel(C.SyntaxTree);
             if (Model.GetDeclaredSymbol(C) is ITypeSymbol TSymbol &&
                 TSymbol.GetAttributes()
                 .Any(E => E.AttributeClass.Equals(Symbol, SymbolEqualityComparer.Default)))
             {
                 var Name = C.GetFullDefined() + "." + C.Identifier.Text;
                 RegCalls.Add($"Services.AddSingleton<{Name}>();");
             }
         }
         var Full = $@"
   namespace CodeGed{{
     using System;
     using Microsoft.Extensions.DependencyInjection;
     public static class AutoRegKits{{
       public static void GeneratedRegister(this IServiceCollection Services){{
         {string.Join(Environment.NewLine, RegCalls)}
       }}
     }}
   }}
 ";
         context.AddSource("g3", SourceText.From(Full, new UTF8Encoding(false)));
     }
 }
 public UniqueSymbolOrMultiNames(TSymbol uniqueSymbol, string multiName)
 {
     _uniqueSymbolOrMultiNames = new Tuple <string, TSymbol>(multiName, uniqueSymbol);
     //if there's no unique symbol, how can there be a multi name?
     Debug.Assert((uniqueSymbol != null) || (multiName == null));
 }
Exemple #14
0
 protected void OnSetSymbol(TSymbol symbol, int row, int column)
 {
     SetSymbol?.Invoke(symbol, row, column);
 }
Exemple #15
0
 public bool ContainsTransition(TSymbol c)
 {
     return(GetTransition(c) != null);
 }
Exemple #16
0
 public TreeNode GetTransition(TSymbol c)
 {
     return((TreeNode)_transHash[c]);
 }
Exemple #17
0
 public TConsolePlayer(string name, TSymbol symbol) : base(name, symbol) { }
Exemple #18
0
 public TComputerPlayer(TSymbol symbol) : this(Environment.MachineName, symbol) { }
Exemple #19
0
 protected TComputerPlayer(string name, TSymbol symbol) : base(name, symbol) { }
Exemple #20
0
 public void OnPlayerSetSymbol(TSymbol symbol, int row, int column)
 {
     _field[row, column] = symbol;
 }
Exemple #21
0
 public StateResult(int?state, TSymbol result)
 {
     State  = state;
     Result = result;
 }
 public void GetUniqueSymbolOrMultiNames(out IEnumerable <string> multiNames, out TSymbol uniqueSymbol)
 {
     if (this.HasUniqueSymbol)
     {
         multiNames   = null;
         uniqueSymbol = (TSymbol)_uniqueSymbolOrMultiNames;
     }
     else
     {
         multiNames   = (ConsList <string>)_uniqueSymbolOrMultiNames;
         uniqueSymbol = null;
     }
 }