internal override void Detect(Lexer l)
        {
            if (!(l.Char == ' ' || (l.Char >= '0' && l.Char <= '9') || (l.Char >= 'a' && l.Char <= 'z') ||
                  (l.Char >= 'A' && l.Char <= 'Z') || l.Char == '\n' || l.Char == '\t' || l.Char == '\r' ||
                  l.Char == '{' || l.Char == '}' || l.Char == ':' || l.Char == '_' || l.Char == ';'))
            {
                l.ForceExclude(); // contains characters we can't accept.
                return;
            }
            if (!(l.GetParent() is ClassDefinitionToken))
            {
                l.ForceExclude(); // not within a class.
                return;
            }

            KeywordResult res = null;

            if (l.Text.IndexOf('{') != -1)
            {
                res = Keywords.GetKeywords(l.Text.Substring(0, l.Text.IndexOf('{')));
            }
            else
            {
                res = Keywords.GetKeywords(l.Text);
            }

            if (res.Keywords.Count > 0 && res.PossibleKeyword == false && res.Keywords.Contains("property"))
            {
                // Now use regular expression checking against the substring starting
                // at res.DeclIndex to determine whether it's a variable declaration.

                string decl = l.Text.Substring(res.DeclIndex).Trim();
                if (!decl.EndsWith("}"))
                {
                    return;                      // Skip if we don't have a terminating character.
                }
                Regex r = new Regex("(?<PropertyName>[a-zA-Z_][a-zA-z0-9_]*)[ \t\r\n]*\\{(?<PropertyContents>[^\\}]*)\\}");
                Match m = r.Match(decl);
                if (m.Success)
                {
                    // It's a property declaration.
                    l.TakeOwnership();
                    l.AddNode(new DirectNode("\n"));
                    l.AddNode(new ClassPropertyDeclarationNode(res.Keywords,
                                                               m.Groups["PropertyName"].Value, m.Groups["PropertyContents"].Value.Trim()));
                    l.EndOwnership();
                }
                else if (decl.IndexOf('{') != -1 && decl.IndexOf('}') != -1)
                {
                    // We can only force exclude if there's an opening bracket
                    // and a closing bracket and we still don't match.
                    l.ForceExclude();
                }
            }
        }
Example #2
0
        internal override void Detect(Lexer l)
        {
            if (!(l.Char == ' ' || (l.Char >= '0' && l.Char <= '9') || (l.Char >= 'a' && l.Char <= 'z') ||
                  (l.Char >= 'A' && l.Char <= 'Z') || l.Char == '\n' || l.Char == '\t' || l.Char == '\r' ||
                  l.Char == ';' || l.Char == '_' || l.Char == ':' || l.Char == '*' || l.Char == '<' ||
                  l.Char == '>') && !l.Text.Contains("="))
            {
                l.ForceExclude(); // contains characters we can't accept.
                return;
            }
            if (!(l.GetParent() is ClassDefinitionToken))
            {
                l.ForceExclude(); // not within a class.
                return;
            }

            KeywordResult res = Keywords.GetKeywords(l.Text);

            if (res.Keywords.Count > 0 && res.PossibleKeyword == false)
            {
                // Now use regular expression checking against the substring starting
                // at res.DeclIndex to determine whether it's a variable declaration.

                string decl = l.Text.Substring(res.DeclIndex).Trim();
                if (!decl.EndsWith(";") && !decl.EndsWith("{"))
                {
                    return;                                             // Skip if we don't have a terminating character.
                }
                Regex r = new Regex(
                    "(?<Type>[a-zA-Z][a-zA-z0-9_\\:\\<\\>]+[ \t\r\n\\*]+)?" +
                    "(?<Name>[a-zA-Z][a-zA-z0-9_]*[ \t\r\n]*)" +
                    "(?<Assign>\\=[ \t\r\n]*((\\\".*\\\")|([a-zA-Z][a-zA-z0-9_\\:\\<\\>]+)|([0-9_.]*)))?;"
                    );
                Match m = r.Match(decl);
                if (m.Success)
                {
                    // It's a variable declaration.
                    l.TakeOwnership();
                    if (m.Groups["Assign"].Success)
                    {
                        l.AddNode(new ClassVariableDeclarationNode(res.Keywords, m.Groups["Type"].Value.Trim(), m.Groups["Name"].Value.Trim(), m.Groups["Assign"].Value.TrimStart('=').TrimStart()));
                    }
                    else
                    {
                        l.AddNode(new ClassVariableDeclarationNode(res.Keywords, m.Groups["Type"].Value.Trim(), m.Groups["Name"].Value.Trim(), ""));
                    }
                    l.EndOwnership();
                }
                else
                {
                    // A different kind of declaration that we aren't handling...
                    l.ForceExclude();
                }
            }
        }
        internal override void Detect(Lexer l)
        {
            if (!(l.Char == ' ' || (l.Char >= '0' && l.Char <= '9') || (l.Char >= 'a' && l.Char <= 'z') ||
                (l.Char >= 'A' && l.Char <= 'Z') || l.Char == '\n' || l.Char == '\t' || l.Char == '\r' ||
                l.Char == ';' || l.Char == '_' || l.Char == ':' || l.Char == '*' || l.Char == '<' ||
                l.Char == '>') && !l.Text.Contains("="))
            {
                l.ForceExclude(); // contains characters we can't accept.
                return;
            }
            if (!(l.GetParent() is ClassDefinitionToken))
            {
                l.ForceExclude(); // not within a class.
                return;
            }

            KeywordResult res = Keywords.GetKeywords(l.Text);

            if (res.Keywords.Count > 0 && res.PossibleKeyword == false)
            {
                // Now use regular expression checking against the substring starting
                // at res.DeclIndex to determine whether it's a variable declaration.

                string decl = l.Text.Substring(res.DeclIndex).Trim();
                if (!decl.EndsWith(";") && !decl.EndsWith("{")) return; // Skip if we don't have a terminating character.
                Regex r = new Regex(
                    "(?<Type>[a-zA-Z][a-zA-z0-9_\\:\\<\\>]+[ \t\r\n\\*]+)?" +
                    "(?<Name>[a-zA-Z][a-zA-z0-9_]*[ \t\r\n]*)" +
                    "(?<Assign>\\=[ \t\r\n]*((\\\".*\\\")|([a-zA-Z][a-zA-z0-9_\\:\\<\\>]+)|([0-9_.]*)))?;"
                    );
                Match m = r.Match(decl);
                if (m.Success)
                {
                    // It's a variable declaration.
                    l.TakeOwnership();
                    if (m.Groups["Assign"].Success)
                        l.AddNode(new ClassVariableDeclarationNode(res.Keywords, m.Groups["Type"].Value.Trim(), m.Groups["Name"].Value.Trim(), m.Groups["Assign"].Value.TrimStart('=').TrimStart()));
                    else
                        l.AddNode(new ClassVariableDeclarationNode(res.Keywords, m.Groups["Type"].Value.Trim(), m.Groups["Name"].Value.Trim(), ""));
                    l.EndOwnership();
                }
                else
                {
                    // A different kind of declaration that we aren't handling...
                    l.ForceExclude();
                }
            }
        }
        internal override void Detect(Lexer l)
        {
            if (l.Text == "#import")
            {
                l.TakeOwnership();
            }
            else if (!l.Text.TrimStart().StartsWith("#"))
            {
                l.ForceExclude();
            }

            if (l.HasOwnership())
            {
                if (l.Char == '\\' && l.MatchNext("\n"))
                {
                    this.m_KeepOwnership = true;
                }
                else if (l.Char == '\n' && !this.m_KeepOwnership)
                {
                    l.AddNode(new ImportNode(l.Text.Substring("#import".Length).Trim()));
                    l.EndOwnership();
                }
                else if (this.m_KeepOwnership)
                {
                    this.m_KeepOwnership = false;
                }
            }
        }
        internal override void Detect(Lexer l)
        {
            if (l.Text.TrimStart().StartsWith("#") &&
                (l.MatchNext(" ") || l.MatchNext("\n")) &&
                l.Text != "#import" &&
                l.Text != "#include")
                l.TakeOwnership();
            else if (!l.Text.TrimStart().StartsWith("#") || l.Text == "#import" || l.Text == "#include")
                l.ForceExclude();

            if (l.HasOwnership())
            {
                if (l.Char == '\\' && l.MatchNext("\n"))
                {
                    this.m_KeepOwnership = true;
                }
                else if (l.Char == '\n' && !this.m_KeepOwnership)
                {
                    l.AddNode(new DirectNode(l.Text));
                    l.EndOwnership();
                }
                else if (this.m_KeepOwnership)
                    this.m_KeepOwnership = false;
            }
        }
Example #6
0
        internal override void Detect(Lexer l)
        {
            if (l.Text.TrimStart().StartsWith("#") &&
                (l.MatchNext(" ") || l.MatchNext("\n")) &&
                l.Text != "#import" &&
                l.Text != "#include")
            {
                l.TakeOwnership();
            }
            else if (!l.Text.TrimStart().StartsWith("#") || l.Text == "#import" || l.Text == "#include")
            {
                l.ForceExclude();
            }

            if (l.HasOwnership())
            {
                if (l.Char == '\\' && l.MatchNext("\n"))
                {
                    this.m_KeepOwnership = true;
                }
                else if (l.Char == '\n' && !this.m_KeepOwnership)
                {
                    l.AddNode(new DirectNode(l.Text));
                    l.EndOwnership();
                }
                else if (this.m_KeepOwnership)
                {
                    this.m_KeepOwnership = false;
                }
            }
        }
        internal override void Detect(Lexer l)
        {
            if (!(l.Char == ' ' || (l.Char >= '0' && l.Char <= '9') || (l.Char >= 'a' && l.Char <= 'z') ||
                (l.Char >= 'A' && l.Char <= 'Z') || l.Char == '\n' || l.Char == '\t' || l.Char == '\r' ||
                l.Char == '{' || l.Char == '}' || l.Char == ':' || l.Char == '_' || l.Char == ';'))
            {
                l.ForceExclude(); // contains characters we can't accept.
                return;
            }
            if (!(l.GetParent() is ClassDefinitionToken))
            {
                l.ForceExclude(); // not within a class.
                return;
            }

            KeywordResult res = null;
            if (l.Text.IndexOf('{') != -1)
                res = Keywords.GetKeywords(l.Text.Substring(0, l.Text.IndexOf('{')));
            else
                res = Keywords.GetKeywords(l.Text);

            if (res.Keywords.Count > 0 && res.PossibleKeyword == false && res.Keywords.Contains("property"))
            {
                // Now use regular expression checking against the substring starting
                // at res.DeclIndex to determine whether it's a variable declaration.

                string decl = l.Text.Substring(res.DeclIndex).Trim();
                if (!decl.EndsWith("}")) return; // Skip if we don't have a terminating character.
                Regex r = new Regex("(?<PropertyName>[a-zA-Z_][a-zA-z0-9_]*)[ \t\r\n]*\\{(?<PropertyContents>[^\\}]*)\\}");
                Match m = r.Match(decl);
                if (m.Success)
                {
                    // It's a property declaration.
                    l.TakeOwnership();
                    l.AddNode(new DirectNode("\n"));
                    l.AddNode(new ClassPropertyDeclarationNode(res.Keywords,
                        m.Groups["PropertyName"].Value, m.Groups["PropertyContents"].Value.Trim()));
                    l.EndOwnership();
                }
                else if (decl.IndexOf('{') != -1 && decl.IndexOf('}') != -1)
                {
                    // We can only force exclude if there's an opening bracket
                    // and a closing bracket and we still don't match.
                    l.ForceExclude();
                }
            }
        }
 internal override void Detect(Lexer l)
 {
     if (l.Char == '{' && !(l.GetParent() is ClassDefinitionToken))
     {
         l.TakeOwnership();
         l.AddNode(new DirectNode(l.Text));
         l.AddParent();
         l.EndOwnership();
     }
 }
        internal override bool DetectEnd(Lexer l)
        {
            if (l.Char == '}')
            {
                l.AddNode(new DirectNode(l.Text));
                return true;
            }

            return false;
        }
Example #10
0
        internal override bool DetectEnd(Lexer l)
        {
            if (l.Char == '}')
            {
                l.AddNode(new DirectNode(l.Text));
                return(true);
            }

            return(false);
        }
Example #11
0
 internal override void Detect(Lexer l)
 {
     if (l.Char == '{' && !(l.GetParent() is ClassDefinitionToken))
     {
         l.TakeOwnership();
         l.AddNode(new DirectNode(l.Text));
         l.AddParent();
         l.EndOwnership();
     }
 }
Example #12
0
        internal override void Detect(Lexer l)
        {
            if (l.Text.TrimStart().StartsWith("class ") && !l.HasOwnership())
            {
                l.TakeOwnership();
            }
            else if (!l.HasOwnership() && !"class ".StartsWith(l.Text.TrimStart()))
            {
                l.ForceExclude();
            }

            if (l.HasOwnership())
            {
                if (l.Char == '{')
                {
                    string n = l.Text.TrimStart().Substring("class ".Length, l.Text.TrimStart().Length - "class ".Length - 1);
                    Regex  r = new Regex("[ \n\r]as[ \n\r]", RegexOptions.Multiline);
                    Match  m = r.Match(n);
                    if (m.Success)
                    {
                        l.AddNode(new ClassDefinitionNode(
                                      n.Substring(0, m.Index),
                                      n.Substring(m.Index + m.Length)
                                      ));
                    }
                    else
                    {
                        l.AddNode(new ClassDefinitionNode(
                                      n,
                                      ""
                                      ));
                    }
                    l.AddParent();
                    l.EndOwnership();
                }
                else if (l.Char == ';')
                {
                    l.AddNode(new DirectNode(l.Text.Substring(0, l.Text.Length - 1)));
                    l.EndOwnership();
                }
            }
        }
Example #13
0
 internal override void Detect(Lexer l)
 {
     if (l.Text.TrimStart().StartsWith("using ") && !l.HasOwnership())
         l.TakeOwnership();
     else if (l.HasOwnership() && l.Char == ';')
     {
         l.AddNode(new UsingNode(l.Text.Substring("using ".Length, l.Text.Length - "using ".Length - 1)));
         l.EndOwnership();
     }
     else if (!l.HasOwnership() && !"using ".StartsWith(l.Text.TrimStart()))
         l.ForceExclude();
 }
        internal override void Detect(Lexer l)
        {
            if (l.Text.TrimStart().StartsWith("class ") && !l.HasOwnership())
                l.TakeOwnership();
            else if (!l.HasOwnership() && !"class ".StartsWith(l.Text.TrimStart()))
                l.ForceExclude();

            if (l.HasOwnership())
            {
                if (l.Char == '{')
                {
                    string n = l.Text.TrimStart().Substring("class ".Length, l.Text.TrimStart().Length - "class ".Length - 1);
                    Regex r = new Regex("[ \n\r]as[ \n\r]", RegexOptions.Multiline);
                    Match m = r.Match(n);
                    if (m.Success)
                    {
                        l.AddNode(new ClassDefinitionNode(
                            n.Substring(0, m.Index),
                            n.Substring(m.Index + m.Length)
                            ));
                    }
                    else
                    {
                        l.AddNode(new ClassDefinitionNode(
                            n,
                            ""
                            ));
                    }
                    l.AddParent();
                    l.EndOwnership();
                }
                else if (l.Char == ';')
                {
                    l.AddNode(new DirectNode(l.Text.Substring(0, l.Text.Length - 1)));
                    l.EndOwnership();
                }
            }
        }
Example #15
0
 internal override void Detect(Lexer l)
 {
     if (l.Text.TrimStart().StartsWith("using ") && !l.HasOwnership())
     {
         l.TakeOwnership();
     }
     else if (l.HasOwnership() && l.Char == ';')
     {
         l.AddNode(new UsingNode(l.Text.Substring("using ".Length, l.Text.Length - "using ".Length - 1)));
         l.EndOwnership();
     }
     else if (!l.HasOwnership() && !"using ".StartsWith(l.Text.TrimStart()))
     {
         l.ForceExclude();
     }
 }
        internal override void Detect(Lexer l)
        {
            if (l.Text == "#include")
                l.TakeOwnership();
            else if (!l.Text.TrimStart().StartsWith("#"))
                l.ForceExclude();

            if (l.HasOwnership())
            {
                if (l.Char == '\\' && l.MatchNext("\n"))
                {
                    this.m_KeepOwnership = true;
                }
                else if (l.Char == '\n' && !this.m_KeepOwnership)
                {
                    l.AddNode(new IncludeNode(l.Text.Substring("#include".Length).Trim()));
                    l.EndOwnership();
                }
                else if (this.m_KeepOwnership)
                    this.m_KeepOwnership = false;
            }
        }
        internal override void Detect(Lexer l)
        {
            if (!(l.Char == ' ' || (l.Char >= '0' && l.Char <= '9') || (l.Char >= 'a' && l.Char <= 'z') ||
                  (l.Char >= 'A' && l.Char <= 'Z') || l.Char == '\n' || l.Char == '\t' || l.Char == '\r' ||
                  l.Char == '{' || l.Char == '_' || l.Char == ',' || l.Char == '(' || l.Char == ')' ||
                  l.Char == ':' || l.Char == ';' || l.Char == '*' || l.Char == '<' || l.Char == '>' ||
                  l.Char == '[' || l.Char == ']' || l.Char == '-' || l.Char == '.' || l.Char == '"' ||
                  l.Char == '&'))
            {
                l.ForceExclude(); // contains characters we can't accept.
                return;
            }
            if (l.Text.Contains('='))
            {
                l.ForceExclude(); // contains characters we can't accept.
                return;
            }
            if (!(l.GetParent() is ClassDefinitionToken))
            {
                l.ForceExclude(); // not within a class.
                return;
            }

            KeywordResult res = Keywords.GetKeywords(l.Text);

            if (res.Keywords.Count > 0 && res.PossibleKeyword == false)
            {
                // Now use regular expression checking against the substring starting
                // at res.DeclIndex to determine whether it's a variable declaration.

                string decl = l.Text.Substring(res.DeclIndex).Trim();
                if (decl.EndsWith(";"))
                {
                    // Show 'expected {' error.
                    Console.WriteLine("Error: expected '{', not ';' on line " + l.LineNumber + " within file " + l.FileName + ".\nError: Check the end of your function definitions.");
                    l.Abort();
                    return;
                }
                if (!decl.EndsWith("{"))
                {
                    return; // Skip if we don't have a terminating character.
                }
                Regex r = new Regex(
                    "(?<Type>[a-zA-Z][a-zA-z0-9_\\:\\<\\>]+[ \t\r\n\\*]+)?" +
                    "(?<Name>[a-zA-Z][a-zA-z0-9_]*[ \t\r\n]*\\([ \t\r\na-zA-Z0-9_&,-\\.\\:\\*\\<\\>\\[\\]\\\"]*\\))[ \t\r\n]*\\{"
                    );
                Match m = r.Match(decl);
                if (m.Success)
                {
                    // It's a function declaration.
                    l.TakeOwnership();
                    l.AddNode(new DirectNode("\n"));
                    l.AddNode(new ClassFunctionDeclarationNode(res.Keywords, m.Groups["Type"].Value.Trim(), m.Groups["Name"].Value.Trim()));
                    l.AddParent();
                    l.EndOwnership();
                }
                else
                {
                    // A different kind of declaration that we aren't handling...
                    l.ForceExclude();
                }
            }
        }