summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRalf Treinen <treinen@free.fr>2019-11-09 00:08:36 +0100
committerRalf Treinen <treinen@free.fr>2019-11-09 00:08:36 +0100
commitc3b74794f5c94d68287bb2d0709db2228cd8f39c (patch)
tree5c3052a509f9b0c689da1adaa8528855a084073b
parent406d294f8ca50f8bc8bf120addbe93574f343372 (diff)
New upstream version 0.3.0
-rw-r--r--.travis.yml1
-rw-r--r--Dockerfile3
-rw-r--r--morsmall.opam2
-rw-r--r--src/AST.ml40
-rw-r--r--src/CST_to_AST.ml42
-rw-r--r--src/dune4
-rw-r--r--src/location.ml17
-rw-r--r--src/morsmall.ml4
-rw-r--r--src/morsmall.mli4
-rw-r--r--src/safePrinter.ml16
10 files changed, 83 insertions, 50 deletions
diff --git a/.travis.yml b/.travis.yml
index 897ee0d..7210cb1 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -8,6 +8,7 @@ env:
- TAG=4.05
- TAG=4.06
- TAG=4.07
+ - TAG=4.08
script:
- docker build --build-arg tag=$TAG --tag colisanr/morsmall:$TRAVIS_BRANCH .
diff --git a/Dockerfile b/Dockerfile
index 5c87b2a..4703087 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -9,7 +9,10 @@ MAINTAINER Nicolas Jeannerod
## Install dependencies. `opam depext` installs first the non-opam
## dependencies that are required and then the OPAM packages.
+RUN opam pin -n morbig.dev https://github.com/colis-anr/morbig.git
RUN opam depext -i morbig
+ADD *.opam .
+RUN opam install . --deps-only --with-test --with-doc
## Work in /home/opam/morsmall, copy all the file there with the right
## owner and group.
diff --git a/morsmall.opam b/morsmall.opam
index 9eb45f7..fe9cb10 100644
--- a/morsmall.opam
+++ b/morsmall.opam
@@ -21,6 +21,8 @@ depends: [
"morbig" {>= "0.10.0"}
"ocaml" {>= "4.04"}
"ppx_deriving" {build}
+ "ppx_deriving_yojson" {build}
+ "yojson"
]
build: [
diff --git a/src/AST.ml b/src/AST.ml
index fb1f8e3..44f9e3b 100644
--- a/src/AST.ml
+++ b/src/AST.ml
@@ -19,8 +19,6 @@
(* along with this program. If not, see <http://www.gnu.org/licenses/>. *)
(***************************************************************************)
-type 'a located = 'a Location.located [@@deriving eq, show]
-
(** Names in Shell are just strings with a few additional
conditions. *)
@@ -44,26 +42,27 @@ and attribute =
| RemoveLargestPrefixPattern of word
and word_component =
- | Literal of string
- | DoubleQuoted of word
- | Variable of name * attribute
- | Subshell of program
- | GlobAll
- | GlobAny
- | BracketExpression of (Morbig.CST.bracket_expression [@equal (=)] [@opaque])
+ | WTildePrefix of string
+ | WLiteral of string
+ | WDoubleQuoted of word
+ | WVariable of name * attribute
+ | WSubshell of program
+ | WGlobAll
+ | WGlobAny
+ | WBracketExpression of (Morbig.CST.bracket_expression [@equal (=)] [@opaque])
and word = word_component list
-and word' = word located
+and word' = word Location.located
(** For now, a {!pattern} is just a {!word}. *)
and pattern = word list
-and pattern' = pattern located
+and pattern' = pattern Location.located
(** An assignment is just a pair of a {!name} and a {!word}. *)
and assignment = name * word
-and assignment' = assignment located
+and assignment' = assignment Location.located
(** A file descriptor {!descr} is an integer. *)
@@ -216,11 +215,11 @@ and command =
| Redirection of command' * descr * kind * word
| HereDocument of command' * descr * word'
-and command' = command located
+and command' = command Location.located
and case_item = pattern' * command' option
-and case_item' = case_item located
+and case_item' = case_item Location.located
and kind =
| Output (* > *)
@@ -231,7 +230,18 @@ and kind =
| InputDuplicate (* <& *)
| InputOutput (* <> *)
-[@@deriving eq, show{with_path=false}]
+[@@deriving
+ eq,
+ show {with_path=false},
+ yojson {exn=true},
+ visitors {variety = "iter"; ancestors=["Location.located_iter"]; nude=true},
+ visitors {variety = "map"; ancestors=["Location.located_map"]; nude=true},
+ visitors {variety = "reduce"; ancestors=["Location.located_reduce"]; nude=true},
+ visitors {variety = "mapreduce"; ancestors=["Location.located_mapreduce"]; nude=true},
+ visitors {variety = "iter2"; ancestors=["Location.located_iter2"]; nude=true},
+ visitors {variety = "map2"; ancestors=["Location.located_map2"]; nude=true},
+ visitors {variety = "reduce2"; ancestors=["Location.located_reduce2"]; nude=true}
+]
let default_redirection_descriptor = function
| Output | OutputDuplicate | OutputAppend | OutputClobber -> 1
diff --git a/src/CST_to_AST.ml b/src/CST_to_AST.ml
index 001ae71..8890c9a 100644
--- a/src/CST_to_AST.ml
+++ b/src/CST_to_AST.ml
@@ -23,10 +23,10 @@ open Morbig.CST
(* Helpers about locations. *)
-let convert_location : 'a 'b. ('a -> 'b) -> 'a located -> 'b AST.located =
+let convert_location : 'a 'b. ('a -> 'b) -> 'a located -> 'b Location.located =
fun f loc -> { value = f loc.value ; position = loc.position }
-let convert_location_2 : 'a 'b 'c. ('a -> 'b -> 'c) -> 'a located -> 'b -> 'c AST.located =
+let convert_location_2 : 'a 'b 'c. ('a -> 'b -> 'c) -> 'a located -> 'b -> 'c Location.located =
fun f loc x ->
{ value = f loc.value x ; position = loc.position }
@@ -769,47 +769,47 @@ and word_component__to__word = function
| WordEmpty ->
[]
| WordName name ->
- [AST.Literal name]
+ [AST.WLiteral name]
+ | WordTildePrefix prefix ->
+ [AST.WTildePrefix prefix]
| WordLiteral literal ->
- [AST.Literal literal]
+ [AST.WLiteral literal]
| WordAssignmentWord (Name name, Word (_, word_cst)) ->
- [AST.Literal name;
- AST.Literal "="]
+ [AST.WLiteral name; AST.WLiteral "="]
@ word_cst__to__word word_cst
| WordSingleQuoted (Word (_, [WordLiteral literal])) ->
- [AST.Literal literal]
+ [AST.WLiteral literal]
| WordSingleQuoted (Word (_, [])) ->
- [AST.Literal ""]
+ [AST.WLiteral ""]
| WordSingleQuoted _ ->
assert false
| WordSubshell (_, program') ->
- [AST.Subshell (program'__to__program program')]
+ [AST.WSubshell (program'__to__program program')]
| WordDoubleQuoted word ->
- [AST.DoubleQuoted (word_double_quoted__to__word word)]
+ [AST.WDoubleQuoted (word_double_quoted__to__word word)]
| WordVariable (VariableAtom (name, variable_attribute)) ->
- [AST.Variable (name, variable_attribute__to__attribute variable_attribute)]
+ [AST.WVariable (name, variable_attribute__to__attribute variable_attribute)]
| WordGlobAll ->
- [AST.GlobAll]
+ [AST.WGlobAll]
| WordGlobAny ->
- [AST.GlobAny]
+ [AST.WGlobAny]
| WordReBracketExpression bracket_expression ->
- [AST.BracketExpression bracket_expression]
+ [AST.WBracketExpression bracket_expression]
and word_component_double_quoted__to__word = function
| WordEmpty ->
[]
- | WordName literal | WordLiteral literal ->
- [AST.Literal literal]
+ | WordName literal | WordLiteral literal | WordTildePrefix literal ->
+ [AST.WLiteral literal]
| WordSubshell (_, program') ->
- [AST.Subshell (program'__to__program program')]
+ [AST.WSubshell (program'__to__program program')]
| WordAssignmentWord (Name name, Word (_, word_cst)) ->
- [AST.Literal name;
- AST.Literal "="]
+ [AST.WLiteral name; AST.WLiteral "="]
@ word_cst_double_quoted__to__word word_cst
| WordVariable (VariableAtom (name, variable_attribute)) ->
- [AST.Variable (name, variable_attribute__to__attribute variable_attribute)]
+ [AST.WVariable (name, variable_attribute__to__attribute variable_attribute)]
| WordReBracketExpression bracket_expression ->
- [AST.BracketExpression bracket_expression]
+ [AST.WBracketExpression bracket_expression]
| WordDoubleQuoted _ | WordSingleQuoted _
| WordGlobAll | WordGlobAny ->
assert false
diff --git a/src/dune b/src/dune
index e6ee42c..4053a9f 100644
--- a/src/dune
+++ b/src/dune
@@ -1,6 +1,6 @@
(library
(name morsmall)
(public_name morsmall)
- (preprocess (pps ppx_deriving.std))
- (libraries morbig morsmall.utilities)
+ (preprocess (pps ppx_deriving.std visitors.ppx ppx_deriving_yojson))
+ (libraries morbig morsmall.utilities visitors.runtime yojson)
(flags :standard -w +A-4-30-42))
diff --git a/src/location.ml b/src/location.ml
index 2230307..474ae35 100644
--- a/src/location.ml
+++ b/src/location.ml
@@ -23,15 +23,26 @@ type lexing_position = Morbig.CST.lexing_position =
{ pos_fname : string ;
pos_lnum : int ;
pos_bol : int ;
- pos_cnum : int } [@@deriving eq, show{with_path=false}]
+ pos_cnum : int }
+[@@deriving eq, show {with_path=false}, yojson]
type position = Morbig.CST.position =
{ start_p : lexing_position ;
- end_p : lexing_position } [@@deriving eq, show{with_path=false}]
+ end_p : lexing_position }
+[@@deriving eq, show {with_path=false}, yojson]
type 'a located = 'a Morbig.CST.located =
{ value : 'a ;
- position : position } [@@deriving eq, show{with_path=false}]
+ position : position }
+[@@deriving eq, show {with_path=false}, yojson]
+
+class virtual ['a] located_iter = ['a] Morbig.CST.located_iter
+class virtual ['a] located_map = ['a] Morbig.CST.located_map
+class virtual ['a] located_reduce = ['a] Morbig.CST.located_reduce
+class virtual ['a] located_mapreduce = ['a] Morbig.CST.located_mapreduce
+class virtual ['a] located_iter2 = ['a] Morbig.CST.located_iter2
+class virtual ['a] located_map2 = ['a] Morbig.CST.located_map2
+class virtual ['a] located_reduce2 = ['a] Morbig.CST.located_reduce2
let dummily_located value =
{ value ; position = Morbig.CSTHelpers.dummy_position }
diff --git a/src/morsmall.ml b/src/morsmall.ml
index 6200005..318ede9 100644
--- a/src/morsmall.ml
+++ b/src/morsmall.ml
@@ -21,6 +21,8 @@
exception SyntaxError of Location.lexing_position
+let from_CST = CST_to_AST.program__to__program
+
let parse_file filename =
let open Morbig in
(
@@ -31,7 +33,7 @@ let parse_file filename =
| Errors.DuringLexing (position, _) ->
raise (SyntaxError position)
)
- |> CST_to_AST.program__to__program
+ |> from_CST
let pp_print_safe = SafePrinter.pp_program
let pp_print_debug = AST.pp_program
diff --git a/src/morsmall.mli b/src/morsmall.mli
index c216bad..20bba5a 100644
--- a/src/morsmall.mli
+++ b/src/morsmall.mli
@@ -22,10 +22,12 @@
module AST = AST
(** Shell AST. *)
-(** {2 Parsers} *)
+(** {2 Parsers and Converters} *)
exception SyntaxError of Location.lexing_position
+val from_CST : Morbig.CST.program -> AST.program
+
val parse_file : string -> AST.program
(** Parses a whole Shell file into a list of {!AST.command}. The list
can be empty. Can raise {!SyntaxError}. *)
diff --git a/src/safePrinter.ml b/src/safePrinter.ml
index 1d5ac6d..2ca778a 100644
--- a/src/safePrinter.ml
+++ b/src/safePrinter.ml
@@ -30,20 +30,22 @@ let rec pp_name ppf =
(* AST.word_component *)
and pp_word_component ppf = function (*FIXME*)
- | Literal literal ->
+ | WLiteral literal ->
fpf ppf "%s" literal
- | DoubleQuoted _word ->
+ | WTildePrefix _ ->
assert false
- | Variable (variable, attribute) ->
+ | WDoubleQuoted _word ->
+ assert false
+ | WVariable (variable, attribute) ->
assert (attribute = NoAttribute);
fpf ppf "${%s}" variable
- | Subshell command_list ->
+ | WSubshell command_list ->
fpf ppf "$(%a)" pp_command'_list command_list
- | GlobAll ->
+ | WGlobAll ->
fpf ppf "*"
- | GlobAny ->
+ | WGlobAny ->
fpf ppf "?"
- | BracketExpression _bracket_expression ->
+ | WBracketExpression _bracket_expression ->
assert false
(* AST.word *)