Skip to content

Commit

Permalink
Cleanup:
Browse files Browse the repository at this point in the history
- Remove old DirectParser
- Remove conjuction-support
  • Loading branch information
judofyr committed Jul 3, 2019
1 parent 9ad397e commit b3019d2
Show file tree
Hide file tree
Showing 10 changed files with 15 additions and 337 deletions.
1 change: 0 additions & 1 deletion README.adoc
Expand Up @@ -7,7 +7,6 @@ Glush is a versatile parser toolkit based on Glushkov's construction algorithm:
- Scannerless: Works directly on characters (no lexer needed).
- Streamable, push-based API: You give it one token at a time; fail-fast supported.
- Supports matching UTF-8 characters.
- Supports conjunctive grammars.
- Reads EBNF grammars.
- Flexible operator precedence.
- Usable as a parser combinator library in Ruby.
Expand Down
4 changes: 2 additions & 2 deletions lib/glush.rb
Expand Up @@ -46,8 +46,8 @@ def unwrap

autoload :SMParser, __dir__ + '/glush/sm_parser.rb'

autoload :DirectParser, __dir__ + '/glush/direct_parser.rb'
autoload :Parser, __dir__ + '/glush/parser.rb'
autoload :DefaultParser, __dir__ + '/glush/default_parser.rb'

autoload :List, __dir__ + '/glush/list.rb'
autoload :MarkProcessor, __dir__ + '/glush/mark_processor.rb'

Expand Down
4 changes: 4 additions & 0 deletions lib/glush/default_parser.rb
@@ -0,0 +1,4 @@
module Glush
DefaultParser = SMParser
end

17 changes: 0 additions & 17 deletions lib/glush/direct_parser.rb

This file was deleted.

4 changes: 2 additions & 2 deletions lib/glush/ebnf.rb
Expand Up @@ -154,7 +154,7 @@ def compile_pattern(ast)
def finalize
fst_call = @calls.values.first
@grammar.finalize(fst_call.call)
DirectParser.new(@grammar)
DefaultParser.new(@grammar)
end

def process_seq(mark)
Expand Down Expand Up @@ -313,7 +313,7 @@ def process_prec_rule(mark)
end
end

Parser = Glush::DirectParser.new(Grammar)
Parser = Glush::DefaultParser.new(Grammar)

def self.create_parser(ebnf)
result = Parser.parse(ebnf).unwrap
Expand Down
253 changes: 0 additions & 253 deletions lib/glush/parser.rb

This file was deleted.

30 changes: 5 additions & 25 deletions lib/glush/patterns.rb
Expand Up @@ -293,49 +293,29 @@ def inspect
end

class Conj < Base
Finalizer = Struct.new(:id, :type)

def initialize(left, right)
@left = left.consume!
@right = right.consume!
raise GrammarError, "only single token can be used in conjuctions" if !@left.single_token? or !@right.single_token?
end

def single_token?
@left.single_token? && @right.single_token?
true
end

def match?(token)
@left.match?(token) && @right.match?(token)
end

def calculate_empty(b)
@is_empty = @left.calculate_empty(b) & @right.calculate_empty(b)
@is_empty = false
end

def static?
@left.static? && @right.static?
end

def first_set
@first_set ||= @left.first_set | @right.first_set
end

def last_set
@last_set ||= Set[self]
false
end

def each_pair(&blk)
@left.each_pair(&blk)
@right.each_pair(&blk)

@left.last_set.each do |lst|
yield lst, Finalizer.new(self, :left)
end

@right.last_set.each do |lst|
yield lst, Finalizer.new(self, :right)
end
end
include Terminal

def inspect
"conj(#{@left.inspect}, #{@right.inspect})"
Expand Down
4 changes: 2 additions & 2 deletions lib/glush/state_machine.rb
Expand Up @@ -41,7 +41,7 @@ def initialize(grammar)
@rules << rule

first_state = @state_mapping[rule]
first_states = @rule_first[rule] = [first_state]
@rule_first[rule] = [first_state]

rule.body.first_set.each do |fst_terminal|
connect(first_state, fst_terminal)
Expand Down Expand Up @@ -73,7 +73,7 @@ def connect(state, terminal)
rule = terminal.rule
action = CallAction.new(rule, return_state)
state.actions << action
when Patterns::Token
when Patterns::Token, Patterns::Conj
next_state = @state_mapping[terminal]
action = TokenAction.new(terminal, next_state)
state.actions << action
Expand Down

0 comments on commit b3019d2

Please sign in to comment.