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

[typescript] Runtime declares CommonToken(source, .....) wrong. #4318

Closed
kaby76 opened this issue Jun 19, 2023 · 7 comments · Fixed by #4319
Closed

[typescript] Runtime declares CommonToken(source, .....) wrong. #4318

kaby76 opened this issue Jun 19, 2023 · 7 comments · Fixed by #4319

Comments

@kaby76
Copy link
Contributor

kaby76 commented Jun 19, 2023

I need to create a CommonToken for python3 but for TypeScript. Unfortunately, "source" is declared as a number here. That's wrong. Completely blocked.

@ericvergnaud
Copy link
Contributor

ericvergnaud commented Jun 19, 2023

Can you try: constructor(source: [ TokenSource, InputStream ], type: number, channel: number, start: number, stop: number); ?
(typically you would get the source from the original token)

@kaby76
Copy link
Contributor Author

kaby76 commented Jun 19, 2023

Tried and got a couple different things.

Python3LexerBase.ts:68:38 - error TS1005: ',' expected.

68         return new CommonToken(source: [ this, this.input_ ], type, 0, start, stop);
                                        ~
Python3LexerBase.ts:68:33 - error TS2345: Argument of type '(CharStream | this)[]' is not assignable to parameter of type 'number'.

68         return new CommonToken( [ this, this.input_ ], type, 0, start, stop);
                                   ~~~~~~~~~~~~~~~~~~~~~

@ericvergnaud
Copy link
Contributor

second issue suggests that you haven't updated CommonToken.d.ts ?
(first issue is invalid syntax)

@kaby76
Copy link
Contributor Author

kaby76 commented Jun 19, 2023

grammars-v4 CI builds use official NPM published packages. 4.13.0 is the latest.

@ericvergnaud
Copy link
Contributor

ah.

I guess in the meantime you could write:
new CommonToken( [ this, this.input_ ] as any as number, ... ?

@kaby76
Copy link
Contributor Author

kaby76 commented Jun 19, 2023

I guess in the meantime you could write:
new CommonToken( [ this, this.input_ ] as any as number, ... ?

Thanks, that works. What a weird type checking, coersion language.

The fix--may be--seems to be with CommonToken.d.ts.

import { Token } from "./Token";
import { CharStream } from "./CharStream";
import { Lexer } from "./Lexer";

export declare class CommonToken extends Token {
    constructor(source: (CharStream | Lexer)[], type: number, channel: number, start: number, stop: number);
    clone(): CommonToken;
    cloneWithType(type: number): CommonToken;
    toString(): string;
}

Good. I'll leave this off here for now as I need to back to cleaning up the horrifying chaos with the grammars-v4/python grammars.

@ericvergnaud
Copy link
Contributor

since that works, the fix is what I initially sent, for CommonToken.d.ts - sorry if I wasn't explicit enough.

@kaby76 kaby76 changed the title [typescript] Runtime declares CommonToken(source, .....) wrong. Completely stuck. [typescript] Runtime declares CommonToken(source, .....) wrong. Jun 23, 2023
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 a pull request may close this issue.

2 participants