aboutsummaryrefslogtreecommitdiff
path: root/src/nbc/substitution.sml
diff options
context:
space:
mode:
authorCalvin <calvin@EESI>2013-03-15 15:26:20 -0400
committerCalvin <calvin@EESI>2013-03-15 15:26:20 -0400
commitb632667ce57af89691407bb8668e1512775278ae (patch)
treeb5742cef185f1cc4a7ba6005b5b4116ce7558a01 /src/nbc/substitution.sml
parent39e39f82cc38d71018882b0aaaf58255858a7c56 (diff)
nbc added
Diffstat (limited to 'src/nbc/substitution.sml')
-rw-r--r--src/nbc/substitution.sml26
1 files changed, 26 insertions, 0 deletions
diff --git a/src/nbc/substitution.sml b/src/nbc/substitution.sml
new file mode 100644
index 0000000..57d55cf
--- /dev/null
+++ b/src/nbc/substitution.sml
@@ -0,0 +1,26 @@
+signature SUBSTITUTION = sig
+ val substitute: (string -> string) -> string -> string option
+end
+
+structure Substitution :> SUBSTITUTION = struct
+ structure LrVals = SubstitutionGrmLrValsFun (structure Token = LrParser.Token)
+ structure Lex = SubstitutionLexFun (structure Tokens = LrVals.Tokens)
+ structure Parser = JoinWithArg (
+ structure ParserData = LrVals.ParserData
+ structure Lex = Lex
+ structure LrParser = LrParser
+ )
+ fun substitute lookup source =
+ let
+ val position = ref 0
+ val instream = TextIO.openString source
+ fun read n = TextIO.inputN (instream, n)
+ val lexer = Parser.makeLexer read (ref 0)
+ fun error (_, _, _) = ()
+ val (result, _) = Parser.parse (0, lexer, error, lookup)
+ val () = TextIO.closeIn instream
+ in
+ SOME result
+ end
+ handle Parser.ParseError => NONE
+end