@@ -2,76 +2,8 @@ import path from "node:path";
2
2
import { readFile } from "node:fs/promises" ;
3
3
import { argv , stdin , stdout , exit } from "node:process" ;
4
4
import { createInterface } from "node:readline/promises" ;
5
- import { buffer_size , rule_t } from "../tsds/tsds.mts" ;
6
-
7
- function * search ( input_strings , buffer_limit , callback ) {
8
- buffer_size ( buffer_limit ) ;
9
-
10
- const rules = { } ;
11
- const facts = { } ;
12
-
13
- let cycle = - 1 ;
14
-
15
- for ( const input_string of input_strings ) {
16
- const rule = new rule_t ( input_string ) ;
17
- if ( rule . length ( ) !== 0 ) {
18
- rules [ rule . key ( ) ] = [ rule , cycle ] ;
19
- } else {
20
- facts [ rule . key ( ) ] = [ rule , cycle ] ;
21
- }
22
- }
23
-
24
- while ( true ) {
25
- const temp_rules = { } ;
26
- const temp_facts = { } ;
27
- let something_new = false ;
28
-
29
- for ( const r_hash in rules ) {
30
- for ( const f_hash in facts ) {
31
- const [ rule , r_cycle ] = rules [ r_hash ] ;
32
- const [ fact , f_cycle ] = facts [ f_hash ] ;
33
- if ( r_cycle !== cycle && f_cycle !== cycle ) {
34
- continue ;
35
- }
36
- const candidate = rule . match ( fact ) ;
37
- if ( candidate === null ) {
38
- continue ;
39
- }
40
- const candidate_hash = candidate . key ( ) ;
41
- if ( candidate . length ( ) !== 0 ) {
42
- // rule
43
- if ( candidate_hash in rules || candidate_hash in temp_rules ) {
44
- continue ;
45
- }
46
- temp_rules [ candidate_hash ] = candidate ;
47
- } else {
48
- // fact
49
- if ( candidate_hash in facts || candidate_hash in temp_facts ) {
50
- continue ;
51
- }
52
- temp_facts [ candidate_hash ] = candidate ;
53
- }
54
- callback ( candidate ) ;
55
- something_new = true ;
56
- }
57
- }
58
-
59
- cycle ++ ;
60
- for ( const r_hash in temp_rules ) {
61
- const rule = temp_rules [ r_hash ] ;
62
- rules [ rule . key ( ) ] = [ rule , cycle ] ;
63
- }
64
- for ( const f_hash in temp_facts ) {
65
- const fact = temp_facts [ f_hash ] ;
66
- facts [ fact . key ( ) ] = [ fact , cycle ] ;
67
- }
68
- if ( ! something_new ) {
69
- return ;
70
- }
71
-
72
- yield ;
73
- }
74
- }
5
+ import { rule_t } from "../tsds/tsds.mts" ;
6
+ import { search } from "./search.mjs" ;
75
7
76
8
async function read_file_to_string_array ( file_path ) {
77
9
const content = await readFile ( file_path , "utf-8" ) ;
0 commit comments