soml-parser/lib/parser/sapphire.rb

39 lines
1.3 KiB
Ruby
Raw Normal View History

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"
require_relative "expression"
require_relative "call_site"
require_relative "function_definition"
require_relative "module_definition"
require_relative "operators"
module Parser
# obviously a work in progress !!
# We "compose" the parser from bits, divide and hopefully conquer
# 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-17 00:07:53 +02:00
class Sapphire < Parslet::Parser
2014-06-04 18:55:04 +02:00
include BasicTypes
include CompoundTypes
include Tokens
include Keywords
include Control
include Expression
include CallSite
include FunctionDefinition
include Operators
include ModuleDef
2014-06-26 12:33:42 +02:00
rule(:root_body) {(module_definition | class_definition | function_definition | expression |
operator_expression | call_site | basic_type | hash_constant | array_constant )}
rule(:root) { root_body.repeat.as(:expression_list) }
2014-06-04 18:55:04 +02:00
end
end