コード例 #1
0
ファイル: StreamTokenizerTests.cs プロジェクト: PKISharp/core
        public void TestComments()
        {
            var res = "ACMESharp.Util.StreamTokenizer.input.txt";
            var asm = typeof(StreamTokenizerTests).GetTypeInfo().Assembly;

            int slashIsCommentStart = 1;
            int slashSlashComment   = 2;
            int slashStarComment    = 4;

            for (int i = 0; i < 8; i++)
            {
                using (var stm = asm.GetManifestResourceStream(res))
                {
                    var st = new StreamTokenizer(stm);

                    /* decide the state of this run */
                    bool slashCommentFlag      = ((i & slashIsCommentStart) != 0);
                    bool slashSlashCommentFlag = ((i & slashSlashComment) != 0);
                    bool slashStarCommentFlag  = ((i & slashStarComment) != 0);

                    /* set the initial state of the tokenizer */
                    if (!slashCommentFlag)
                    {
                        st.OrdinaryChars('/', '/');
                    }
                    st.SlashSlashComments(slashSlashCommentFlag);
                    st.SlashStarComments(slashStarCommentFlag);

                    /* now go throgh the input file */
                    while (st.NextToken() != StreamTokenizer.TT_EOF)
                    {
                        String token = st.sval;
                        if (token == null)
                        {
                            continue;
                        }
                        else
                        {
                            if ((token.CompareTo("Error1") == 0) && slashStarCommentFlag)
                            {
                                throw new Exception("Failed to pass one line C comments!");
                            }
                            if ((token.CompareTo("Error2") == 0) && slashStarCommentFlag)
                            {
                                throw new Exception("Failed to pass multi line C comments!");
                            }
                            if ((token.CompareTo("Error3") == 0) && slashSlashCommentFlag)
                            {
                                throw new Exception("Failed to pass C++ comments!");
                            }
                            if ((token.CompareTo("Error4") == 0) && slashCommentFlag)
                            {
                                throw new Exception("Failed to pass / comments!");
                            }
                        }
                    }
                }
            }
        }
コード例 #2
0
 private void EnableWords(bool flag)
 {
     if (flag)
     {
         _tok.WordChars('a', 'z');
         _tok.WordChars('A', 'Z');
         _tok.WordChars('0', '9');
         _tok.WordChars('.', '.');
         _tok.WordChars(':', ':');
     }
     else
     {
         _tok.OrdinaryChars('a', 'z');
         _tok.OrdinaryChars('A', 'Z');
         _tok.OrdinaryChars('0', '9');
         _tok.OrdinaryChars('.', '.');
         _tok.OrdinaryChars(':', ':');
     }
 }