File tree Expand file tree Collapse file tree 1 file changed +31
-1
lines changed Expand file tree Collapse file tree 1 file changed +31
-1
lines changed Original file line number Diff line number Diff line change 3
3
4
4
how to use:
5
5
simply run command irb with '--simple-prompt' agrument
6
- =end
6
+ =end
7
+
8
+ require 'set'
9
+
10
+ class FARule < Struct . new ( :state , :character , :next_state )
11
+ def applies_to? ( state , character )
12
+ self . state == state && self . character == character
13
+ end
14
+
15
+ def follow
16
+ next_state ;
17
+ end
18
+
19
+ def inspect
20
+ "#<FARule #{ state . inspect } --#{ character } --> #{ next_state } >"
21
+ end
22
+ end
23
+
24
+ class NFARuleSet < Struct . new ( :rules )
25
+ def next_states ( states , character )
26
+ states . flat_map { |state | follow_rules_for ( state , character ) } . to_set
27
+ end
28
+
29
+ def follow_rules_for ( state , character )
30
+ rules_for ( state , character ) . map ( &:follow )
31
+ end
32
+
33
+ def rules_for ( state , character )
34
+ rules . select { |rule | rule . applies_to? ( state , character ) } # select * where
35
+ end
36
+ end
You can’t perform that action at this time.
0 commit comments