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

Move comments after opening curly to a different line #4

Merged
merged 1 commit into from
Jan 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion crates/lexer/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -524,7 +524,8 @@ impl Cursor<'_> {
self.bump();
// n.b. example of `empty_exponent` : 3.4e; This is a syntax error
let mut empty_exponent = false;
if self.first().is_ascii_digit() { // preferred to is_digit(10), in rust lexer
// preferred to is_digit(10), in rust lexer
if self.first().is_ascii_digit() {
self.eat_decimal_digits();
match self.first() {
'e' | 'E' => {
Expand Down
3 changes: 2 additions & 1 deletion crates/oq3_syntax/examples/demotest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ fn main() {
println!("{:?}", tok);
}
}
None => { // TODO shoul pring usage here.
None => {
// FIXME should print usage here.
println!("Commands are parse, parse-green, and lex")
}
}
Expand Down
6 changes: 4 additions & 2 deletions crates/oq3_syntax/src/ast/expr_ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -236,9 +236,11 @@ impl ast::RangeExpr {
let first = children.next();
let second = children.next();
let third = children.next();
if third.is_none() { // start:stop
if third.is_none() {
// start:stop
(first, third, second)
} else { // start:step:stop
} else {
// start:step:stop
(first, second, third)
}
}
Expand Down
7 changes: 4 additions & 3 deletions crates/parser/src/grammar/expressions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ pub(crate) fn stmt(p: &mut Parser<'_>, semicolon: Semicolon) {
return;
};
if let Some((cm, blocklike)) = expr_stmt(p, Some(m)) {
if !p.at(T!['}']) { // && ( semicolon == Semicolon::Required || ! p.at(EOF)) {
if !p.at(T!['}']) {
let cm_kind = cm.kind();
let m = cm.precede(p);
if blocklike.is_block() {
Expand Down Expand Up @@ -287,8 +287,9 @@ const LHS_FIRST: TokenSet =
// Handles only prefix and postfix expressions?? Not binary infix?
fn lhs(p: &mut Parser<'_>, r: Restrictions) -> Option<(CompletedMarker, BlockLike, bool)> {
let m;
let kind = match p.current() { // Unary operators. In OQ3 should be ~ ! -
T![~] | T![!] | T![-] => { // In r-a this is * ! -
// Unary operators. In OQ3 should be ~ ! -, In r-a this is * ! -
let kind = match p.current() {
T![~] | T![!] | T![-] => {
m = p.start();
p.bump_any();
PREFIX_EXPR
Expand Down
10 changes: 6 additions & 4 deletions crates/parser/src/grammar/items.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,8 @@ pub(super) fn opt_item(p: &mut Parser<'_>, m: Marker) -> Result<(), Marker> {
// return Ok(())
// }
// if p.current().is_classical_type() {
// if la == T!['('] { // we should not be handling expressions here, only statements.
// // we should not be handling expressions here, only statements.
// if la == T!['('] {
// expressions::cast_expr(p, m);
// } else {
// expressions::classical_declaration_stmt(p, m);
Expand Down Expand Up @@ -131,7 +132,8 @@ fn gate_call_stmt(p: &mut Parser<'_>, m: Marker) {
// expressions::var_name(p);
expressions::atom::identifier(p); // name of gate
assert!(! p.at(T!['(']));
if p.at(T!['(']) { // This is never true, I hope
// This is never true, I hope
if p.at(T!['(']) {
expressions::call_arg_list(p);
}
params::arg_list_gate_call_qubits(p);
Expand All @@ -147,7 +149,7 @@ fn gphase_call(p: &mut Parser<'_>, m: Marker) {
m.complete(p, G_PHASE_CALL_STMT);
}

fn if_stmt(p: &mut Parser<'_>, m: Marker) { // -> CompletedMarker {
fn if_stmt(p: &mut Parser<'_>, m: Marker) {
assert!(p.at(T![if]));
// let m = p.start();
p.bump(T![if]);
Expand Down Expand Up @@ -262,7 +264,7 @@ fn reset_(p: &mut Parser<'_>, m: Marker) {
}

// FIXME: this has underscore, so should be private.
// We shoudld be able to refactor to keep this private.
// We should be able to refactor to keep this private.
pub(crate) fn measure_(p: &mut Parser<'_>, m: Marker) {
p.bump(T![measure]);
match p.current() {
Expand Down
25 changes: 15 additions & 10 deletions crates/parser/src/grammar/params.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,9 @@ fn _param_list_openqasm(p: &mut Parser<'_>, flavor: DefFlavor, m: Option<Marker>
// DefCalQubits => {TokenSet::new(&[T!['{'], T![->]])},
ExpressionList => [T![']'], T![']']],
GateParams | DefParams | DefCalParams => [T![')'], T![')']],
GateQubits => [T!['{'], T!['{']], // When no parens are present `{` terminates the list of parameters.
GateCallQubits => [SEMICOLON, SEMICOLON], // ugh.
// When no parens are present `{` terminates the list of parameters.
GateQubits => [T!['{'], T!['{']],
GateCallQubits => [SEMICOLON, SEMICOLON],
DefCalQubits => [T!['{'], T![->]],
// SetExpression => [T!['}'], T!['}']],
};
Expand All @@ -104,7 +105,7 @@ fn _param_list_openqasm(p: &mut Parser<'_>, flavor: DefFlavor, m: Option<Marker>
// while !p.at(EOF) && !p.at_ts(list_end_tokens) {
while !p.at(EOF) && !list_end_tokens.iter().any(|x| p.at(*x)) {
let m = param_marker.take().unwrap_or_else(|| p.start());
if !(p.current().is_type_name() || p.at_ts(PARAM_FIRST)) { //
if !(p.current().is_type_name() || p.at_ts(PARAM_FIRST)) {
p.error("expected value parameter");
println!("!!!! Got {:?}", p.current());
m.abandon(p);
Expand All @@ -126,17 +127,20 @@ fn _param_list_openqasm(p: &mut Parser<'_>, flavor: DefFlavor, m: Option<Marker>
num_params += 1;
// FIXME: This is only needed to support `->` as terminating tokens.
// Not for `{`. But I don't know why. prbly because `->` is compound.
if list_end_tokens.iter().any(|x| p.at(*x)) { // FIXME: use at_ts()
// FIXME: use at_ts()
if list_end_tokens.iter().any(|x| p.at(*x)) {
// if p.at_ts(list_end_tokens) {
break;
}
if !p.at(T![,]) { // Params must be separated by commas.
// Params must be separated by commas.
if !p.at(T![,]) {
if p.at_ts(PARAM_FIRST) {
p.error("Expected `,`");
} else {
break;
}
} else { // We found the expected comma, so consume it.
} else {
// We found the expected comma, so consume it.
p.bump(T![,]);
}
}
Expand All @@ -150,7 +154,8 @@ fn _param_list_openqasm(p: &mut Parser<'_>, flavor: DefFlavor, m: Option<Marker>
m.abandon(p);
}
// FIXME: rewrite followig as match statement.
if want_parens { // Error if we don't find closing paren.
// Error if we don't find closing paren.
if want_parens {
p.expect(T![')']);
}
// if matches!(flavor, SetExpression) {
Expand Down Expand Up @@ -197,7 +202,7 @@ const PARAM_FIRST: TokenSet = PATTERN_FIRST.union(TYPE_FIRST);
// TODO: Look again at the r-a code to copy the idioms there.
// We have removed all of the code that can serve as an example.
// In OQ 3, parameters in gate defs don't have type annotations.
fn param_untyped(p: &mut Parser<'_>, m: Marker) -> bool { // GJL
fn param_untyped(p: &mut Parser<'_>, m: Marker) -> bool {
if !p.at(IDENT) {
p.error("Expected parameter name");
m.abandon(p);
Expand All @@ -208,7 +213,7 @@ fn param_untyped(p: &mut Parser<'_>, m: Marker) -> bool { // GJL
true
}

fn param_typed(p: &mut Parser<'_>, m: Marker) -> bool { // GJL
fn param_typed(p: &mut Parser<'_>, m: Marker) -> bool {
let mut success = true;
if p.current().is_type_name() {
p.bump_any();
Expand All @@ -226,7 +231,7 @@ fn param_typed(p: &mut Parser<'_>, m: Marker) -> bool { // GJL
success
}

fn arg_gate_call_qubit(p: &mut Parser<'_>, m: Marker) -> bool { // GJL
fn arg_gate_call_qubit(p: &mut Parser<'_>, m: Marker) -> bool {
if p.at(HARDWAREIDENT) {
p.bump(HARDWAREIDENT);
m.complete(p, HARDWARE_QUBIT);
Expand Down