Class: LLIP::Parser

Inherits:
Object
  • Object
show all
Defined in:
lib/llip/parser.rb

Overview

It’s a facade of the LLIP library.

To use it subclass it and then use the methods: production, scope and token to build the parser and its scanner.

Defined Under Namespace

Modules: ClassMethods

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeParser



26
27
28
29
30
# File 'lib/llip/parser.rb', line 26

def initialize
  @parser = self.class.parser.new
  @scanner = self.class.scanner.new
  @scanner = Buffer.new(@scanner) if self.class.lookahead
end

Instance Attribute Details

#parserObject (readonly)

The parser of the Parser subclass. It’s created from the class returned from LLIP::Parser::ClassMethods.parser.



21
22
23
# File 'lib/llip/parser.rb', line 21

def parser
  @parser
end

#scannerObject (readonly)

The scanner of the Parser subclass. It’s created from the class returned from LLIP::Parser::ClassMethods.scanner.



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

def scanner
  @scanner
end

Class Method Details

.inherited(other) ⇒ Object



15
16
17
18
# File 'lib/llip/parser.rb', line 15

def self.inherited(other)
  other.extend(ClassMethods)
  other.send(:init_parser)
end

Instance Method Details

#parse(source) ⇒ Object

Parse the source using the parser and the scanner.

See AbstractScanner#scan to know what is a valid source.



35
36
37
# File 'lib/llip/parser.rb', line 35

def parse(source)
  @parser.parse(@scanner.scan(source))
end