Skip to content
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

Allow typed tokens of the Tavor format to be defined outside from the parser #85

Merged
merged 2 commits into from
Apr 2, 2015

Conversation

yblein
Copy link
Contributor

@yblein yblein commented Mar 24, 2015

Types tokens are now in charge of parsing their arguments and registering themselves.
I'm wondering if token/types.go should be moved to a separate package token/typedso that token.RegisterTyped becomes typed.Register.

type CreateTyped func(argParser ArgumentsParser) (Token, error)

// typedLookup is a mapping from typed token names to their creation functions
var typedLookup = make(map[string]CreateTyped)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's be more specific here since this is a global variable, please name this "typedTokenLookup"

@zimmski
Copy link
Owner

zimmski commented Mar 27, 2015

Ok so I think this is pretty good looking :-) Please attend to the comments.
As you can see I am a bit particular about new lines. If you look through the code you can see a lot of new lines. This is at first a little weird but this can by very handy.

@yblein
Copy link
Contributor Author

yblein commented Mar 27, 2015

I'm not quite familiar with the PR system of Github yet. At this point, in order to fix the code according to your remarks, should I overwrite this commit or make new commits?

@zimmski
Copy link
Owner

zimmski commented Mar 27, 2015

Squash them in the current commit. The comments should then marked as "resolved" when their code reference changes.

@zimmski
Copy link
Owner

zimmski commented Mar 27, 2015

If you like you can change the documentation too https://github.com/zimmski/tavor#extend-typed-tokens but I can also put that on my list.

@yblein yblein force-pushed the external-typed-tokens branch 2 times, most recently from 772b4b6 to de600d5 Compare March 27, 2015 15:44
@@ -0,0 +1,59 @@
package token
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The issue closed itself, sorry. Re-opening here.
"NewTyped, ListTyped, RegisterTyped, typedLookup, CreateTypedFunc and ArgumentsTypedParser" sounds coherent.
However I'm still wondering if this shouldn't move to a new token/typed package.

  • An almost empty package is not that bad if it permits a clean API;
  • The functions are going to get mixed up with the whole token package in godoc and this will get worse when adding e.g. the token attributes.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The argument for the empty package is very true. The argument about the functions is also true, but godoc is already too crowded when it comes to the token package. Do not get me wrong, my API-mind also screams to put this into token/typed but the Go-way is a bit different. Have a look at the io package. It seems also crowded. So I think it is OK to put this into token since it resides in its own file there. And I rather have another token specific API in the token package than a pattern breakage.
There is however a problem with the token package. I put some things there that should be somewhere else, e.g., the parser stuff. I need to refactore the package but that is another issue and does not concern your PR.

Allow typed tokens of the Tavor format to be defined outside from the
parser.
@yblein
Copy link
Contributor Author

yblein commented Mar 31, 2015

I believe I fixed everything according to your remarks. We can move token/typed.go to a new package later if needed. I also updated the README.

@zimmski
Copy link
Owner

zimmski commented Apr 2, 2015

I will take another look. Sorry for taking so long I received a big amount of mails in the last couple of days because of the GSoC. Since the deadline has passed, it finally slowed down 👍

> **Note:** The mentioned implementation inconveniences will be addressed in future versions of Tavor.
Typed tokens provide additional types for formats. It is possible to define new typed tokens by calling the [`token.RegisterTyped`](https://godoc.org/github.com/zimmski/tavor/token#RegisterTyped) function. It is only necessary to implement the [Token interface](https://godoc.org/github.com/zimmski/tavor/token#Token), since typed tokens behave like regular tokens. Arguments for the typed tokens are used as initialization values for the instanced token. It is therefore not possible to lookup argument values after the typed token definition is processed.
An example of typed token creation function can be found in [the sequence token](/token/sequences/sequence.go#L29). Currently, the arguments of a typed token are limited to integers. To support new argument types, it is necessary to extend the [ArgumentsTypedParser](https://godoc.org/github.com/zimmski/tavor/token#ArgumentsTypedParser) interface and [its implementation](/parser/typed.go). To add token attributes to typed tokens, please have a look at the [token attributes section](#extend-token-attributes).
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am wondering if it is a good idea to put a reference to a line number in the documentation but since this is an init function I do not know a way to do this with godoc.

zimmski added a commit that referenced this pull request Apr 2, 2015
Allow typed tokens of the Tavor format to be defined outside the parser
@zimmski zimmski merged commit e33a26f into zimmski:master Apr 2, 2015
@zimmski
Copy link
Owner

zimmski commented Apr 2, 2015

This looks superb, well done! Your argumentation was also very sharp during the issue planing and the PR. I am looking forward to see more :-)

@yblein yblein deleted the external-typed-tokens branch April 2, 2015 12:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants