Class: Language

Inherits:
Object
  • Object
show all
Defined in:
lib/language.rb,
lib/language/atom.rb,
lib/language/output.rb,
lib/language/parser.rb,
lib/language/atom/or.rb,
lib/language/atom/aka.rb,
lib/language/atom/and.rb,
lib/language/atom/any.rb,
lib/language/atom/str.rb,
lib/language/atom/then.rb,
lib/language/atom/maybe.rb,
lib/language/parser/str.rb,
lib/language/atom/absent.rb,
lib/language/atom/ignore.rb,
lib/language/atom/repeat.rb,
lib/language/parser/absent.rb,
lib/language/parser/interuption.rb,
lib/language/parser/end_of_input.rb,
lib/language/parser/str/not_found.rb,
lib/language/parser/absent/present.rb,
lib/language/parser/not_end_of_input.rb

Defined Under Namespace

Classes: Atom, Output, Parser

Constant Summary collapse

Version =
Gem::Version.new(File.read(File.expand_path("../../VERSION", __dir__)))

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.<<(other) ⇒ Object



36
37
38
# File 'lib/language.rb', line 36

def self.<<(other)
  Atom::And.new(left: new, right: other)
end

.>>(other) ⇒ Object



32
33
34
# File 'lib/language.rb', line 32

def self.>>(other)
  Atom::And.new(left: new, right: other)
end

.absentObject



8
9
10
# File 'lib/language.rb', line 8

def self.absent
  Atom::Absent.new(parent: new)
end

.aka(name) ⇒ Object



24
25
26
# File 'lib/language.rb', line 24

def self.aka(name)
  Atom::Aka.new(parent: new, name:)
end

.ignoreObject



12
13
14
# File 'lib/language.rb', line 12

def self.ignore
  Atom::Ignore.new(parent: new)
end

.maybeObject



16
17
18
# File 'lib/language.rb', line 16

def self.maybe
  Atom::Maybe.new(parent: new)
end

.parse(input) ⇒ Object



4
5
6
# File 'lib/language.rb', line 4

def self.parse(input)
  new.parse(input)
end

.repeat(minimum = 0, maximum = nil) ⇒ Object



20
21
22
# File 'lib/language.rb', line 20

def self.repeat(minimum = 0, maximum = nil)
  Atom::Repeat.new(parent: new, minimum:, maximum:)
end

.then(&block) ⇒ Object



40
41
42
# File 'lib/language.rb', line 40

def self.then(&block)
  Atom::Then.new(parent: new, block:)
end

.|(other) ⇒ Object



28
29
30
# File 'lib/language.rb', line 28

def self.|(other)
  Atom::Or.new(left: new, right: other)
end

Instance Method Details

#anyObject



71
72
73
# File 'lib/language.rb', line 71

def any
  Atom::Any.new
end

#inspectObject



79
80
81
# File 'lib/language.rb', line 79

def inspect
  to_s
end

#parse(input_or_parser) ⇒ Object



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/language.rb', line 44

def parse(input_or_parser)
  if input_or_parser.is_a?(Parser)
    parser = input_or_parser
    clone =
      Parser.new(
        root:,
        input: parser.input,
        cursor: parser.cursor,
        buffer: parser.buffer,
        output: parser.output
      )

    clone.parse(check_end_of_input: false)

    parser.cursor = clone.cursor
    parser.buffer = clone.buffer
    parser.output = clone.output
  else
    input = input_or_parser
    Parser.new(root:, input:).parse
  end
end

#str(string) ⇒ Object



67
68
69
# File 'lib/language.rb', line 67

def str(string)
  Atom::Str.new(string:)
end

#to_sObject



75
76
77
# File 'lib/language.rb', line 75

def to_s
  "<#{self.class.name}>"
end