2426 |
2447 |
2427 "Modified: 13.9.1997 / 01:05:49 / cg" |
2448 "Modified: 13.9.1997 / 01:05:49 / cg" |
2428 "Created: 13.9.1997 / 06:18:41 / cg" |
2449 "Created: 13.9.1997 / 06:18:41 / cg" |
2429 ! |
2450 ! |
2430 |
2451 |
|
2452 searchForAndSelectMatchingParenthesisFromLine:startLine col:startCol |
|
2453 "select characters enclosed by matching parenthesis if one is under startLine/Col" |
|
2454 |
|
2455 self |
|
2456 searchForMatchingParenthesisFromLine:startLine col:startCol |
|
2457 ifFound:[:line :col | |
|
2458 self selectFromLine:startLine col:startCol |
|
2459 toLine:line col:col] |
|
2460 ifNotFound:[self showNotFound] |
|
2461 onError:[self beep] |
|
2462 |
|
2463 "Modified: 9.10.1997 / 12:57:34 / cg" |
|
2464 ! |
|
2465 |
2431 searchForMatchingParenthesisFromLine:startLine col:startCol |
2466 searchForMatchingParenthesisFromLine:startLine col:startCol |
2432 ifFound:foundBlock |
2467 ifFound:foundBlock |
2433 ifNotFound:notFoundBlock |
2468 ifNotFound:notFoundBlock |
2434 onError:failBlock |
2469 onError:failBlock |
2435 |
2470 |
2436 "search for a matching parenthesis, parChar is one of '$( $[ ${ $) $] $}'. |
2471 "search for a matching parenthesis; start search with character at startLine/startCol. |
2437 Search for the corresponding character is done forward if its an opening, |
2472 Search for the corresponding character is done forward if its an opening, |
2438 backwards if its a closing parenthesis. |
2473 backwards if its a closing parenthesis. |
2439 Performs foundBlock with line/col as argument if found, notFoundBlock if not. |
2474 Evaluate foundBlock with line/col as argument if found, notFoundBlock if not. |
2440 If there is a nesting error, performs failBlock." |
2475 If there is a nesting error, evaluate failBlock." |
2441 |
2476 |
2442 ^ self |
2477 ^ self |
2443 searchForMatchingParenthesisFromLine:startLine col:startCol |
2478 searchForMatchingParenthesisFromLine:startLine col:startCol |
2444 ifFound:foundBlock |
2479 ifFound:foundBlock |
2445 ifNotFound:notFoundBlock |
2480 ifNotFound:notFoundBlock |
2446 onError:failBlock |
2481 onError:failBlock |
2447 ignoring:#( $' $" '$[' '$]' '${' '$)' ) |
2482 ignoring:(parenthesisSpecification at:#ignore) "/ #( $' $" '$[' '$]' '${' '$)' ) |
2448 |
2483 |
2449 "Modified: 18.5.1996 / 11:05:57 / cg" |
2484 "Modified: 18.5.1996 / 11:05:57 / cg" |
2450 ! |
2485 ! |
2451 |
2486 |
2452 searchForMatchingParenthesisFromLine:startLine col:startCol |
2487 searchForMatchingParenthesisFromLine:startLine col:startCol |
2453 ifFound:foundBlock |
2488 ifFound:foundBlock |
2454 ifNotFound:notFoundBlock |
2489 ifNotFound:notFoundBlock |
2455 onError:failBlock |
2490 onError:failBlock |
2456 ignoring:ignoreSet |
2491 ignoring:ignoreSet |
2457 "search for a matching parenthesis, parChar is one of '$( $[ ${ $) $] $}'. |
2492 |
|
2493 "search for a matching parenthesis; start search with character at startLine/startCol. |
2458 Search for the corresponding character is done forward if its an opening, |
2494 Search for the corresponding character is done forward if its an opening, |
2459 backwards if its a closing parenthesis. |
2495 backwards if its a closing parenthesis. |
2460 Performs foundBlock with line/col as argument if found, notFoundBlock if not. |
2496 Evaluate foundBlock with line/col as argument if found, notFoundBlock if not. |
2461 If there is a nesting error, performs failBlock." |
2497 If there is a nesting error, evaluate failBlock." |
|
2498 |
|
2499 ^ self |
|
2500 searchForMatchingParenthesisFromLine:startLine col:startCol |
|
2501 ifFound:foundBlock |
|
2502 ifNotFound:notFoundBlock |
|
2503 onError:failBlock |
|
2504 openingCharacters: (parenthesisSpecification at:#open) "/ #( $( $[ ${ "$> $<") |
|
2505 closingCharacters: (parenthesisSpecification at:#close) "/ #( $) $] $} "$> $<") |
|
2506 ignoredCharacters: ignoreSet |
|
2507 specialEOLComment: (parenthesisSpecification at:#eolComment) "/ |
|
2508 |
|
2509 "/ |i direction lineString |
|
2510 "/ parChar charSet closingChar |
|
2511 "/ ignoring |
|
2512 "/ line "{ Class: SmallInteger }" |
|
2513 "/ col "{ Class: SmallInteger }" |
|
2514 "/ delta "{ Class: SmallInteger }" |
|
2515 "/ endCol "{ Class: SmallInteger }" |
|
2516 "/ runCol "{ Class: SmallInteger }" |
|
2517 "/ cc prevCC nextCC incSet decSet |
|
2518 "/ nesting "{ Class: SmallInteger }" |
|
2519 "/ maxLine "{ Class: SmallInteger }" |
|
2520 "/ ign skip anySet| |
|
2521 "/ |
|
2522 "/ charSet := #( $( $) $[ $] ${ $} " $< $> " ). |
|
2523 "/ |
|
2524 "/ parChar := self characterAtLine:startLine col:startCol. |
|
2525 "/ i := charSet indexOf:parChar. |
|
2526 "/ i == 0 ifTrue:[ |
|
2527 "/ ^ failBlock value "not a parenthesis" |
|
2528 "/ ]. |
|
2529 "/ direction := #( fwd bwd fwd bwd fwd bwd fwd bwd) at:i. |
|
2530 "/ closingChar := #( $) $( $] $[ $} ${ "$> $<") at:i. |
|
2531 "/ |
|
2532 "/ col := startCol. |
|
2533 "/ line := startLine. |
|
2534 "/ direction == #fwd ifTrue:[ |
|
2535 "/ delta := 1. |
|
2536 "/ incSet := #( $( $[ ${ "$<" ). |
|
2537 "/ decSet := #( $) $] $} "$>" ). |
|
2538 "/ ] ifFalse:[ |
|
2539 "/ delta := -1. |
|
2540 "/ incSet := #( $) $] $} "$>" ). |
|
2541 "/ decSet := #( $( $[ ${ "$<" ). |
|
2542 "/ ]. |
|
2543 "/ anySet := Set new. |
|
2544 "/ anySet addAll:incSet; addAll:decSet; addAll:ignoreSet. |
|
2545 "/ anySet := (anySet select:[:c | c isCharacter]) asString. |
|
2546 "/ |
|
2547 "/ nesting := 1. |
|
2548 "/ ignoring := false. |
|
2549 "/ lineString := list at:line. |
|
2550 "/ maxLine := list size. |
|
2551 "/ |
|
2552 "/ col := col + delta. |
|
2553 "/ [nesting ~~ 0] whileTrue:[ |
|
2554 "/ (lineString notNil |
|
2555 "/ and:[lineString includesAny:anySet]) ifTrue:[ |
|
2556 "/ direction == #fwd ifTrue:[ |
|
2557 "/ endCol := lineString size. |
|
2558 "/ ] ifFalse:[ |
|
2559 "/ endCol := 1 |
|
2560 "/ ]. |
|
2561 "/ |
|
2562 "/ col to:endCol by:delta do:[:rCol | |
|
2563 "/ runCol := rCol. |
|
2564 "/ |
|
2565 "/ cc := lineString at:runCol. |
|
2566 "/ runCol < lineString size ifTrue:[ |
|
2567 "/ nextCC := lineString at:runCol+1 |
|
2568 "/ ] ifFalse:[ |
|
2569 "/ nextCC := nil |
|
2570 "/ ]. |
|
2571 "/ runCol > 1 ifTrue:[ |
|
2572 "/ prevCC := lineString at:runCol-1 |
|
2573 "/ ] ifFalse:[ |
|
2574 "/ prevCC := nil |
|
2575 "/ ]. |
|
2576 "/ |
|
2577 "/ ign := skip := false. |
|
2578 "/ |
|
2579 "/ "/ check for comments. |
|
2580 "/ |
|
2581 "/ ((cc == $" and:[nextCC == $/]) |
|
2582 "/ or:[prevCC == $$ ]) ifTrue:[ |
|
2583 "/ "/ do nothing |
|
2584 "/ |
|
2585 "/ skip := true. |
|
2586 "/ ] ifFalse:[ |
|
2587 "/ ignoreSet do:[:ignore | |
|
2588 "/ ignore == cc ifTrue:[ |
|
2589 "/ ign := true |
|
2590 "/ ] ifFalse:[ |
|
2591 "/ ignore isString ifTrue:[ |
|
2592 "/ cc == (ignore at:2) ifTrue:[ |
|
2593 "/ runCol > 1 ifTrue:[ |
|
2594 "/ (lineString at:(runCol-1)) == (ignore at:1) ifTrue:[ |
|
2595 "/ skip := true |
|
2596 "/ ] |
|
2597 "/ ] |
|
2598 "/ ] ifFalse:[ |
|
2599 "/ cc == (ignore at:1) ifTrue:[ |
|
2600 "/ runCol < lineString size ifTrue:[ |
|
2601 "/ (lineString at:(runCol+1)) == (ignore at:2) ifTrue:[ |
|
2602 "/ skip := true |
|
2603 "/ ] |
|
2604 "/ ] |
|
2605 "/ ] |
|
2606 "/ ] |
|
2607 "/ ] |
|
2608 "/ ] |
|
2609 "/ ] |
|
2610 "/ ]. |
|
2611 "/ |
|
2612 "/ ign ifTrue:[ |
|
2613 "/ ignoring := ignoring not |
|
2614 "/ ]. |
|
2615 "/ |
|
2616 "/ ignoring ifFalse:[ |
|
2617 "/ skip ifFalse:[ |
|
2618 "/ (incSet includes:cc) ifTrue:[ |
|
2619 "/ nesting := nesting + 1 |
|
2620 "/ ] ifFalse:[ |
|
2621 "/ (decSet includes:cc) ifTrue:[ |
|
2622 "/ nesting := nesting - 1 |
|
2623 "/ ] |
|
2624 "/ ] |
|
2625 "/ ] |
|
2626 "/ ]. |
|
2627 "/ |
|
2628 "/ nesting == 0 ifTrue:[ |
|
2629 "/ "check if legal" |
|
2630 "/ |
|
2631 "/ skip ifFalse:[ |
|
2632 "/ cc == closingChar ifFalse:[ |
|
2633 "/ ^ failBlock value |
|
2634 "/ ]. |
|
2635 "/ ^ foundBlock value:line value:runCol. |
|
2636 "/ ] |
|
2637 "/ ] |
|
2638 "/ ]. |
|
2639 "/ ]. |
|
2640 "/ line := line + delta. |
|
2641 "/ (line < 1 or:[line > maxLine]) ifTrue:[ |
|
2642 "/ ^ failBlock value |
|
2643 "/ ]. |
|
2644 "/ lineString := list at:line. |
|
2645 "/ direction == #fwd ifTrue:[ |
|
2646 "/ col := 1 |
|
2647 "/ ] ifFalse:[ |
|
2648 "/ col := lineString size |
|
2649 "/ ] |
|
2650 "/ ]. |
|
2651 "/ ^ notFoundBlock value |
|
2652 |
|
2653 "Modified: 15.10.1996 / 12:22:30 / cg" |
|
2654 ! |
|
2655 |
|
2656 searchForMatchingParenthesisFromLine:startLine col:startCol |
|
2657 ifFound:foundBlock |
|
2658 ifNotFound:notFoundBlock |
|
2659 onError:failBlock |
|
2660 openingCharacters:openingCharacters |
|
2661 closingCharacters:closingCharacters |
|
2662 ignoredCharacters:ignoreSet |
|
2663 specialEOLComment:eolCommentSequence |
|
2664 |
|
2665 "search for a matching parenthesis; start search with character at startLine/startCol. |
|
2666 Search for the corresponding character is done forward if its an opening, |
|
2667 backwards if its a closing parenthesis. |
|
2668 Evaluate foundBlock with line/col as argument if found, notFoundBlock if not. |
|
2669 If there is a nesting error, evaluate failBlock." |
2462 |
2670 |
2463 |i direction lineString |
2671 |i direction lineString |
2464 parChar charSet closingChar |
2672 parChar charSet closingChar |
2465 ignoring |
2673 ignoring |
2466 line "{ Class: SmallInteger }" |
2674 line "{ Class: SmallInteger }" |
2469 endCol "{ Class: SmallInteger }" |
2677 endCol "{ Class: SmallInteger }" |
2470 runCol "{ Class: SmallInteger }" |
2678 runCol "{ Class: SmallInteger }" |
2471 cc prevCC nextCC incSet decSet |
2679 cc prevCC nextCC incSet decSet |
2472 nesting "{ Class: SmallInteger }" |
2680 nesting "{ Class: SmallInteger }" |
2473 maxLine "{ Class: SmallInteger }" |
2681 maxLine "{ Class: SmallInteger }" |
2474 ign skip anySet| |
2682 ign skip anySet |
2475 |
2683 eol1 eol2| |
2476 charSet := #( $( $) $[ $] ${ $} " $< $> " ). |
2684 |
|
2685 charSet := openingCharacters , closingCharacters. |
2477 |
2686 |
2478 parChar := self characterAtLine:startLine col:startCol. |
2687 parChar := self characterAtLine:startLine col:startCol. |
2479 i := charSet indexOf:parChar. |
2688 i := charSet indexOf:parChar. |
2480 i == 0 ifTrue:[ |
2689 i == 0 ifTrue:[ |
2481 ^ failBlock value "not a parenthesis" |
2690 ^ failBlock value "not a parenthesis" |
2482 ]. |
2691 ]. |
2483 direction := #( fwd bwd fwd bwd fwd bwd fwd bwd) at:i. |
2692 |
2484 closingChar := #( $) $( $] $[ $} ${ "$> $<") at:i. |
2693 direction := ((openingCharacters collect:[:c | #fwd]) , (closingCharacters collect:[:c | #bwd])) at:i. |
|
2694 closingChar := (closingCharacters , openingCharacters) at:i. |
|
2695 |
|
2696 eol1 := eolCommentSequence at:1 ifAbsent:nil. |
|
2697 eol2 := eolCommentSequence at:2 ifAbsent:nil. |
2485 |
2698 |
2486 col := startCol. |
2699 col := startCol. |
2487 line := startLine. |
2700 line := startLine. |
2488 direction == #fwd ifTrue:[ |
2701 direction == #fwd ifTrue:[ |
2489 delta := 1. |
2702 delta := 1. |
2490 incSet := #( $( $[ ${ "$<" ). |
2703 incSet := openingCharacters. |
2491 decSet := #( $) $] $} "$>" ). |
2704 decSet := closingCharacters. |
2492 ] ifFalse:[ |
2705 ] ifFalse:[ |
2493 delta := -1. |
2706 delta := -1. |
2494 incSet := #( $) $] $} "$>" ). |
2707 incSet := closingCharacters. |
2495 decSet := #( $( $[ ${ "$<" ). |
2708 decSet := openingCharacters. |
2496 ]. |
2709 ]. |
2497 anySet := Set new. |
2710 anySet := Set new. |
2498 anySet addAll:incSet; addAll:decSet; addAll:ignoreSet. |
2711 anySet addAll:incSet; addAll:decSet; addAll:ignoreSet. |
2499 anySet := (anySet select:[:c | c isCharacter]) asString. |
2712 anySet := (anySet select:[:c | c isCharacter]) asString. |
2500 |
2713 |