1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101
|
# -*- Tcl -*-
package require nx
package require nx::test
package require nx::doc
namespace import -force ::nx::*
namespace import -force ::nx::doc::*
nx::test configure -count 1
#
# some helper
#
proc lcompare {a b} {
foreach x $a y $b {
if {$a ne $b} {return -1}
}
return 1
}
# --
#
# Source the "Document Comment" backend
#
package require nx::doc::dc
Test case scanning {
set lines {
"# @package o" 1
"#@package o" 1
"bla" 0
"# @object o" 1
"# 1 2 3" 1
"#" 1
"# " 1
" # " 1
"\t#\t \t" 1
"# 345" 1
"# @tag1 part1" 1
"bla; # no comment" 0
"" 0
"\t\t" 0
"### # # # # @object o # ####" 1
"# # # # # 345" 1
"# # # @tag1 part1" 1
"bla; # # # # # no comment" 0
" " 0
}
set ::prj [@project new -name _PROJECT_]
foreach {::line ::result} $lines {
? {lassign [$::prj analyze_line $::line] is_comment text; set is_comment} $::result "processor analyze_line '$::line'"
}
set script {
# @package o
# 1 2 3
bla
bla
# @object o
# 1 2 3
#
# 345
# @tag1 part1
# @tag2 part2
bla; # no comment
bla
bla
bla
### # # # # @object o # ####
# 1 2 3
#
# # # # # 345
# # # @tag1 part1
# @tag2 part2
bla; # # # # # no comment
}
set blocks {1 {{ @package o} { 1 2 3}} 5 {{ @object o} { 1 2 3} {} { 345} { @tag1 part1} { @tag2 part2}} 17 {{ @object o # ####} { 1 2 3} {} { 345} { @tag1 part1} { @tag2 part2}}}
? [list ::lcompare [$::prj comment_blocks $script] $blocks] 1
}
Test case parsing {
set ::prj [@project new -name _PROJECT_]
namespace import -force ::nx::doc::CommentBlockParser
#
# TODO: Add tests for doc-parsing state machine.
#
set block {
{@command ::cc}
}
set ::cbp [CommentBlockParser process $block]
? [list $::cbp status ? COMPLETED] 1
set block {
{}
}
set cbp [CommentBlockParser process $block]
? [list $cbp status ? COMPLETED] 0
? [list $cbp status ? STYLEVIOLATION] 1
#
# For now, a valid comment block must start with a non-space line
# (i.e., a tag or text line, depending on the section: context
# vs. description)
#
set block {
{}
{@command ::cc}
}
set cbp [CommentBlockParser process $block]
? [list $cbp status ? STYLEVIOLATION] 1
set block {
{command ::cc}
{}
}
set cbp [CommentBlockParser process $block]
? [list $cbp status ? STYLEVIOLATION] 1
set block {
{@command ::cc}
{some description}
}
set cbp [CommentBlockParser process $block]
? [list $cbp status ? STYLEVIOLATION] 1
set block {
{@command ::cc}
{}
{}
{}
{@see ::o}
}
set cbp [CommentBlockParser process $block]
? [list $cbp status ? STYLEVIOLATION] 0
? [list $cbp status ? COMPLETED] 1
set block {
{@command ::cc}
{}
{some description}
{some description2}
{}
{}
}
set cbp [CommentBlockParser process $block]
? [list $cbp status ? STYLEVIOLATION] 0
# Note: We do allow description blocks with intermediate space
# lines, for now.
set block {
{@command ::cc}
{}
{some description}
{some description2}
{}
{an erroreneous description line, for now}
}
set cbp [CommentBlockParser process $block]
? [list $cbp status ? STYLEVIOLATION] 0
#
# TODO: Do not enforce space line between the context and immediate
# part block (when description is skipped)?
#
# OR: For absolutely object::qualifying parts (e.g., outside of an initblock),
# do we need sequences of _two_ (or more) tag lines, e.g.
#
# --
# @object Foo
# @param attr1
# --
#
# THEN, we can only discriminate between the context and an
# immediate part section by requiring a space line!
#
# Alternatively, we can use the @see like syntax for object::qualifying:
# @param ::Foo#attr1 (I have a preference for this option).
set block {
{@command ::cc}
{@see someOtherEntity}
}
set cbp [CommentBlockParser process $block]
? [list $cbp status ? STYLEVIOLATION] 1
#
# TODO: Disallow space lines between parts? Check back with Javadoc spec.
#
set block {
{@command ::cc}
{}
{@see SomeOtherEntity}
{add a line of description}
{}
{}
{@see SomeOtherEntity2}
{}
}
set cbp [CommentBlockParser process $block]
? [list $cbp status ? STYLEVIOLATION] 1
#
# TODO: Should we enforce a mandatory space line between description and part block?
#
set block {
{@command ::cc}
{}
{add a line of description}
{a second line of description}
{a third line of description}
{@see entity3}
{@see SomeOtherEntity2}
}
set cbp [CommentBlockParser process $block]
? [list $cbp status ? STYLEVIOLATION] 1
set block {
{@command ::cc}
{}
{add a line of description}
{a second line of description}
{a third line of description}
{}
{@see SomeOtherEntity2}
{}
{}
{an erroreneous description line, for now}
}
set cbp [CommentBlockParser process $block]
? [list $cbp status ? STYLEVIOLATION] 1
set block {
{@command ::cc}
{}
{add a line of description}
{a second line of description}
{}
{a third line of description}
{}
{@see SomeOtherEntity2}
}
set cbp [CommentBlockParser process $block]
? [list $cbp status ? STYLEVIOLATION] 0
set block {
{@object ::cc}
{}
{add a line of description}
{a second line of description}
{}
{@see SomeOtherEntity2}
{@xyz SomeOtherEntity2}
}
set cbp [CommentBlockParser process $block]
? [list $cbp status ? INVALIDTAG] 1
set block {
{@class ::cc}
{}
{add a line of description}
{a second line of description}
{}
{@see SomeOtherEntity2}
{@xyz SomeOtherEntity2}
}
set cbp [CommentBlockParser process $block]
? [list $cbp status ? INVALIDTAG] 1
#
# TODO: Where shall we allow the @author tag?! Re-activate
# later, if necessary ...
#
if {0} {
#
# testing the doc object construction
#
set block {
{@object ::o}
{}
{some more text}
{and another line for the description}
{}
{@author stefan.sobernig@wu.ac.at}
{@author gustaf.neumann@wu-wien.ac.at}
}
set cbp [CommentBlockParser process $block]
? [list $cbp status ? COMPLETED] 1
set entity [$cbp current_entity]
? [list ::nsf::is object $entity] 1
? [list $entity info has type ::nx::doc::@object] 1
? [list $entity @author] "stefan.sobernig@wu.ac.at gustaf.neumann@wu-wien.ac.at";
? [list $entity as_text] "some more text and another line for the description";
}
set block {
{@command ::c}
{}
{some text on the command}
{}
{@see ::o}
}
set cbp [CommentBlockParser process $block]
? [list $cbp status ? COMPLETED] 1
set entity [$cbp current_entity]
? [list ::nsf::is object $entity] 1
? [list $entity info has type ::nx::doc::@command] 1
? [list $entity as_text] "some text on the command";
? [list $entity @see] "::o";
set block {
{@class ::C}
{}
{some text on the class entity}
{}
{@class-property attr1 Here! we check whether we can get a valid description block}
{for text spanning multiple lines}
}
set cbp [CommentBlockParser process $block]
? [list $cbp status ? COMPLETED] 1
set entity [$cbp current_entity]
? [list ::nsf::is object $entity] 1
? [list $entity info has type ::nx::doc::@class] 1
? [list $entity as_text] "some text on the class entity";
? [list llength [$entity @property]] 1
? [list [$entity @property] info has type ::nx::doc::@param] 1
? [list [$entity @property] as_text] "Here! we check whether we can get a valid description block for text spanning multiple lines"
}
if {0} {
Test case in-situ-basics {
#
# basic test for in-situ documentation (initblock)
#
#
set script {
package req nx
namespace import -force ::nx::Class
Class create ::Foo {
# The class Foo defines the behavior for all Foo objects
#
# @author gustaf.neumann@wu-wien.ac.at
# @author ssoberni@wu.ac.at
# @.property attr1
#
# This property 1 is wonderful
#
# @see ::nx::VariableSlot
# @see ::nx::MetaSlot
:property attr1
:property attr2
:property attr3
# @.method foo
#
# This describes the foo method
#
# @parameter a Provides a first value
# @parameter b Provides a second value
:method foo {a b} {;}
}
}
# set prj [processor process -sandboxed -type eval $script]
set prj [@project new -name _PROJECT_]
set entity [@class id ::Foo]
? [list ::nsf::is object $entity] 1
? [list $entity info has type ::nx::doc::@class] 1
? [list $entity as_text] "The class Foo defines the behavior for all Foo objects";
? [list $entity @author] "gustaf.neumann@wu-wien.ac.at ssoberni@wu.ac.at"
# TODO: Fix the [@param id] programming scheme to allow (a) for
# entities to be passed and the (b) documented structures
set entity [@property id [@class id ::Foo] class attr1]
? [list ::nsf::is object $entity] 1
? [list $entity info has type ::nx::doc::@property] 1
? [list $entity @see] "::nx::VariableSlot ::nx::MetaSlot";
set entity [@method id ::Foo class foo]
? [list [@class id ::Foo] @method] $entity
? [list ::nsf::is object $entity] 1
? [list $entity info has type ::nx::doc::@method] 1
? [list $entity as_text] "This describes the foo method";
foreach p [$entity @parameter] expected {
"Provides a first value"
"Provides a second value"
} {
? [list expr [list [$p as_text] eq $expected]] 1;
}
$prj destroy
}
# TODO: how to realize scanning and parsing for mixed ex- and
# in-situ documentation? That is, how to differentiate between
# absolutely and relatively qualified comment blocks in line-based
# scanning phase (or later)?
Test case mixed-mode-parsing {
set script {
package req nx
namespace import -force ::nx::*
# @class ::Bar
#
# The class Bar defines the behavior for all Bar objects
#
# @author gustaf.neumann@wu-wien.ac.at
# @author ssoberni@wu.ac.at
# @class.property {::Bar attr1}
#
# This property 1 is wonderful
#
# @see ::nx::VariableSlot
# @see ::nx::MetaSlot
# @class.class-method {::Bar foo}
#
#
# This describes the foo method
#
# @parameter a Provides a first value
# @parameter b Provides a second value
# @class.object-method {::Bar foo}
#
# This describes the per-object foo method
#
# @parameter a Provides a first value
# @parameter b Provides a second value
namespace eval ::ns1 {
::nx::Object create ooo
}
Class create Bar {
:property attr1
:property attr2
:property attr3
# @.method foo
#
# This describes the foo method in the initblock
#
# @parameter a Provides a first value
# @parameter b Provides a second value
:public method foo {a b} {
# This describes the foo method in the method body
#
# @parameter a Provides a first value (refined)
}
:public class method foo {a b c} {
# This describes the per-object foo method in the method body
#
# @parameter b Provides a second value (refined)
# @parameter c Provides a third value (first time)
}
}
}
set prj [processor process -sandboxed -type eval $script]
set entity [@class id ::Bar]
? [list ::nsf::is object $entity] 1
? [list $entity info has type ::nx::doc::@class] 1
? [list $entity as_text] "The class Bar defines the behavior for all Bar objects";
? [list $entity @author] "gustaf.neumann@wu-wien.ac.at ssoberni@wu.ac.at"
# TODO: Fix the [@param id] programming scheme to allow (a) for
# entities to be passed and the (b) documented structures
set entity [@property id [@class id ::Bar] class attr1]
? [list ::nsf::is object $entity] 1
? [list $entity info has type ::nx::doc::@property] 1
? [list $entity @see] "::nx::VariableSlot ::nx::MetaSlot";
set entity [@method id ::Bar class foo]
? [list [@class id ::Bar] @method] $entity
? [list ::nsf::is object $entity] 1
? [list $entity info has type ::nx::doc::@method] 1
? [list $entity as_text] "This describes the foo method in the method body";
foreach p [$entity @parameter] expected {
"Provides a first value (refined)"
"Provides a second value"
} {
? [list expr [list [$p as_text] eq $expected]] 1;
}
set entity [@method id ::Bar object foo]
? [list [@class id ::Bar] @class-object-method] $entity
? [list ::nsf::is object $entity] 1
? [list $entity info has type ::nx::doc::@method] 1
? [list $entity as_text] "This describes the per-object foo method in the method body";
foreach p [$entity @parameter] expected {
"Provides a first value"
"Provides a second value (refined)"
"Provides a third value (first time)"
} {
? [list expr [list [$p as_text] eq $expected]] 1;
}
$prj destroy
}
Test case tag-notations-basics {
#
# Some tests on structured/navigatable tag notations
#
# adding support for parsing levels
# -- @class.object.object {::D o1 o2}
set block {
{@..object o2 We have a tag notation sensitive to the parsing level}
}
set entity [[@ @class ::D] @object o1]
set cbp [CommentBlockParser process -parsing_level 1 -partof_entity $entity $block]
? [list $cbp status ? LEVELMISMATCH] 1
set cbp [CommentBlockParser process -parsing_level 2 -partof_entity $entity $block]
? [list $cbp status ? COMPLETED] 1
set entity [$cbp current_entity]
? [list ::nsf::object::exists $entity] 1
? [list $entity info has type ::nx::doc::@object] 1
? [list $entity as_text] "We have a tag notation sensitive to the parsing level"
set block {
{@..object {o2 o3} We still look for balanced specs}
}
set entity [[@ @class ::D] @object o1]
set cbp [CommentBlockParser process -parsing_level 2 -partof_entity $entity $block]
? [list $cbp status ? STYLEVIOLATION] 1
# This fails because we do not allow uninitialized/non-existing
# entity objects (@object o) along the resolution path ...
set block {
{@class.object.property {::C o attr1} We have an invalid specification}
}
set cbp [CommentBlockParser process $block]
? [list $cbp status ? INVALIDTAG] 1
# ? [list $cbp message] "The tag 'object' is not supported for the entity type '@class'"
set block {
{@class.method.property attr1 We have an imbalanced specification (the names are underspecified!)}
}
set cbp [CommentBlockParser process $block]
? [list $cbp status ? STYLEVIOLATION] 1
? [list $cbp message] "Imbalanced tag line spec: 'class method property' vs. 'attr1'"
# For now, we do not verify and use a fixed scope of permissive tag
# names. So, punctuation errors or typos are most probably reported
# as imbalanced specs. In the mid-term run, this should rather
# become an INVALIDTAG condition.
set block {
{@cla.ss.method.parameter {::C foo p1} We mistyped a tag fragment}
}
set cbp [CommentBlockParser process $block]
? [list $cbp status ? STYLEVIOLATION] 1
? [list $cbp message] "Imbalanced tag line spec: 'cla ss method parameter' vs. '::C foo p1'"
set block {
{@cla,ss.method.parameter {::C foo p1} We mistyped a tag fragment}
}
set cbp [CommentBlockParser process $block]
? [list $cbp status ? INVALIDTAG] 1
? [list $cbp message] "The entity type '@cla,ss' is not available."
}
Test case tag-notations-extended {
set script {
# @class ::C
#
# The global description of ::C
#
# @property attr1 Here we can only provide a description block for object parameters
# @class.object-method {::C sub}
#
# For now, we have to declare a family of sub methods explicitly
# (allows for providing some overview, shared description)
# @class.property {::C attr1} Here, we could also write '@class.class-property \{::C attr1\}', @property is a mere forwarder! In the context section, only one-liners are allowed!
# @class.object.property {::C foo p1} A short description is ...
#
# .. is overruled by a long one ...
# If addressing to a nested object, one strategy would be to use
# @object and provide the object identifier (which reflects the
# nesting, e.g. ::C::foo). However, we cannot distinguish between
# namespace qualifiers denoting an object, class or owning
# namespace!
#
# ISSUE: If specifying an axis ".object", we would have to define
# a part property @object on @class and @object. However, @object
# would be ambiguous now: It could be called in a freestanding
# (absolute) manner AND in a contextualised manner (in an init
# block). In the latter case, it would fail because we would have
# to provide a FQ'ed name (which defeats the purpose of a nested =
# contextualised notation).
#
# SO: for now, we introduce a part property child-object (and
# child-class?) to discrimate between the two situations ...
#
# TODO: How to register this so created @object entity as nested
# object with the doc entity represented the parent object?
Class create C {
# This is the initblock description of ::C which overwrites the
# global description (see above)
# @.property attr1
#
# This is equivalent to writing "@class-property attr1"
:property attr1 {
# This description does not apply to the object parameter
# "attr1" owned by the ::C class, rather it is a description
# of the property slot object! How should we deal with this
# situation? Should this level overwrite the top-level and
# initblock descriptions?
}
# @.class-object-property attr2 Carries a short desc only
:class property attr2
# @.method foo
#
# @parameter p1
set fooHandle [:public method foo {p1} {
# Here goes some method-body-level description
#
# @parameter p1 The most specific level!
return [current method]-$p1-[current]
}]
# @.object-method bar
#
# Before referring to its parts, an entity must exist; so
# declare eagerly ...
# @.class-object-method.parameter {bar p1}
#
# This extended form allows one to describe a method parameter with all
# its structural features!
set barHandle [:public class method bar {p1} {
return [current method]-$p1-[current]
}]
# @.object foo 'foo' needs to be defined before referencing any of its parts!
# @.object.property {foo p1}
#
# The first element in the name list is resolved into a fully
# qualified (absolute) entity, based on the object owning the
# initblock!
Object create [current]::foo {
# Adding a line for the first time (not processed in the initblock phase!)
# @..property p1
#
# This is equivalent to stating "@class-object-property p1"
:property p1
}
# @.class Foo X
#
# By providing a fully-qualified identifier ("::Foo") you leave the
# context of the initblock-owning object, i.e. you would NOT refer to
# a nested class object named "Foo" anymore!
# @.class.property {Foo p1}
#
# This is equivalent to stating "@child-class.class-property {Foo p1}"
# @.class.class-object-property {Foo p2} Y
Class create [current]::Foo {
# @..property p1
#
#
# This is equivalent to stating "@class-property p1"; or
# '@class.object.property {::C Foo p1}' from the top-level.
:property p1
# @..class-object-property p2
:class property p2
}
# @.class-object-method.sub-method {sub foo}
#
# ISSUE: Should submethods be navigatable through "method" (i.e.,
# "@method.method.method ...") or "submethod" (i.e.,
# "@method.submethod.submethod ...")? ISSUE: Should it be sub* with
# "-" (to correspond to "@class-object-method", "@class-method")? Also, we
# could allow both (@sub-method is the property name, @method is a
# forwarder in the context of an owning @method object!)
#
# @parameter p1 Some words on p1
:class alias "sub foo" $fooHandle
# @.method sub
#
# The desc of the ensemble object 'sub'
#
# @sub-method bar Only description available here ...
# ISSUE: Should the helper object "sub" be documentable in its own
# right? This would be feasible with the dotted notation from
# within and outside the init block, e.g. "@object sub" or
# "@class.object {::C sub}"
#
# ISSUE: Is it correct to say the sub appears as per-object method
# and so do its submethods? Or is it misleading to document it that
# way? Having an "@class-object-submethod" would not make much sense to
# me?!
:alias "sub bar" $barHandle
# @.class-object-method sub A brief desc
# @.class-object-method {"sub foo2"}
#
# could allow both (@sub-method is the property name, @method is a
# forwarder in the context of an owning @method object!)
#
# @parameter p1 Some words on p1
# @see anotherentity
# @author ss@thinkersfoot.net
:class alias "sub foo2" $fooHandle
}
}
#
# 1) process the top-level comments (PARSING LEVEL 0)
#
processor readin $script
# --testing-- "@class ::C"
set entity [@class id ::C]
? [list ::nsf::object::exists $entity] 1
? [list $entity info has type ::nx::doc::@class] 1
? [list $entity as_text] "The global description of ::C";
# --testing-- "@class.property {::C attr1}"
set entity [@property id $entity class attr1]
? [list ::nsf::object::exists $entity] 1
? [list $entity info has type ::nx::doc::@property] 1
? [list $entity as_text] "Here, we could also write '@class.class-property {::C attr1}', @property is a mere forwarder! In the context section, only one-liners are allowed!"
# --testing-- "@class.object.property {::C foo p1} A short description is ..."
# set entity [@property id $entity class attr1]
# set entity [@object id -partof_name ::C -scope child foo]
# ? [list ::nsf::object::exists $entity] 1
# ? [list $entity info has type ::nx::doc::@object] 1
# ? [list $entity as_text] ""
# set entity [@property id $entity object p1]
# ? [list ::nsf::object::exists $entity] 1
# ? [list $entity info has type ::nx::doc::@property] 1
# ? [list $entity as_text] ".. is overruled by a long one ..."
set entity [@object id ::C::foo]
? [list ::nsf::object::exists $entity] 0
set entity [@property id $entity class p1]
? [list ::nsf::object::exists $entity] 0
# ? [list $entity info has type ::nx::doc::@property] 1
# ? [list $entity as_text] ".. is overruled by a long one ..."
# --testing-- @class-object-property attr2 (its non-existence)
set entity [@property id [@class id ::C] object attr2]
? [list ::nsf::object::exists $entity] 0
# --testing-- @child-class Foo (its non-existence)
set entity [@class id ::C::Foo]
? [list ::nsf::object::exists $entity] 0
# --testing -- @method foo (its non-existence)
set entity [@method id ::C class foo]
? [list ::nsf::object::exists $entity] 0
# --testing-- @class-object-method.parameter {bar p1} (its non-existence)
set entity [@parameter id [@method id ::C class bar] "" p1]
? [list ::nsf::object::exists $entity] 0
# --testing-- @child-object.property {foo p1} (its non-existence)
set cl [@class id ::C::Foo]
? [list ::nsf::object::exists $entity] 0
set entity [@property id $cl class p1]
? [list ::nsf::object::exists $entity] 0
set entity [@property id $cl object p2]
? [list ::nsf::object::exists $entity] 0
#
# 2) process the initblock comments (PARSING LEVEL 1)
#
puts stderr -----CMD------
::nsf::configure keepcmds true
eval $script
::nsf::configure keepcmds false
lassign [processor readin \
-parsing_level 1 \
-docstring \
-tag @class \
-name ::C \
[::C eval {set :__cmd(__initblock)}]] _ processed_entities
# a) existing, but modified ...
set entity [@class id ::C]
? $_ $entity
? [list ::nsf::object::exists $entity] 1
? [list $entity info has type ::nx::doc::@class] 1
? [list $entity as_text] "This is the initblock description of ::C which overwrites the global description (see above)"
set entity [@property id $entity class attr1]
? [list ::nsf::object::exists $entity] 1
? [list $entity info has type ::nx::doc::@property] 1
? [list $entity as_text] {This is equivalent to writing "@class-property attr1"}
set entity [@object id ::C::foo]
? [list ::nsf::object::exists $entity] 1
? [list $entity info has type ::nx::doc::@object] 1
? [list $entity as_text] "'foo' needs to be defined before referencing any of its parts!"; # still empty!
set entity [@property id $entity object p1]
? [list ::nsf::object::exists $entity] 1
? [list $entity info has type ::nx::doc::@property] 1
? [list $entity as_text] "The first element in the name list is resolved into a fully qualified (absolute) entity, based on the object owning the initblock!"
# b) newly added ...
# --testing-- @class-object-property attr2
set entity [@property id [@class id ::C] object attr2]
? [list ::nsf::object::exists $entity] 1
? [list $entity info has type ::nx::doc::@property] 1
? [list $entity as_text] "Carries a short desc only";
# --testing-- @child-class Foo
# TODO: provide a check against fully-qualified names in part specifications
set entity [@class id ::C::Foo]
? [list ::nsf::object::exists $entity] 1
? [list $entity info has type ::nx::doc::@class] 1
? [list $entity as_text] {By providing a fully-qualified identifier ("::Foo") you leave the context of the initblock owning object, i.e. you would NOT refer to a nested class object named "Foo" anymore!}
set entity [@property id [@class id ::C] class p1]
? [list ::nsf::object::exists $entity] 0; # should be 0 at this stage!
# --testing -- @method foo
set entity [@method id ::C class foo]
? [list ::nsf::object::exists $entity] 1
? [list $entity as_text] ""
# --testing-- @class-object-method.parameter {bar p1} (its non-existence) It
# still cannot exist as a documented entity, as the class method
# has not been initialized before!
set entity [@parameter id [@method id ::C class bar] "" p1]
? [list ::nsf::object::exists $entity] 0
# --testing-- @child-class.property {foo p1} (its non-existence)
# --testing-- @child-class.object-property {foo p2} (its non-existence)
set cl [@class id ::C::Foo]
? [list ::nsf::object::exists $cl] 1
set entity [@property id $cl class p1]
? [list ::nsf::object::exists $entity] 1
? [list $entity as_text] {This is equivalent to stating "@child-class.class-property {Foo p1}"}
set entity [@property id $cl object p2]
? [list ::nsf::object::exists $entity] 1
? [list $entity as_text] "Y"
set entity [@method id ::C class sub]
? [list ::nsf::object::exists $entity] 1
? [list $entity as_text] "The desc of the ensemble object 'sub'"
set entity [@method id ::C class sub::bar]
? [list ::nsf::object::exists $entity] 1
? [list $entity as_text] "Only description available here ..."
set entity [@method id ::C object sub]
? [list ::nsf::object::exists $entity] 1
? [list $entity as_text] "A brief desc"
set entity [@method id ::C object sub::foo2]
? [list ::nsf::object::exists $entity] 1
? [list $entity info has type ::nx::doc::@method] 1
? [list $entity as_text] "could allow both (@sub-method is the property name, @method is a forwarder in the context of an owning @method object!)"
? [list $entity @see] "anotherentity"
# TODO: @author not supported for @method (fine so?)
# ? [list $entity @author] "ss@thinkersfoot"
set entity [@parameter id $entity "" p1]
? [list ::nsf::object::exists $entity] 1
? [list $entity as_text] "Some words on p1"
#
# 3a) process the property initblocks and method bodies (PARSING LEVEL 2)!
#
set project [@project new -name "_%@"]
$project sandbox [Sandbox new]
processor process=@class $project [@class id ::C]
# methods ...
set entity [@method id ::C class foo]
? [list ::nsf::object::exists $entity] 1
? [list $entity as_text] "Here goes some method-body-level description"
set entity [@parameter id [@method id ::C class foo] "" p1]
? [list ::nsf::object::exists $entity] 1
? [list $entity as_text] "The most specific level!"
# attributes ...
# attr1
set entity [@property id [@class id ::C] class attr1]
? [list ::nsf::object::exists $entity] 1
? [list $entity info has type ::nx::doc::@property] 1
? [list $entity as_text] {This description does not apply to the object parameter "attr1" owned by the ::C class, rather it is a description of the property slot object! How should we deal with this situation? Should this level overwrite the top-level and initblock descriptions?}
#
# 3b) nested objects/ classes (PARSING LEVEL 2)!
#
processor readin \
-docstring \
-parsing_level 2 \
-tag @object \
-name ::C::foo \
[::C::foo eval {set :__cmd(__initblock)}]
processor process=@object $project [@object id ::C::foo]
set entity [@object id ::C::foo]
? [list ::nsf::object::exists $entity] 1
? [list $entity info has type ::nx::doc::@object] 1
? [list $entity as_text] "Adding a line for the first time (not processed in the initblock phase!)"; # still empty!
set entity [@property id $entity object p1]
? [list ::nsf::object::exists $entity] 1
? [list $entity info has type ::nx::doc::@property] 1
? [list $entity as_text] {This is equivalent to stating "@class-object-property p1"}
processor readin \
-docstring \
-parsing_level 2 \
-tag @class \
-name ::C::Foo \
[::C::Foo eval {set :__cmd(__initblock)}]
processor process=@class $project [@class id ::C::Foo]
set cl [@class id ::C::Foo]
? [list ::nsf::object::exists $cl] 1
set entity [@property id $cl class p1]
? [list ::nsf::object::exists $entity] 1
? [list $entity as_text] {This is equivalent to stating "@class-property p1"; or '@class.object.property {::C Foo p1}' from the top-level.}
set entity [@property id $cl object p2]
? [list ::nsf::object::exists $entity] 1
? [list $entity as_text] ""
#
# basic testing of "properties" (switch attributes)
#
? [list $cl eval {set :@deprecated}] 0
? [list $cl eval {set :@stashed}] 0
? [list $cl eval {set :@c-implemented}] 0
? [list $cl @deprecated] 1
? [list $cl @stashed] 1
? [list $cl @c-implemented] 1
? [list $cl eval {set :@deprecated}] 1
? [list $cl eval {set :@stashed}] 1
? [list $cl eval {set :@c-implemented}] 1
set entity [@method id ::C class foo]
? [list $entity eval {set :@syshook}] 0
? [list $entity @syshook] 1
? [list $entity eval {set :@syshook}] 1
? [list $entity @syshook 0] {wrong # args: should be "get obj prop"}
? [list $entity eval {set :@syshook 0}] 0
? [list $entity @syshook] 1
}
Test case switch-parts {
set script {
package req nx
namespace import ::nx::*
Class create Enil {
# The class Enil defines the behavior for all Enil objects,
# however, it is deprecated and will be removed from the
# provided doc entities in the next iteration ...
#
# @author ssoberni@wu.ac.at
# @deprecated
# @.property attr1
#
# This property 1 will be invisible in the generated doc
#
# @stashed
:property attr1
# @.method foo
#
# This describes the foo method which is called from within the
# nx-enabled Tcl engine
#
# @syshook
:public method foo {a b} {;}
:public method baz {} {
# This method entity sets a couple of properties in series ...
#
# @property c-implemented syshook
}
}
}
set prj [processor process -sandboxed -type eval $script]
set cl [@class id ::Enil]
? [list $cl eval {set :@deprecated}] 1
? [list $cl @deprecated] 1
? [list $cl eval {set :@c-implemented}] 0
? [list $cl eval {set :@stashed}] 0
? [list $cl @author] ssoberni@wu.ac.at
set entity [@property id $cl class attr1]
? [list $entity eval {set :@deprecated}] 0
? [list $entity eval {set :@stashed}] 1
? [list $entity @stashed] 1
? [list $entity eval {set :@c-implemented}] 0
set entity [@method id ::Enil class foo]
? [list $entity eval {set :@deprecated}] 0
? [list $entity eval {set :@stashed}] 0
? [list $entity eval {set :@c-implemented}] 0
? [list $entity eval {set :@syshook}] 1
? [list $entity @syshook] 1
set entity [@method id ::Enil class baz]
? [list $entity eval {set :@deprecated}] 0
? [list $entity eval {set :@stashed}] 0
? [list $entity eval {set :@c-implemented}] 1
? [list $entity @c-implemented] 1
? [list $entity eval {set :@syshook}] 1
? [list $entity @syshook] 1
}
}
# # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # #
#
# Local variables:
# mode: tcl
# tcl-indent-level: 2
# indent-tabs-mode: nil
# End:
|