Skip to content

Commit

Permalink
Rename repository name
Browse files Browse the repository at this point in the history
  • Loading branch information
tanzaku committed May 12, 2024
1 parent d94f634 commit eb857d1
Show file tree
Hide file tree
Showing 58 changed files with 92 additions and 86 deletions.
10 changes: 5 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@ resolver = "2"
members = [
"crates/lexer-generator",
"crates/parser-generator",
"crates/postgresql-lst-parser",
"crates/postgresql-lst-parser-wasm",
"crates/postgresql-cst-parser",
"crates/postgresql-cst-parser-wasm",
]

default-members = ["crates/postgresql-lst-parser"]
default-members = ["crates/postgresql-cst-parser"]

[workspace.package]
exclude = ["crates/lexer-generator", "crates/parser-generator", "crates/postgresql-lst-parser-wasm"]
exclude = ["crates/lexer-generator", "crates/parser-generator", "crates/postgresql-cst-parser-wasm"]

[profile.release.package.postgresql-lst-parser-wasm]
[profile.release.package.postgresql-cst-parser-wasm]
opt-level = "s"


Expand Down
14 changes: 7 additions & 7 deletions README.ja.md
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
# postgresql-lst-parser
# postgresql-cst-parser

## 概要

`postgresql-lst-parser`は、Pure Rust で開発された PostgreSQL 専用の Lossless Syntax Tree(LST)パーサーです。この文書では、パーサーの特徴、動機、使用方法、および実装の詳細について説明します。
`postgresql-cst-parser`は、Pure Rust で開発された PostgreSQL 専用の Lossless Syntax Tree(CST)パーサーです。この文書では、パーサーの特徴、動機、使用方法、および実装の詳細について説明します。

## 主な特徴

- **自動生成された LST パーサー**: PostgreSQL の文法から自動的に生成されるため、幅広い文法に対応。
- **自動生成された CST パーサー**: PostgreSQL の文法から自動的に生成されるため、幅広い文法に対応。
- **部分的な制限**: スキャナーの一部の実装が不完全であるため、全ての文法に対応しているわけではありません。

## 開発の動機

1. Rust から利用でき、広範な文法をサポートする PostgreSQL の LST パーサーが不足している。
2. [pg_query.rs](https://github.com/pganalyze/pg_query.rs)はとても素晴らしいライブラリだが、LST は構築できず WebAssembly(wasm)でビルドできない。
1. Rust から利用でき、広範な文法をサポートする PostgreSQL の CST パーサーが不足している。
2. [pg_query.rs](https://github.com/pganalyze/pg_query.rs)はとても素晴らしいライブラリだが、CST は構築できず WebAssembly(wasm)でビルドできない。

## 使用方法

以下のコード例のようにして使用します。

```rust
let resolved_root = postgresql_lst_parser::parse("SELECT 1;");
let resolved_root = postgresql_cst_parser::parse("SELECT 1;");
dbg!(resolved_root);
```

さらに、このパーサーを実際に体験してみたい場合は、[こちら](https://tanzaku.github.io/postgresql-lst-parser/)でオンラインで直接試すことができます。実際のコードを入力し、パーサーがどのように動作するかを確認してみましょう。
さらに、このパーサーを実際に体験してみたい場合は、[こちら](https://tanzaku.github.io/postgresql-cst-parser/)でオンラインで直接試すことができます。実際のコードを入力し、パーサーがどのように動作するかを確認してみましょう。

## 実装方法

Expand Down
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
# postgresql-lst-parser
# postgresql-cst-parser

## Overview

The `postgresql-lst-parser` is a PostgreSQL-specific Lossless Syntax Tree (LST) parser developed in Pure Rust. This document describes the parser's features, motivation, usage, and details of its implementation.
The `postgresql-cst-parser` is a PostgreSQL-specific Lossless Syntax Tree (CST) parser developed in Pure Rust. This document describes the parser's features, motivation, usage, and details of its implementation.

## Key Features

- **Automatically Generated LST Parser**: Automatically generated from PostgreSQL grammar, allowing it to support a wide range of syntaxes.
- **Automatically Generated CST Parser**: Automatically generated from PostgreSQL grammar, allowing it to support a wide range of syntaxes.
- **Partial Limitations**: Due to some incomplete implementations in the scanner, it does not support all grammatical structures.

## Motivation for Development

1. There is a lack of PostgreSQL LST (Lossless Syntax Tree) parsers that can be utilized from Rust and support a wide range of syntax.
1. There is a lack of PostgreSQL CST (Lossless Syntax Tree) parsers that can be utilized from Rust and support a wide range of syntax.
1. [pg_query.rs](https://github.com/pganalyze/pg_query.rs) is an excellent library, however, it does not construct CSTs and cannot be built for WebAssembly (wasm).

## Usage

Use it as shown in the following code examples.

```rust
let resolved_root = postgresql_lst_parser::parse("SELECT 1;");
let resolved_root = postgresql_cst_parser::parse("SELECT 1;");
dbg!(resolved_root);
```

If you would like to experience this parser in action, you can try it out directly online [here](https://tanzaku.github.io/postgresql-lst-parser/). Enter your own code to see how the parser operates in real-time.
If you would like to experience this parser in action, you can try it out directly online [here](https://tanzaku.github.io/postgresql-cst-parser/). Enter your own code to see how the parser operates in real-time.


## Implementation
Expand Down
2 changes: 1 addition & 1 deletion build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ set -eux

cargo run -p lexer-generator --release
cargo run -p parser-generator --release
cargo test --package postgresql-lst-parser --test test -- test_all --exact --show-output
cargo test --package postgresql-cst-parser --test test -- test_all --exact --show-output
2 changes: 1 addition & 1 deletion build_wasm.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

set -eux

cd crates/postgresql-lst-parser-wasm
cd crates/postgresql-cst-parser-wasm
rm -rf ./pkg
wasm-pack build --release --target web
cp pkg/*.js pkg/*.ts pkg/*.wasm ../../docs/js
Expand Down
2 changes: 1 addition & 1 deletion crates/lexer-generator/src/lexer_generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ pub fn generate() {
.replace("{keyword_map}", &keywords.join("\n"));

let paths = [
"./crates/postgresql-lst-parser/src/lexer/generated.rs",
"./crates/postgresql-cst-parser/src/lexer/generated.rs",
"./crates/parser-generator/src/parser_generator/lexer/generated.rs",
];
for path in paths {
Expand Down
4 changes: 2 additions & 2 deletions crates/parser-generator/src/parser_generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ fn write_parser_file(
.replace("{end_rule_kind}", r#"TokenKind::RAW("$end".to_string())"#)
.replace("{end_rule_id}", &end_rule_id);

let paths = ["./crates/postgresql-lst-parser/src/parser.rs"];
let paths = ["./crates/postgresql-cst-parser/src/parser.rs"];
for path in paths {
std::fs::write(path, &parser_template).unwrap();
let _ = Command::new("rustfmt").arg(path).output();
Expand Down Expand Up @@ -195,7 +195,7 @@ fn write_syntax_file(
kinds.join("\n\t")
);

let path = "./crates/postgresql-lst-parser/src/syntax_kind.rs";
let path = "./crates/postgresql-cst-parser/src/syntax_kind.rs";
std::fs::write(path, source).unwrap();
let _ = Command::new("rustfmt").arg(path).output();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[package]
name = "postgresql-lst-parser-wasm"
name = "postgresql-cst-parser-wasm"
version = "0.1.0"
authors = ["tanzaku <[email protected]>"]
edition = "2018"
Expand All @@ -15,7 +15,7 @@ default = ["console_error_panic_hook"]

[dependencies]
wasm-bindgen = "0.2.84"
postgresql-lst-parser = { path = "../postgresql-lst-parser" }
postgresql-cst-parser = { path = "../postgresql-cst-parser" }

# The `console_error_panic_hook` crate provides better debugging of panics by
# logging them with `console.error`. This is great for development, but requires
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
mod utils;

use postgresql_lst_parser::parse;
use postgresql_cst_parser::parse;
use wasm_bindgen::prelude::*;

#[wasm_bindgen]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
[package]
name = "postgresql-lst-parser"
name = "postgresql-cst-parser"
version = "0.1.0"
edition = "2021"
repository = "https://github.com/tanzaku/postgresql-lst-parser"
description = "PostgreSQL lst parser"
repository = "https://github.com/tanzaku/postgresql-cst-parser"
description = "PostgreSQL cst parser"
documentation = ""
license-file = "../../LICENSE"

Expand Down
File renamed without changes.
File renamed without changes.
25 changes: 25 additions & 0 deletions crates/postgresql-cst-parser/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#![allow(non_camel_case_types)]

mod lexer;

mod parser;

mod cst;
pub mod syntax_kind;

pub use cst::NodeOrToken;
pub use cst::ParseError;
pub use cst::PostgreSQLSyntax;
pub use cst::ResolvedNode;
pub use cst::ResolvedToken;
pub use cst::SyntaxElement;
pub use cst::SyntaxElementRef;
pub use cst::SyntaxNode;
pub use cst::SyntaxToken;

pub fn parse(input: &str) -> Result<ResolvedNode, ParseError> {
cst::parse(input)
}

#[cfg(test)]
mod tests {}
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use postgresql_lst_parser::parse;
use postgresql_cst_parser::parse;

#[test]
fn test_all() -> Result<(), std::io::Error> {
Expand Down
25 changes: 0 additions & 25 deletions crates/postgresql-lst-parser/src/lib.rs

This file was deleted.

25 changes: 14 additions & 11 deletions demo/index.html
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>PostgreSQL LST Parser</title>
</head>
<body>
<div id="root"></div>
<script type="module" src="/src/main.tsx"></script>
</body>
</html>

<head>
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>PostgreSQL CST Parser</title>
</head>

<body>
<div id="root"></div>
<script type="module" src="/src/main.tsx"></script>
</body>

</html>
2 changes: 1 addition & 1 deletion demo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"build": "rm -rf ../docs && tsc && vite build",
"lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0",
"preview": "vite preview",
"copy-wasm": "cd ../crates/postgresql-lst-parser-wasm && rm -rf ./pkg && wasm-pack build --release --target web && cp pkg/*.js pkg/*.ts pkg/*.wasm ../../demo/src/postgresql-lst-parser"
"copy-wasm": "rm ./src/postgresql-cst-parser/* && cd ../crates/postgresql-cst-parser-wasm && rm -rf ./pkg && wasm-pack build --release --target web && cp pkg/*.js pkg/*.ts pkg/*.wasm ../../demo/src/postgresql-cst-parser"
},
"dependencies": {
"@emotion/react": "^11.11.4",
Expand Down
4 changes: 2 additions & 2 deletions demo/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import './App.css'
import Button from '@mui/material/Button';
import { Box, CssBaseline, TextField, Typography } from '@mui/material';

import init, { parse_sql } from "./postgresql-lst-parser/postgresql_lst_parser_wasm.js";
import init, { parse_sql } from "./postgresql-cst-parser/postgresql_cst_parser_wasm.js";

function App() {
const [sql, setSQL] = useState('SELECT\n\ttbl.a as a\nfrom\n\tTBL tbl')
Expand All @@ -27,7 +27,7 @@ function App() {
variant="h6"
sx={{ p: 1, flexGrow: 1 }}
align="left"
>PostgreSQL LST Parser
>PostgreSQL CST Parser
</Typography>
</Box>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ async function __wbg_init(input) {
if (wasm !== undefined) return wasm;

if (typeof input === 'undefined') {
input = new URL('postgresql_lst_parser_wasm_bg.wasm', import.meta.url);
input = new URL('postgresql_cst_parser_wasm_bg.wasm', import.meta.url);
}
const imports = __wbg_get_imports();

Expand Down
Binary file not shown.
2 changes: 1 addition & 1 deletion demo/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import react from '@vitejs/plugin-react-swc'
// https://vitejs.dev/config/
export default defineConfig({
plugins: [react()],
base: '/postgresql-lst-parser/',
base: '/postgresql-cst-parser/',
build: {
outDir: '../docs',
}
Expand Down

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Binary file not shown.
27 changes: 15 additions & 12 deletions docs/index.html
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/postgresql-lst-parser/vite.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>PostgreSQL LST Parser</title>
<script type="module" crossorigin src="/postgresql-lst-parser/assets/index-rSMo3Li_.js"></script>
<link rel="stylesheet" crossorigin href="/postgresql-lst-parser/assets/index-BplpfIhJ.css">
</head>
<body>
<div id="root"></div>
</body>
</html>

<head>
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/postgresql-cst-parser/vite.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>PostgreSQL CST Parser</title>
<script type="module" crossorigin src="/postgresql-cst-parser/assets/index-jkz93e-M.js"></script>
<link rel="stylesheet" crossorigin href="/postgresql-cst-parser/assets/index-C8lOUYDE.css">
</head>

<body>
<div id="root"></div>
</body>

</html>

0 comments on commit eb857d1

Please sign in to comment.