public override void OnGUI(Rect rect)
        {
            EditorGUI.LabelField(rect.GetLine(0), "Select a token to add");
            EditorGUI.BeginChangeCheck();
            filter = SearchTextField(rect.GetLine(1), filter);
            if (EditorGUI.EndChangeCheck())
            {
                editorWindow.Repaint();
                return;
            }
            var i = 0;

            foreach (var type in TokenLoader.KnownTokenTypes)
            {
                if (!string.IsNullOrEmpty(filter) &&
                    !type.Name.StartsWith(filter, StringComparison.InvariantCultureIgnoreCase))
                {
                    continue;
                }
                GUI.color = MappedToken.For(type).Color;
                if (GUI.Button(rect.GetLine((uint)(i + BuiltInLines)), type.Name))
                {
                    CurrentEditor.AddToken(type);
                }
                i++;
            }
        }
        protected override void ResolveImpl(MappedToken token)
        {
            try
            {
                var type = TypeSystemServices.GetType(Node);
                if (type is Error)
                    return;

                format = Formats.BooType;
                var prefix = "struct ";
                if (type.IsClass)
                    prefix = "class ";
                if (type.IsInterface)
                    prefix = "interface ";
                if (type.IsEnum)
                    prefix = "enumeration ";
                quickInfoTip = prefix + type.FullName;

                var internalType = type as AbstractInternalType;
                if (internalType != null)
                    declaringNode = CompileResults.GetMappedNode(internalType.Node);

            }
            catch (Exception)
            {
                return;
            }
        }
Example #3
0
        private void DrawBackground(Rect rect, int index, bool isactive, bool isfocused)
        {
            if (index == -1)
            {
                return;
            }

            var m         = MappedToken.For(Cutscene[index]);
            var initColor = GUI.backgroundColor;

            GUI.backgroundColor = isfocused ? m.SelectedColor : m.Color;
            GUI.Box(rect, GUIContent.none);
            GUI.backgroundColor = initColor;
        }
Example #4
0
        private float GetTokenHeight(int tokenIndex)
        {
            if (tokenIndex >= Cutscene.Count)
            {
                Debug.LogWarningFormat(
                    "[ShiroiCutscenes] Token index '{0}' is out of range in cutscenes {1}!",
                    tokenIndex,
                    Cutscene.name);
                return(ShiroiStyles.SingleLineHeight);
            }

            var token = Cutscene[tokenIndex];

            return(MappedToken.For(token).Height + ShiroiStyles.SingleLineHeight * TotalExtraFields);
        }
Example #5
0
 protected override void ResolveImpl(MappedToken token)
 {
     try
     {
         var type = TypeSystemServices.GetType(Node);
         if (type is Error)
             return;
     //                quickInfoTip = "class " + type.FullName;
         format = Formats.BooType;
     }
     catch
     {
         return;
     }
 }
Example #6
0
 static Configs()
 {
     ColorfulTokens.OnChanged += delegate {
         MappedToken.Clear();
         RepaintEditors();
     };
     ErrorColors.OnChanged += delegate {
         ShiroiStyles.Reload();
         RepaintEditors();
     };
     ErrorIcons.OnChanged += delegate {
         ShiroiStyles.Reload();
         RepaintEditors();
     };
 }
 internal override void Record(RecordingStage stage, MappedToken token)
 {
     switch (stage)
     {
         case RecordingStage.Completed:
             var macro = token.Nodes.Where(
                 node => (node.Node is MacroStatement &&
                             ((MacroStatement)node.Node).Name == ((ReferenceExpression)Node).Name)
                 ).FirstOrDefault();
             if (macro != null)
                 token.Nodes.Remove(macro);
             break;
         default:
             break;
     }
     base.Record(stage, token);
 }
Example #8
0
        protected override void ResolveImpl(MappedToken token)
        {
            try
            {
                var type = TypeSystemServices.GetType(Node);
                if (type is Error)
                {
                    return;
                }
//                quickInfoTip = "class " + type.FullName;
                format = Formats.BooType;
            }
            catch
            {
                return;
            }
        }
Example #9
0
 protected override void ResolveImpl(MappedToken token)
 {
     try
     {
         var type = TypeSystemServices.GetType(Node);
         if (type is Error)
             return;
         var a = Node as Attribute;
         if (a == null)
             return;
         quickInfoTip = "class " + a.Name;
         format = Formats.BooType;
     }
     catch
     {
         return;
     }
 }
Example #10
0
        private void DrawToken(Rect rect, int i, bool isactive, bool isfocused)
        {
            var  token       = Cutscene[i];
            var  mappedToken = MappedToken.For(token);
            bool changed;
            var  content    = new GUIContent(string.Format("#{0} - {1}", i, mappedToken.Label));
            var  headerRect = rect.GetLine(0);
            var  buttonRect = rect.SubRectFarRight(ContextWindow.RemoveTokenContent);

            EditorGUI.LabelField(headerRect, content, ShiroiStyles.Bold);
            var initColor = GUI.backgroundColor;

            GUI.backgroundColor = ShiroiStyles.ErrorBackgroundColor;
            var remove = GUI.Button(buttonRect, ContextWindow.RemoveTokenContent);

            GUI.backgroundColor = initColor;
            token.name          = EditorGUI.TextField(rect.GetLine(1), "Token Name", token.name);
            var subRect = rect;

            subRect.yMin += TotalExtraFields * ShiroiStyles.SingleLineHeight;
            mappedToken.DrawFields(editor, subRect, i, token, Cutscene, editor.Player, content, out changed);

            if (remove)
            {
                editor.RemoveToken(i);
            }

            if (changed || remove)
            {
                EditorUtility.SetDirty(Cutscene);
            }

            if (!changed)
            {
                return;
            }

            var l = token as ITokenChangedListener;

            if (l != null)
            {
                l.OnChanged(Cutscene);
            }
        }
        public static void CheckErrors(CutsceneEditor editor, List <ErrorMessage> errors)
        {
            var cutscene = editor.Cutscene;
            var total    = cutscene.Count;

            for (var i = 0; i < total; i++)
            {
                var token  = cutscene[i];
                var mapped = MappedToken.For(token);
                foreach (var checker in Checkers)
                {
                    for (var fieldIndex = 0; fieldIndex < mapped.SerializedFields.Length; fieldIndex++)
                    {
                        var serializedField = mapped.SerializedFields[fieldIndex];
                        var value           = serializedField.GetValue(token);
                        checker.Check(editor, editor.ErrorManager, i, token, value, fieldIndex, serializedField);
                    }
                }
            }
        }
Example #12
0
        internal override void Record(RecordingStage stage, MappedToken token)
        {
            switch (stage)
            {
            case RecordingStage.Completed:
                var macro = token.Nodes.Where(
                    node => (node.Node is MacroStatement &&
                             ((MacroStatement)node.Node).Name == ((ReferenceExpression)Node).Name)
                    ).FirstOrDefault();
                if (macro != null)
                {
                    token.Nodes.Remove(macro);
                }
                break;

            default:
                break;
            }
            base.Record(stage, token);
        }
        internal override void Record(RecordingStage stage, MappedToken token)
        {
            switch (stage)
            {
            case RecordingStage.Completed:
                var oldref = token.Nodes.Where(
                    node => (node.Node.NodeType == NodeType.ReferenceExpression &&
                             ((ReferenceExpression)node.Node).Name == ((ReferenceExpression)Node).Name)
                    ).FirstOrDefault();
                if (oldref != null)
                {
                    token.Nodes.Remove(oldref);
                    base.Record(stage, token);
                }
                break;

            default:
                base.Record(stage, token);
                break;
            }
        }
Example #14
0
        private Tuple <int, int> CalculateEndpoint(antlr.IToken token, int endLine, int endIndex, int delimiterLength)
        {
            var startIndex = positionMap[token.getLine() - 1][token.getColumn() - 1];
            var startLine  = token.getLine() - 1;

            if (startLine > endLine || startLine == endLine && startIndex > endIndex)
            {
                whitespaces.Add(new TextSpan {
                    iStartLine = endLine, iStartIndex = endIndex, iEndLine = startLine, iEndIndex = startIndex
                });
            }

            endLine  = startLine - 1;
            endIndex = 0;

            var runningIndex = startIndex + delimiterLength;

            foreach (var part in token.getText().Split(new[] { "\r\n" }, StringSplitOptions.None))
            {
                endLine++;
                endIndex     = runningIndex + part.Length;
                runningIndex = 0;
            }
            endIndex += delimiterLength;

            //endIndex = positionMap[endLine][endIndex];

            var cluster = new MappedToken(
                startLine * lineSize + startIndex,
                endIndex - startIndex);

            if (tokenMap.Count > 0 &&
                tokenMap[tokenMap.Count() - 1].Index >= cluster.Index)
            {
                throw new ArgumentException("Token Mapping order");
            }

            tokenMap.Add(cluster);
            return(new Tuple <int, int>(endLine, endIndex));
        }
Example #15
0
 protected override void ResolveImpl(MappedToken token)
 {
     try
     {
         var type = TypeSystemServices.GetType(Node);
         if (type is Error)
         {
             return;
         }
         var a = Node as Attribute;
         if (a == null)
         {
             return;
         }
         quickInfoTip = "class " + a.Name;
         format       = Formats.BooType;
     }
     catch
     {
         return;
     }
 }
Example #16
0
        protected override void ResolveImpl(MappedToken token)
        {
            try
            {
                var type = TypeSystemServices.GetType(Node);
                if (type is Error)
                {
                    return;
                }

                format = Formats.BooType;
                var prefix = "struct ";
                if (type.IsClass)
                {
                    prefix = "class ";
                }
                if (type.IsInterface)
                {
                    prefix = "interface ";
                }
                if (type.IsEnum)
                {
                    prefix = "enumeration ";
                }
                quickInfoTip = prefix + type.FullName;

                var internalType = type as AbstractInternalType;
                if (internalType != null)
                {
                    declaringNode = CompileResults.GetMappedNode(internalType.Node);
                }
            }
            catch (Exception)
            {
                return;
            }
        }
Example #17
0
        internal virtual void Record(RecordingStage stage, MappedToken token)
        {
            if (token.Nodes.Any(node => node.Node == Node))
                return;

            token.Nodes.Add(this);
        }
Example #18
0
 protected virtual void ResolveImpl(MappedToken token)
 {
 }
Example #19
0
 internal void Resolve(MappedToken token)
 {
     if (!resolved)
         ResolveImpl(token);
     resolved = true;
 }
Example #20
0
 internal virtual void Record(RecordingStage stage, MappedToken token)
 {
     token.Nodes.Add(this);
 }
        protected override void ResolveImpl(MappedToken token)
        {
            switch (Node.NodeType)
            {
            case NodeType.SelfLiteralExpression:
                var classDefinition = Node;
                while (classDefinition.ParentNode != null)
                {
                    if (classDefinition.NodeType != NodeType.ClassDefinition)
                    {
                        classDefinition = classDefinition.ParentNode;
                    }
                    else
                    {
                        varType = TypeSystemServices.GetType(classDefinition);
                        break;
                    }
                }
                break;

            case NodeType.MemberReferenceExpression:
            case NodeType.ReferenceExpression:
                var     expression = (ReferenceExpression)Node;
                IEntity entity;
                try
                {
                    entity = TypeSystemServices.GetEntity(expression);
                }
                catch
                {
                    break;
                }
                var prefix = "";
                if (entity is InternalParameter)
                {
                    prefix          = "(parameter) ";
                    varType         = TypeSystemServices.GetType(expression);
                    declarationNode = CompileResults.GetMappedNode(((InternalParameter)entity).Parameter);
                }
                if (entity is InternalLocal)
                {
                    prefix          = "(local variable) ";
                    varType         = ((InternalLocal)entity).Type;
                    declarationNode = CompileResults.GetMappedNode(((InternalLocal)entity).Local);
                }
                if (entity is InternalField)
                {
                    varType         = TypeSystemServices.GetType(Node);
                    declaringType   = ((InternalField)entity).DeclaringType;
                    declarationNode = CompileResults.GetMappedNode(((InternalField)entity).Field);
                }
                if (entity is InternalMethod)
                {
                    declaringType   = ((InternalMethod)entity).DeclaringType;
                    declarationNode = CompileResults.GetMappedNode(((InternalMethod)entity).Method);
                    if (entity is InternalConstructor)
                    {
                        varType = ((InternalConstructor)entity).DeclaringType;
                    }
                    else
                    {
                        varType = ((InternalMethod)entity).ReturnType;
                    }
                }
                if (entity is InternalProperty)
                {
                    declaringType   = ((InternalProperty)entity).DeclaringType;
                    varType         = TypeSystemServices.GetType(Node);
                    declarationNode = CompileResults.GetMappedNode(((InternalProperty)entity).Property);
                }
                if (entity is InternalEvent)
                {
                    declaringType   = ((InternalEvent)entity).DeclaringType;
                    varType         = TypeSystemServices.GetType(Node);
                    declarationNode = CompileResults.GetMappedNode(((InternalEvent)entity).Event);
                }
                if (entity is ExternalType)
                {
                    varType         = ((ExternalType)entity).Type;
                    format          = Formats.BooType;
                    isTypeReference = true;
                }
                if (entity is AbstractInternalType)
                {
                    varType         = ((AbstractInternalType)entity).Type;
                    format          = Formats.BooType;
                    isTypeReference = true;
                    declarationNode = CompileResults.GetMappedNode(((AbstractInternalType)entity).TypeDefinition);
                }
                if (entity is ExternalField)
                {
                    varType       = TypeSystemServices.GetType(Node);
                    declaringType = ((ExternalField)entity).DeclaringType;
//                        declarationNode = CompileResults.GetMappedNode(((ExternalField)entity).Field);
                }
                if (entity is ExternalMethod)
                {
                    declaringType = ((ExternalMethod)entity).DeclaringType;
//                        declarationNode = CompileResults.GetMappedNode(declaration);
                    if (entity is ExternalConstructor)
                    {
                        varType = ((ExternalConstructor)entity).DeclaringType;
                    }
                    else
                    {
                        varType = ((ExternalMethod)entity).ReturnType;
                    }
                }
                if (entity is ExternalProperty)
                {
                    declaringType = ((ExternalProperty)entity).DeclaringType;
                    varType       = TypeSystemServices.GetType(Node);
//                        declarationNode = CompileResults.GetMappedNode(((ExternalProperty)entity).Property);
                }
                if (entity is ExternalEvent)
                {
                    declaringType = ((ExternalEvent)entity).DeclaringType;
                    varType       = TypeSystemServices.GetType(Node);
//                        declarationNode = CompileResults.GetMappedNode(((ExternalEvent)entity).Event);
                }
                if (expression.ExpressionType != null)
                {
                    if (declaringType != null)
                    {
                        prefix += declaringType.FullName + '.';
                    }
                    quickInfoTip = prefix + expression.Name + " as " + expression.ExpressionType.FullName;
                }
                break;

            default:
                break;
            }
        }
Example #22
0
        private Tuple<int, int> CalculateEndpoint(antlr.IToken token, int endLine, int endIndex, int delimiterLength)
        {
            var startIndex = positionMap[token.getLine() - 1][token.getColumn() - 1];
            var startLine = token.getLine() - 1;

            if (startLine > endLine || startLine == endLine && startIndex > endIndex)
                whitespaces.Add(new TextSpan { iStartLine = endLine, iStartIndex = endIndex, iEndLine = startLine, iEndIndex = startIndex });

            endLine = startLine - 1;
            endIndex = 0;

            var runningIndex = startIndex + delimiterLength;
            foreach (var part in token.getText().Split(new[] { "\r\n" }, StringSplitOptions.None))
            {
                endLine++;
                endIndex = runningIndex + part.Length;
                runningIndex = 0;
            }
            endIndex += delimiterLength;

            //endIndex = positionMap[endLine][endIndex];

            var cluster = new MappedToken(
                startLine * lineSize + startIndex,
                endIndex - startIndex);

            if (tokenMap.Count > 0
                && tokenMap[tokenMap.Count() - 1].Index >= cluster.Index)
                throw new ArgumentException("Token Mapping order");

            tokenMap.Add(cluster);
            return new Tuple<int, int>(endLine, endIndex);
        }
 internal override void Record(RecordingStage stage, MappedToken token)
 {
     switch (stage)
     {
         case RecordingStage.Completed:
             var oldref = token.Nodes.Where(
                 node => (node.Node.NodeType == NodeType.ReferenceExpression &&
                             ((ReferenceExpression)node.Node).Name == ((ReferenceExpression)Node).Name)
                 ).FirstOrDefault();
             if (oldref != null)
             {
                 token.Nodes.Remove(oldref);
                 base.Record(stage, token);
             }
             break;
         default:
             base.Record(stage, token);
             break;
     }
 }
Example #24
0
        private void MapTokens(int tabSize, string source)
        {
            var endLine = 0;
            var endIndex = 0;

            var tokens = BooParser.CreateBooLexer(tabSize, "code stream", new StringReader(source));

            antlr.IToken token;
            while ((token = NextToken(tokens)).Type != BooLexer.EOF)
            {
                int length;

                switch (token.Type)
                {
                    case BooLexer.INDENT:
                    case BooLexer.DEDENT:
                    case BooLexer.EOL:
                        continue;
                    case BooLexer.SINGLE_QUOTED_STRING:
                    case BooLexer.DOUBLE_QUOTED_STRING:
                        length = token.getText().Length + 2;
                        break;
                    case BooLexer.TRIPLE_QUOTED_STRING:
                        length = token.getText().Length + 6;
                        break;
                    default:
                        length = token.getText().Length;
                        break;
                }

                var startIndex = positionMap[token.getLine() - 1][token.getColumn() - 1];
                var startLine = token.getLine() - 1;

                if (startLine > endLine || startLine == endLine && startIndex > endIndex)
                    whitespaces.Add(new TextSpan { iStartLine = endLine, iStartIndex = endIndex, iEndLine = startLine, iEndIndex = startIndex });

                endIndex = positionMap[token.getLine() - 1][token.getColumn() - 1 + length];
                endLine = startLine;

                var cluster = new MappedToken(
                    startLine * lineSize + startIndex,
                    endIndex - startIndex);

                if (tokenMap.Count > 0
                    && tokenMap[tokenMap.Count() - 1].Index >= cluster.Index)
                    throw new ArgumentException("Token Mapping order");
                tokenMap.Add(cluster);
            }

            var sIndex = positionMap[token.getLine() - 1][token.getColumn() - 1];
            var sLine = token.getLine() - 1;

            if (sLine > endLine || sLine == endLine && sIndex > endIndex)
                whitespaces.Add(new TextSpan { iStartLine = endLine, iStartIndex = endIndex, iEndLine = sLine, iEndIndex = sIndex });
        }
Example #25
0
        private void MapTokens(int tabSize, string source)
        {
            var endLine  = 0;
            var endIndex = 0;

            var tokens = BooParser.CreateBooLexer(tabSize, "code stream", new StringReader(source));

            antlr.IToken token;
            while ((token = NextToken(tokens)).Type != BooLexer.EOF)
            {
                int length;

                switch (token.Type)
                {
                case BooLexer.INDENT:
                case BooLexer.DEDENT:
                case BooLexer.EOL:
                    continue;

                case BooLexer.SINGLE_QUOTED_STRING:
                case BooLexer.DOUBLE_QUOTED_STRING:
                    length = token.getText().Length + 2;
                    break;

                case BooLexer.TRIPLE_QUOTED_STRING:
                    length = token.getText().Length + 6;
                    break;

                default:
                    length = token.getText().Length;
                    break;
                }

                var startIndex = positionMap[token.getLine() - 1][token.getColumn() - 1];
                var startLine  = token.getLine() - 1;

                if (startLine > endLine || startLine == endLine && startIndex > endIndex)
                {
                    whitespaces.Add(new TextSpan {
                        iStartLine = endLine, iStartIndex = endIndex, iEndLine = startLine, iEndIndex = startIndex
                    });
                }

                endIndex = positionMap[token.getLine() - 1][token.getColumn() - 1 + length];
                endLine  = startLine;

                var cluster = new MappedToken(
                    startLine * lineSize + startIndex,
                    endIndex - startIndex);

                if (tokenMap.Count > 0 &&
                    tokenMap[tokenMap.Count() - 1].Index >= cluster.Index)
                {
                    throw new ArgumentException("Token Mapping order");
                }
                tokenMap.Add(cluster);
            }

            var sIndex = positionMap[token.getLine() - 1][token.getColumn() - 1];
            var sLine  = token.getLine() - 1;

            if (sLine > endLine || sLine == endLine && sIndex > endIndex)
            {
                whitespaces.Add(new TextSpan {
                    iStartLine = endLine, iStartIndex = endIndex, iEndLine = sLine, iEndIndex = sIndex
                });
            }
        }
        protected override void ResolveImpl(MappedToken token)
        {
            switch (Node.NodeType)
            {
                case NodeType.SelfLiteralExpression:
                    var classDefinition = Node;
                    while (classDefinition.ParentNode != null)
                        if (classDefinition.NodeType != NodeType.ClassDefinition)
                            classDefinition = classDefinition.ParentNode;
                        else
                        {
                            varType = TypeSystemServices.GetType(classDefinition);
                            break;
                        }
                    break;

                case NodeType.MemberReferenceExpression:
                case NodeType.ReferenceExpression:
                    var expression = (ReferenceExpression)Node;
                    IEntity entity;
                    try
                    {
                        entity = TypeSystemServices.GetEntity(expression);
                    }
                    catch
                    {
                        break;
                    }
                    var prefix = "";
                    if (entity is InternalParameter)
                    {
                        prefix = "(parameter) ";
                        varType = TypeSystemServices.GetType(expression);
                        declarationNode = CompileResults.GetMappedNode(((InternalParameter)entity).Parameter);
                    }
                    if (entity is InternalLocal)
                    {
                        prefix = "(local variable) ";
                        varType = ((InternalLocal)entity).Type;
                        declarationNode = CompileResults.GetMappedNode(((InternalLocal)entity).Local);
                    }
                    if (entity is InternalField)
                    {
                        varType = TypeSystemServices.GetType(Node);
                        declarationNode = CompileResults.GetMappedNode(((InternalField)entity).Field);
                    }
                    if (entity is InternalMethod)
                    {
                        var declaration = ((InternalMethod)entity).Method;
                        declarationNode = CompileResults.GetMappedNode(declaration);
                        if (entity is InternalConstructor)
                            varType = ((InternalConstructor) entity).DeclaringType;
                        else
                            varType = TypeSystemServices.GetType(declaration.ReturnType);
                    }
                    if (entity is InternalProperty)
                    {
                        varType = TypeSystemServices.GetType(Node);
                        declarationNode = CompileResults.GetMappedNode(((InternalProperty)entity).Property);
                    }
                    if (entity is InternalEvent)
                    {
                        varType = TypeSystemServices.GetType(Node);
                        declarationNode = CompileResults.GetMappedNode(((InternalEvent)entity).Event);
                    }
                    if (entity is ExternalType)
                    {
                        varType = ((ExternalType)entity).Type;
                        format = Formats.BooType;
                        isTypeReference = true;
                    }
                    if (entity is AbstractInternalType)
                    {
                        varType = ((AbstractInternalType)entity).Type;
                        format = Formats.BooType;
                        isTypeReference = true;
                        declarationNode = CompileResults.GetMappedNode(((AbstractInternalType)entity).TypeDefinition);
                    }
                    if (expression.ExpressionType != null)
                        quickInfoTip = prefix + expression.Name + " as " + expression.ExpressionType.FullName;
                    break;
                default:
                    break;
            }
        }