Skip to content

Commit d2216b8

Browse files
committed
fix: comment
1 parent 118a1c6 commit d2216b8

File tree

5 files changed

+44
-90
lines changed

5 files changed

+44
-90
lines changed

crates/lexer-generator/src/lexer_generator.rs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use self::flex_file::{parse_flex_file, FlexFile};
44

55
mod flex_file;
66

7-
/// 各状態の全ルールに一意な名前を付ける
7+
/// Assign unique names to all rules in each state
88
fn construct_rule_kinds(flex_file: &FlexFile) -> String {
99
let mut res = Vec::new();
1010
let mut map: HashMap<&String, usize> = HashMap::new();
@@ -20,7 +20,7 @@ fn construct_rule_kinds(flex_file: &FlexFile) -> String {
2020
res.join(",\n")
2121
}
2222

23-
/// action部分のコードを生成する
23+
/// Generate code for the action part
2424
fn construct_actions(flex_file: &FlexFile) -> String {
2525
let mut res = Vec::new();
2626
let mut map: HashMap<&String, usize> = HashMap::new();
@@ -30,7 +30,7 @@ fn construct_actions(flex_file: &FlexFile) -> String {
3030
let e = map.entry(s).or_default();
3131
*e += 1;
3232

33-
// actionが | の場合、後続のルールが実行される
33+
// If the action is |, the subsequent rule will be executed
3434
if rule.actions.trim() == "|" {
3535
res.push(format!(
3636
r#"RuleKind::{kind}|"#,
@@ -51,17 +51,17 @@ fn construct_actions(flex_file: &FlexFile) -> String {
5151
res.join("\n")
5252
}
5353

54-
/// ルールのパターンを正規表現に変換する
54+
/// Convert rule patterns to regular expressions
5555
fn extract_rule_pattern(flex_file: &FlexFile, pattern: &str) -> String {
5656
if pattern == "<<EOF>>" {
5757
return "^$".to_string();
5858
}
5959

60-
// {xxx}のパターンを抽出する正規表現パターン
60+
// Regular expression pattern to extract {xxx} patterns
6161
let p = regex::Regex::new(r#"\{([a-zA-Z0-9_]+)\}"#).unwrap();
6262

63-
// flexではダブルクオートをエスケープする必要があるが、正規表現では不要である
64-
// そのため、正規表現パターンにする前にダブルクオートのエスケープを除外する
63+
// In flex, double quotes need to be escaped, but not in regular expressions
64+
// Therefore, remove the escaping of double quotes before converting to regex pattern
6565
fn remove_unnecessary_quote(s: &str) -> String {
6666
let chars = s.chars().collect::<Vec<_>>();
6767
let mut remove = vec![false; chars.len()];
@@ -98,11 +98,11 @@ fn extract_rule_pattern(flex_file: &FlexFile, pattern: &str) -> String {
9898
.collect()
9999
}
100100

101-
// {xxx}を実際の正規表現パターンに展開する
101+
// Expand {xxx} to actual regular expression patterns
102102
p.replace_all(&pattern, |caps: &regex::Captures| {
103103
let name = caps.get(1).unwrap().as_str();
104104

105-
// {xxx}のxxxが定義されているかをチェックする
105+
// Check if xxx in {xxx} is defined
106106
if let Some(def) = flex_file.definitions.iter().find(|def| def.name == name) {
107107
let pattern = remove_unnecessary_quote(&def.def);
108108
let rep = extract_rule_pattern(flex_file, &pattern);
@@ -114,7 +114,7 @@ fn extract_rule_pattern(flex_file: &FlexFile, pattern: &str) -> String {
114114
.to_string()
115115
}
116116

117-
/// Rule構造体を生成する
117+
/// Generate Rule structures
118118
fn construct_rule_defs(flex_file: &FlexFile) -> String {
119119
let mut res = Vec::new();
120120
let mut map: HashMap<&String, usize> = HashMap::new();
@@ -142,12 +142,12 @@ fn construct_rule_defs(flex_file: &FlexFile) -> String {
142142
res.join(",\n")
143143
}
144144

145-
/// 状態を表すenumを生成する
145+
/// Generate enum representing states
146146
fn construct_states(flex_file: &FlexFile) -> String {
147147
flex_file.all_states.clone().join(",\n")
148148
}
149149

150-
/// scan.lに基づいてLexerを生成する
150+
/// Generate Lexer based on scan.l
151151
pub fn generate() {
152152
let flex_file = parse_flex_file(include_str!("../resources/scan.l"));
153153
let template = include_str!("../templates/lex_template.rs");
@@ -157,7 +157,7 @@ pub fn generate() {
157157
let rule_defs = construct_rule_defs(&flex_file);
158158
let states = construct_states(&flex_file);
159159

160-
// キーワード一覧を抽出する
160+
// Extract keyword list
161161
let mut keywords = Vec::new();
162162
for line in include_str!("../resources/kwlist.h").lines() {
163163
if line.starts_with("PG_KEYWORD") {

crates/lexer-generator/templates/lex_template.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
use std::collections::HashMap;
55

6-
// use regex::{Match, Regex};
76
use regex::bytes::Regex;
87

98
use super::{

crates/parser-generator/src/parser_generator/bison.rs

Lines changed: 8 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,12 @@ pub enum RawComponent {
3939
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize)]
4040
pub struct ComponentId(pub u16);
4141

42-
/// 構文規則のコンポーネント
42+
/// Component of the syntax rule
4343
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize)]
4444
pub enum Component {
45-
/// 非終端記号
45+
/// Non-terminal symbol
4646
NonTerminal(String),
47-
/// 終端記号
47+
/// Terminal symbol
4848
Terminal(TokenKind),
4949
}
5050

@@ -134,25 +134,6 @@ pub struct Bison {
134134
pub rules: Vec<Rule>,
135135

136136
pub rule_names: Vec<String>,
137-
// これ使ってる?
138-
// pub comments: Vec<Token>,
139-
140-
// 構文解析表作るやつなので消す
141-
// pub components: Vec<Component>,
142-
// pub component_map: HashMap<Component, ComponentId>,
143-
144-
// pub name_to_rules: HashMap<String, Vec<usize>>,
145-
146-
// pub first_set: HashMap<ComponentId, HashSet<ComponentId>>,
147-
// pub nullable: HashMap<ComponentId, bool>,
148-
149-
// pub state_set: StateSet,
150-
// pub action_table: HashMap<(usize, ComponentId), Action>,
151-
// pub goto_table: HashMap<(usize, ComponentId), usize>,
152-
// pub accept_rule_component_id: ComponentId,
153-
// pub accept_rule_component: Component,
154-
// pub end_rule_component_id: ComponentId,
155-
// pub end_rule_component: Component,
156137
}
157138

158139
impl Bison {
@@ -191,7 +172,7 @@ fn parse_type(bison: &mut Bison, line: &str, deq: &mut VecDeque<String>) {
191172
.insert(non_terminal_symbol.to_string(), typ.to_string());
192173
}
193174

194-
// 空白スタートの場合継続業とみなす
175+
// If it starts with a space, consider it as a continuation line
195176
if deq.front().map_or(false, is_start_whitespace) {
196177
line = deq.pop_front().unwrap();
197178
} else {
@@ -221,7 +202,7 @@ fn parse_token(bison: &mut Bison, line: &str, deq: &mut VecDeque<String>) {
221202
bison.token.insert(terminal_symbol.to_string(), typ.clone());
222203
}
223204

224-
// 空白スタートの場合継続業とみなす
205+
// If it starts with a space, consider it as a continuation line
225206
if deq
226207
.front()
227208
.map_or(false, |line| is_start_whitespace(line) || line.is_empty())
@@ -249,8 +230,8 @@ fn parse_assoc(
249230

250231
loop {
251232
for name in line.split_whitespace() {
252-
// ブロックコメントの開始を見つけたら終了
253-
// 雑だがpostgresqlのgrammerをparseする分には問題ない
233+
// If we find the start of a block comment, end
234+
// This is rough but works fine for parsing postgresql's grammar
254235
if name == "/*" {
255236
break;
256237
}
@@ -264,7 +245,7 @@ fn parse_assoc(
264245
bison.assoc.insert(name.to_string(), assoc);
265246
}
266247

267-
// 空白スタートの場合継続業とみなす
248+
// If it starts with a space, consider it as a continuation line
268249
if deq.front().map_or(false, is_start_whitespace) {
269250
line = deq.pop_front().unwrap();
270251
} else {
@@ -603,29 +584,6 @@ pub fn parse_bison(s: impl AsRef<str>) -> Bison {
603584
assoc: HashMap::new(),
604585
rules: Vec::new(),
605586
rule_names: Vec::new(),
606-
// 未使用
607-
// comments: Vec::new(),
608-
609-
// Lalr構造体に移動
610-
// components: Vec::new(),
611-
// component_map: HashMap::new(),
612-
613-
// name_to_rules: HashMap::new(),
614-
615-
// first_set: HashMap::new(),
616-
// nullable: HashMap::new(),
617-
618-
// state_set: StateSet {
619-
// states: Vec::new(),
620-
// need_update: HashSet::new(),
621-
// },
622-
// action_table: HashMap::new(),
623-
// goto_table: HashMap::new(),
624-
625-
// accept_rule_component: Component::NonTerminal("dummy".to_string()),
626-
// accept_rule_component_id: ComponentId(0),
627-
// end_rule_component: Component::NonTerminal("dummy".to_string()),
628-
// end_rule_component_id: ComponentId(0),
629587
};
630588

631589
while let Some(line) = deq.pop_front() {

crates/parser-generator/src/parser_generator/lalr.rs

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ pub struct State {
8989
}
9090

9191
impl State {
92-
// LALR用の差分。先読み記号を無視する
92+
// Difference for LALR: ignore lookahead symbols
9393
fn equals_without_lookahead(&self, other: &State) -> bool {
9494
if self.items.len() != other.items.len() {
9595
return false;
@@ -101,7 +101,7 @@ impl State {
101101
.all(|(l, r)| l.rule_index == r.rule_index && l.dot_pos == r.dot_pos)
102102
}
103103

104-
// LALR用の差分。先読み記号を無視する
104+
// Difference for LR: Distinguish lookahead symbols
105105
fn equals(&self, other: &State) -> bool {
106106
if self.items.len() != other.items.len() {
107107
return false;
@@ -141,7 +141,7 @@ impl StateSet {
141141
{
142142
self.states[from_index].edge.insert((comp, i));
143143

144-
// 先読み記号まで含めて同一ならスキップ
144+
// Skip if it's identical including lookahead symbols
145145
if state.equals(&self.states[i]) {
146146
return;
147147
}
@@ -375,13 +375,13 @@ impl Lalr {
375375
.collect();
376376
}
377377

378-
// TODO closureをテストする
378+
// TODO: Test the closure function
379379
fn closure(&mut self, state: &mut State) {
380380
let mut in_deq = vec![false; state.items.len()];
381381

382382
let prev_item_len = state.items.len();
383383

384-
// LR(1)アイテム集合の単一状態の変化がなくなるまで繰り返す
384+
// Repeat until there are no more changes in the LR(1) item set for a single state
385385
let mut deq = VecDeque::from_iter(0..state.items.len());
386386
while let Some(j) = deq.pop_front() {
387387
in_deq[j] = false;
@@ -396,7 +396,7 @@ impl Lalr {
396396
continue;
397397
}
398398

399-
// ドットの次の要素が非終端記号の場合には、その非終端記号を左辺に持つ全ての規則について、非終端記号の先頭にドットおるアイテムを追加する。
399+
// If the element after the dot is a non-terminal symbol, add an item with the dot at the beginning of all rules that have that non-terminal symbol on the left-hand side.
400400
let component_id = self.rules[rule_index].components[dot_pos];
401401
if let Component::Terminal(_) = &self.id_mapper.components[component_id.0 as usize] {
402402
continue;
@@ -405,7 +405,7 @@ impl Lalr {
405405
let mut lookaheads = self.first_set_after[rule_index][dot_pos + 1].clone();
406406
let nullable = self.nullable[rule_index][dot_pos + 1];
407407

408-
// その際の先読み記号は、first_set(非終端記号の続き + lookahead)で求まる
408+
// The lookahead symbols are determined by first_set(continuation of non-terminal + lookahead)
409409
if nullable {
410410
state.items[j]
411411
.lookahead
@@ -416,17 +416,17 @@ impl Lalr {
416416
self.rule_indices_by_name_id[component_id.0 as usize]
417417
.iter()
418418
.for_each(|&new_item_index| {
419-
// 追加予定のアイテムが既に存在するかチェックする
419+
// Check if the item to be added already exists
420420
let j: Option<&usize> = state.item_indices.get(&new_item_index);
421421

422422
if let Some(&j) = j {
423-
// あれば先読み記号のみ追加
423+
// If it exists, only add lookahead symbols
424424
if state.items[j].insert_lookaheads(&lookaheads) && !in_deq[j] {
425425
deq.push_back(j);
426426
in_deq[j] = true;
427427
}
428428
} else {
429-
// なければ追加
429+
// If it doesn't exist, add it
430430
let new_item = Item {
431431
rule_index: new_item_index,
432432
dot_pos: 0,
@@ -445,11 +445,11 @@ impl Lalr {
445445
}
446446
}
447447

448-
/// 構文解析表を作成する
449-
/// 1. LR(1)項集合の作成
448+
/// Create a syntax analysis table
449+
/// 1. Create LR(1) item sets
450450
pub fn build_lalr1_parse_table(&mut self) {
451-
// bisonでは明示的に指定しない場合、最初のルールが起点のルールになる
452-
// PostgreSQLの場合、明示的に指定していないため、最初のルールを起点とする
451+
// In bison, if not explicitly specified, the first rule becomes the starting rule
452+
// In the case of PostgreSQL, it's not explicitly specified, so we use the first rule as the starting point
453453
let start_rule_index = self.rules.len();
454454
let start_component_id = self.rules[0].name_id;
455455

@@ -494,8 +494,8 @@ impl Lalr {
494494

495495
// dbg!(i, state_set.states.len());
496496

497-
// ドットを進めた状態を作る
498-
// ドットを進める状態を、次の記号でグループ化
497+
// Create states by advancing the dot
498+
// Group the states where the dot is advanced by the next symbol
499499
let mut next_states: BTreeMap<ComponentId, Vec<_>> = BTreeMap::new();
500500
for j in 0..state_set.states[i].items.len() {
501501
let dot_pos = state_set.states[i].items[j].dot_pos;
@@ -528,7 +528,7 @@ impl Lalr {
528528

529529
dbg!(state_set.states.len());
530530

531-
// 構文解析表を構築
531+
// Build the syntax analysis table
532532
let mut action_table: HashMap<(usize, ComponentId), Action> = HashMap::new();
533533
let mut goto_table: HashMap<(usize, ComponentId), usize> = HashMap::new();
534534

@@ -577,29 +577,29 @@ impl Lalr {
577577

578578
match (reduce, shift) {
579579
(Some(reduce), Some(shift)) if reduce.priority < shift.priority => {
580-
// shiftを採用
580+
// adopt shift
581581
}
582582
(Some(reduce), Some(shift)) if reduce.priority > shift.priority => {
583-
// reduceを採用
583+
// adopt reduce
584584
action_table.insert(key, reduce_action);
585585
}
586586
(Some(_), Some(shift)) => {
587587
match shift.directive {
588588
AssocDirective::NonAssoc => {
589-
// このケースはparse error
589+
// This case is a parse error
590590
action_table.insert(key, Action::Error);
591591
}
592592
AssocDirective::Left => {
593-
// reduceを採用
593+
// adopt reduce
594594
action_table.insert(key, reduce_action);
595595
}
596596
AssocDirective::Right => {
597-
// shiftを採用
597+
// adopt shift
598598
}
599599
}
600600
}
601601
_ => {
602-
// いずれかに優先度がなければshift優先らしい
602+
// If either one doesn't have a priority, shift seems to be preferred
603603
}
604604
}
605605
}

crates/postgresql-cst-parser/src/lib.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,3 @@ pub use cst::SyntaxToken;
2020
pub fn parse(input: &str) -> Result<ResolvedNode, ParseError> {
2121
cst::parse(input)
2222
}
23-
24-
#[cfg(test)]
25-
mod tests {}

0 commit comments

Comments
 (0)