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

TokenType structure and API #1041

Open
bd82 opened this issue Sep 11, 2019 · 3 comments
Open

TokenType structure and API #1041

bd82 opened this issue Sep 11, 2019 · 3 comments
Labels

Comments

@bd82
Copy link
Member

bd82 commented Sep 11, 2019

The TokenType structure has many optional properties.

export interface TokenType {
    name: string
    GROUP?: string
    PATTERN?: TokenPattern
    LABEL?: string
    LONGER_ALT?: TokenType
    POP_MODE?: boolean
    PUSH_MODE?: string
    LINE_BREAKS?: boolean
    CATEGORIES?: TokenType[]
    tokenTypeIdx?: number
    categoryMatches?: number[]
    categoryMatchesMap?: {
        [tokType: number]: boolean
    }
    isParent?: boolean
    START_CHARS_HINT?: (string | number)[]
}

I believe this is due to legacy reasons as in the past TokenTypes could be classes with static properties. The fact this structure only has a single mandatory property (name) means that any API that accepts TokenType (e.g CONSUME) could also accept (by mistake) other similar structures. For example a JS Function has name property and is therefore acceptable anywhere a TokenType is accepted.

I believe the TokenType structure should more closely match what is returned by "createToken"
which means a-lot less if any optional properties.

Also getting rid of the upper case property names would also be advisable.

@bd82 bd82 added the API label Sep 11, 2019
@bd82
Copy link
Member Author

bd82 commented Sep 11, 2019

By definition this is a breaking change, however if the creation of TokenTypes is always done by
calling createToken, does it matter if the API gets broken? does it really mandate an new major version?

@bd82
Copy link
Member Author

bd82 commented Sep 11, 2019

I think this structure may actually be missing one of the more important properties (tokenIdx/Idx)

@bd82
Copy link
Member Author

bd82 commented Jul 8, 2023

It may be a good idea to "hide" some of the internal properties using symbols instead of string properties.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant