-
Notifications
You must be signed in to change notification settings - Fork 0
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
Spec draft tokens #1
base: spec-draft
Are you sure you want to change the base?
Conversation
By definition, `typedef` is strictly an alias for a type. Therefore, the following sequence mean that `IdentifierName` and `Identifier` are interchangeable: ``` typedef string IdentifierName; typedef string Identifier; ``` As this is not true, the current patch is a first attempt to remove this aliasing. We solve this by introducing an annotation `[Token(...)]`, which lets us specify the token-space in which an alias of string belongs. So, ``` typedef [Token(IdentifierName)] string IdentifierName; typedef [Token(Identifier)] string Identifier; ``` specifies that an `IdentifierName` is a string from the set of tokens `IdentifierName`. This is an early draft for feedback, we haven't yet actually defined the set of tokens.
cbff53d
to
01ae007
Compare
Sorry I seem so obstinate about this: I still don't understand the motivation very well. Why is it undesirable to have the implementation understand the, e.g. the |
For one thing, we have the problem that Now, I find your example undesirable because it forces us to introduce hardcoded logics specifically to work around the fact that we use the same type for unrelated pieces of data. In any programming language, if I have different types of data, I'm going to |
I agree that for string literals with different lexical grammars, this type differentiation is desirable. On the other hand I think differences beyond grammar differences don't need to be encoded as different types in the AST tree grammar. Do you agree with that? For example, one can argue that an identifier use of a local binding is different than an identifier use of an outer binding, or that a function statement that contains a recursive use is different than a function statement that is non-recursive. I am explicitly not interested in encoding semantic differences of that kind. |
I can go with that. |
@syg So, what's your opinion on this specific patch? |
An alternative would be to wrap them in interfaces instead interface Identifier {
value: string;
}
interface IdentifierName {
value: string;
}
interface Label {
value: string;
}
interface IdentifierLikePropertyNameLiteral {
value: string;
}
interface PropertynameLiteral {
value: string;
}
interface ModuleSpecifierLiteral {
value: string;
}
interface RegExpFlags {
value: string;
}
interface StringLiteral {
value: string;
} with specifications for the correct values for each of these Either choice will require some work on the implementation side. |
I prefer the interface wrapping for now. |
Ok, that works. I'll reformulate this as an interface. Then I'll spend a few days trying to get the code to work with that :) |
Hey, @syg, could you take a look at this?