Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/NTTVy03/ccls
Browse files Browse the repository at this point in the history
  • Loading branch information
NTTVy03 committed Dec 30, 2024
2 parents 84e960b + 40268bf commit d9f369e
Show file tree
Hide file tree
Showing 8 changed files with 1,209 additions and 1,179 deletions.
527 changes: 264 additions & 263 deletions crates/lsp/src/handler/goto_definition.rs

Large diffs are not rendered by default.

261 changes: 131 additions & 130 deletions crates/parser/src/grammar/declaration.rs
Original file line number Diff line number Diff line change
@@ -1,130 +1,131 @@
use super::{
expression::{tuple, tuple_init},
*,
};

// "signal" --> None
// "signal input" --> Some(true)
// "signal output" --> Some(false)
fn signal_header(p: &mut Parser) -> Option<bool> {
let mut res = None;
let m = p.open();
p.expect(SignalKw);
if p.at_any(&[InputKw, OutputKw]) {
if p.at(InputKw) {
res = Some(true);
} else {
res = Some(false);
}
p.advance();

if p.at(LCurly) {
p.expect(Identifier);
p.expect(RCurly);
}
}
p.close(m, SignalHeader);
res
}

/**
* Declaration := "var" (SimpleSymbol, ..., SimpleSymbol) TupleInitialization |
*
*
*/
pub(super) fn var_declaration(p: &mut Parser) {
let m = p.open();
p.expect(VarKw);

if p.at(LParen) {
tuple(p);
if p.at(Assign) {
tuple_init(p);
}
} else {
p.expect(Identifier);
if p.at(Assign) {
p.expect(Assign);
expression::expression(p);
}
// list of var
while p.at(Comma) && !p.eof() {
p.expect(Comma);
p.expect(Identifier);
if p.at(Assign) {
p.expect(Assign);
expression::expression(p);
}
}
}
p.close(m, VarDecl);
}

pub(super) fn signal_declaration(p: &mut Parser) {
if !p.at(SignalKw) {
p.advance_with_error("Signal error");
return;
}

let m = p.open();
let io_signal = signal_header(p);

if p.at(LParen) {
tuple(p);
if p.at_any(&[Assign, RAssignSignal, RAssignConstraintSignal]) {
tuple_init(p);
}
} else {
p.expect(Identifier);
// list of var
while p.at(Comma) && !p.eof() {
p.skip();
p.expect(Identifier);
}
}

if let Some(is_input) = io_signal {
if is_input {
p.close(m, InputSignalDecl);
} else {
p.close(m, OutputSignalDecl);
}
} else {
p.close(m, SignalDecl);
}
}

pub(super) fn component_declaration(p: &mut Parser) {
let m = p.open();
p.expect(ComponentKw);
let m_c = p.open();
p.expect(Identifier);
p.close(m_c, ComponentIdentifier);

p.expect(Assign);
let m_c = p.open();
p.expect(Identifier);
p.close(m_c, TemplateName);
p.expect(LParen);

if p.at(Identifier) {
expression::expression(p);
while !p.at(RParen) && !p.eof() {
p.expect(Comma);
expression::expression(p);
}
}

p.expect(RParen);

p.close(m, ComponentDecl);
}

pub(super) fn declaration(p: &mut Parser) {
match p.current() {
SignalKw => signal_declaration(p),
VarKw => var_declaration(p),
ComponentKw => component_declaration(p),
_ => unreachable!(),
}
}
use super::{
expression::{tuple, tuple_init},
*,
};

// "signal" --> None
// "signal input" --> Some(true)
// "signal output" --> Some(false)
fn signal_header(p: &mut Parser) -> Option<bool> {
let mut res = None;
let m = p.open();
p.expect(SignalKw);
if p.at_any(&[InputKw, OutputKw]) {
if p.at(InputKw) {
res = Some(true);
} else {
res = Some(false);
}
p.advance();

if p.at(LCurly) {
p.expect(Identifier);
p.expect(RCurly);
}
}
p.close(m, SignalHeader);
res
}

/**
* Declaration := "var" (SimpleSymbol, ..., SimpleSymbol) TupleInitialization |
*
*
*/
pub(super) fn var_declaration(p: &mut Parser) {
let m = p.open();
p.expect(VarKw);

if p.at(LParen) {
tuple(p);
if p.at(Assign) {
tuple_init(p);
}
} else {
p.expect(Identifier);
if p.at(Assign) {
p.expect(Assign);
expression::expression(p);
}
// list of var
while p.at(Comma) && !p.eof() {
p.expect(Comma);
p.expect(Identifier);
if p.at(Assign) {
p.expect(Assign);
expression::expression(p);
}
}
}
p.close(m, VarDecl);
}

pub(super) fn signal_declaration(p: &mut Parser) {
if !p.at(SignalKw) {
p.advance_with_error("Signal error");
return;
}

let m = p.open();
let io_signal = signal_header(p);

if p.at(LParen) {
tuple(p);
if p.at_any(&[Assign, RAssignSignal, RAssignConstraintSignal]) {
tuple_init(p);
}
} else {
p.expect(Identifier);
// list of var
while p.at(Comma) && !p.eof() {
p.skip();
p.expect(Identifier);
}
}

if let Some(is_input) = io_signal {
if is_input {
p.close(m, InputSignalDecl);
} else {
p.close(m, OutputSignalDecl);
}
} else {
p.close(m, SignalDecl);
}
}

pub(super) fn component_declaration(p: &mut Parser) {
let m = p.open();
p.expect(ComponentKw);
let m_c = p.open();
p.expect(Identifier);
p.close(m_c, ComponentIdentifier);

p.expect(Assign);
let m_c = p.open();
p.expect(Identifier);
p.close(m_c, TemplateName);
p.expect(LParen);

if p.at(Identifier) {
expression::expression(p);
while !p.at(RParen) && !p.eof() {
p.expect(Comma);
expression::expression(p);
}
}

p.expect(RParen);

p.close(m, ComponentDecl);
}

pub(super) fn declaration(p: &mut Parser) {
match p.current() {
SignalKw => signal_declaration(p),
VarKw => var_declaration(p),
ComponentKw => component_declaration(p),
_ => unreachable!(),
}
}

Loading

0 comments on commit d9f369e

Please sign in to comment.