~tim/scheme-vm

ref: c5110102ce2df2d78a0c87f293edf20f5a3984e7 scheme-vm/src/lisp.rustpeg -rw-r--r-- 1.3 KiB
c5110102Tim Morgan Add more char functions 2 years ago
                                                                                
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
#![arguments(filename: &str, newlines: &Vec<usize>)]

use rb;
use rb::Value;
use atom::atom;
use quotes::QUOTES;

whitespace
	= [ \t\n]*

escape
	= "\\" .

string -> Option<Value>
	= s:$("\"" (escape / [^"])* "\"") { Some(rb::str_new(&s.to_string())) }

delimited_identifier -> &'input str
	= "|" i:$([^|]+) "|" {i}

simple_atom -> Value
	= p:#position a:(delimited_identifier / $([^\(\) \t\n\[\]\{\}\|"]+)) { atom(&a, &filename, p, newlines) }

quoted_atom -> Value
	= q:quote a:simple_atom { rb::vec2rbarr(vec![q, a]) }

atom -> Option<Value>
	= a:(quoted_atom / simple_atom) { Some(a) }

sexp -> Option<Value>
	= n:(quoted_sexp / simple_sexp) { Some(n) }

comment -> Option<Value>
	= (block_comment / line_comment / datum_comment) { None }

expression -> Option<Value>
	= string / comment / sexp / atom

quote -> Value
	= q:$("'" / ",@" / "," / "`") { rb::str_new(&QUOTES.get(&q).unwrap().to_string()) }

quoted_sexp -> Value
	= q:quote s:simple_sexp { rb::vec2rbarr(vec![q, s]) }

simple_sexp -> Value
	= "(" s:expressions ")" {s}

block_comment
	= "#|" (!"|#" .)* "|#"

line_comment
	= ";" [^\n]*

datum_comment
	= "#;" " "? (atom / sexp)

expressions -> Value
  = whitespace s:(expression ** whitespace) whitespace { rb::vec2rbarr(s.into_iter().filter_map(|i| i).collect()) }

pub program -> Value
	= expressions