コード例 #1
0
ファイル: lgspBackend.cs プロジェクト: tmaierhofer/grgen
        /// <summary>
        /// Tries to match a string at the current position of a SimpleCharStream.
        /// If the string at the current position does not match, it is skipped.
        /// Here all characters other than A-Z, a-z, 0-9, _, and # are skipped.
        /// </summary>
        /// <param name="charStream">The char stream.</param>
        /// <param name="str">The string to be matched.</param>
        /// <returns>True, iff the string was found.</returns>
        private bool MatchStringOrIgnoreOther(SimpleCharStream charStream, String str)
        {
            IgnoreOther(charStream);

            char curChar;

            for (int i = 0; i < str.Length; i++)
            {
                curChar = charStream.ReadChar();
                if (curChar != str[i])
                {
                    IgnoreRest(charStream, curChar);
                    return(false);
                }
            }

            // Does the string really end here?
            curChar = charStream.ReadChar();
            if (curChar != ' ' && curChar != '\t' && curChar != '\n' && curChar != '\r')
            {
                IgnoreRest(charStream, curChar);
                return(false);
            }
            return(true);
        }
コード例 #2
0
ファイル: lgspBackend.cs プロジェクト: tmaierhofer/grgen
        private void IgnoreComment(SimpleCharStream charStream)
        {
            char curChar = charStream.ReadChar();

            if (curChar == '/')
            {
                do
                {
                    curChar = charStream.ReadChar();
                }while(curChar != '\n' && curChar != '\r');
            }
            else if (curChar == '*')
            {
                bool foundStar = false;
                while (true)
                {
                    curChar = charStream.ReadChar();
                    if (foundStar && curChar == '/')
                    {
                        break;
                    }
                    foundStar = curChar == '*';
                }
            }
            // otherwise its just not a comment
        }
コード例 #3
0
ファイル: lgspBackend.cs プロジェクト: tmaierhofer/grgen
 /// <summary>
 /// Ignores the rest of a string.
 /// </summary>
 /// <param name="charStream">The SimpleCharStream object.</param>
 /// <param name="curChar">The last character read. Set to '\0' to ignore.</param>
 private void IgnoreRest(SimpleCharStream charStream, char curChar)
 {
     while (curChar >= 'A' && curChar <= 'Z' || curChar >= 'a' && curChar <= 'z' ||
            curChar >= '0' && curChar <= '9' || curChar == '_' || curChar == '#')
     {
         curChar = charStream.ReadChar();
     }
     charStream.Backup(1);
 }
コード例 #4
0
ファイル: lgspBackend.cs プロジェクト: tmaierhofer/grgen
        private void MatchCharOrThrow(SimpleCharStream charStream, char ch)
        {
            char curChar = charStream.ReadChar();

            if (curChar != ch)
            {
                throw new Exception("Parse error: Unexpected token '" + GetPrintable(curChar) + "' at line " + charStream.EndLine + ":" + charStream.EndColumn + "!");
            }
        }
コード例 #5
0
ファイル: lgspBackend.cs プロジェクト: tmaierhofer/grgen
        private void IgnoreString(SimpleCharStream charStream)
        {
            IgnoreSpace(charStream);

            char curChar;

            do
            {
                curChar = charStream.ReadChar();
            }while(curChar >= 'A' && curChar <= 'Z' || curChar >= 'a' && curChar <= 'z' ||
                   curChar >= '0' && curChar <= '9' || curChar == '_' || curChar == '#');
            charStream.Backup(1);
        }
コード例 #6
0
ファイル: lgspBackend.cs プロジェクト: tmaierhofer/grgen
        private bool MatchString(SimpleCharStream charStream, String str)
        {
            IgnoreSpace(charStream);

            char curChar;

            for (int i = 0; i < str.Length; i++)
            {
                curChar = charStream.ReadChar();
                if (curChar != str[i])
                {
                    charStream.Backup(i + 1);       // unread chars
                    return(false);
                }
            }
            curChar = charStream.ReadChar();
            if (curChar != ' ' && curChar != '\t' && curChar != '\n' && curChar != '\r')
            {
                charStream.Backup(str.Length + 1);  // unread chars
                return(false);
            }
            return(true);
        }
コード例 #7
0
ファイル: lgspBackend.cs プロジェクト: tmaierhofer/grgen
        private void IgnoreSpace(SimpleCharStream charStream)
        {
            char curChar;

            do
            {
                curChar = charStream.ReadChar();
                if (curChar == '/')
                {
                    IgnoreComment(charStream);
                    curChar = ' ';
                    continue;
                }
            }while(curChar == ' ' || curChar == '\t' || curChar == '\n' || curChar == '\r');
            charStream.Backup(1);
        }
コード例 #8
0
ファイル: lgspBackend.cs プロジェクト: tmaierhofer/grgen
        private void IgnoreOther(SimpleCharStream charStream)
        {
            char curChar;

            do
            {
                curChar = charStream.ReadChar();
                if (curChar == '/')
                {
                    IgnoreComment(charStream);
                    curChar = ' ';
                    continue;
                }
            }while(!(curChar >= 'A' && curChar <= 'Z' || curChar >= 'a' && curChar <= 'z' ||
                     curChar >= '0' && curChar <= '9' || curChar == '_' || curChar == '#'));
            charStream.Backup(1);
        }
コード例 #9
0
ファイル: lgspBackend.cs プロジェクト: tmaierhofer/grgen
        private String ReadQuotedString(SimpleCharStream charStream)
        {
            IgnoreSpace(charStream);

            MatchCharOrThrow(charStream, '\"');

            char          curChar;
            StringBuilder sb = new StringBuilder();

            while (true)
            {
                curChar = charStream.ReadChar();
                if (curChar == '\"')
                {
                    break;
                }
                sb.Append(curChar);
            }
            return(sb.ToString());
        }
コード例 #10
0
ファイル: lgspBackend.cs プロジェクト: tmaierhofer/grgen
        private String ReadString(SimpleCharStream charStream)
        {
            IgnoreSpace(charStream);

            char          curChar;
            StringBuilder sb = new StringBuilder();

            while (true)
            {
                curChar = charStream.ReadChar();
                if (!(curChar >= 'A' && curChar <= 'Z' || curChar >= 'a' && curChar <= 'z' ||
                      curChar >= '0' && curChar <= '9' || curChar == '_' || curChar == '#'))
                {
                    break;
                }
                sb.Append(curChar);
            }
            charStream.Backup(1);
            return(sb.ToString());
        }
コード例 #11
0
ファイル: lgspBackend.cs プロジェクト: jblomer/GrGen.NET
        private void IgnoreOther(SimpleCharStream charStream)
        {
            char curChar;
            do
            {
                curChar = charStream.ReadChar();
                if(curChar == '/')
                {
                    IgnoreComment(charStream);
                    curChar = ' ';
                    continue;
                }
            }
            while(!(curChar >= 'A' && curChar <= 'Z' || curChar >= 'a' && curChar <= 'z'
					|| curChar >= '0' && curChar <= '9' || curChar == '_' || curChar == '#'));
            charStream.Backup(1);
        }
コード例 #12
0
ファイル: lgspBackend.cs プロジェクト: jblomer/GrGen.NET
        private void IgnoreString(SimpleCharStream charStream)
        {
            IgnoreSpace(charStream);

            char curChar;
            do
            {
                curChar = charStream.ReadChar();
            }
            while(curChar >= 'A' && curChar <= 'Z' || curChar >= 'a' && curChar <= 'z'
					|| curChar >= '0' && curChar <= '9' || curChar == '_' || curChar == '#');
            charStream.Backup(1);
        }
コード例 #13
0
ファイル: lgspBackend.cs プロジェクト: jblomer/GrGen.NET
        /// <summary>
        /// Ignores the rest of a string.
        /// </summary>
        /// <param name="charStream">The SimpleCharStream object.</param>
        /// <param name="curChar">The last character read. Set to '\0' to ignore.</param>
        private void IgnoreRest(SimpleCharStream charStream, char curChar)
        {
            while(curChar >= 'A' && curChar <= 'Z' || curChar >= 'a' && curChar <= 'z'
					|| curChar >= '0' && curChar <= '9' || curChar == '_' || curChar == '#')
            {
                curChar = charStream.ReadChar();
            }
            charStream.Backup(1);
        }
コード例 #14
0
ファイル: lgspBackend.cs プロジェクト: jblomer/GrGen.NET
        private String ReadString(SimpleCharStream charStream)
        {
            IgnoreSpace(charStream);

            char curChar;
            StringBuilder sb = new StringBuilder();
            while(true)
            {
                curChar = charStream.ReadChar();
                if(!(curChar >= 'A' && curChar <= 'Z' || curChar >= 'a' && curChar <= 'z'
						|| curChar >= '0' && curChar <= '9' || curChar == '_' || curChar == '#'))
                    break;
                sb.Append(curChar);
            }
            charStream.Backup(1);
            return sb.ToString();
        }
コード例 #15
0
ファイル: lgspBackend.cs プロジェクト: jblomer/GrGen.NET
        private bool MatchString(SimpleCharStream charStream, String str)
        {
            IgnoreSpace(charStream);

            char curChar;
            for(int i = 0; i < str.Length; i++)
            {
                curChar = charStream.ReadChar();
                if(curChar != str[i])
                {
                    charStream.Backup(i + 1);       // unread chars
                    return false;
                }
            }
            curChar = charStream.ReadChar();
            if(curChar != ' ' && curChar != '\t' && curChar != '\n' && curChar != '\r')
            {
                charStream.Backup(str.Length + 1);  // unread chars
                return false;
            }
            return true;
        }
コード例 #16
0
    public Token GetNextToken()
    {
        int   kind;
        Token specialToken = null;
        Token matchedToken;
        int   curPos = 0;

        for (;;)
        {
            try {
                curChar = input_stream.BeginToken();
            } catch (System.IO.IOException) {
                mccmatchedKind = 0;
                matchedToken   = mccFillToken();
                return(matchedToken);
            }

            mccmatchedKind = Int32.MaxValue;
            mccmatchedPos  = 0;
            curPos         = mccMoveStringLiteralDfa0_0();
            if (mccmatchedKind != Int32.MaxValue)
            {
                if (mccmatchedPos + 1 < curPos)
                {
                    input_stream.Backup(curPos - mccmatchedPos - 1);
                }
                if ((mcctoToken[mccmatchedKind >> 6] & (1L << (mccmatchedKind & 63))) != 0L)
                {
                    matchedToken = mccFillToken();
                    return(matchedToken);
                }
                else
                {
                    goto EOFLoop;
                }
            }
            int    error_line   = input_stream.EndLine;
            int    error_column = input_stream.EndColumn;
            string error_after  = null;
            bool   EOFSeen      = false;
            try { input_stream.ReadChar(); input_stream.Backup(1); }
            catch (System.IO.IOException) {
                EOFSeen     = true;
                error_after = curPos <= 1 ? "" : input_stream.GetImage();
                if (curChar == '\n' || curChar == '\r')
                {
                    error_line++;
                    error_column = 0;
                }
                else
                {
                    error_column++;
                }
            }
            if (!EOFSeen)
            {
                input_stream.Backup(1);
                error_after = curPos <= 1 ? "" : input_stream.GetImage();
            }
            throw new TokenMgrError(EOFSeen, curLexState, error_line, error_column, error_after, curChar, TokenMgrError.LexicalError);
            EOFLoop :;
        }
    }
コード例 #17
0
ファイル: lgspBackend.cs プロジェクト: jblomer/GrGen.NET
 private void IgnoreSpace(SimpleCharStream charStream)
 {
     char curChar;
     do
     {
         curChar = charStream.ReadChar();
         if(curChar == '/')
         {
             IgnoreComment(charStream);
             curChar = ' ';
             continue;
         }
     }
     while(curChar == ' ' || curChar == '\t' || curChar == '\n' || curChar == '\r');
     charStream.Backup(1);
 }
コード例 #18
0
ファイル: lgspBackend.cs プロジェクト: jblomer/GrGen.NET
        // scans through a gm on the search for model usages
        private void GetNeededFiles(String basePath, String modelName, List<String> neededFiles,
            Dictionary<String, object> processedModelFiles)
        {
            processedModelFiles[modelName] = null;

            if(!File.Exists(modelName))
                throw new FileNotFoundException("Used model file \"" + modelName + "\" does not exist!");

            using(StreamReader reader = new StreamReader(modelName))
            {
                SimpleCharStream charStream = new SimpleCharStream(reader);
                char curChar;
                try
                {
                    if(MatchString(charStream, "#using"))
                    {
                        String usedModelName = ReadQuotedString(charStream);
                        usedModelName = basePath + FixDirectorySeparators(usedModelName);
                        neededFiles.Add(usedModelName);
                        GetNeededFiles(basePath, usedModelName, neededFiles, processedModelFiles);
                    }

                    if(MatchString(charStream, "using"))
                    {
                        while(true)
                        {
                            String usedModelName = ReadString(charStream);
                            neededFiles.Add(basePath + usedModelName + ".gm");
                            GetNeededFiles(basePath, basePath + usedModelName + ".gm", neededFiles, processedModelFiles);
                            IgnoreSpace(charStream);
                            curChar = charStream.ReadChar();
                            if(curChar == ';') break;
                            if(curChar != ',')
                                throw new Exception("Parse error: Unexpected token '" + GetPrintable(curChar)
                                    + "' in '" + basePath + modelName + ".gm" + "' at line " + charStream.EndLine + ":" + charStream.EndColumn + "!");
                        }
                    }

                    // search the rest of the file for include tokens
                    while(true)
                    {
                        curChar = charStream.ReadChar();
 
                        if(curChar == '\\') charStream.ReadChar();			// skip escape sequences
                        else if(curChar == '/') IgnoreComment(charStream);
                        else if(curChar == '"')
                        {
                            while(true)
                            {
                                curChar = charStream.ReadChar();
                                if(curChar == '"') break;
                                else if(curChar == '\\') charStream.ReadChar();		// skip escape sequence
                            }
                        }
                        else if(MatchString(charStream, "#using"))
                        {
                            String usedModelName = ReadQuotedString(charStream);
                            usedModelName = basePath + FixDirectorySeparators(usedModelName);
                            neededFiles.Add(usedModelName);
                            GetNeededFiles(basePath, usedModelName, neededFiles, processedModelFiles);
                        }
                        else if(curChar == 'u' && MatchString(charStream, "sing"))
                        {
                            while(true)
                            {
                                String usedModelName = ReadString(charStream);
                                neededFiles.Add(basePath + usedModelName + ".gm");
                                GetNeededFiles(basePath, basePath + usedModelName + ".gm", neededFiles, processedModelFiles);
                                IgnoreSpace(charStream);
                                curChar = charStream.ReadChar();
                                if(curChar == ';') break;
                                if(curChar != ',')
                                    throw new Exception("Parse error: Unexpected token '" + GetPrintable(curChar)
                                        + "' in '" + basePath + modelName + ".gm" + "' at line " + charStream.EndLine + ":" + charStream.EndColumn + "!");
                            }
                        }
                    }
                }
                catch(IOException)
                {
                    // end of file reached
                }
            }
        }
コード例 #19
0
ファイル: lgspBackend.cs プロジェクト: jblomer/GrGen.NET
        // scans through a grg on the search for model usages and rule file inclusions
        // processedActionFiles are for preventing circular includes, full path
        // processedModelFiles are for determining the amount of models, getting the name of the one model in case it's only one
        private void GetNeededFiles(String basePath, String grgFilename, List<String> neededFiles,
            Dictionary<String, object> processedActionFiles, Dictionary<String, object> processedModelFiles)
        {
            if(processedActionFiles.ContainsKey(grgFilename))
                throw new Exception("Circular include detected with file \"" + grgFilename + "\"!");
            processedActionFiles[grgFilename] = null;

            if(!File.Exists(grgFilename))
				throw new FileNotFoundException("Included file \"" + grgFilename + "\" does not exist!");

            using(StreamReader reader = new StreamReader(grgFilename))
            {
                SimpleCharStream charStream = new SimpleCharStream(reader);
                char curChar;
                try
                {
                    // check optional header

                    bool needSemicolon = false;

                    // read optional "actions <name>"
                    if(MatchString(charStream, "actions"))
                    {
                        needSemicolon = true;
                        IgnoreString(charStream);                                       // ignore actions name
                    }

					if(MatchString(charStream, "#include"))
					{
						String includedGRG = ReadQuotedString(charStream);
						includedGRG = basePath + FixDirectorySeparators(includedGRG);
						neededFiles.Add(includedGRG);
						GetNeededFiles(basePath, includedGRG, neededFiles, processedActionFiles, processedModelFiles);
					}

                    if(MatchString(charStream, "#using"))
                    {
                        String modelName = ReadQuotedString(charStream);
                        modelName = basePath + FixDirectorySeparators(modelName);
                        neededFiles.Add(modelName);
                        GetNeededFiles(basePath, modelName, neededFiles, processedModelFiles);
                    }

                    if(MatchString(charStream, "using"))
                    {
                        while(true)
                        {
                            String modelName = ReadString(charStream);
                            neededFiles.Add(basePath + modelName + ".gm");
                            GetNeededFiles(basePath, basePath + modelName + ".gm", neededFiles, processedModelFiles);
                            IgnoreSpace(charStream);
                            curChar = charStream.ReadChar();
                            if(curChar == ';') break;
                            if(curChar != ',')
                                throw new Exception("Parse error: Unexpected token '" + GetPrintable(curChar)
                                    + "' in '" + grgFilename + "' at line " + charStream.EndLine + ":" + charStream.EndColumn + "!");
                        }
                    }
                    else if(needSemicolon)
                    {
                        IgnoreSpace(charStream);
                        MatchCharOrThrow(charStream, ';');
                    }

                    // search the rest of the file for includes and usings
                    while(true)
                    {
                        curChar = charStream.ReadChar();
						
                        if(curChar == '#' && MatchString(charStream, "include"))
						{
							String includedGRG = ReadQuotedString(charStream);
							includedGRG = basePath + FixDirectorySeparators(includedGRG);
							neededFiles.Add(includedGRG);
                            GetNeededFiles(basePath, includedGRG, neededFiles, processedActionFiles, processedModelFiles);
						}
                        else if(curChar == '\\') charStream.ReadChar();			// skip escape sequences
						else if(curChar == '/') IgnoreComment(charStream);
						else if(curChar == '"')
						{
							while(true)
							{
								curChar = charStream.ReadChar();
								if(curChar == '"') break;
								else if(curChar == '\\') charStream.ReadChar();		// skip escape sequence
							}
						}
                        else if(curChar == '#' && MatchString(charStream, "using"))
                        {
                            String modelName = ReadQuotedString(charStream);
                            modelName = basePath + FixDirectorySeparators(modelName);
                            neededFiles.Add(modelName);
                            GetNeededFiles(basePath, modelName, neededFiles, processedModelFiles);
                        }
                        else if(curChar == 'u' && MatchString(charStream, "sing"))
                        {
                            while(true)
                            {
                                String modelName = ReadString(charStream);
                                neededFiles.Add(basePath + modelName + ".gm");
                                GetNeededFiles(basePath, basePath + modelName + ".gm", neededFiles, processedModelFiles);
                                IgnoreSpace(charStream);
                                curChar = charStream.ReadChar();
                                if(curChar == ';') break;
                                if(curChar != ',')
                                    throw new Exception("Parse error: Unexpected token '" + GetPrintable(curChar)
                                        + "' in '" + grgFilename + "' at line " + charStream.EndLine + ":" + charStream.EndColumn + "!");
                            }
                        }
                    }
                }
                catch(IOException)
                {
                    // end of file reached
                }
            }
        }
コード例 #20
0
ファイル: lgspBackend.cs プロジェクト: jblomer/GrGen.NET
        /// <summary>
        /// Tries to match a string at the current position of a SimpleCharStream.
        /// If the string at the current position does not match, it is skipped.
        /// Here all characters other than A-Z, a-z, 0-9, _, and # are skipped.
        /// </summary>
        /// <param name="charStream">The char stream.</param>
        /// <param name="str">The string to be matched.</param>
        /// <returns>True, iff the string was found.</returns>
        private bool MatchStringOrIgnoreOther(SimpleCharStream charStream, String str)
        {
            IgnoreOther(charStream);

            char curChar;
            for(int i = 0; i < str.Length; i++)
            {
                curChar = charStream.ReadChar();
                if(curChar != str[i])
                {
                    IgnoreRest(charStream, curChar);
                    return false;
                }
            }

            // Does the string really end here?
            curChar = charStream.ReadChar();
            if(curChar != ' ' && curChar != '\t' && curChar != '\n' && curChar != '\r')
            {
                IgnoreRest(charStream, curChar);
                return false;
            }
            return true;
        }
コード例 #21
0
ファイル: lgspBackend.cs プロジェクト: tmaierhofer/grgen
        // scans through a grg on the search for model usages and rule file inclusions
        // processedActionFiles are for preventing circular includes, full path
        // processedModelFiles are for determining the amount of models, getting the name of the one model in case it's only one
        private void GetNeededFiles(String basePath, String grgFilename, List <String> neededFiles,
                                    Dictionary <String, object> processedActionFiles, Dictionary <String, object> processedModelFiles)
        {
            if (processedActionFiles.ContainsKey(grgFilename))
            {
                throw new Exception("Circular include detected with file \"" + grgFilename + "\"!");
            }
            processedActionFiles[grgFilename] = null;

            if (!File.Exists(grgFilename))
            {
                throw new FileNotFoundException("Included file \"" + grgFilename + "\" does not exist!");
            }

            using (StreamReader reader = new StreamReader(grgFilename))
            {
                SimpleCharStream charStream = new SimpleCharStream(reader);
                char             curChar;
                try
                {
                    // check optional header

                    bool needSemicolon = false;

                    // read optional "actions <name>"
                    if (MatchString(charStream, "actions"))
                    {
                        needSemicolon = true;
                        IgnoreString(charStream);                                       // ignore actions name
                    }

                    if (MatchString(charStream, "#include"))
                    {
                        String includedGRG = ReadQuotedString(charStream);
                        includedGRG = basePath + FixDirectorySeparators(includedGRG);
                        neededFiles.Add(includedGRG);
                        GetNeededFiles(basePath, includedGRG, neededFiles, processedActionFiles, processedModelFiles);
                    }

                    if (MatchString(charStream, "#using"))
                    {
                        String modelName = ReadQuotedString(charStream);
                        modelName = basePath + FixDirectorySeparators(modelName);
                        neededFiles.Add(modelName);
                        GetNeededFiles(basePath, modelName, neededFiles, processedModelFiles);
                    }

                    if (MatchString(charStream, "using"))
                    {
                        while (true)
                        {
                            String modelName = ReadString(charStream);
                            neededFiles.Add(basePath + modelName + ".gm");
                            GetNeededFiles(basePath, basePath + modelName + ".gm", neededFiles, processedModelFiles);
                            IgnoreSpace(charStream);
                            curChar = charStream.ReadChar();
                            if (curChar == ';')
                            {
                                break;
                            }
                            if (curChar != ',')
                            {
                                throw new Exception("Parse error: Unexpected token '" + GetPrintable(curChar)
                                                    + "' in '" + grgFilename + "' at line " + charStream.EndLine + ":" + charStream.EndColumn + "!");
                            }
                        }
                    }
                    else if (needSemicolon)
                    {
                        IgnoreSpace(charStream);
                        MatchCharOrThrow(charStream, ';');
                    }

                    // search the rest of the file for includes and usings
                    while (true)
                    {
                        curChar = charStream.ReadChar();

                        if (curChar == '#' && MatchString(charStream, "include"))
                        {
                            String includedGRG = ReadQuotedString(charStream);
                            includedGRG = basePath + FixDirectorySeparators(includedGRG);
                            neededFiles.Add(includedGRG);
                            GetNeededFiles(basePath, includedGRG, neededFiles, processedActionFiles, processedModelFiles);
                        }
                        else if (curChar == '\\')
                        {
                            charStream.ReadChar();                      // skip escape sequences
                        }
                        else if (curChar == '/')
                        {
                            IgnoreComment(charStream);
                        }
                        else if (curChar == '"')
                        {
                            while (true)
                            {
                                curChar = charStream.ReadChar();
                                if (curChar == '"')
                                {
                                    break;
                                }
                                else if (curChar == '\\')
                                {
                                    charStream.ReadChar();              // skip escape sequence
                                }
                            }
                        }
                        else if (curChar == '#' && MatchString(charStream, "using"))
                        {
                            String modelName = ReadQuotedString(charStream);
                            modelName = basePath + FixDirectorySeparators(modelName);
                            neededFiles.Add(modelName);
                            GetNeededFiles(basePath, modelName, neededFiles, processedModelFiles);
                        }
                        else if (curChar == 'u' && MatchString(charStream, "sing"))
                        {
                            while (true)
                            {
                                String modelName = ReadString(charStream);
                                neededFiles.Add(basePath + modelName + ".gm");
                                GetNeededFiles(basePath, basePath + modelName + ".gm", neededFiles, processedModelFiles);
                                IgnoreSpace(charStream);
                                curChar = charStream.ReadChar();
                                if (curChar == ';')
                                {
                                    break;
                                }
                                if (curChar != ',')
                                {
                                    throw new Exception("Parse error: Unexpected token '" + GetPrintable(curChar)
                                                        + "' in '" + grgFilename + "' at line " + charStream.EndLine + ":" + charStream.EndColumn + "!");
                                }
                            }
                        }
                    }
                }
                catch (IOException)
                {
                    // end of file reached
                }
            }
        }
コード例 #22
0
ファイル: lgspBackend.cs プロジェクト: jblomer/GrGen.NET
        private String ReadQuotedString(SimpleCharStream charStream)
        {
            IgnoreSpace(charStream);

            MatchCharOrThrow(charStream, '\"');

            char curChar;
            StringBuilder sb = new StringBuilder();
            while(true)
            {
                curChar = charStream.ReadChar();
                if(curChar == '\"')
                    break;
                sb.Append(curChar);
            }
            return sb.ToString();
        }
コード例 #23
0
ファイル: lgspBackend.cs プロジェクト: tmaierhofer/grgen
        // scans through a gm on the search for model usages
        private void GetNeededFiles(String basePath, String modelName, List <String> neededFiles,
                                    Dictionary <String, object> processedModelFiles)
        {
            processedModelFiles[modelName] = null;

            if (!File.Exists(modelName))
            {
                throw new FileNotFoundException("Used model file \"" + modelName + "\" does not exist!");
            }

            using (StreamReader reader = new StreamReader(modelName))
            {
                SimpleCharStream charStream = new SimpleCharStream(reader);
                char             curChar;
                try
                {
                    if (MatchString(charStream, "#using"))
                    {
                        String usedModelName = ReadQuotedString(charStream);
                        usedModelName = basePath + FixDirectorySeparators(usedModelName);
                        neededFiles.Add(usedModelName);
                        GetNeededFiles(basePath, usedModelName, neededFiles, processedModelFiles);
                    }

                    if (MatchString(charStream, "using"))
                    {
                        while (true)
                        {
                            String usedModelName = ReadString(charStream);
                            neededFiles.Add(basePath + usedModelName + ".gm");
                            GetNeededFiles(basePath, basePath + usedModelName + ".gm", neededFiles, processedModelFiles);
                            IgnoreSpace(charStream);
                            curChar = charStream.ReadChar();
                            if (curChar == ';')
                            {
                                break;
                            }
                            if (curChar != ',')
                            {
                                throw new Exception("Parse error: Unexpected token '" + GetPrintable(curChar)
                                                    + "' in '" + basePath + modelName + ".gm" + "' at line " + charStream.EndLine + ":" + charStream.EndColumn + "!");
                            }
                        }
                    }

                    // search the rest of the file for include tokens
                    while (true)
                    {
                        curChar = charStream.ReadChar();

                        if (curChar == '\\')
                        {
                            charStream.ReadChar();                      // skip escape sequences
                        }
                        else if (curChar == '/')
                        {
                            IgnoreComment(charStream);
                        }
                        else if (curChar == '"')
                        {
                            while (true)
                            {
                                curChar = charStream.ReadChar();
                                if (curChar == '"')
                                {
                                    break;
                                }
                                else if (curChar == '\\')
                                {
                                    charStream.ReadChar();              // skip escape sequence
                                }
                            }
                        }
                        else if (MatchString(charStream, "#using"))
                        {
                            String usedModelName = ReadQuotedString(charStream);
                            usedModelName = basePath + FixDirectorySeparators(usedModelName);
                            neededFiles.Add(usedModelName);
                            GetNeededFiles(basePath, usedModelName, neededFiles, processedModelFiles);
                        }
                        else if (curChar == 'u' && MatchString(charStream, "sing"))
                        {
                            while (true)
                            {
                                String usedModelName = ReadString(charStream);
                                neededFiles.Add(basePath + usedModelName + ".gm");
                                GetNeededFiles(basePath, basePath + usedModelName + ".gm", neededFiles, processedModelFiles);
                                IgnoreSpace(charStream);
                                curChar = charStream.ReadChar();
                                if (curChar == ';')
                                {
                                    break;
                                }
                                if (curChar != ',')
                                {
                                    throw new Exception("Parse error: Unexpected token '" + GetPrintable(curChar)
                                                        + "' in '" + basePath + modelName + ".gm" + "' at line " + charStream.EndLine + ":" + charStream.EndColumn + "!");
                                }
                            }
                        }
                    }
                }
                catch (IOException)
                {
                    // end of file reached
                }
            }
        }
コード例 #24
0
ファイル: lgspBackend.cs プロジェクト: jblomer/GrGen.NET
 private void MatchCharOrThrow(SimpleCharStream charStream, char ch)
 {
     char curChar = charStream.ReadChar();
     if(curChar != ch)
         throw new Exception("Parse error: Unexpected token '" + GetPrintable(curChar) + "' at line " + charStream.EndLine + ":" + charStream.EndColumn + "!");
 }
コード例 #25
0
        /// <summary>Get the next Token.</summary>
        public Token GetNextToken()
        {
            Token matchedToken;
            int   curPos = 0;

            for (;;)
            {
                try
                {
                    curChar = input_stream.BeginToken();
                }
                catch (System.IO.IOException)
                {
                    jjmatchedKind = 0;
                    matchedToken  = JjFillToken();
                    return(matchedToken);
                }

                switch (curLexState)
                {
                case 0:
                    jjmatchedKind = 0x7fffffff;
                    jjmatchedPos  = 0;
                    curPos        = JjMoveStringLiteralDfa0_0();
                    break;

                case 1:
                    jjmatchedKind = 0x7fffffff;
                    jjmatchedPos  = 0;
                    curPos        = JjMoveStringLiteralDfa0_1();
                    break;
                }
                if (jjmatchedKind != 0x7fffffff)
                {
                    if (jjmatchedPos + 1 < curPos)
                    {
                        input_stream.Backup(curPos - jjmatchedPos - 1);
                    }
                    matchedToken = JjFillToken();
                    if (jjnewLexState[jjmatchedKind] != -1)
                    {
                        curLexState = jjnewLexState[jjmatchedKind];
                    }
                    return(matchedToken);
                }
                int    error_line   = input_stream.GetEndLine();
                int    error_column = input_stream.GetEndColumn();
                string error_after  = null;
                bool   EOFSeen      = false;
                try { input_stream.ReadChar(); input_stream.Backup(1); }
                catch (System.IO.IOException)
                {
                    EOFSeen     = true;
                    error_after = curPos <= 1 ? "" : input_stream.GetImage();
                    if (curChar == '\n' || curChar == '\r')
                    {
                        error_line++;
                        error_column = 0;
                    }
                    else
                    {
                        error_column++;
                    }
                }
                if (!EOFSeen)
                {
                    input_stream.Backup(1);
                    error_after = curPos <= 1 ? "" : input_stream.GetImage();
                }
                throw new TokenManagerException(EOFSeen, curLexState, error_line, error_column, error_after, curChar, TokenManagerException.ErrorCodes.LexicalError);
            }
        }
コード例 #26
0
ファイル: lgspBackend.cs プロジェクト: jblomer/GrGen.NET
 private void IgnoreComment(SimpleCharStream charStream)
 {
     char curChar = charStream.ReadChar();
     if(curChar == '/')
     {
         do
         {
             curChar = charStream.ReadChar();
         }
         while(curChar != '\n' && curChar != '\r');
     }
     else if(curChar == '*')
     {
         bool foundStar = false;
         while(true)
         {
             curChar = charStream.ReadChar();
             if(foundStar && curChar == '/') break;
             foundStar = curChar == '*';
         }
     }
     // otherwise its just not a comment
 }