⚡ improve comment parsing
This commit is contained in:
		
							parent
							
								
									b53c6e2f81
								
							
						
					
					
						commit
						e9bfcf7255
					
				
					 2 changed files with 64 additions and 80 deletions
				
			
		| 
						 | 
				
			
			@ -8902,62 +8902,54 @@ class lexer : public lexer_base<BasicJsonType>
 | 
			
		|||
     */
 | 
			
		||||
    bool scan_comment()
 | 
			
		||||
    {
 | 
			
		||||
        // remember character after '/' to distinguish comment types
 | 
			
		||||
        const auto comment_char = get();
 | 
			
		||||
 | 
			
		||||
        // expect // or /* to start a comment
 | 
			
		||||
        if (comment_char != '/' and comment_char != '*')
 | 
			
		||||
        switch (get())
 | 
			
		||||
        {
 | 
			
		||||
            return false;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        while (true)
 | 
			
		||||
        {
 | 
			
		||||
            switch (get())
 | 
			
		||||
            case '/':
 | 
			
		||||
            {
 | 
			
		||||
                // EOF inside a /* comment is an error, in // it is OK
 | 
			
		||||
                case std::char_traits<char_type>::eof():
 | 
			
		||||
                case '\0':
 | 
			
		||||
                while (true)
 | 
			
		||||
                {
 | 
			
		||||
                    return comment_char == '/';
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
                // a newline ends the // comment
 | 
			
		||||
                case '\n':
 | 
			
		||||
                case '\r':
 | 
			
		||||
                {
 | 
			
		||||
                    if (comment_char == '/')
 | 
			
		||||
                    switch (get())
 | 
			
		||||
                    {
 | 
			
		||||
                        return true;
 | 
			
		||||
                        case '\n':
 | 
			
		||||
                        case '\r':
 | 
			
		||||
                            return true;
 | 
			
		||||
 | 
			
		||||
                        default:
 | 
			
		||||
                            break;
 | 
			
		||||
                    }
 | 
			
		||||
                    break;
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
                // */ ends the /* comment
 | 
			
		||||
                case '*':
 | 
			
		||||
            case '*':
 | 
			
		||||
            {
 | 
			
		||||
                while (true)
 | 
			
		||||
                {
 | 
			
		||||
                    if (comment_char == '*')
 | 
			
		||||
                    switch (get())
 | 
			
		||||
                    {
 | 
			
		||||
                        switch (get())
 | 
			
		||||
                        {
 | 
			
		||||
                            case '/':
 | 
			
		||||
                            {
 | 
			
		||||
                                return true;
 | 
			
		||||
                            }
 | 
			
		||||
                        case std::char_traits<char_type>::eof():
 | 
			
		||||
                        case '\0':
 | 
			
		||||
                            return false;
 | 
			
		||||
 | 
			
		||||
                            default:
 | 
			
		||||
                        case '*':
 | 
			
		||||
                        {
 | 
			
		||||
                            switch (get())
 | 
			
		||||
                            {
 | 
			
		||||
                                unget();
 | 
			
		||||
                                break;
 | 
			
		||||
                                case '/':
 | 
			
		||||
                                    return true;
 | 
			
		||||
 | 
			
		||||
                                default:
 | 
			
		||||
                                {
 | 
			
		||||
                                    unget();
 | 
			
		||||
                                    break;
 | 
			
		||||
                                }
 | 
			
		||||
                            }
 | 
			
		||||
                        }
 | 
			
		||||
                    }
 | 
			
		||||
                    break;
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
                default:
 | 
			
		||||
                    break;
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            default:
 | 
			
		||||
                return false;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue