Skip to content

Commit

Permalink
move existing codegen_syntax to a legacy folder (#542)
Browse files Browse the repository at this point in the history
  • Loading branch information
OmarTawfik committed Jul 24, 2023
1 parent 0d04f95 commit 14ec43a
Show file tree
Hide file tree
Showing 99 changed files with 1,042 additions and 949 deletions.
12 changes: 6 additions & 6 deletions .github/workflows/_jobs_check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,6 @@ jobs:
with:
entrypoint: "scripts/cargo/test.sh"

- name: "Run linters"
if: "${{ (success() || failure()) && steps.installDependencies.outcome == 'success' }}"
uses: "./.devcontainer"
with:
entrypoint: "scripts/lint/all.sh"

- name: "NPM build"
if: "${{ (success() || failure()) && steps.installDependencies.outcome == 'success' }}"
uses: "./.devcontainer"
Expand All @@ -86,6 +80,12 @@ jobs:
with:
entrypoint: "scripts/mkdocs/build.sh"

- name: "Run linters"
if: "${{ (success() || failure()) && steps.installDependencies.outcome == 'success' }}"
uses: "./.devcontainer"
with:
entrypoint: "scripts/lint/all.sh"

#
# Update cache files:
#
Expand Down
28 changes: 14 additions & 14 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ publish = false
members = [
"crates/codegen/ebnf",
"crates/codegen/syntax",
"crates/codegen/syntax_templates",
"crates/codegen/legacy_syntax_templates",
"crates/codegen/schema",
"crates/codegen/spec",
"crates/codegen/testing",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[package]
name = "codegen_syntax_templates"
name = "codegen_legacy_syntax_templates"
version.workspace = true
rust-version.workspace = true
edition.workspace = true
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#[macro_use]
extern crate napi_derive;

pub mod napi;
pub mod rust;
pub mod typescript;
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use napi::bindgen_prelude::*;
use napi::JsObject;
use napi::NapiValue;

#[napi(object)]
#[napi(object, namespace = "legacy")]
#[derive(Copy, Clone)]
pub struct TextIndex {
pub utf8: u32,
Expand All @@ -29,7 +29,7 @@ impl From<&RustTextIndex> for TextIndex {
}
}

#[napi(object)]
#[napi(object, namespace = "legacy")]
#[derive(Copy, Clone)]
pub struct TextRange {
pub start: TextIndex,
Expand All @@ -45,19 +45,19 @@ impl From<&RustTextRange> for TextRange {
}
}

#[napi(object)]
#[napi(object, namespace = "legacy")]
pub enum NodeType {
Rule,
Token,
}

#[napi]
#[napi(namespace = "legacy")]
pub struct RuleNode(Rc<RustRuleNode>);

#[napi]
#[napi(namespace = "legacy")]
pub struct TokenNode(Rc<RustTokenNode>);

#[napi]
#[napi(namespace = "legacy")]
impl RuleNode {
#[napi(getter, js_name = "type", ts_return_type = "NodeType.Rule")]
pub fn tipe(&self) -> NodeType {
Expand Down Expand Up @@ -88,7 +88,7 @@ impl RuleNode {
}
}

#[napi]
#[napi(namespace = "legacy")]
impl TokenNode {
#[napi(getter, js_name = "type", ts_return_type = "NodeType.Token")]
pub fn tipe(&self) -> NodeType {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ use super::{
use napi::bindgen_prelude::*;
use napi::JsObject;

#[napi]
#[napi(namespace = "legacy")]
pub struct Cursor(Box<RustCursor>);

#[napi]
#[napi(namespace = "legacy")]
impl Cursor {
pub(crate) fn new(cursor: RustCursor) -> Self {
Self(Box::new(cursor))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use serde::Serialize;
strum_macros::AsRefStr,
strum_macros::Display,
)]
#[napi]
#[napi(namespace = "legacy")]
pub enum TokenKind {
SKIPPED,
XXX,
Expand All @@ -32,7 +32,7 @@ pub enum TokenKind {
strum_macros::AsRefStr,
strum_macros::Display,
)]
#[napi]
#[napi(namespace = "legacy")]
pub enum RuleKind {
XXX,
}
Expand All @@ -48,7 +48,7 @@ pub enum RuleKind {
strum_macros::AsRefStr,
strum_macros::Display,
)]
#[napi]
#[napi(namespace = "legacy")]
pub enum ProductionKind {
XXX,
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ use super::{
};
use napi::bindgen_prelude::*;

#[napi]
#[napi(namespace = "legacy")]
pub struct ParseOutput {
pub(crate) parse_tree: cst::Node,
pub(crate) errors: Vec<ParseError>,
}

#[napi]
#[napi(namespace = "legacy")]
impl ParseOutput {
#[napi(getter, ts_return_type = "RuleNode | TokenNode | null")]
pub fn parse_tree(&self, env: Env) -> napi::JsObject {
Expand All @@ -33,14 +33,14 @@ impl ParseOutput {
}
}

#[napi]
#[napi(namespace = "legacy")]
#[derive(PartialEq, Clone)]
pub struct ParseError {
pub(crate) text_range: RustTextRange,
pub(crate) tokens_that_would_have_allowed_more_progress: Vec<TokenKind>,
}

#[napi]
#[napi(namespace = "legacy")]
impl ParseError {
#[napi(getter)]
pub fn text_range(&self) -> TextRange {
Expand All @@ -59,7 +59,7 @@ impl ParseError {
.collect();
}

#[napi]
#[napi(namespace = "legacy")]
pub fn to_error_report(&self, source_id: String, source: String, with_colour: bool) -> String {
return render_error_report(self, &source_id, &source, with_colour);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ pub enum Node {
Token(Rc<TokenNode>),
}

#[allow(dead_code)]
impl Node {
#[allow(dead_code)]
pub(crate) fn rule(kind: RuleKind, children: Vec<Self>) -> Self {
let mut text_len = Default::default();
for child in &children {
Expand All @@ -42,7 +42,6 @@ impl Node {
}));
}

#[allow(dead_code)]
pub(crate) fn token(kind: TokenKind, text: String) -> Self {
Self::Token(Rc::new(TokenNode { kind, text }))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ pub struct Cursor {
is_completed: bool,
}

#[allow(dead_code)]
impl Cursor {
pub(crate) fn new(node: Node) -> Self {
Self {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,22 @@ pub trait Visitor<E> {
}
}

#[allow(dead_code)]
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub enum VisitorEntryResponse {
Quit,
StepIn,
StepOver,
}

#[allow(dead_code)]
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub enum VisitorExitResponse {
Quit,
Continue,
}

#[allow(dead_code)]
impl Cursor {
pub fn drive_visitor<E, V: Visitor<E>>(
&mut self,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::char_set::CharSet;
use crate::legacy::char_set::CharSet;

pub struct CharFirstSet {
pub includes_epsilon: bool,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use codegen_schema::types::{ProductionDefinition, ScannerDefinition, ScannerRef}
use proc_macro2::TokenStream;
use quote::quote;

use crate::combinator_tree::CombinatorTree;
use crate::legacy::combinator_tree::CombinatorTree;

#[derive(Clone, Debug)]
pub struct CharSet(Vec<Range<u32>>);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -429,14 +429,14 @@ impl CodeGenerator {
codegen.track_input_dir(
&codegen
.repo_root
.join("crates/codegen/syntax_templates/src"),
.join("crates/codegen/legacy_syntax_templates/src"),
);

codegen
.copy_file(
&codegen
.repo_root
.join("crates/codegen/syntax_templates/src/shared/cst.rs"),
.join("crates/codegen/legacy_syntax_templates/src/shared/cst.rs"),
&output_dir.join("cst.rs"),
)
.unwrap();
Expand All @@ -445,7 +445,7 @@ impl CodeGenerator {
.copy_file(
&codegen
.repo_root
.join("crates/codegen/syntax_templates/src/shared/cursor.rs"),
.join("crates/codegen/legacy_syntax_templates/src/shared/cursor.rs"),
&output_dir.join("cursor.rs"),
)
.unwrap();
Expand All @@ -454,7 +454,7 @@ impl CodeGenerator {
.copy_file(
&codegen
.repo_root
.join("crates/codegen/syntax_templates/src/shared/scanner_macros.rs"),
.join("crates/codegen/legacy_syntax_templates/src/shared/scanner_macros.rs"),
&output_dir.join("scanner_macros.rs"),
)
.unwrap();
Expand All @@ -463,7 +463,7 @@ impl CodeGenerator {
.copy_file(
&codegen
.repo_root
.join("crates/codegen/syntax_templates/src/shared/parser_helpers.rs"),
.join("crates/codegen/legacy_syntax_templates/src/shared/parser_helpers.rs"),
&output_dir.join("parser_helpers.rs"),
)
.unwrap();
Expand All @@ -472,7 +472,7 @@ impl CodeGenerator {
.copy_file(
&codegen
.repo_root
.join("crates/codegen/syntax_templates/src/shared/parse_error.rs"),
.join("crates/codegen/legacy_syntax_templates/src/shared/parse_error.rs"),
&output_dir.join("parse_error.rs"),
)
.unwrap();
Expand All @@ -481,7 +481,7 @@ impl CodeGenerator {
.copy_file(
&codegen
.repo_root
.join("crates/codegen/syntax_templates/src/shared/parser_function.rs"),
.join("crates/codegen/legacy_syntax_templates/src/shared/parser_function.rs"),
&output_dir.join("parser_function.rs"),
)
.unwrap();
Expand All @@ -490,7 +490,7 @@ impl CodeGenerator {
.copy_file(
&codegen
.repo_root
.join("crates/codegen/syntax_templates/src/shared/parser_result.rs"),
.join("crates/codegen/legacy_syntax_templates/src/shared/parser_result.rs"),
&output_dir.join("parser_result.rs"),
)
.unwrap();
Expand All @@ -499,7 +499,7 @@ impl CodeGenerator {
.copy_file(
&codegen
.repo_root
.join("crates/codegen/syntax_templates/src/shared/scanner_function.rs"),
.join("crates/codegen/legacy_syntax_templates/src/shared/scanner_function.rs"),
&output_dir.join("scanner_function.rs"),
)
.unwrap();
Expand All @@ -508,7 +508,7 @@ impl CodeGenerator {
.copy_file(
&codegen
.repo_root
.join("crates/codegen/syntax_templates/src/shared/stream.rs"),
.join("crates/codegen/legacy_syntax_templates/src/shared/stream.rs"),
&output_dir.join("stream.rs"),
)
.unwrap();
Expand All @@ -517,7 +517,7 @@ impl CodeGenerator {
.copy_file(
&codegen
.repo_root
.join("crates/codegen/syntax_templates/src/shared/text_index.rs"),
.join("crates/codegen/legacy_syntax_templates/src/shared/text_index.rs"),
&output_dir.join("text_index.rs"),
)
.unwrap();
Expand All @@ -526,7 +526,7 @@ impl CodeGenerator {
.copy_file(
&codegen
.repo_root
.join("crates/codegen/syntax_templates/src/shared/visitor.rs"),
.join("crates/codegen/legacy_syntax_templates/src/shared/visitor.rs"),
&output_dir.join("visitor.rs"),
)
.unwrap();
Expand Down
Loading

0 comments on commit 14ec43a

Please sign in to comment.