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

Do something reasonable with string literals #122

Open
jlapeyre opened this issue Feb 15, 2024 · 1 comment
Open

Do something reasonable with string literals #122

jlapeyre opened this issue Feb 15, 2024 · 1 comment

Comments

@jlapeyre
Copy link
Collaborator

OQ3 supports neither a string type nor string literals. (It does support bit string literals, eg "1001")

Currently a string literal will cause a panic in syntax_to_semantics.rs here
here

_ => todo!(), // error. can/should be caught at syntax level, obviously

The lexer tokenizes string literals (eg "abc") as token STRING. The parser then constructs the variant SyntaxKind::Literal

pub(crate) const LITERAL_FIRST: TokenSet = TokenSet::new(&[
T![true],
T![false],
INT_NUMBER,
FLOAT_NUMBER,
SIMPLE_FLOAT_NUMBER,
BYTE,
CHAR,
STRING,
BIT_STRING,
]);
pub(crate) fn literal(p: &mut Parser<'_>) -> Option<CompletedMarker> {
if !p.at_ts(LITERAL_FIRST) {
return None;
}
let m = p.start();
p.bump_any();
Some(m.complete(p, LITERAL))
}

I'm pretty sure that everywhere a string literal is encountered in the code above it is a string literal that is not part of the language (ie bit string literals, pragmas, etc. have been filtered out). So we could record a parse error here. Since we currently do not proceed with semantic analysis if there are parse errors, the panic mentioned above would not occur. But we'd still want to do something reasonable in place of the todo!.

I should also note that you can get a string literal at the level of the AST (really CST) although this should not be part of the language:

pub enum LiteralKind {
String(ast::String),
BitString(ast::BitString),
IntNumber(ast::IntNumber),
FloatNumber(ast::FloatNumber),
SimpleFloatNumber(ast::SimpleFloatNumber),
TimingFloatNumber(ast::TimingFloatNumber),
Char(ast::Char),
Byte(ast::Byte),
Bool(bool),

version/commit

b9e9ae8

@jlapeyre
Copy link
Collaborator Author

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

No branches or pull requests

1 participant