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

New "createToken" helper functions. #329

Closed
bd82 opened this issue Dec 19, 2016 · 3 comments · Fixed by #330
Closed

New "createToken" helper functions. #329

bd82 opened this issue Dec 19, 2016 · 3 comments · Fixed by #330
Labels

Comments

@bd82
Copy link
Member

bd82 commented Dec 19, 2016

The Old "extendToken" helpers were not suitable for handling multiple optional arguments.
So a config object is now in the new API.

// instead of:
extendToken("Integer", /\d+/, Literal)
// the new API is:
createToken(name: "Integer", pattern: /\d+/, parent: Literal)

The old APIs are still present but are considered deprecated and will probably be removed at (or before)
version 1.0.0

@bd82 bd82 added the API label Dec 19, 2016
bd82 added a commit that referenced this issue Dec 19, 2016
The old extendToken utilities have been deprecated
as their API did not allow to support multiple optional arguments easily.

fixes #156
fixes #329
@bd82
Copy link
Member Author

bd82 commented Dec 19, 2016

open question:
Use "pattern" or "PATTERN" (low/upper case) for the property names?

The problem is that when defining Tokens ESNext classes, the Chevrotain convention was to use
upper case names:

class Integer extends Token {
  static PATTERN = /\d+/
  static LABEL = "A whole number"
}

but when using helper functions with the config object it seems more idiomatic to use low case property names.

or perhaps we should(can?) be idiot proof for these case issues?

bd82 added a commit that referenced this issue Dec 20, 2016
The old extendToken utilities have been deprecated
as their API did not allow to support multiple optional arguments easily.

fixes #156
fixes #329
bd82 added a commit that referenced this issue Dec 20, 2016
The old extendToken utilities have been deprecated
as their API did not allow to support multiple optional arguments easily.

fixes #156
fixes #329
bd82 added a commit that referenced this issue Dec 20, 2016
The old extendToken utilities have been deprecated
as their API did not allow to support multiple optional arguments easily.

fixes #156
fixes #329
bd82 added a commit that referenced this issue Dec 20, 2016
The old extendToken utilities have been deprecated
as their API did not allow to support multiple optional arguments easily.

fixes #156
fixes #329
bd82 added a commit that referenced this issue Dec 20, 2016
The old extendToken utilities have been deprecated
as their API did not allow to support multiple optional arguments easily.

fixes #156
fixes #329
bd82 added a commit that referenced this issue Dec 21, 2016
The old extendToken utilities have been deprecated
as their API did not allow to support multiple optional arguments easily.

fixes #156
fixes #329
bd82 added a commit that referenced this issue Dec 21, 2016
The old extendToken utilities have been deprecated
as their API did not allow to support multiple optional arguments easily.

fixes #156
fixes #329
bd82 added a commit that referenced this issue Dec 21, 2016
The old extendToken utilities have been deprecated
as their API did not allow to support multiple optional arguments easily.

fixes #156
fixes #329
bd82 added a commit that referenced this issue Dec 21, 2016
The old extendToken utilities have been deprecated
as their API did not allow to support multiple optional arguments easily.

fixes #156
fixes #329
bd82 added a commit that referenced this issue Dec 21, 2016
The old extendToken utilities have been deprecated
as their API did not allow to support multiple optional arguments easily.

fixes #156
fixes #329
@bd82 bd82 closed this as completed in #330 Dec 21, 2016
@bd82
Copy link
Member Author

bd82 commented Dec 21, 2016

Use "pattern" or "PATTERN" (low/upper case) for the property names?

Being 100% tolerant to API mistakes in this case will just add unneeded complexity.
The common case is a user transitioning from ES5 "createToken" syntax to
ESNext classes with static properties.

In that case the static property names will have to be renamed to uppercase (pattern --> PATTERN).
There already exists a validation that checks for missing PATTERN when initializing a Lexer.
This means that the most common mistake will be caught and properly displayed to the user.

I do not believe additional validations are warranted at this time.

@bd82
Copy link
Member Author

bd82 commented Dec 22, 2016

reopening to remind myself to modify the playground examples.

@bd82 bd82 reopened this Dec 22, 2016
@bd82 bd82 closed this as completed in 6669919 Dec 25, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant