-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathREADME
96 lines (77 loc) · 2.72 KB
/
README
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
Ruby.scala is a simple parser written in the language Scala by using
parser combinators for ISO Ruby, ISO/IEC 30170:2012. It is written by
Dr. Ikuo Nakata, the chairman of the working group for the standardization
of the language Ruby, with the help by Dr. Kota Mizushima, a deputation of
Japan Scala Users Group and working at Ubiregi Inc.
Ruby.scala directly follows the syntax of ISO Ruby, except the following:
1. The left recursions are eliminated.
2. A local-variable-identifier which begins with the letter 'm' is
considered as a method name. Any other local-variable-identifiers are
considered as local variable names.
3. The nested brackets in an array-literal are not permitted.
4. The production rules for multiple-right-hand-side, class-definition,
method-definition and singleton-method-definition are corrected as follows:
11.4.2.4
multiple-right-hand-side ::
operator-expression-list [no line-terminator here] , splatting-right-hand-side
| operator-expression [no line-terminator here] , operator-expression-list
| splatting-right-hand-side
13.2.2
class-definition ::
class class-path ( [no line-terminator here] < superclass )?
separator class-body end
13.3.1
method-definition ::
def defined-method-name
( [no line-terminator here] method-parameter-part | separator )
method-body end
13.4.3
singleton-method-definition ::
def singleton-object ( . | :: ) defined-method-name
( [no line-terminator here] method-parameter-part | separator )
method-body end
5. "method-identifier block" in the right hand of production of primary-method-
invocation (11.3.1) is changed to "method-identifier block?".
6. Expressions which end with a do-block are not permitted as the expression in
while-expression, until-expression or for-expression.
Usage:
$ scalac Ruby.scala
$ scala -cp . RubyParser test.rb
Example 1:
------ test.rb --------
class X
@@a = 'abc'
def mprint_a
mputs @@a
end
def mset_a(value)
@@a = value
end
end
-----------------------
------- output --------
class X
var-assign-ex(@@a='abc')
def mprint_a;
method-inv-without-par(command(mputs @@a)) end-def
def mset_a(value)
var-assign-ex(@@a=value) end-def
end-class
----------------------
Example 2:
------ test.rb --------
<<ABC + <<XXX
efg
ABC
pqr
XXX
----------------------
------- output --------
(Heredoc("efg
") + Heredoc("pqr
"))
----------------------
The output is customizable by modifying each Parser object
corresponding to a production rule.
The current output is a string, and the string can be easily modified
by changing the output strings of relevant Parser objects.