summaryrefslogtreecommitdiff
path: root/grammar
diff options
context:
space:
mode:
authorAdrian Thurston <thurston@colm.net>2019-10-07 09:42:29 -0700
committerAdrian Thurston <thurston@colm.net>2019-10-07 09:42:29 -0700
commit4f2b259a3dcfc644aabbc462e845498aab5b94f9 (patch)
tree141676b59237be691ad048c1052c0f4f684ca404 /grammar
parentdd4978d207229687338379bf7946bbc6fe8b2e04 (diff)
downloadcolm-4f2b259a3dcfc644aabbc462e845498aab5b94f9.tar.gz
rust grammar: added else blocks and rudimentary float
Diffstat (limited to 'grammar')
-rw-r--r--grammar/rust.lm41
1 files changed, 29 insertions, 12 deletions
diff --git a/grammar/rust.lm b/grammar/rust.lm
index 089c5c7f..f7474a2d 100644
--- a/grammar/rust.lm
+++ b/grammar/rust.lm
@@ -1,5 +1,5 @@
lex
- literal `fn `use `let `mut `if `struct `for `in
+ literal `fn `use `let `mut `if `else `struct `for `in
literal `true `false
literal `ref `match
@@ -22,14 +22,15 @@ lex
literal `_
- token id /[A-Za-z_] [A-Za-z_0-9]*/
- token string / '"' ( [^\"] | '\\' any )* '"' /
- token char / "'" ( [^\'] | '\\' any ) "'" /
- token lifetime /"'" id/
- token number /[0-9]+/
+ token id / [A-Za-z_] [A-Za-z_0-9]* /
+ token string / '"' ( [^\"] | '\\' any )* '"' /
+ token char / "'" ( [^\'] | '\\' any ) "'" /
+ token lifetime / "'" id /
+ token number / [0-9]+ /
+ token float / [0-9]+ '.' [0-9]+ /
- ignore /'//' [^\n]* '\n'/
- ignore /[ \t\n]+/
+ ignore / "//" [^\n]* '\n' /
+ ignore / [ \t\n]+ /
end
#
@@ -49,6 +50,7 @@ def literal_pattern
| [char]
| [string]
| [number]
+| [float]
def identifier_pattern
[opt_ref opt_mut id]
@@ -231,6 +233,7 @@ def paths
| [char]
| [string]
| [number]
+| [float]
| [id `{ cons_list `}]
| [ `[ number `; number `]]
| [`( `)]
@@ -355,7 +358,8 @@ def expression_without_block
def expression_with_block
[block_expression]
| [`for id `in expression block_expression]
-| [if_stmt]
+| [if_expression]
+| [if_let_expression]
| [match_expression]
def expression_statement
@@ -372,9 +376,17 @@ def statements
| [statement+ expression_without_block]
| [expression_without_block]
-def if_stmt
- [`if expression block_expression]
-| [`if `let match_arm_patterns `= expression block_expression]
+def if_expression
+ [`if expression block_expression opt_else_expression]
+
+def opt_else_expression
+ [`else block_expression]
+| [`else if_expression]
+| [`else if_let_expression]
+| []
+
+def if_let_expression
+ [`if `let match_arm_patterns `= expression block_expression]
def field
[id `: type]
@@ -516,6 +528,11 @@ if P {
for CL: cons_list in FN {
print " construct list: [^CL]
}
+
+ for M: mult in FN {
+ if !match M [as]
+ print " mult: [^M]
+ }
}
}
else {