soml-parser/lib/parser/basic.citrus
2015-08-29 16:08:28 +03:00

34 lines
789 B
Plaintext

grammar BasicTypes
# space really is just space. ruby is newline sensitive, so there is more whitespace footwork
# rule of thumb is that anything eats space behind it, but only space, no newlines
rule space [ \t]* end
rule linebreak "\n" end
rule comment
"#" (/.*/ !linebreak) linebreak
end
rule name_expression
(name:([a-z_] [a-zA-Z0-9_]*) space?) { Ast::NameExpression.new(capture(:name).to_str)}
end
rule digits
[0-9] [0-9]*
end
rule integer_expression
(digits space?) { Ast::IntegerExpression.new(to_str.to_i) }
end
rule instance_variable
('@' ivar:name_expression) { Ast::VariableExpression.new (capture(:ivar).value).name }
end
rule basic_expression
name_expression | integer_expression | instance_variable
end
end