-
Notifications
You must be signed in to change notification settings - Fork 15
Added parametrized chunks #147
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,6 +16,9 @@ | |
| ## | ||
| ###################################### | ||
|
|
||
| BindGlobal( "AUTODOC_IdentifierLetters", | ||
| "+-0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz" ); | ||
|
|
||
| DeclareGlobalFunction( "AUTODOC_TREE_NODE_NAME_ITERATOR" ); | ||
| DeclareGlobalFunction( "AUTODOC_LABEL_OF_CONTEXT" ); | ||
| DeclareGlobalFunction( "AUTODOC_INSTALL_TREE_SETTERS" ); | ||
|
|
@@ -57,6 +60,7 @@ DeclareOperation( "DocumentationExample", [ IsTreeForDocumentation, IsList ] ); | |
| DeclareOperation( "DocumentationExample", [ IsTreeForDocumentation ] ); | ||
| DeclareOperation( "DocumentationDummy", [ IsTreeForDocumentation, IsString, IsList ] ); | ||
| DeclareOperation( "DocumentationDummy", [ IsTreeForDocumentation, IsString ] ); | ||
| DeclareOperation( "DocumentationDummyInstance", [ IsTreeForDocumentation, IsTreeForDocumentationNode ] ); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why this name
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is not related to parametrized chunks. Previously, for a chunk a dummy was created, and the same dummy was inserted into the tree. Now, for a chunk a dummy is created, but each time a chunk is inserted in the tree, a dummy instance is inserted.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't see how you can say it is not related when clearly they are related (one is used to implement the other) :-). Anyway: I guess I find these names very unfortunate. What's a "dummy" here? I grepped through the code, and the whole "dummy" stuff is only ever used to implement chunks. So why isn't it called "chunk"? I am also confused as to the relation between "Dummy" and "DummyInstance". While I am pretty hopeful I could figure it out from digging through the code, I feel that (a) better names, and (b) at least some minimal comments, would go a long way to making this code more understandable (and hence maintainable). What I gathered so far is that before this PR, |
||
| DeclareOperation( "DocumentationCode", [ IsTreeForDocumentation, IsString, IsList ] ); | ||
| DeclareOperation( "DocumentationCode", [ IsTreeForDocumentation, IsString ] ); | ||
| DeclareOperation( "DocumentationManItem", [ IsTreeForDocumentation ] ); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,10 +10,6 @@ | |
| ## | ||
| ############################################################################# | ||
|
|
||
| ## | ||
| BindGlobal( "AUTODOC_IdentifierLetters", | ||
| "+-0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz" ); | ||
|
|
||
| DeclareRepresentation( "IsTreeForDocumentationRep", | ||
| IsAttributeStoringRep and IsTreeForDocumentation, | ||
| [ ] ); | ||
|
|
@@ -117,6 +113,15 @@ BindGlobal( "TheTypeOfDocumentationTreeCodeNodes", | |
| NewType( TheFamilyOfDocumentationTreeNodes, | ||
| IsTreeForDocumentationCodeNodeRep ) ); | ||
|
|
||
| ## DocumentationDummyInstance | ||
| DeclareRepresentation( "IsTreeForDocumentationDummyInstanceNodeRep", | ||
| IsTreeForDocumentationNodeRep, | ||
| [ ] ); | ||
|
|
||
| BindGlobal( "TheTypeOfDocumentationTreeDummyInstanceNodes", | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why does the type have an extra "Tree" in the name? |
||
| NewType( TheFamilyOfDocumentationTreeNodes, | ||
| IsTreeForDocumentationDummyInstanceNodeRep ) ); | ||
|
|
||
| ################################### | ||
| ## | ||
| ## Tools | ||
|
|
@@ -263,6 +268,15 @@ InstallMethod( DocumentationDummy, [ IsTreeForDocumentation, IsString ], | |
| return node; | ||
| end ); | ||
|
|
||
| InstallMethod( DocumentationDummyInstance, [ IsTreeForDocumentation, IsTreeForDocumentationDummyNodeRep ], | ||
| function( tree, dummy_node ) | ||
| local node; | ||
| node := rec( dummy_node := dummy_node ); | ||
| ObjectifyWithAttributes( node, TheTypeOfDocumentationTreeDummyInstanceNodes, | ||
| Label, Concatenation( Label( dummy_node ), "_", String( AUTODOC_TREE_NODE_NAME_ITERATOR( tree ) ) ) ); | ||
| return node; | ||
| end ); | ||
|
|
||
| ## | ||
| InstallMethod( DocumentationCode, [ IsTreeForDocumentation, IsString, IsList ], | ||
| function( tree, name, context ) | ||
|
|
@@ -637,6 +651,36 @@ InstallMethod( WriteDocumentation, [ IsTreeForDocumentationDummyNodeRep, IsStrea | |
| fi; | ||
| end ); | ||
|
|
||
| ## | ||
| InstallMethod( WriteDocumentation, [ IsTreeForDocumentationDummyInstanceNodeRep, IsStream ], | ||
| function( node, filestream ) | ||
| local dummy, variables, variable_values, new_content, current_variable, current_variable_value, | ||
| i, j, current_string, dummy_label; | ||
|
|
||
| dummy := node!.dummy_node; | ||
| dummy_label := Label( dummy ); | ||
| if not IsBound( dummy!.content ) then | ||
| return; | ||
| fi; | ||
| new_content := ShallowCopy( dummy!.content ); | ||
| variables := dummy!.variable_names; | ||
| variables := List( variables, i -> Concatenation( "%{", i, "}" ) ); | ||
| variable_values := node!.variable_values; | ||
| if Length( variables ) <> Length( variable_values ) then | ||
| Error( "While inserting chunk ", dummy_label, ": wrong number of parameter values" ); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This error should not ever happen, right? Because of filtering we performed before. So, Perhaps turn this into an Although... does the system prevent the user from re-defining a chunk? I.e. from using
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I just tried this, and you can do it (undocumented!) -- seems the chunks get concatenated. Is that intentional? I am tempted to forbid it. Conversely, it is possible to insert a non-existing chunk, which I think will make for hilarious debugging fun. Now it's OK to insert a chunk before it is declared (so you can't check for this in
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unrelated, but while looking through the code, I saw that there is a 3-arg version of |
||
| fi; | ||
| for i in [ 1 .. Length( variables ) ] do | ||
| current_variable := variables[ i ]; | ||
| current_variable_value := variable_values[ i ]; | ||
| for j in [ 1 .. Length( new_content ) ] do | ||
| new_content[ j ] := ReplacedString( new_content[ j ], current_variable, current_variable_value ); | ||
| od; | ||
| od; | ||
|
|
||
| WriteDocumentation( new_content, filestream ); | ||
|
|
||
| end ); | ||
|
|
||
| ## | ||
| InstallMethod( WriteDocumentation, [ IsTreeForDocumentationExampleNodeRep, IsStream ], | ||
| function( node, filestream ) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -613,14 +613,50 @@ InstallGlobalFunction( AutoDoc_Parser_ReadFiles, | |
| current_item!.level := Int( current_command[ 2 ] ); | ||
| end, | ||
| @InsertChunk := function() | ||
| Add( current_item, DocumentationDummy( tree, current_command[ 2 ] ) ); | ||
| local parameters, vars, title, inserted_dummy, position_first_space; | ||
| parameters := current_command[ 2 ]; | ||
| position_first_space := Position( parameters, ' ' ); | ||
| if position_first_space = fail then | ||
| title := parameters; | ||
| vars := [ ]; | ||
| elif IsInt( position_first_space ) then | ||
| title := parameters{[ 1 .. position_first_space - 1 ]}; | ||
| vars := parameters{[ position_first_space + 1 .. Length( parameters ) ]}; | ||
| vars := SplitString( vars, "," ); | ||
| else | ||
| ErrorWithPos( Concatenation( "Wrong InsertChunk parameters: ", parameters ) ); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That error text is no very helpful. What is wrong? |
||
| fi; | ||
| inserted_dummy := DocumentationDummyInstance( tree, DocumentationDummy( tree, title ) ); | ||
| inserted_dummy!.variable_values := vars; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It'd feel more natural to me pass |
||
| Add( current_item, inserted_dummy ); | ||
| end, | ||
| @InsertSystem := ~.@InsertChunk, | ||
| @BeginChunk := function() | ||
| local parameters, title, vars, current_var; | ||
| if IsBound( current_item ) then | ||
| Add( context_stack, current_item ); | ||
| fi; | ||
| current_item := DocumentationDummy( tree, current_command[ 2 ] ); | ||
| parameters := SplitString( current_command[ 2 ], " " ); | ||
| if Length( parameters ) = 1 then | ||
| vars := [ ]; | ||
| title := parameters[ 1 ]; | ||
| elif Length( parameters ) = 2 then | ||
| vars := parameters[ 2 ]; | ||
| vars := SplitString( vars, "," ); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would add a check like Thinking about it, the chunk name should also be restricted this way.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we can restrict the var names to be alphanumeric, probably with |
||
| title := parameters[ 1 ]; | ||
| else | ||
| ErrorWithPos( Concatenation( "Wrong chunk parameters: ", current_command[ 2 ] ) ); | ||
| fi; | ||
| if not ForAll( title, i -> i in AUTODOC_IdentifierLetters ) then | ||
| ErrorWithPos( Concatenation( "Wrong character in chunk title: ", title ) ); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That error message is not very helpful. Which character is wrong? And what does that mean? Perhaps "Invalid chunk name TITLE (chunk names must be identifiers)" -- the user can lookup in the manual what an "identifier" is. Or else explicitly say it, e.g., "(chunk names must only contain letters, digits and underscores)" |
||
| fi; | ||
| for current_var in vars do | ||
| if not ForAll( current_var, i -> i in AUTODOC_IdentifierLetters ) then | ||
| ErrorWithPos( Concatenation( "Wrong character in chunk parameter: ", current_var ) ); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Similar as above. |
||
| fi; | ||
| od; | ||
| current_item := DocumentationDummy( tree, title ); | ||
| current_item!.variable_names := vars; | ||
| end, | ||
| @Chunk := ~.@BeginChunk, | ||
| @System := ~.@BeginChunk, | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So an AutoDoc identifier is allowed to contain minus and plus? Why? What is this used for?