2014-06-04 18:55:04 +02:00
|
|
|
require_relative "basic_types"
|
|
|
|
require_relative "compound_types"
|
|
|
|
require_relative "tokens"
|
|
|
|
require_relative "keywords"
|
|
|
|
require_relative "control"
|
2015-10-09 16:32:34 +02:00
|
|
|
require_relative "statement"
|
2014-06-04 18:55:04 +02:00
|
|
|
require_relative "call_site"
|
|
|
|
require_relative "function_definition"
|
2015-10-08 21:57:39 +02:00
|
|
|
require_relative "class_definition"
|
2014-06-04 18:55:04 +02:00
|
|
|
require_relative "operators"
|
|
|
|
|
|
|
|
module Parser
|
2015-09-20 11:50:06 +02:00
|
|
|
|
2014-06-04 18:55:04 +02:00
|
|
|
# obviously a work in progress !!
|
|
|
|
# We "compose" the parser from bits, divide and hopefully conquer
|
2015-09-20 11:50:06 +02:00
|
|
|
|
2014-06-04 18:55:04 +02:00
|
|
|
# a note about .maybe : .maybe is almost every respect the same as .repeat(0,1)
|
|
|
|
# so either 0, or 1, in other words maybe. Nice feature, but there are strings attached:
|
|
|
|
# a maybe removes the 0 a sequence (array) to a single (hash). Thus 2 transformations are needed
|
|
|
|
# More work than the prettiness is worth, so only use .maybe on something that does not need capturing
|
|
|
|
|
2014-07-29 17:36:18 +02:00
|
|
|
class Salama < Parslet::Parser
|
2014-06-04 18:55:04 +02:00
|
|
|
include BasicTypes
|
|
|
|
include CompoundTypes
|
|
|
|
include Tokens
|
|
|
|
include Keywords
|
|
|
|
include Control
|
2015-10-09 16:32:34 +02:00
|
|
|
include Statement
|
2014-06-04 18:55:04 +02:00
|
|
|
include CallSite
|
|
|
|
include FunctionDefinition
|
|
|
|
include Operators
|
|
|
|
include ModuleDef
|
|
|
|
|
2015-10-09 11:39:31 +02:00
|
|
|
rule(:root_body) {( class_definition | function_definition )}
|
2015-10-09 16:32:34 +02:00
|
|
|
rule(:root) { root_body.repeat.as(:statement_list) }
|
2014-06-04 18:55:04 +02:00
|
|
|
end
|
|
|
|
end
|