Skip to content

Commit

Permalink
Remove objects left over from lexing timing numbers (#172)
Browse files Browse the repository at this point in the history
Timing numbers and also a "simple float" was lexed. There were a few
variants and associated types that would be completely useless now.
  • Loading branch information
jlapeyre authored Mar 1, 2024
1 parent 4568ee7 commit 52aa014
Show file tree
Hide file tree
Showing 11 changed files with 9 additions and 161 deletions.
3 changes: 2 additions & 1 deletion codegen_scripts/cpnodes.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@
# Copy the generated code from the temporary files to which it is written
# to its final location where it will be compiled into the library.

cd .. && cp -a --backup=t crates/oq3_syntax/src/ast/generated/_new_nodes.rs crates/oq3_syntax/src/ast/generated/nodes.rs
cd .. && cp -a --backup=t crates/oq3_syntax/src/ast/generated/_new_nodes.rs crates/oq3_syntax/src/ast/generated/nodes.rs && \
cp -a --backup=t crates/oq3_syntax/src/ast/generated/_new_tokens.rs crates/oq3_syntax/src/ast/generated/tokens.rs
2 changes: 1 addition & 1 deletion crates/oq3_parser/src/grammar/expressions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ pub(crate) fn designator(p: &mut Parser<'_>) -> bool {
// see this addressed in the spec.
if matches!(
p.current(),
FLOAT_NUMBER | SIMPLE_FLOAT_NUMBER | BYTE | CHAR | STRING | BIT_STRING
FLOAT_NUMBER | BYTE | CHAR | STRING | BIT_STRING
) && matches!(p.nth(1), T![']'])
{
p.error("Literal type designator must be an integer.")
Expand Down
4 changes: 0 additions & 4 deletions crates/oq3_parser/src/grammar/expressions/atom.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,7 @@ pub(crate) const LITERAL_FIRST: TokenSet = TokenSet::new(&[
CHAR,
FLOAT_NUMBER,
INT_NUMBER,
SIMPLE_FLOAT_NUMBER,
STRING,
// FIXME, remove the following two. They are no longer used.
TIMING_FLOAT_NUMBER,
TIMING_INT_NUMBER,
T![true],
T![false],
]);
Expand Down
13 changes: 1 addition & 12 deletions crates/oq3_parser/src/syntax_kind/syntax_kind_enum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,13 +111,10 @@ pub enum SyntaxKind {
#[doc = r" literals"]
INT_NUMBER,
FLOAT_NUMBER,
SIMPLE_FLOAT_NUMBER,
CHAR,
BYTE,
STRING,
BIT_STRING,
TIMING_FLOAT_NUMBER,
TIMING_INT_NUMBER,
#[doc = r" scalar_types"]
FLOAT_TY,
INT_TY,
Expand Down Expand Up @@ -331,15 +328,7 @@ impl SyntaxKind {
pub fn is_literal(self) -> bool {
matches!(
self,
INT_NUMBER
| FLOAT_NUMBER
| SIMPLE_FLOAT_NUMBER
| CHAR
| BYTE
| STRING
| BIT_STRING
| TIMING_FLOAT_NUMBER
| TIMING_INT_NUMBER
INT_NUMBER | FLOAT_NUMBER | CHAR | BYTE | STRING | BIT_STRING
)
}
pub fn is_scalar_type(self) -> bool {
Expand Down
5 changes: 1 addition & 4 deletions crates/oq3_semantics/src/syntax_to_semantics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -850,10 +850,7 @@ fn from_literal(literal: &synast::Literal) -> Option<asg::TExpr> {

synast::LiteralKind::Byte(_)
| synast::LiteralKind::Char(_)
| synast::LiteralKind::SimpleFloatNumber(_)
| synast::LiteralKind::String(_)
| synast::LiteralKind::TimingFloatNumber(_)
| synast::LiteralKind::TimingIntNumber(_) => todo!(),
| synast::LiteralKind::String(_) => todo!(),
};
Some(literal_texpr)
}
Expand Down
12 changes: 0 additions & 12 deletions crates/oq3_syntax/src/ast/expr_ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -293,10 +293,7 @@ pub enum LiteralKind {
Char(ast::Char),
FloatNumber(ast::FloatNumber),
IntNumber(ast::IntNumber),
SimpleFloatNumber(ast::SimpleFloatNumber),
String(ast::String),
TimingFloatNumber(ast::TimingFloatNumber),
TimingIntNumber(ast::TimingIntNumber),
}

// Literal strings in OQ3 occur only in a few contexts.
Expand Down Expand Up @@ -355,15 +352,6 @@ impl ast::Literal {
if let Some(t) = ast::FloatNumber::cast(token.clone()) {
return LiteralKind::FloatNumber(t);
}
if let Some(t) = ast::SimpleFloatNumber::cast(token.clone()) {
return LiteralKind::SimpleFloatNumber(t);
}
if let Some(t) = ast::TimingFloatNumber::cast(token.clone()) {
return LiteralKind::TimingFloatNumber(t);
}
if let Some(t) = ast::TimingIntNumber::cast(token.clone()) {
return LiteralKind::TimingIntNumber(t);
}
if let Some(t) = ast::String::cast(token.clone()) {
return LiteralKind::String(t);
}
Expand Down
77 changes: 0 additions & 77 deletions crates/oq3_syntax/src/ast/generated/tokens.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
// Copyright contributors to the openqasm-parser project
// SPDX-License-Identifier: Apache-2.0

//! Generated by `sourcegen_ast`, do not edit by hand.

use crate::{
Expand Down Expand Up @@ -200,80 +197,6 @@ impl AstToken for Ident {
&self.syntax
}
}
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct TimingIntNumber {
pub(crate) syntax: SyntaxToken,
}
impl std::fmt::Display for TimingIntNumber {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
std::fmt::Display::fmt(&self.syntax, f)
}
}
impl AstToken for TimingIntNumber {
fn can_cast(kind: SyntaxKind) -> bool {
kind == TIMING_INT_NUMBER
}
fn cast(syntax: SyntaxToken) -> Option<Self> {
if Self::can_cast(syntax.kind()) {
Some(Self { syntax })
} else {
None
}
}
fn syntax(&self) -> &SyntaxToken {
&self.syntax
}
}
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct TimingFloatNumber {
pub(crate) syntax: SyntaxToken,
}
impl std::fmt::Display for TimingFloatNumber {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
std::fmt::Display::fmt(&self.syntax, f)
}
}
impl AstToken for TimingFloatNumber {
fn can_cast(kind: SyntaxKind) -> bool {
kind == TIMING_FLOAT_NUMBER
}
fn cast(syntax: SyntaxToken) -> Option<Self> {
if Self::can_cast(syntax.kind()) {
Some(Self { syntax })
} else {
None
}
}
fn syntax(&self) -> &SyntaxToken {
&self.syntax
}
}

#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct SimpleFloatNumber {
pub(crate) syntax: SyntaxToken,
}
impl std::fmt::Display for SimpleFloatNumber {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
std::fmt::Display::fmt(&self.syntax, f)
}
}
impl AstToken for SimpleFloatNumber {
fn can_cast(kind: SyntaxKind) -> bool {
kind == SIMPLE_FLOAT_NUMBER
}
fn cast(syntax: SyntaxToken) -> Option<Self> {
if Self::can_cast(syntax.kind()) {
Some(Self { syntax })
} else {
None
}
}
fn syntax(&self) -> &SyntaxToken {
&self.syntax
}
}

#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct BitString {
pub(crate) syntax: SyntaxToken,
Expand Down
39 changes: 0 additions & 39 deletions crates/oq3_syntax/src/ast/token_ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -371,45 +371,6 @@ impl ast::FloatNumber {
}
}

// impl ast::TimingFloatNumber {
// pub fn split_into_parts(&self) -> (&str, &str) {
// let text = self.text();
// let mut float_text = self.text();
// let mut suffix = "";
// let mut indices = text.char_indices();
// if let Some((mut suffix_start, c)) = indices.by_ref().find(|(_, c)| c.is_ascii_alphabetic())
// {
// if c == 'e' || c == 'E' {
// if let Some(suffix_start_tuple) = indices.find(|(_, c)| c.is_ascii_alphabetic()) {
// suffix_start = suffix_start_tuple.0;

// float_text = &text[..suffix_start];
// suffix = &text[suffix_start..];
// }
// } else {
// float_text = &text[..suffix_start];
// suffix = &text[suffix_start..];
// }
// }

// (float_text, suffix)
// }

// pub fn suffix(&self) -> Option<&str> {
// let (_, suffix) = self.split_into_parts();
// if suffix.is_empty() {
// None
// } else {
// Some(suffix)
// }
// }

// pub fn value(&self) -> Option<f64> {
// let (text, _) = self.split_into_parts();
// text.replace('_', "").parse::<f64>().ok()
// }
// }

#[derive(Debug, PartialEq, Eq, Copy, Clone)]
pub enum Radix {
Binary = 2,
Expand Down
3 changes: 0 additions & 3 deletions crates/oq3_syntax/src/tests/ast_src.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,13 +127,10 @@ pub(crate) const KINDS_SRC: KindsSrc<'_> = KindsSrc {
literals: &[
"INT_NUMBER",
"FLOAT_NUMBER",
"SIMPLE_FLOAT_NUMBER",
"CHAR",
"BYTE",
"STRING",
"BIT_STRING",
"TIMING_FLOAT_NUMBER",
"TIMING_INT_NUMBER",
],
tokens: &[
"ERROR",
Expand Down
9 changes: 4 additions & 5 deletions crates/oq3_syntax/src/tests/sourcegen_ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -662,11 +662,10 @@ impl Field {

fn lower(grammar: &Grammar) -> AstSrc {
let mut res = AstSrc {
tokens:
"Whitespace Comment String IntNumber FloatNumber Char Byte Ident TimingIntNumber TimingFloatNumber SimpleFloatNumber BitString"
.split_ascii_whitespace()
.map(|it| it.to_string())
.collect::<Vec<_>>(),
tokens: "Whitespace Comment String IntNumber FloatNumber Char Byte Ident BitString"
.split_ascii_whitespace()
.map(|it| it.to_string())
.collect::<Vec<_>>(),
..Default::default()
};

Expand Down
3 changes: 0 additions & 3 deletions crates/oq3_syntax/src/validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,9 +175,6 @@ fn validate_literal(literal: ast::Literal, acc: &mut Vec<SyntaxError>) {
}
ast::LiteralKind::IntNumber(_)
| ast::LiteralKind::FloatNumber(_)
| ast::LiteralKind::TimingFloatNumber(_)
| ast::LiteralKind::TimingIntNumber(_)
| ast::LiteralKind::SimpleFloatNumber(_)
| ast::LiteralKind::Bool(_) => {}
}
}
Expand Down

0 comments on commit 52aa014

Please sign in to comment.