Skip to content

Commit 51b4ccc

Browse files
committed
allow sharing code between rust and napi
1 parent 14ec43a commit 51b4ccc

78 files changed

Lines changed: 1228 additions & 1773 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.changeset/gold-knives-jump.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"changelog": patch
3+
---
4+
5+
Move `syntax::parser::ProductionKind` to `syntax::nodes` namespace.

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/codegen/legacy_syntax_templates/src/lib.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,9 @@ extern crate napi_derive;
33

44
pub mod napi;
55
pub mod rust;
6+
7+
pub mod syntax {
8+
pub mod nodes {
9+
pub use crate::napi::kinds::{ProductionKind, RuleKind, TokenKind};
10+
}
11+
}

crates/codegen/legacy_syntax_templates/src/napi/cst_ts_wrappers.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
use super::{
22
cst::{Node as RustNode, RuleNode as RustRuleNode, TokenNode as RustTokenNode},
33
cursor_ts_wrappers::Cursor,
4-
kinds::*,
54
text_index::{TextIndex as RustTextIndex, TextRange as RustTextRange},
65
};
76

@@ -11,6 +10,8 @@ use napi::bindgen_prelude::*;
1110
use napi::JsObject;
1211
use napi::NapiValue;
1312

13+
use crate::syntax::nodes::{RuleKind, TokenKind};
14+
1415
#[napi(object, namespace = "legacy")]
1516
#[derive(Copy, Clone)]
1617
pub struct TextIndex {

crates/codegen/legacy_syntax_templates/src/napi/cursor_ts_wrappers.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
use super::{
22
cst_ts_wrappers::{TextIndex, TextRange, ToJS},
33
cursor::Cursor as RustCursor,
4-
kinds::*,
54
};
65

76
use napi::bindgen_prelude::*;
87
use napi::JsObject;
98

9+
use crate::syntax::nodes::{RuleKind, TokenKind};
10+
1011
#[napi(namespace = "legacy")]
1112
pub struct Cursor(Box<RustCursor>);
1213

crates/codegen/legacy_syntax_templates/src/napi/parse_output.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
use std::collections::BTreeSet;
22

3+
use napi::bindgen_prelude::*;
4+
35
use super::{
46
cst,
57
cst_ts_wrappers::{TextRange, ToJS},
6-
kinds::TokenKind,
78
parse_error::render_error_report,
89
text_index::TextRange as RustTextRange,
910
};
10-
use napi::bindgen_prelude::*;
11+
12+
use crate::syntax::nodes::TokenKind;
1113

1214
#[napi(namespace = "legacy")]
1315
pub struct ParseOutput {

crates/codegen/legacy_syntax_templates/src/rust/parse_output.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
use std::collections::BTreeSet;
22

3-
use super::{cst, kinds::TokenKind, parse_error::render_error_report, text_index::TextRange};
3+
use super::{cst, parse_error::render_error_report, text_index::TextRange};
4+
5+
use crate::syntax::nodes::TokenKind;
46

57
#[derive(Debug, PartialEq)]
68
pub struct ParseOutput {

crates/codegen/legacy_syntax_templates/src/shared/cst.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,9 @@ use std::rc::Rc;
22

33
use serde::Serialize;
44

5-
use super::{
6-
cursor::Cursor,
7-
kinds::{RuleKind, TokenKind},
8-
text_index::TextIndex,
9-
};
5+
use super::{cursor::Cursor, text_index::TextIndex};
6+
7+
use crate::syntax::nodes::{RuleKind, TokenKind};
108

119
#[derive(Clone, Debug, PartialEq, Eq, Serialize)]
1210
pub struct RuleNode {

crates/codegen/legacy_syntax_templates/src/shared/cursor.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@ use std::rc::Rc;
22

33
use super::{
44
cst::{Node, RuleNode, TokenNode},
5-
kinds::{RuleKind, TokenKind},
65
text_index::{TextIndex, TextRange},
76
};
87

8+
use crate::syntax::nodes::{RuleKind, TokenKind};
9+
910
#[derive(Clone, Debug, PartialEq, Eq)]
1011
struct CursorPathElement {
1112
rule_node: Rc<RuleNode>,

crates/codegen/legacy_syntax_templates/src/shared/language.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,7 @@
22
use semver::Version;
33

44
#[allow(unused_imports)]
5-
use super::{kinds::*, parse_output::*, parser_function::*, scanner_function::*};
5+
use super::{parse_output::*, parser_function::*, scanner_function::*};
6+
7+
#[allow(unused_imports)]
8+
use crate::syntax::nodes::{ProductionKind, RuleKind, TokenKind};

0 commit comments

Comments
 (0)