Bash++: Bash with classes
Find a file
2024-11-18 13:47:41 +08:00
antlr Resolving object references by scope 2024-11-18 13:47:41 +08:00
scripts Fixed example bpp code in scripts folder 2024-10-25 15:05:57 +08:00
LICENSE Licensed under GPLv3 2024-10-22 03:43:10 +00:00
main.cpp Removed comment that belongs in readme 2024-10-22 21:24:27 +08:00
makefile Bash++ is a much better name than Object Bash 2024-10-22 11:35:18 +08:00
README.md Fixed mistake in the example Bash++ code 2024-10-25 14:45:41 +08:00

Bash++

Bash with classes

The Basic Idea

This is intended to be a source-to-source compiler.

A Bash++ script will be converted into ordinary Bash for execution

Syntax

  • The Bash++ syntax will be a superset of the Bash syntax

  • The syntax will be designed to be easily converted to ordinary Bash script

Here is some (rather silly/useless) example Bash++ code:

@class Bool {
	@private value="false"

	@public @method get {
		echo "@value"
	}

	@public @method set input_value {
		if [[ $input_value == "true" ]] || [[ $input_value -eq 1 ]]; then
			@value="true"
		else
			@value="false"
		fi
	}
	
	@constructor input_value {
		@this.set "$input_value"
	}
}

@class File {
	@private file_path
	@private @Bool file_exists

	@constructor {
		@file_path=""
		@file_exists.set false
	}

	@constructor input_file_path {
		@file_path="$input_file_path"
		@file_exists.set $([[ -f "@file_path" ]] && echo "true" || echo "false")
	}

	@public @method read {
		if [[ @file_exists.get == "true" ]]; then
			cat "@file_path"
		fi
	}

	@public @method append input_string {
		echo "$input_string" >> "@file_path"
	}
}

@File new_file "./new-file"
@new_file.read

@new_file.append "Hello from Bash++!"
@new_file.read

@File old_file "./old-file"
for word in @old_file.read; do
	echo "Word: $word"
done