From b4f5e2753a4435c225079ebbdef6acb2457ea06a Mon Sep 17 00:00:00 2001 From: ishaangandhi Date: Fri, 25 Sep 2020 22:50:48 -0400 Subject: [PATCH 1/2] Added AST rep of CST WordArith --- src/AST.ml | 1 + src/CST_to_AST.ml | 4 ++++ src/safePrinter.ml | 3 +++ 3 files changed, 8 insertions(+) diff --git a/src/AST.ml b/src/AST.ml index e84c108..e317678 100644 --- a/src/AST.ml +++ b/src/AST.ml @@ -45,6 +45,7 @@ and word_component = | WTildePrefix of string | WLiteral of string | WDoubleQuoted of word + | WArith of word | WVariable of name * attribute | WSubshell of program | WGlobAll diff --git a/src/CST_to_AST.ml b/src/CST_to_AST.ml index a4bc9b2..e0cd2bf 100644 --- a/src/CST_to_AST.ml +++ b/src/CST_to_AST.ml @@ -772,6 +772,8 @@ and word_component__to__word = function [AST.WTildePrefix prefix] | WordLiteral literal -> [AST.WLiteral literal] + | WordArith word -> + [AST.WArith (word__to__word word)] | WordAssignmentWord (Name name, Word (_, word_cst)) -> [AST.WLiteral name; AST.WLiteral "="] @ word_cst__to__word word_cst @@ -799,6 +801,8 @@ and word_component_double_quoted__to__word = function [] | WordName literal | WordLiteral literal | WordTildePrefix literal -> [AST.WLiteral literal] + | WordArith word -> + [AST.WArith (word__to__word word)] | WordSubshell (_, program') -> [AST.WSubshell (program'__to__program program')] | WordAssignmentWord (Name name, Word (_, word_cst)) -> diff --git a/src/safePrinter.ml b/src/safePrinter.ml index 5efd322..a7326c6 100644 --- a/src/safePrinter.ml +++ b/src/safePrinter.ml @@ -32,6 +32,9 @@ let rec pp_name ppf = and pp_word_component ppf = function (*FIXME*) | WLiteral literal -> fpf ppf "%s" literal + | WArith _word -> + assert false + (* fpf ppf "$((%s))" word *) | WTildePrefix _ -> assert false | WDoubleQuoted _word -> From 10a3873118030e4cca1c667d9849b205377434c1 Mon Sep 17 00:00:00 2001 From: ishaangandhi Date: Fri, 25 Sep 2020 23:25:53 -0400 Subject: [PATCH 2/2] pretty print --- src/safePrinter.ml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/safePrinter.ml b/src/safePrinter.ml index a7326c6..05ea025 100644 --- a/src/safePrinter.ml +++ b/src/safePrinter.ml @@ -32,9 +32,8 @@ let rec pp_name ppf = and pp_word_component ppf = function (*FIXME*) | WLiteral literal -> fpf ppf "%s" literal - | WArith _word -> - assert false - (* fpf ppf "$((%s))" word *) + | WArith word -> + fpf ppf "$((%a))" pp_word word | WTildePrefix _ -> assert false | WDoubleQuoted _word ->