| 1 |
(* calc-test.sml |
| 2 |
* |
| 3 |
* COPYRIGHT (c) 2011 The Fellowship of SML/NJ (http://www.smlnj.org) |
| 4 |
* All rights reserved. |
| 5 |
*) |
| 6 |
|
| 7 |
structure CalcTest = |
| 8 |
struct |
| 9 |
|
| 10 |
structure Tok = CalcParseTokens |
| 11 |
|
| 12 |
structure ListLex = struct |
| 13 |
type strm = Tok.token list |
| 14 |
fun lex [] = (Tok.EOF, (0, 0), []) |
| 15 |
| lex (t::ts) = (t, (0, 0), ts) |
| 16 |
type pos = AntlrStreamPos.pos |
| 17 |
type span = pos * pos |
| 18 |
fun getPos _ = 0 |
| 19 |
end |
| 20 |
|
| 21 |
structure CP = CalcParseFn(ListLex) |
| 22 |
|
| 23 |
fun fragToToks (SMLofNJ.QUOTE s) = let |
| 24 |
val sref = ref true |
| 25 |
fun input _ = if !sref then |
| 26 |
(sref := false; s) |
| 27 |
else "" |
| 28 |
val lex = CalcLex.lex (AntlrStreamPos.mkSourcemap()) |
| 29 |
fun loop ((Tok.EOF, _, _), accum) = rev accum |
| 30 |
| loop ((s, _, strm), accum) = loop (lex strm, s::accum) |
| 31 |
in |
| 32 |
loop (lex (CalcLex.streamify input), []) |
| 33 |
end |
| 34 |
| fragToToks (SMLofNJ.ANTIQUOTE i) = [Tok.DummyExp i] |
| 35 |
|
| 36 |
fun % frags = let |
| 37 |
val (r, s', errs, {vars, nums}) = CP.parseexp ListLex.lex AtomMap.empty (List.concat (map fragToToks frags)) |
| 38 |
in |
| 39 |
app (fn (pos, repair) => print (AntlrRepair.actionToString Tok.toString repair ^ "\n")) errs; |
| 40 |
print (" -- VARS: " ^ (String.concatWith ", " vars) ^ "\n"); |
| 41 |
print (" -- NUMS: " ^ (String.concatWith ", " (map Int.toString nums)) ^ "\n"); |
| 42 |
(r, s') |
| 43 |
end |
| 44 |
|
| 45 |
(* val _ = Control.quotation := true *) |
| 46 |
|
| 47 |
end |