Class: Chronar::Parser

Inherits:
Object
  • Object
show all
Defined in:
lib/chronar/parser.rb,
lib/chronar/parser/slot.rb,
lib/chronar/parser/bubble.rb,
lib/chronar/parser/number.rb,
lib/chronar/parser/string.rb,
lib/chronar/parser/comment.rb,
lib/chronar/parser/literal.rb,
lib/chronar/parser/operator.rb,
lib/chronar/parser/a_program.rb,
lib/chronar/parser/statement.rb,
lib/chronar/parser/assignment.rb,
lib/chronar/parser/expression.rb,
lib/chronar/parser/identifier.rb,
lib/chronar/parser/conditional.rb,
lib/chronar/parser/method_call.rb,
lib/chronar/parser/argument_list.rb,
lib/chronar/parser/abstract_parslet.rb,
lib/chronar/parser/a_program_transform.rb

Defined Under Namespace

Classes: AProgram, AProgramTransform, AbstractParslet, ArgumentList, Assignment, Bubble, Comment, Conditional, Expression, Identifier, Literal, MethodCall, Number, Operator, Slot, Statement, String, SwapAssignment

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.parseObject

Instantiate a new parser and parse the given program.



9
10
11
# File 'lib/chronar/parser.rb', line 9

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

Instance Method Details

#parse(program) ⇒ Object

Parse the given program.

Parameters:

  • program (String)

    The program to parse.

Returns:

  • (Object)

    The parsed program.



17
18
19
# File 'lib/chronar/parser.rb', line 17

def parse(program)
  transform(raw_parse(program))
end

#raw_parse(program) ⇒ Object

Parse the given program without transforming the result.

Parameters:

  • program (String)

    The program to parse.

Returns:

  • (Object)

    The parsed program.



25
26
27
28
29
# File 'lib/chronar/parser.rb', line 25

def raw_parse(program)
  AProgram.new.parse(program)
rescue Parslet::ParseFailed => e
  puts e.parse_failure_cause.ascii_tree
end

#transform(tree) ⇒ Object

Transform the given tree.

Parameters:

  • tree (Object)

    The tree to transform.

Returns:

  • (Object)

    The transformed tree.



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

def transform(tree)
  AProgramTransform.new.apply(tree)
end