[Toss-devel-svn] SF.net SVN: toss:[1712] trunk/Toss
Status: Beta
Brought to you by:
lukaszkaiser
|
From: <luk...@us...> - 2012-05-20 21:12:06
|
Revision: 1712
http://toss.svn.sourceforge.net/toss/?rev=1712&view=rev
Author: lukaszkaiser
Date: 2012-05-20 21:11:56 +0000 (Sun, 20 May 2012)
Log Message:
-----------
Term operations, rewriting and parsing adapted to current build system.
Modified Paths:
--------------
trunk/Toss/Formula/Aux.ml
trunk/Toss/Formula/Aux.mli
trunk/Toss/Makefile
trunk/Toss/Server/Tests.ml
trunk/Toss/Term/Makefile
trunk/Toss/Term/ParseArc.ml
trunk/Toss/Term/SyntaxDef.ml
trunk/Toss/Term/TRS.ml
trunk/Toss/Term/TRS.mli
trunk/Toss/Term/Term.ml
trunk/Toss/Term/Term.mli
trunk/Toss/Term/TermType.ml
trunk/Toss/Term/TermType.mli
trunk/Toss/Term/tests/differentiation.log
trunk/Toss/Term/tests/english.log
trunk/Toss/Term/tests/entanglement.log
trunk/Toss/Term/tests/fo_formula.log
trunk/Toss/Term/tests/sasha_basic.log
trunk/Toss/Term/tests/short_checks.log
trunk/Toss/Term/tests/simple_algo.log
trunk/Toss/Toss.odocl
Added Paths:
-----------
trunk/Toss/Term/TRSTest.ml
trunk/Toss/Term/lib/
trunk/Toss/Term/tests/
Removed Paths:
-------------
trunk/Toss/Term/lib/Makefile
trunk/Toss/Term/library/
trunk/Toss/Term/speagram.ml
trunk/Toss/Term/tests/Makefile
trunk/Toss/Term/testsuite/
Modified: trunk/Toss/Formula/Aux.ml
===================================================================
--- trunk/Toss/Formula/Aux.ml 2012-05-20 12:31:12 UTC (rev 1711)
+++ trunk/Toss/Formula/Aux.ml 2012-05-20 21:11:56 UTC (rev 1712)
@@ -78,6 +78,30 @@
let split_newlines s = split_charprop (fun c -> c = '\n' || c = '\r') s
+
+type split_result =
+ | Text of string
+ | Delim of string
+
+(* Look for characters from the list [l] after [c], split on such pairs. *)
+let split_chars_after c l s =
+ let split_c = split_charprop ~keep_split_chars:true (fun x -> x = c) s in
+ let c_str = String.make 1 c in
+ let rec process acc = function
+ | [] -> acc | [x] -> (Text x) :: acc
+ | delim :: str :: rest when
+ delim = c_str && String.length str > 0 && List.mem str.[0] l ->
+ let d = String.make 2 c in
+ d.[1] <- str.[0];
+ let txt = String.sub str 1 ((String.length str) - 1) in
+ process ((Text txt) :: (Delim d) :: acc) rest
+ | s1 :: (delim :: str :: rest as x) when
+ delim = c_str && String.length str > 0 && List.mem str.[0] l ->
+ process ((Text s1) :: acc) x
+ | s1 :: str :: rest -> process acc ((s1 ^ str) :: rest) in
+ List.rev (process [] split_c)
+
+
let split_empty_lines s = (* Split a string on empty lines. *)
let lstr accs = if accs = "" then [] else [accs] in
let rec concat_nonempty accs = function
@@ -112,14 +136,17 @@
if pat = "" then failwith "str_subst_once: empty pattern" else
try
let i, l, pl = str_index pat s, String.length s, String.length pat in
- ((String.sub s 0 i) ^ res ^ (String.sub s (i+pl) (l-i-pl)), true)
- with Not_found -> (s, false)
+ ((String.sub s 0 i) ^ res ^ (String.sub s (i+pl) (l-i-pl)), i)
+ with Not_found -> (s, -1)
let str_subst_once pat res s = fst (str_subst_once_report pat res s)
let rec str_subst_all pat res s =
- let (new_s, didsth) = str_subst_once_report pat res s in
- if didsth then str_subst_all pat res new_s else s
+ let (new_s, index) = str_subst_once_report pat res s in
+ if index < 0 then s else
+ let sl, rl = String.length new_s, String.length res in
+ (String.sub new_s 0 (index+rl)) ^
+ (str_subst_all pat res (String.sub new_s (index+rl) (sl-index-rl)))
let str_subst_once_from_to_report sfrom sto res s =
if sfrom = "" || sto = "" then failwith "str_subst_once_from_to: empty" else
Modified: trunk/Toss/Formula/Aux.mli
===================================================================
--- trunk/Toss/Formula/Aux.mli 2012-05-20 12:31:12 UTC (rev 1711)
+++ trunk/Toss/Formula/Aux.mli 2012-05-20 21:11:56 UTC (rev 1712)
@@ -359,7 +359,15 @@
(** Split a string on characters satisfying [f]. *)
val split_charprop : ?keep_split_chars: bool ->
(char -> bool) -> string -> string list
-
+
+(** Type for some split results. *)
+type split_result =
+ | Text of string
+ | Delim of string
+
+(** Look for characters from the list [l] after [c], split on such pairs. **)
+val split_chars_after : char -> char list -> string -> split_result list
+
(** Split a string on spaces. *)
val split_spaces : string -> string list
Modified: trunk/Toss/Makefile
===================================================================
--- trunk/Toss/Makefile 2012-05-20 12:31:12 UTC (rev 1711)
+++ trunk/Toss/Makefile 2012-05-20 21:11:56 UTC (rev 1712)
@@ -116,14 +116,15 @@
FormulaINC=MenhirLib,Formula,Formula/Sat,Formula/Sat/dpll
SolverINC=MenhirLib,Formula,Formula/Sat,Formula/Sat/dpll,Solver/RealQuantElim,Solver/Num
SolverINCRealQuantElimINC=MenhirLib,Formula,Formula/Sat,Formula/Sat/dpll,Solver/RealQuantElim,Solver/Num
-ArenaINC=MenhirLib,Formula,Formula/Sat,Formula/Sat/dpll,Solver/RealQuantElim,Solver/Num,Solver
-PlayINC=MenhirLib,Formula,Formula/Sat,Formula/Sat/dpll,Solver/RealQuantElim,Solver/Num,Solver,Arena
-LearnINC=MenhirLib,Formula,Formula/Sat,Formula/Sat/dpll,Solver/RealQuantElim,Solver/Num,Solver,Arena
-GGPINC=MenhirLib,Formula,Formula/Sat,Formula/Sat/dpll,Solver/RealQuantElim,Solver/Num,Solver,Arena,Play
-ServerINC=MenhirLib,Formula,Formula/Sat,Formula/Sat/dpll,Solver/RealQuantElim,Solver/Num,Solver,Arena,Play,GGP,Learn
-ClientINC=MenhirLib,Formula,Formula/Sat,Formula/Sat/dpll,Solver/RealQuantElim,Solver/Num,Solver,Arena,Play,GGP,Learn,Server
+TermINC=MenhirLib,Formula,Formula/Sat,Formula/Sat/dpll,Solver/RealQuantElim,Solver/Num
+ArenaINC=MenhirLib,Formula,Formula/Sat,Formula/Sat/dpll,Solver/RealQuantElim,Solver/Num,Solver,Term
+PlayINC=MenhirLib,Formula,Formula/Sat,Formula/Sat/dpll,Solver/RealQuantElim,Solver/Num,Solver,Term,Arena
+LearnINC=MenhirLib,Formula,Formula/Sat,Formula/Sat/dpll,Solver/RealQuantElim,Solver/Num,Solver,Term,Arena
+GGPINC=MenhirLib,Formula,Formula/Sat,Formula/Sat/dpll,Solver/RealQuantElim,Solver/Num,Solver,Term,Arena,Play
+ServerINC=MenhirLib,Formula,Formula/Sat,Formula/Sat/dpll,Solver/RealQuantElim,Solver/Num,Solver,Term,Arena,Play,GGP,Learn
+ClientINC=MenhirLib,Formula,Formula/Sat,Formula/Sat/dpll,Solver/RealQuantElim,Solver/Num,Solver,Term,Arena,Play,GGP,Learn,Server
-.INC=MenhirLib,Formula,Formula/Sat,Formula/Sat/dpll,Solver/RealQuantElim,Solver/Num,Solver,Arena,Play,GGP,Learn,Server
+.INC=MenhirLib,Formula,Formula/Sat,Formula/Sat/dpll,Solver/RealQuantElim,Solver/Num,Solver,Term,Arena,Play,GGP,Learn,Server
%.native: %.ml $(EXTDEPS)
$(OCAMLBUILD) -Is $($(subst /,INC,$(dir $@))) $@
Modified: trunk/Toss/Server/Tests.ml
===================================================================
--- trunk/Toss/Server/Tests.ml 2012-05-20 12:31:12 UTC (rev 1711)
+++ trunk/Toss/Server/Tests.ml 2012-05-20 21:11:56 UTC (rev 1712)
@@ -36,6 +36,10 @@
"ArenaTest", [ArenaTest.tests];
]
+let term_tests = "Term", [
+ "TRSTest", [TRSTest.tests; TRSTest.bigtests];
+]
+
let play_tests = "Play", [
"HeuristicTest", [HeuristicTest.tests; HeuristicTest.bigtests];
"GameTreeTest", [GameTreeTest.tests];
@@ -62,6 +66,7 @@
formula_tests;
solver_tests;
arena_tests;
+ term_tests;
play_tests;
ggp_tests;
learn_tests;
Modified: trunk/Toss/Term/Makefile
===================================================================
--- trunk/Toss/Term/Makefile 2012-05-20 12:31:12 UTC (rev 1711)
+++ trunk/Toss/Term/Makefile 2012-05-20 21:11:56 UTC (rev 1712)
@@ -1,101 +1,16 @@
-OCAMLTOP = ocaml -I +camlp4 camlp4o.cma str.cma
+all: parsed
-OCAMLCARGS = -I +camlp4 -pp "camlp4o" str.cma unix.cma
-OCAMLC = ocamlc $(OCAMLCARGS)
+RUN = ../TRSTest.native -c -f -l "../Term/lib"
-OCAMLOPTARGS = -I +camlp4 -pp "camlp4o" str.cmxa unix.cmxa
-OCAMLOPT = ocamlopt $(OCAMLOPTARGS)
+parsed:
+ make -C .. ./Term/TRSTest.native
+ $(RUN) -o lib/core.spg.parsed < lib/core.spg > /dev/null
+ $(RUN) -o lib/arithmetics.spg.parsed < lib/arithmetics.spg > /dev/null
+ $(RUN) -o lib/lists.spg.parsed < lib/lists.spg > /dev/null
+ $(RUN) -o lib/basic.spg.parsed < lib/basic.spg > /dev/null
+ $(RUN) -o lib/sasha.spg.parsed < lib/sasha.spg > /dev/null
-
-LATEX = latex
-DVIPS = dvips
-PS2PDF = ps2pdf
-
-DIFF = diff
-SED = sed
-Q = @
-
-
-############################################################
-# VARIABLES
-############################################################
-
-DISTFILES = speagram speagram.exe
-
-SRCFILES = Makefile *.ml *.mli
-
-
-############################################################
-# TARGETS
-############################################################
-
-
-all: speagram
-
-%.cmi: %.mli
- $(OCAMLC) -c $(addsuffix .mli, $(basename $<))
-
-%.cmo: %.ml %.mli
- $(OCAMLC) -c $(addsuffix .ml, $(basename $@))
-
-%.cmx: %.ml %.mli
- $(OCAMLOPT) -c $(addsuffix .ml, $(basename $@))
-
-USEDOCAML = $(OCAMLOPT)
-
-#
-# Use the definitions below to compile with MetaOCaml.
-# You need to adjust MetaOCaml path in ../config.mak first.
-#
-# %.cmi: %.mli
-# $(METAOCAMLC) -c $(addsuffix .mli, $(basename $<)) -o $@
-#
-# %.cmo: %.ml %.mli
-# mv $(addsuffix .ml, $(basename $@)) tmp.ml
-# $(CAMLP4) tmp.ml > $(addsuffix .ml, $(basename $@))
-# $(METAOCAMLC) -c $(addsuffix .ml, $(basename $@))
-# mv tmp.ml $(addsuffix .ml, $(basename $@))
-#
-# %.cmx: %.ml %.mli
-# mv $(addsuffix .ml, $(basename $@)) tmp.ml
-# $(CAMLP4) tmp.ml > $(addsuffix .ml, $(basename $@))
-# $(METAOCAMLOPT) -c $(addsuffix .ml, $(basename $@))
-# mv tmp.ml $(addsuffix .ml, $(basename $@))
-#
-# USEDOCAML = $(METAOCAMLOPT)
-#
-
-
-speagram: speagram.ml \
- TermType.cmi TermType.cmo TermType.cmx \
- SyntaxDef.cmi SyntaxDef.cmo SyntaxDef.cmx \
- BuiltinLang.cmi BuiltinLang.cmo BuiltinLang.cmx \
- Term.cmi Term.cmo Term.cmx \
- ParseArc.cmi ParseArc.cmo ParseArc.cmx \
- Rewriting.cmi Rewriting.cmo Rewriting.cmx \
- TRS.cmi TRS.cmo TRS.cmx
- $(USEDOCAML) \
- TermType.cmx SyntaxDef.cmx BuiltinLang.cmx Term.cmx Rewriting.cmx \
- ParseArc.cmx TRS.cmx speagram.ml -o speagram
-
-
-parsed: speagram
- $(MAKE) -C library
-
.PHONY:
-
-check: speagram
- $(MAKE) -C testsuite check
-
-
-tarball:
- cp $(DISTFILES) $(top_srcdir)/$(DIR)
- cp $(SRCFILES) $(top_srcdir)/$(DIR)/src
-
-
clean:
- rm -rf *.cmi *.cmo *.cmx *.o *~ speagram temptemp.html
- $(MAKE) -C library clean
- $(MAKE) -C testsuite clean
-
+ rm -rf *.cmi *.cmo *.cmx *.o *~ lib/*.parsed
Modified: trunk/Toss/Term/ParseArc.ml
===================================================================
--- trunk/Toss/Term/ParseArc.ml 2012-05-20 12:31:12 UTC (rev 1711)
+++ trunk/Toss/Term/ParseArc.ml 2012-05-20 21:11:56 UTC (rev 1712)
@@ -3,15 +3,10 @@
open List;;
-open Str;;
open TermType;;
open SyntaxDef;;
open Term;;
-(* * #load "Type.cmo";; *)
-(* * #load "SyntaxDef.cmo";; *)
-(* * #load "BuiltinLang.cmo";; *)
-(* * #load "Term.cmo";; *)
(* The type of elements created during parsing.
@@ -298,31 +293,47 @@
(* Splitting the whole input string. *)
let split_input_string str =
- let split_space s = split (regexp "[ \t\n\r]+") s in
+ let split_space s = Aux.split_spaces s in
let split_all_nonstr s = flatten (map split_word (split_space s)) in
- let string_regexp = regexp "[^&]\"\\|^\"" in
+ (*let string_regexp = Str.regexp "[^&]\"\\|^\"" in
let rec split_delims = function
- [] -> []
- | Text s :: Delim d :: rest when String.length d = 2 && d.[1] = '\"' ->
- Text (s ^ (String.make 1 (d.[0]))) :: Delim "\"" :: split_delims rest
- | Delim d :: rest when String.length d = 2 && d.[1] = '\"' ->
- Text (String.make 1 (d.[0])) :: Delim "\"" :: split_delims rest
- | Text s :: rest -> Text s :: split_delims rest
- | Delim "\"" :: rest -> Delim "\"" :: split_delims rest
+ | [] -> []
+ | Str.Text s :: Str.Delim d :: rest when String.length d =2 && d.[1]='\"' ->
+ Aux.Text (s ^ (String.make 1 (d.[0]))) :: Aux.Delim "\"" ::
+ split_delims rest
+ | Str.Delim d :: rest when String.length d = 2 && d.[1] = '\"' ->
+ Aux.Text (String.make 1 (d.[0])) :: Aux.Delim "\"" :: split_delims rest
+ | Str.Text s :: rest -> Aux.Text s :: split_delims rest
+ | Str.Delim "\"" :: rest -> Aux.Delim "\"" :: split_delims rest
| _ -> failwith "unrecognized delimiter which can not be here!" in
+ let split_delims_str = split_delims (Str.full_split string_regexp str) in*)
+ let split_delims_str =
+ let l = Aux.split_charprop ~keep_split_chars:true (fun c->c='"') str in
+ let res = List.map (fun s -> if String.length s = 1 && s.[0] = '"' then
+ Aux.Delim s else Aux.Text s) l in
+ let last_is_and s = s.[String.length s - 1] = '&' in
+ let all_but_last s = String.sub s 0 (String.length s - 1) in
+ let rec escape_ands = function
+ | [] -> []
+ | Aux.Text s1 :: Aux.Delim _ :: Aux.Text s2 :: rest when last_is_and s1 ->
+ escape_ands ( (Aux.Text ((all_but_last s1) ^ "\"" ^ s2)) :: rest )
+ | x :: rest -> x :: (escape_ands rest) in
+ escape_ands res in
let clear_escaped s =
- let s_1 = global_replace (regexp "&\\.") "." s in
- let s_2 = global_replace (regexp "&;") ";" s_1 in
- global_replace (regexp "&\"") "\"" s_2 in
+ let s_1 = Aux.str_subst_all "&\\." "." s in
+ let s_2 = Aux.str_subst_all "&;" ";" s_1 in
+ Aux.str_subst_all "&\"" "\"" s_2 in
let rec split_string_all = function
- [] -> []
- | Delim "\"" :: Delim "\"" :: rest ->
+ | [] -> []
+ | Aux.Delim "\"" :: Aux.Delim "\"" :: rest ->
"\"" :: "\"" :: split_string_all (rest)
- | Delim "\"" :: Text s :: Delim "\"" :: rest ->
+ | Aux.Delim "\"" :: Aux.Text s :: Aux.Delim "\"" :: rest ->
"\"" :: (clear_escaped s) :: "\"" :: split_string_all rest
- | Text s :: rest -> (split_all_nonstr s) @ split_string_all rest
- | Delim d :: rest -> d :: split_string_all rest in
- first_down (split_string_all (split_delims (full_split string_regexp str)))
+ | Aux.Text s :: rest -> (split_all_nonstr s) @ split_string_all rest
+ | Aux.Delim d :: rest -> d :: split_string_all rest in
+ let res = first_down (split_string_all split_delims_str) in
+ (* print_endline (String.concat " " res); *)
+ res
;;
Modified: trunk/Toss/Term/SyntaxDef.ml
===================================================================
--- trunk/Toss/Term/SyntaxDef.ml 2012-05-20 12:31:12 UTC (rev 1711)
+++ trunk/Toss/Term/SyntaxDef.ml 2012-05-20 21:11:56 UTC (rev 1712)
@@ -4,7 +4,7 @@
open Array;;
-open Str;;
+open Aux;;
open TermType;;
@@ -41,8 +41,8 @@
| SDvar (se, _) -> se
;;
-let double_slash s = global_replace (regexp "\\") "\\\\\\\\" s;;
-let slash_underscore s = global_replace (regexp "_") "\\_" s;;
+let double_slash s = Aux.str_subst_all "\\" "\\\\" s;;
+let slash_underscore s = Aux.str_subst_all "_" "\\_" s;;
let name_of_se_list sel =
let n s = slash_underscore (double_slash s) in
@@ -50,27 +50,28 @@
;;
let clean_name name =
- let split_name = full_split (regexp "[(),`@']\\|\\[\\|\\]") name in
+ let split_name = Aux.split_charprop ~keep_split_chars:true (fun c ->
+ (c = '(') || (c = ')') || (c = '[') || (c = ']') || (c = ',') ||
+ (c = '`') || (c = ''') || (c = '@') ) name in
let subst = function
- Text s -> s
- | Delim "(" -> "\\lb"
- | Delim ")" -> "\\rb"
- | Delim "[" -> "\\ls"
- | Delim "]" -> "\\rs"
- | Delim "," -> "\\cm"
- | Delim "`" -> "\\qt"
- | Delim "'" -> "\\ap"
- | Delim "@" -> "\\at"
- | Delim s -> failwith ("unexpected delimiter " ^ s) in
+ | "(" -> "\\lb"
+ | ")" -> "\\rb"
+ | "[" -> "\\ls"
+ | "]" -> "\\rs"
+ | "," -> "\\cm"
+ | "`" -> "\\qt"
+ | "'" -> "\\ap"
+ | "@" -> "\\at"
+ | s -> s in
String.concat "" (List.map subst split_name)
;;
let name_of_sd sd =
let name = clean_name (name_of_se_list (syntax_elems_of_sd sd)) in
match sd with
- SDtype se -> "T" ^ name
- | SDfun (se, _) -> "F" ^ name
- | SDvar (se, _) -> "V" ^ name
+ | SDtype se -> "T" ^ name
+ | SDfun (se, _) -> "F" ^ name
+ | SDvar (se, _) -> "V" ^ name
;;
let unique_name name used =
@@ -154,7 +155,7 @@
if n.[i-1] = '\\' then 1 + prefixing_slashes n (i-1) else 0 in
let end_slashes n = prefixing_slashes n (String.length n) in
match split with
- [] -> []
+ | [] -> []
| [x] -> [x]
| Delim s :: xs -> Delim s :: (correct_split xs)
| Text s1 :: (Text s2 :: _ as xs) -> Text s1 :: (correct_split xs)
@@ -168,30 +169,28 @@
(* Adds forbidden characters that were removed. *)
let unclean_name name =
- let delim = "\\\\lb\\|\\\\rb\\|\\\\ls\\|\\\\rs\\|\\\\cm\\|" ^
- "\\\\qt\\|\\\\ap\\|\\\\at" in
- let split_name = full_split (regexp delim) name in
- let subst = function
- Text s -> s
- | Delim "\\lb" -> "("
- | Delim "\\rb" -> ")"
- | Delim "\\ls" -> "["
- | Delim "\\rs" -> "]"
- | Delim "\\cm" -> ","
- | Delim "\\qt" -> "`"
- | Delim "\\ap" -> "'"
- | Delim "\\at" -> "@"
- | Delim s -> failwith ("unexpected delimiter " ^ s) in
- String.concat "" (List.map subst (correct_split split_name))
+ Aux.str_subst_all "\\lb" "(" (
+ Aux.str_subst_all "\\rb" ")" (
+ Aux.str_subst_all "\\ls" "[" (
+ Aux.str_subst_all "\\rs" "]" (
+ Aux.str_subst_all "\\cm" "," (
+ Aux.str_subst_all "\\qt" "`" (
+ Aux.str_subst_all "\\ap" "'" (
+ Aux.str_subst_all "\\at" "@" name
+ )))))))
;;
(* Splits name generated by syntax definition on underscores. *)
let split_sd_name_underscore name =
let uncleaned_name = unclean_name (basic_name_of_sd_name name) in
- let split_name = full_split (regexp "_") uncleaned_name in
+ let split_name =
+ let l = Aux.split_charprop ~keep_split_chars:true (fun c -> c = '_')
+ uncleaned_name in
+ List.map (fun s -> if String.length s = 1 && s.[0] = '_' then
+ Aux.Delim s else Aux.Text s) l in
let corrected_split = correct_split split_name in
let rec combine_underscore = function
- Text "\\" :: Text "_" :: rest ->
+ | Text "\\" :: Text "_" :: rest ->
combine_underscore (Text "\\_" :: rest)
| Text s1 :: Text "_" :: Text s2 :: rest ->
combine_underscore (Text (s1 ^ "_" ^ s2) :: rest)
@@ -200,8 +199,8 @@
combine_underscore (corrected_split)
;;
-let undouble_slash s = global_replace (regexp "\\\\\\\\") "\\\\" s;;
-let unslash_underscore s = global_replace (regexp "\\\\_") "_" s;;
+let undouble_slash s = Aux.str_subst_all "\\\\" "\\" s;;
+let unslash_underscore s = Aux.str_subst_all "\\_" "_" s;;
(* Split name to get strings and args in syntax definition. *)
let split_sd_name name =
@@ -378,9 +377,9 @@
let print_grammar gr =
let clean_grammar_name name =
if name.[0] = '$' then
- let r1 = global_replace (regexp "\\") "bslash" name in
- let r2 = global_replace (regexp "?") "qmark" r1 in
- global_replace (regexp "@") "AT" r2
+ let r1 = Aux.str_subst_all "\\" "bslash" name in
+ let r2 = Aux.str_subst_all "?" "qmark" r1 in
+ Aux.str_subst_all "@" "AT" r2
else
name in
let get_rule_branch sl =
@@ -398,11 +397,11 @@
exception NONXSLT;;
let make_xml_compatible str =
- let s = global_replace (regexp "&") "&" str in
- let s_0 = global_replace (regexp "'") "'" s in
- let s_1 = global_replace (regexp "\"") """ s_0 in
- let s_2 = global_replace (regexp "<") "<" s_1 in
- global_replace (regexp ">") ">" s_2
+ let s = Aux.str_subst_all "&" "&" str in
+ let s_0 = Aux.str_subst_all "'" "'" s in
+ let s_1 = Aux.str_subst_all "\"" """ s_0 in
+ let s_2 = Aux.str_subst_all "<" "<" s_1 in
+ Aux.str_subst_all ">" ">" s_2
;;
let xslt_content_for_sel sels =
Modified: trunk/Toss/Term/TRS.ml
===================================================================
--- trunk/Toss/Term/TRS.ml 2012-05-20 12:31:12 UTC (rev 1711)
+++ trunk/Toss/Term/TRS.ml 2012-05-20 21:11:56 UTC (rev 1712)
@@ -2,7 +2,6 @@
open List;;
-open Str;;
open TermType;;
open SyntaxDef;;
@@ -127,15 +126,13 @@
let rec process s =
try
let line = input_line in_file in
- if line = "" then process s else
- (
- (* print_endline ("parsing: " ^ line); *)
- let te = term_of_string line in
- s := update_on_term k te !s bs;
- process s
+ if line = "" then process s else (
+ (* print_endline ("parsing: " ^ line); *)
+ let te = term_of_string line in
+ s := update_on_term k te !s bs;
+ process s
)
- with
- End_of_file -> !s in
+ with End_of_file -> !s in
process (ref bs)
with
Sys_error s -> raise (Sys_error s)
@@ -413,12 +410,12 @@
exception FAILED_PARSE_OR_EXN of string;;
-let process_with_system_bs lp verbose s str fail xml_out bs =
+let process_with_system_bs lp verbose s str fail xml_out bs outprint =
match parse_disambiguate_with_sys verbose s str with
[] ->
let msg = "NO PARSE" in
if fail then
- (if (not xml_out) then print_endline msg else ();
+ (if (not xml_out) then outprint msg else ();
flush stdout;
raise (FAILED_PARSE_OR_EXN msg))
else
@@ -436,7 +433,7 @@
| ts ->
let msg = "AMBIGUOUS\n" ^ (terms_info verbose ts) in
if fail then
- (if (not xml_out) then print_endline msg else ();
+ (if (not xml_out) then outprint msg else ();
flush stdout;
raise (FAILED_PARSE_OR_EXN msg))
else
@@ -481,16 +478,16 @@
fold_left updr system1 basic_rules
;;
-let process_with_system lp verbose s str fail xml_out =
- process_with_system_bs lp verbose s str fail xml_out basic_system
+let process_with_system lp verbose s str fail xml_out outprint =
+ process_with_system_bs lp verbose s str fail xml_out basic_system outprint
;;
(* TESTS *
let s1 = "function *new* syntax definition as syntax definition";;
- let (sys1, msg) = process_with_system basic_system s1;;
+ let (sys1, msg) = process_with_system basic_system s1 print_endline;;
let s2 = "[]";;
- let (sys2, msg) = process_with_system sys1 s2;;
+ let (sys2, msg) = process_with_system sys1 s2 print_endline;;
*)
@@ -501,7 +498,7 @@
let read_to_sep channel =
(* We do not break on .,;,&. and &; and amp, quot, apos, lt, gt. *)
let rec read_to_sep_prev prev amp quot apos lt gt =
- let c = input_char channel in
+ let c = channel () in
if (c = '.' || c = ';') && (not (prev = '&')) && (not (amp = 5)) &&
(not (amp = 4 && c=';')) && (not (quot = 5 && c=';')) &&
(not (apos = 5 && c=';')) && (not (lt = 3 && c=';')) &&
@@ -540,16 +537,16 @@
if gt = 3 && c = ';' then 4 else 0 in
(String.make 1 prev) ^
(read_to_sep_prev c new_amp new_quot new_apos new_lt new_gt) in
- let ch = input_char channel in
+ let ch = channel () in
let no = if ch = '&' then 1 else 0 in
if (ch = '.' || ch = ';') then "" else read_to_sep_prev ch no no no no no
;;
let starts_comment s =
- match split (regexp "[ \t\n\r]+") s with
- [] -> false
+ match Aux.split_spaces s with
+ | [] -> false
| w :: _ ->
- if String.length w < 2 then false else
+ if String.length w < 2 then false else
(w.[0] = '/') && (w.[1] = '/')
;;
@@ -568,29 +565,29 @@
count_occurences s (i+1) c
;;
-let step_shell lp verb cmode sys channel should_fail xml_out parsed =
+let step_shell lp verb cmode sys channel should_fail xml_out parsed outprint =
let _ = (if not cmode then print_string "> " else (); flush stdout;) in
let s_read = read_to_sep channel in
let s_stripped = strip_first_space s_read in
- let s_0 = global_replace (regexp "'") "'" s_stripped in
- let s_1 = global_replace (regexp """) "\"" s_0 in
- let s_2 = global_replace (regexp "<") "<" s_1 in
- let s_3 = global_replace (regexp ">") ">" s_2 in
- let s = global_replace (regexp "&") "&" s_3 in
+ let s_0 = Aux.str_subst_all "'" "'" s_stripped in
+ let s_1 = Aux.str_subst_all """ "\"" s_0 in
+ let s_2 = Aux.str_subst_all "<" "<" s_1 in
+ let s_3 = Aux.str_subst_all ">" ">" s_2 in
+ let s = Aux.str_subst_all "&" "&" s_3 in
if starts_comment s then
if not xml_out then
if cmode then
(if (count_occurences s_read 0 '\n') > 1 then
- print_endline ("\n" ^ s ^ ".")
+ outprint ("\n" ^ s ^ ".")
else
- print_endline (s ^ ".");
+ outprint (s ^ ".");
flush stdout;
sys
)
else
- (print_endline ("SPG: " ^ s ^ "\n"); flush stdout; sys)
+ (outprint ("SPG: " ^ s ^ "\n"); flush stdout; sys)
else (
- print_endline ("<speagram-comment>" ^
+ outprint ("<speagram-comment>" ^
(make_xml_compatible (s ^ ".")) ^ "</speagram-comment>");
sys
)
@@ -598,16 +595,15 @@
(
if not cmode then (print_string "SPG: "; flush stdout) else ();
let (nsys, nparsed, msg) =
- process_with_system lp verb sys s should_fail xml_out in
+ process_with_system lp verb sys s should_fail xml_out outprint in
(parsed := (nparsed @ !parsed);
if cmode then
if (count_occurences s_read 0 '\n') > 1 then
- print_endline ("\n" ^ msg)
+ outprint ("\n" ^ msg)
else
- print_endline msg
+ outprint msg
else
- print_endline (msg ^ "\n");
- flush stdout;
+ outprint (msg ^ "\n");
nsys
)
)
Modified: trunk/Toss/Term/TRS.mli
===================================================================
--- trunk/Toss/Term/TRS.mli 2012-05-20 12:31:12 UTC (rev 1711)
+++ trunk/Toss/Term/TRS.mli 2012-05-20 21:11:56 UTC (rev 1712)
@@ -25,7 +25,7 @@
exception FAILED_PARSE_OR_EXN of string;;
val process_with_system : string -> bool -> spg_system -> string -> bool ->
- bool -> spg_system * Term.term list * string;;
+ bool -> (string -> unit) -> spg_system * Term.term list * string;;
val basic_sdefs : syntax_def list;;
@@ -33,5 +33,7 @@
(* -------- COMPLETE ONE STEP OF A SHELL ------- *)
-val step_shell : string -> bool -> bool -> spg_system ->
- in_channel -> bool -> bool -> Term.term list ref -> spg_system
+(* A step of the computation. The channel (unit -> char) argument should
+ raise End_of_file on end of channel, as does input_char. *)
+val step_shell : string -> bool -> bool -> spg_system -> (unit -> char) ->
+ bool -> bool -> Term.term list ref -> (string -> unit) -> spg_system
Copied: trunk/Toss/Term/TRSTest.ml (from rev 1711, trunk/Toss/Term/speagram.ml)
===================================================================
--- trunk/Toss/Term/TRSTest.ml (rev 0)
+++ trunk/Toss/Term/TRSTest.ml 2012-05-20 21:11:56 UTC (rev 1712)
@@ -0,0 +1,167 @@
+(* The speagram binary for command line use. *)
+
+
+open List;;
+
+open Term;;
+open TRS;;
+open SyntaxDef;;
+
+open OUnit;;
+
+let rec run lp v grammar_path xslt_path out_path
+ cmode sys channel fail xmlo res outprint =
+ let save_parsed () =
+ let parsed_strs = map term_to_string (rev !res) in
+ let out_file = open_out (out_path) in
+ (if not cmode then
+ outprint ("SAVING PARSED TERMS TO " ^ out_path ^ ".")
+ else ();
+ output_string out_file ((String.concat "\n" parsed_strs) ^ "\n");
+ close_out out_file;); in
+ let save_xslt () = (
+ if not cmode then
+ outprint ("SAVING XSLT TO " ^ xslt_path ^ ".")
+ else ();
+ let addon_term = Term (BuiltinLang.additional_xslt_name, [||]) in
+ let addon_str = decode_string (normalise_with_sys !sys addon_term) in
+ let xslt_str =
+ print_xslt addon_str (syntax_defs_of_sys !sys) in
+ let out_file = open_out (xslt_path) in
+ (output_string out_file xslt_str; close_out out_file;)) in
+ let save_grammar () = (
+ if not cmode then
+ outprint ("SAVING GRAMMAR TO " ^ grammar_path ^ ".")
+ else ();
+ let grammar_str =
+ let sys_sdefs = fst (List.split (syntax_defs_of_sys !sys)) in
+ print_grammar (flat_grammar_of_sd_list (sys_sdefs)) in
+ let out_file = open_out (grammar_path) in
+ (output_string out_file grammar_str; close_out out_file;)) in
+ let save_requested () = (
+ if (not (grammar_path = "")) then save_grammar () else ();
+ if (not (xslt_path = "")) then save_xslt () else ();
+ if (not (out_path = "")) then save_parsed () else ();
+ ) in
+ try
+ (sys := step_shell lp v cmode !sys channel fail xmlo res outprint;
+ run lp v grammar_path xslt_path out_path cmode sys channel fail xmlo res outprint)
+ with
+ | End_of_file -> save_requested ();
+ | FAILED_PARSE_OR_EXN msg ->
+ (save_requested ();
+ if xmlo then
+ (outprint "\n<speagram-failure>\n";
+ outprint (make_xml_compatible msg);
+ outprint "\n</speagram-failure>\n";
+ outprint "\n</speagram-response>\n";)
+ else ();
+ failwith msg)
+;;
+
+let test fname =
+ let s = ref (AuxIO.input_file ("./Term/tests/" ^ fname ^ ".spg")) in
+ let read_s () = if !s = "" then raise End_of_file else (
+ let c = !s.[0] in s := String.sub !s 1 ((String.length !s)-1); c) in
+ let o = ref "" in
+ let print_o str = o := !o ^ str ^ "\n" in
+ run "./Term/lib" false "" "" "" true
+ (ref basic_system) read_s true false (ref []) print_o;
+ assert_equal ~printer:(fun x -> x) (Aux.normalize_spaces (
+ AuxIO.input_file ("./Term/tests/" ^ fname ^ ".log")))
+ (Aux.normalize_spaces !o)
+
+let tests = "TRS" >::: [
+ "test short_checks" >::
+ (fun () -> test "short_checks";);
+]
+
+let bigtests = "TRS" >::: [
+ "test fo_formula" >::
+ (fun () -> test "fo_formula";);
+ "test sasha_basic" >::
+ (fun () -> test "sasha_basic";);
+ "test english" >::
+ (fun () -> test "english";);
+ "test simple_algo" >::
+ (fun () -> test "simple_algo";);
+ "test entanglement" >::
+ (fun () -> test "entanglement";);
+ "test differentiation" >::
+ (fun () -> test "differentiation";);
+]
+
+
+let main () =
+ let _ = Gc.set { (Gc.get()) with
+ Gc.space_overhead = 128; Gc.max_overhead = 512;
+ Gc.minor_heap_size = 1048576; Gc.major_heap_increment = 4194304 } in
+ let should_fail = ref false in
+ let make_it_fail () = (should_fail := true) in
+ let verbose = ref false in
+ let make_verbose () = (verbose := true) in
+ let out_path = ref "" in
+ let set_output_file s = (out_path := s) in
+ let lib_path = ref "library" in
+ let set_lib_path s = (lib_path := s) in
+ let print_mem_after = ref false in
+ let print_mem_set () = (print_mem_after := true) in
+ let builtin_out = ref false in
+ let set_builtin_out () = (builtin_out := true) in
+ let compile_mode = ref false in
+ let set_compile () = (compile_mode := true) in
+ let xml_out = ref false in
+ let set_xml_out () = (xml_out := true; compile_mode := true) in
+ let grammar_path = ref "" in
+ let set_gram_path s = (grammar_path := s) in
+ let xslt_path = ref "" in
+ let set_xslt_path s = (xslt_path := s) in
+ let opts = [
+ ("-f", Arg.Unit (make_it_fail), "make speagram fail on bad parses");
+ ("-v", Arg.Unit (make_verbose), "make speagram verbose");
+ ("-m", Arg.Unit (print_mem_set), "show memory use when quitting");
+ ("-o", Arg.String (set_output_file), "output parsed terms to file");
+ ("-l", Arg.String (set_lib_path), "set path to library directory");
+ ("-b", Arg.Unit (set_builtin_out), "print builtin language definitions");
+ ("-c", Arg.Unit (set_compile), "work in compile and not interactive mode");
+ ("-x", Arg.Unit (set_xml_out), "output normalised terms in XML format");
+ ("-g", Arg.String (set_gram_path), "output (flat EBNF) grammar to file");
+ ("-s", Arg.String (set_xslt_path), "output corresponding XSLT to file");
+ ] in
+ let _ = Arg.parse opts (fun _ -> ()) "try -h for help" in
+ if not !should_fail then
+ ignore (OUnit.run_test_tt ~verbose:true tests)
+ else (
+ let parsed_terms = ref [] in
+ let basic_sys = ref basic_system in
+ if !builtin_out then
+ let defs = String.concat "\n" (map pretty_print_sd basic_sdefs) in
+ print_endline ("// SPEAGRAM BUILT-IN DEFS.\n" ^ defs ^ "\n")
+ else (
+ if not (!compile_mode) then
+ print_endline "\nWELCOME TO SPEAGRAM, PARSING INPUT:\n"
+ else
+ if (!xml_out) then print_endline "<speagram-response>" else ();
+ run !lib_path !verbose !grammar_path !xslt_path !out_path !compile_mode
+ basic_sys (fun ()->input_char stdin) !should_fail !xml_out
+ parsed_terms (fun s -> print_endline s);
+ if (!print_mem_after && (not (!compile_mode))) then
+ let mem = Gc.allocated_bytes () in
+ let mem_str = string_of_int (int_of_float (mem /. 1024.0) / 1024) in
+ let gc_overhd= float_of_int ((Gc.get()).Gc.space_overhead+100)/.100.0 in
+ let min_heap_unit = float_of_int (4*(Gc.get()).Gc.minor_heap_size) in
+ let est_use_mem = ((mem *. gc_overhd) /. 1024.0) +. min_heap_unit in
+ let est_use_str = string_of_int ((int_of_float est_use_mem) / 1024) in
+ let est = "<est. " ^ est_use_str ^ " KB used>" in
+ let mem_msg = "(ocaml reports " ^ mem_str ^" MB allocated "^est^")" in
+ print_endline ("\n\nBYE " ^ mem_msg ^ " :)\n")
+ else
+ if not !compile_mode then
+ print_endline "\n\nBYE :)\n"
+ else
+ if (!xml_out) then print_endline "</speagram-response>\n" else ();
+ )
+ )
+;;
+
+let _ = AuxIO.run_if_target "TRSTest" main
Modified: trunk/Toss/Term/Term.ml
===================================================================
--- trunk/Toss/Term/Term.ml 2012-05-20 12:31:12 UTC (rev 1711)
+++ trunk/Toss/Term/Term.ml 2012-05-20 21:11:56 UTC (rev 1712)
@@ -3,7 +3,7 @@
open Array;;
-open Str;;
+open Aux;;
open TermType;;
open SyntaxDef;;
@@ -528,27 +528,27 @@
let term_array_to_string ta =
String.concat ", " (to_list (map term_to_string ta)) in
match term with
- _ when is_some (decode_string_opt term) ->
+ | _ when is_some (decode_string_opt term) ->
let s = (match (decode_string_opt term) with Some s -> s | None -> "") in
- "@`" ^ (global_replace (regexp "[\n\r\t]") " " s) ^ "@`"
- | _ when is_some (decode_list_opt (fun x -> x) term) ->
+ "@`" ^ (Aux.normalize_spaces s) ^ "@`"
+ | _ when is_some (decode_list_opt (fun x -> x) term) ->
(match (decode_list_opt (fun x -> x) term) with None -> ""
- | Some l -> "@L["^ (String.concat ", " (List.map term_to_string l)) ^"]")
- | _ when is_some (decode_term_type_opt term) ->
+ | Some l -> "@L["^ (String.concat ", " (List.map term_to_string l))^"]")
+ | _ when is_some (decode_term_type_opt term) ->
(match (decode_term_type_opt term) with None -> ""
- | Some ty -> "@Y " ^ (type_to_string ty))
- | _ when is_some (decode_term_opt term) ->
+ | Some ty -> "@Y " ^ (type_to_string ty))
+ | _ when is_some (decode_term_opt term) ->
(match (decode_term_opt term) with None -> ""
- | Some te -> "@T " ^ (term_to_string te))
- | Var (v, t, d, [||]) ->
+ | Some te -> "@T " ^ (term_to_string te))
+ | Var (v, t, d, [||]) ->
"@V [" ^ v ^ " @: " ^ (type_to_string t) ^
" @: "^ string_of_int (d) ^ " ]"
- | Var (v, t, d, a) ->
+ | Var (v, t, d, a) ->
"@V [" ^ v ^ " @: " ^ (type_to_string t) ^
" @: "^ string_of_int (d) ^ " ] (" ^
- (term_array_to_string a) ^ " )"
- | Term (n, [||]) -> n
- | Term (n, a) ->
+ (term_array_to_string a) ^ " )"
+ | Term (n, [||]) -> n
+ | Term (n, a) ->
n ^ " (" ^ (term_array_to_string a) ^ " )"
;;
Modified: trunk/Toss/Term/Term.mli
===================================================================
--- trunk/Toss/Term/Term.mli 2012-05-20 12:31:12 UTC (rev 1711)
+++ trunk/Toss/Term/Term.mli 2012-05-20 21:11:56 UTC (rev 1712)
@@ -87,7 +87,7 @@
val display_term_xml : term -> string;;
val term_to_string : term -> string;;
-val parse_term : Str.split_result Stream.t -> term;;
+val parse_term : Aux.split_result Stream.t -> term;;
val term_of_string : string -> term;;
Modified: trunk/Toss/Term/TermType.ml
===================================================================
--- trunk/Toss/Term/TermType.ml 2012-05-20 12:31:12 UTC (rev 1711)
+++ trunk/Toss/Term/TermType.ml 2012-05-20 21:11:56 UTC (rev 1712)
@@ -3,9 +3,7 @@
open Array;;
-open Str;;
-
(* The type of term types. *)
type term_type =
Term_type of string * term_type array
@@ -131,20 +129,33 @@
(* Lexer for types and terms. *)
let split_to_list str =
- let split_space s = split (regexp "[ \t\n\r]+") s in
- let special_regexp = regexp "[(,)]\\|\\[\\|\\]\\|@[FLVYT`:\\?]" in
+ let split_space s = Aux.split_spaces s in
+ let full_special_split s =
+ let l = Aux.split_chars_after '@' ['F';'L';'V';'Y';'T';'`';':';'?'] s in
+ let is_special c = (c = '(') || (c = ')') ||(c = '[') || (c = ']') ||
+ (c = ',') in
+ let divide s =
+ let l = Aux.split_charprop ~keep_split_chars:true is_special s in
+ List.map (fun s -> if String.length s = 1 && is_special s.[0] then
+ Aux.Delim s else Aux.Text s) l in
+ let restsplit =
+ function | Aux.Delim d -> [Aux.Delim d] | Aux.Text s -> divide s in
+ List.concat (List.map restsplit l) in
let split_special_space s =
- List.concat (List.map (full_split special_regexp) (split_space s)) in
- let string_regexp = regexp "@`" in
+ List.concat (List.map full_special_split (split_space s)) in
let rec split_special = function
- [] -> []
- | Delim "@`" :: Delim "@`" :: rest ->
- Delim "@`" :: Delim "@`" :: split_special (rest)
- | Delim "@`" :: Text s :: Delim "@`" :: rest ->
- Delim "@`" :: Text s :: Delim "@`" :: split_special (rest)
- | Text s :: rest -> (split_special_space s) @ split_special (rest)
- | Delim d :: rest -> Delim d :: split_special (rest) in
- split_special (full_split string_regexp str)
+ | [] -> []
+ | Aux.Delim "@`" :: Aux.Delim "@`" :: rest ->
+ Aux.Delim "@`" :: Aux.Delim "@`" :: split_special (rest)
+ | Aux.Delim "@`" :: Aux.Text s :: Aux.Delim "@`" :: rest ->
+ Aux.Delim "@`" :: Aux.Text s :: Aux.Delim "@`" :: split_special (rest)
+ | Aux.Text s :: rest -> (split_special_space s) @ split_special (rest)
+ | Aux.Delim d :: rest -> Aux.Delim d :: split_special (rest) in
+ let r1 = Aux.split_chars_after '@' ['`'] str in
+ (*print_endline (String.concat " |"
+ (List.map (function Aux.Delim d -> "D " ^ d |
+ Aux.Text d -> "T " ^ d) r1));*)
+ split_special r1
;;
(* TESTS *
@@ -152,26 +163,32 @@
split_to_list "@`[] \n \t @F@` [ ]\t (@`@`, @`@`) ";;
*)
-let split_to_stream str = Stream.of_list (split_to_list str);;
+let split_to_stream str =
+ let l = split_to_list str in
+ (*print_endline "ALA";
+ print_endline (String.concat " |"
+ (List.map (function Aux.Delim d -> "D " ^ d |
+ Aux.Text d -> "T " ^ d) l));*)
+ Stream.of_list l
(* Parser for types. *)
let rec parse_type = parser
- [< 'Delim "@?"; 'Text n >] -> Type_var n
- | [< 'Delim "@F"; l = parse_list >] -> (
+ [< 'Aux.Delim "@?"; 'Aux.Text n >] -> Type_var n
+ | [< 'Aux.Delim "@F"; l = parse_list >] -> (
match l with
[] -> failwith "Function w/o return type."
| r :: a -> Fun_type (of_list a, r)
)
- | [< 'Text n; l = parse_list >] -> Term_type (n, of_list l)
+ | [< 'Aux.Text n; l = parse_list >] -> Term_type (n, of_list l)
and parse_list = parser
- [< 'Delim "("; l = parse_type_list; 'Delim ")" >] -> l
+ [< 'Aux.Delim "("; l = parse_type_list; 'Aux.Delim ")" >] -> l
| [< >] -> []
and parse_type_list = parser
[< n = parse_type; l = parse_type_list_delim >] -> n :: l
| [< >] -> []
and parse_type_list_delim = parser
- [< 'Delim ","; l = parse_type_list >] -> l
+ [< 'Aux.Delim ","; l = parse_type_list >] -> l
| [< >] -> []
;;
Modified: trunk/Toss/Term/TermType.mli
===================================================================
--- trunk/Toss/Term/TermType.mli 2012-05-20 12:31:12 UTC (rev 1711)
+++ trunk/Toss/Term/TermType.mli 2012-05-20 21:11:56 UTC (rev 1712)
@@ -26,10 +26,10 @@
val type_to_string : term_type -> string;;
(* Lexer for terms and types in internal format. *)
-val split_to_stream : string -> Str.split_result Stream.t;;
+val split_to_stream : string -> Aux.split_result Stream.t;;
(* Parser for types in internal format from lexed stream. *)
-val parse_type : Str.split_result Stream.t -> term_type;;
+val parse_type : Aux.split_result Stream.t -> term_type;;
(* Parsing types in internal format from string. *)
val type_of_string : string -> term_type;;
Deleted: trunk/Toss/Term/lib/Makefile
===================================================================
--- trunk/Toss/Term/library/Makefile 2012-05-20 12:31:12 UTC (rev 1711)
+++ trunk/Toss/Term/lib/Makefile 2012-05-20 21:11:56 UTC (rev 1712)
@@ -1,104 +0,0 @@
-#
-# Speagram
-#
-# Copyright (c) 2003-2006, Speagram Authors.
-#
-# Redistribution and use in source and binary forms, with or without
-# modification, are permitted provided that the following conditions are met:
-#
-# * Redistributions of source code must retain the above copyright notice,
-# this list of conditions and the following disclaimer.
-# * Redistributions in binary form must reproduce the above copyright notice,
-# this list of conditions and the following disclaimer in the documentation
-# and/or other materials provided with the distribution.
-#
-# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
-# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
-# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
-# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
-# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
-# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
-# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
-# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
-# OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
-# EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-#
-
-top_srcdir = ..
-
-OCAMLTOP = ocaml -I +camlp4 camlp4o.cma str.cma
-
-OCAMLCARGS = -thread -I +camlp4 -pp "camlp4o" str.cma unix.cma threads.cma
-OCAMLC = ocamlc $(OCAMLCARGS)
-
-OCAMLOPTARGS = -thread -I +camlp4 -pp "camlp4o" str.cmxa unix.cmxa threads.cmxa
-OCAMLOPT = ocamlopt $(OCAMLOPTARGS)
-
-DIFF = diff
-SED = sed
-Q = @
-
-
-############################################################
-# VARIABLES
-############################################################
-
-DISTFILES = \
- basic.spg \
- basic.spg.parsed \
- core.spg \
- core.spg.parsed \
- arithmetics.spg \
- arithmetics.spg.parsed \
- lists.spg \
- lists.spg.parsed \
- sasha.spg \
- sasha.spg.parsed \
-
-SPEAGRAM_CMD = ../speagram -v -f -l ""
-EXTRACT_CMD = ../spg-extract
-
-############################################################
-# TARGETS
-############################################################
-
-all: basic.spg.parsed sasha.spg.parsed
-
-core.spg.parsed: core.spg
- $(Q)echo "Creating $@."
- $(Q)$(SPEAGRAM_CMD) -o core.spg.parsed < core.spg > /dev/null
-
-
-arithmetics.spg.parsed: arithmetics.spg core.spg.parsed
- $(Q)echo "Creating $@."
- $(Q)$(SPEAGRAM_CMD) -o arithmetics.spg.parsed < arithmetics.spg\
- > /dev/null
-
-lists.spg.parsed: lists.spg arithmetics.spg.parsed
- $(Q)echo "Creating $@."
- $(Q)$(SPEAGRAM_CMD) -o lists.spg.parsed < lists.spg > /dev/null
-
-basic.spg.parsed: basic.spg \
- core.spg.parsed \
- arithmetics.spg.parsed \
- lists.spg.parsed
- $(Q)echo "Creating $@."
- $(Q)$(SPEAGRAM_CMD) -o basic.spg.parsed < basic.spg > /dev/null
-
-
-sasha.spg.parsed: sasha.spg basic.spg.parsed
- $(Q)echo "Creating $@."
- $(Q)$(SPEAGRAM_CMD) -o sasha.spg.parsed < sasha.spg > /dev/null
-
-
-
-.PHONY:
-
-tarball:
- cp $(DISTFILES) $(top_srcdir)/$(DIR)
- $(SED) "s/top_srcdir = ..\/../top_srcdir = .. < Makefile > Mf.adjst
- mv Mf.adjst $(top_srcdir)/$(DIR)/Makefile
-
-clean:
- rm -f *.spg.parsed *~
Deleted: trunk/Toss/Term/speagram.ml
===================================================================
--- trunk/Toss/Term/speagram.ml 2012-05-20 12:31:12 UTC (rev 1711)
+++ trunk/Toss/Term/speagram.ml 2012-05-20 21:11:56 UTC (rev 1712)
@@ -1,129 +0,0 @@
-(* The speagram binary for command line use. *)
-
-
-open List;;
-open Str;;
-
-open Term;;
-open TRS;;
-open SyntaxDef;;
-
-
-let rec run lp v grammar_path xslt_path out_path
- cmode sys channel fail xmlo res =
- let save_parsed () =
- let parsed_strs = map term_to_string (rev !res) in
- let out_file = open_out (out_path) in
- (if not cmode then
- print_endline ("SAVING PARSED TERMS TO " ^ out_path ^ ".")
- else ();
- output_string out_file ((String.concat "\n" parsed_strs) ^ "\n");
- close_out out_file;); in
- let save_xslt () = (
- if not cmode then
- print_endline ("SAVING XSLT TO " ^ xslt_path ^ ".")
- else ();
- let addon_term = Term (BuiltinLang.additional_xslt_name, [||]) in
- let addon_str = decode_string (normalise_with_sys !sys addon_term) in
- let xslt_str =
- print_xslt addon_str (syntax_defs_of_sys !sys) in
- let out_file = open_out (xslt_path) in
- (output_string out_file xslt_str; close_out out_file;)) in
- let save_grammar () = (
- if not cmode then
- print_endline ("SAVING GRAMMAR TO " ^ grammar_path ^ ".")
- else ();
- let grammar_str =
- let sys_sdefs = fst (List.split (syntax_defs_of_sys !sys)) in
- print_grammar (flat_grammar_of_sd_list (sys_sdefs)) in
- let out_file = open_out (grammar_path) in
- (output_string out_file grammar_str; close_out out_file;)) in
- let save_requested () = (
- if (not (grammar_path = "")) then save_grammar () else ();
- if (not (xslt_path = "")) then save_xslt () else ();
- if (not (out_path = "")) then save_parsed () else ();
- ) in
- try
- (sys := step_shell lp v cmode !sys channel fail xmlo res;
- run lp v grammar_path xslt_path out_path cmode sys channel fail xmlo res)
- with
- End_of_file -> save_requested ();
- | FAILED_PARSE_OR_EXN msg ->
- (save_requested ();
- if xmlo then
- (print_endline "\n<speagram-failure>\n";
- print_endline (make_xml_compatible msg);
- print_endline "\n</speagram-failure>\n";
- print_endline "\n</speagram-response>\n";)
- else ();
- failwith msg)
-;;
-
-
-let _ =
- let _ = Gc.set { (Gc.get()) with
- Gc.space_overhead = 128; Gc.max_overhead = 512;
- Gc.minor_heap_size = 1048576; Gc.major_heap_increment = 4194304 } in
- let should_fail = ref false in
- let make_it_fail () = (should_fail := true) in
- let verbose = ref false in
- let make_verbose () = (verbose := true) in
- let out_path = ref "" in
- let set_output_file s = (out_path := s) in
- let lib_path = ref "library" in
- let set_lib_path s = (lib_path := s) in
- let print_mem_after = ref false in
- let print_mem_set () = (print_mem_after := true) in
- let builtin_out = ref false in
- let set_builtin_out () = (builtin_out := true) in
- let compile_mode = ref false in
- let set_compile () = (compile_mode := true) in
- let xml_out = ref false in
- let set_xml_out () = (xml_out := true; compile_mode := true) in
- let grammar_path = ref "" in
- let set_gram_path s = (grammar_path := s) in
- let xslt_path = ref "" in
- let set_xslt_path s = (xslt_path := s) in
- let opts = [
- ("-f", Arg.Unit (make_it_fail), "make speagram fail on bad parses");
- ("-v", Arg.Unit (make_verbose), "make speagram verbose");
- ("-m", Arg.Unit (print_mem_set), "show memory use when quitting");
- ("-o", Arg.String (set_output_file), "output parsed terms to file");
- ("-l", Arg.String (set_lib_path), "set path to library directory");
- ("-b", Arg.Unit (set_builtin_out), "print builtin language definitions");
- ("-c", Arg.Unit (set_compile), "work in compile and not interactive mode");
- ("-x", Arg.Unit (set_xml_out), "output normalised terms in XML format");
- ("-g", Arg.String (set_gram_path), "output (flat EBNF) grammar to file");
- ("-s", Arg.String (set_xslt_path), "output corresponding XSLT to file");
- ] in
- let _ = Arg.parse opts (fun _ -> ()) "try -h for help" in
- let parsed_terms = ref [] in
- let basic_sys = ref basic_system in
- if !builtin_out then
- let defs = String.concat "\n" (map pretty_print_sd basic_sdefs) in
- print_endline ("// SPEAGRAM BUILT-IN DEFS.\n" ^ defs ^ "\n")
- else
- (
- if not (!compile_mode) then
- print_endline "\nWELCOME TO SPEAGRAM, PARSING INPUT:\n"
- else
- if (!xml_out) then print_endline "<speagram-response>" else ();
- run !lib_path !verbose !grammar_path !xslt_path !out_path !compile_mode
- basic_sys stdin !should_fail !xml_out parsed_terms;
- if (!print_mem_after && (not (!compile_mode))) then
- let mem = Gc.allocated_bytes () in
- let mem_str = string_of_int (int_of_float (mem /. 1024.0) / 1024) in
- let gc_overhd = float_of_int ((Gc.get()).Gc.space_overhead+100)/.100.0 in
- let min_heap_unit = float_of_int (4 * (Gc.get()).Gc.minor_heap_size) in
- let est_use_mem = ((mem *. gc_overhd) /. 1024.0) +. min_heap_unit in
- let est_use_str = string_of_int ((int_of_float est_use_mem) / 1024) in
- let est = "<est. " ^ est_use_str ^ " KB used>" in
- let mem_msg = "(ocaml reports " ^ mem_str ^ " MB allocated "^est^")" in
- print_endline ("\n\nBYE " ^ mem_msg ^ " :)\n")
- else
- if not !compile_mode then
- print_endline "\n\nBYE :)\n"
- else
- if (!xml_out) then print_endline "</speagram-response>\n" else ();
- )
-;;
Deleted: trunk/Toss/Term/tests/Makefile
===================================================================
--- trunk/Toss/Term/testsuite/Makefile 2012-05-20 12:31:12 UTC (rev 1711)
+++ trunk/Toss/Term/tests/Makefile 2012-05-20 21:11:56 UTC (rev 1712)
@@ -1,169 +0,0 @@
-#
-# Speagram
-#
-# Copyright (c) 2003-2006, Speagram Authors.
-#
-# Redistribution and use in source and binary forms, with or without
-# modification, are permitted provided that the following conditions are met:
-#
-# * Redistributions of source code must retain the above copyright notice,
-# this list of conditions and the following disclaimer.
-# * Redistributions in binary form must reproduce the above copyright notice,
-# this list of conditions and the following disclaimer in the documentation
-# and/or other materials provided with the distribution.
-#
-# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
-# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
-# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
-# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
-# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
-# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
-# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
-# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
-# OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
-# EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-#
-
-OCAMLTOP = ocaml -I +camlp4 camlp4o.cma str.cma
-
-OCAMLCARGS = -thread -I +camlp4 -pp "camlp4o" str.cma unix.cma threads.cma
-OCAMLC = ocamlc $(OCAMLCARGS)
-
-OCAMLOPTARGS = -thread -I +camlp4 -pp "camlp4o" str.cmxa unix.cmxa threads.cmxa
-OCAMLOPT = ocamlopt $(OCAMLOPTARGS)
-
-DIFF = diff
-SED = sed
-Q = @
-
-top_srcdir = ..
-
-
-SPG_TEST_IN_FILES = $(notdir $(shell find . -maxdepth 1 -name '*.spg'))
-SPG_TEST_STRIP_FILES = $(basename $(SPG_TEST_IN_FILES))
-SPG_TEST_LOG_FILES = $(addsuffix .log, $(SPG_TEST_STRIP_FILES))
-
-SPEAGRAM_CMD = ../speagram -c -f -l "../library" -s generated.xslt
-GEN_XSLTPROC_CMD = xsltproc generated.xslt generated.xml | sed "s/>/>/g" |\
- sed "s/</</g" | sed "s/<br\/>/\n/g" | sed "s/<?xml.*?>//g"> generated.log
-
-all: $(SPG_TEST_LOG_FILES)
-
-
-differentiation: differentiation.spg differentiation.log
- $(Q)echo Testing [$@.spg]...
- $(Q)$(SPEAGRAM_CMD) < $@.spg > generated.log
-# $(Q)$(SPEAGRAM_CMD) -x < $@.spg > generated.xml; $(GEN_XSLTPROC_CMD)
- $(Q)echo ...differences between achieved and expected output:
- $(Q)($(DIFF) -Bw -s generated.log $@.log | cat -)
- $(Q)echo ...differences printed.
-
-differentiation.log: differentiation.spg
- $(Q)echo Parsing [$(addsuffix .spg, $(basename $@))]...
- $(Q)$(SPEAGRAM_CMD) < $(addsuffix .spg, $(basename $@)) > generated.log
- $(Q)mv generated.log $@
-
-
-english: english.spg english.log
- $(Q)echo Testing [$@.spg]...
- $(Q)$(SPEAGRAM_CMD) < $@.spg > generated.log
-# $(Q)$(SPEAGRAM_CMD) -x < $@.spg > generated.xml; $(GEN_XSLTPROC_CMD)
- $(Q)echo ...differences between achieved and expected output:
- $(Q)($(DIFF) -Bw -s generated.log $@.log | cat -)
- $(Q)echo ...differences printed.
-
-english.log: english.spg
- $(Q)echo Parsing [$(addsuffix .spg, $(basename $@))]...
- $(Q)$(SPEAGRAM_CMD) < $(addsuffix .spg, $(basename $@)) > generated.log
- $(Q)mv generated.log $@
-
-
-fo_formula: fo_formula.spg fo_formula.log
- $(Q)echo Testing [$@.spg]...
- $(Q)$(SPEAGRAM_CMD) < $@.spg > generated.log
-# $(Q)$(SPEAGRAM_CMD) -x < $@.spg > generated.xml; $(GEN_XSLTPROC_CMD)
- $(Q)echo ...differences between achieved and expected output:
- $(Q)($(DIFF) -Bw -s generated.log $@.log | cat -)
- $(Q)echo ...differences printed.
-
-fo_formula.log: fo_formula.spg
- $(Q)echo Parsing [$(addsuffix .spg, $(basename $@))]...
- $(Q)$(SPEAGRAM_CMD) < $(addsuffix .spg, $(basename $@)) > generated.log
- $(Q)mv generated.log $@
-
-
-sasha_basic: sasha_basic.spg sasha_basic.log
- $(Q)echo Testing [$@.spg]...
- $(Q)$(SPEAGRAM_CMD) < $@.spg > generated.log
-# $(Q)$(SPEAGRAM_CMD) -x < $@.spg > generated.xml; $(GEN_XSLTPROC_CMD)
- $(Q)echo ...differences between achieved and expected output:
- $(Q)($(DIFF) -Bw -s generated.log $@.log | cat -)
- $(Q)echo ...differences printed.
-
-sasha_basic.log: sasha_basic.spg
- $(Q)echo Parsing [$(addsuffix .spg, $(basename $@))]...
- $(Q)$(SPEAGRAM_CMD) < $(addsuffix .spg, $(basename $@)) > generated.log
- $(Q)mv generated.log $@
-
-
-short_checks: short_checks.spg short_checks.log
- $(Q)echo Testing [$@.spg]...
- $(Q)$(SPEAGRAM_CMD) < $@.spg > generated.log
-# $(Q)$(SPEAGRAM_CMD) -x < $@.spg > generated.xml; $(GEN_XSLTPROC_CMD)
- $(Q)echo ...differences between achieved and expected output:
- $(Q)($(DIFF) -Bw -s generated.log $@.log | cat -)
- $(Q)echo ...differences printed.
-
-short_checks.log: short_checks.spg
- $(Q)echo Parsing [$(addsuffix .spg, $(basename $@))]...
- $(Q)$(SPEAGRAM_CMD) < $(addsuffix .spg, $(basename $@)) > generated.log
- $(Q)mv generated.log $@
-
-
-simple_algo: simple_algo.spg simple_algo.log
- $(Q)echo Testing [$@.spg]...
- $(Q)$(SPEAGRAM_CMD) < $@.spg > generated.log
-# $(Q)$(SPEAGRAM_CMD) -x < $@.spg > generated.xml; $(GEN_XSLTPROC_CMD)
- $(Q)echo ...differences between achieved and expected output:
- $(Q)($(DIFF) -Bw -s generated.log $@.log | cat -)
- $(Q)echo ...differences printed.
-
-simple_algo.log: simple_algo.spg
- $(Q)echo Parsing [$(addsuffix .spg, $(basename $@))]...
- $(Q)$(SPEAGRAM_CMD) < $(addsuffix .spg, $(basename $@)) > generated.log
- $(Q)mv generated.log $@
-
-entanglement: entanglement.spg entanglement.log
- $(Q)echo Testing [$@.spg]...
- $(Q)$(SPEAGRAM_CMD) < $@.spg > generated.log
-# $(Q)$(SPEAGRAM_CMD) -x < $@.spg > generated.xml; $(GEN_XSLTPROC_CMD)
- $(Q)echo ...differences between achieved and expected output:
- $(Q)($(DIFF) -Bw -s generated.log $@.log | cat -)
- $(Q)echo ...differences printed.
-
-entanglement.log: entanglement.spg
- $(Q)echo Parsing [$(addsuffix .spg, $(basename $@))]...
- $(Q)$(SPEAGRAM_CMD) < $(addsuffix .spg, $(basename $@)) > generated.log
- $(Q)mv generated.log $@
-
-
-
-check: $(SPG_TEST_STRIP_FILES)
-
-
-
-.PHONY:
-
-
-tarball:
- $(Q)echo Copying tests, logs and Makefile into tarball...
- $(Q)$(foreach file, $(SPG_TEST_IN_FILES), echo ...[$(file)] ;\
- cp $(file) $(top_srcdir)/$(DIR) ;)
- $(Q)$(foreach file, $(SPG_TEST_LOG_FILES), echo ...[$(file)] ;\
- cp $(file) $(top_srcdir)/$(DIR) ;)
- $(SED) "s/top_srcdir = ..\/../top_srcdir = .. < Makefile > Mf.adjst
- $(Q)mv Mf.adjst $(top_srcdir)/$(DIR)/Makefile
-
-clean:
- -rm -f *.exe *~ generated.log .last_tested
Modified: trunk/Toss/Term/tests/differentiation.log
===================================================================
--- trunk/Toss/Term/testsuite/differentiation.log 2012-05-20 12:31:12 UTC (rev 1711)
+++ trunk/Toss/Term/tests/differentiation.log 2012-05-20 21:11:56 UTC (rev 1712)
@@ -1,4 +1,4 @@
-Loaded state ../library/basic.
+Loaded state ./Term/lib/basic.
// SYMBOLIC DIFFERENTIATION EXAMPLE.
Modified: trunk/Toss/Term/tests/english.log
===================================================================
--- trunk/Toss/Term/testsuite/english.log 2012-05-20 12:31:12 UTC (rev 1711)
+++ trunk/Toss/Term/tests/english.log 2012-05-20 21:11:56 UTC (rev 1712)
@@ -1,4 +1,4 @@
-Loaded state ../library/basic.
+Loaded state ./Term/lib/basic.
New class "singular" "noun" declared.
Modified: trunk/Toss/Term/tests/entanglement.log
===================================================================
--- trunk/Toss/Term/testsuite/entanglement.log 2012-05-20 12:31:12 UTC (rev 1711)
+++ trunk/Toss/Term/tests/entanglement.log 2012-05-20 21:11:56 UTC (rev 1712)
@@ -1,6 +1,6 @@
// LoadBasicState.
-Loaded state ../library/basic.
+Loaded state ./Term/lib/basic.
// VertexAndSuccessorDeclarations.
Modified: trunk/Toss/Term/tests/fo_formula.log
===================================================================
--- trunk/Toss/Term/testsuite/fo_formula.log 2012-05-20 12:31:12 UTC (rev 1711)
+++ trunk/Toss/Term/tests/fo_formula.log 2012-05-20 21:11:56 UTC (rev 1712)
@@ -1,4 +1,4 @@
-Loaded state ../library/sasha.
+Loaded state ./Term/lib/sasha.
New class "FO" "term" declared.
Modified: trunk/Toss/Term/tests/sasha_basic.log
===================================================================
--- trunk/Toss/Term/testsuite/sasha_basic.log 2012-05-20 12:31:12 UTC (rev 1711)
+++ trunk/Toss/Term/tests/sasha_basic.log 2012-05-20 21:11:56 UTC (rev 1712)
@@ -1,4 +1,4 @@
-Loaded state ../library/sasha.
+Loaded state ./Term/lib/sasha.
// FIB.
Modified: trunk/Toss/Term/tests/short_checks.log
===================================================================
--- trunk/Toss/Term/testsuite/short_checks.log 2012-05-20 12:31:12 UTC (rev 1711)
+++ trunk/Toss/Term/tests/short_checks.log 2012-05-20 21:11:56 UTC (rev 1712)
@@ -1,4 +1,4 @@
-Loaded state ../library/basic.
+Loaded state ./Term/lib/basic.
// SPEAGRAM TYPE AND NORMAL VARS.
Modified: trunk/Toss/Term/tests/simple_algo.log
===================================================================
--- trunk/Toss/Term/testsuite/simple_algo.log 2012-05-20 12:31:12 UTC (rev 1711)
+++ trunk/Toss/Term/tests/simple_algo.log 2012-05-20 21:11:56 UTC (rev 1712)
@@ -1,4 +1,4 @@
-Loaded state ../library/basic.
+Loaded state ./Term/lib/basic.
New variable "n" declared.
Modified: trunk/Toss/Toss.odocl
===================================================================
--- trunk/Toss/Toss.odocl 2012-05-20 12:31:12 UTC (rev 1711)
+++ trunk/Toss/Toss.odocl 2012-05-20 21:11:56 UTC (rev 1712)
@@ -21,8 +21,13 @@
Solver/Solver
Solver/Class
Solver/ClassParser
-Arena/Term
-Arena/TermParser
+Term/TermType
+Term/SyntaxDef
+Term/BuiltinLang
+Term/Term
+Term/Rewriting
+Term/ParseArc
+Term/TRS
Arena/DiscreteRule
Arena/DiscreteRuleParser
Arena/ContinuousRule
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|