Vapor Language

Vapor (vLang) is a language that sits on top of python

Home

Syntax

Get Interpreter

1) Calculator in Vapor

using wait.vap

obj calculator {
	m calculate(_, expression) {
		self.clean(expression) true {
			result = eval(expression)
			-> result
		} else {
			error = 'Invalid expression provided'
			throw error
		}
	}

	m clean(_, expression) {
		allowed = '1234567890+-*/()'
		expression each letter {
			letter not in allowed true {
				-> False
			}
		}
		-> True
	}
}

m calc() {
	while(True) {
		expression = input('Enter an expression to be calculated\n')
		log(calculator().calculate(expression))
	}
}

thread calc

1) Transpiled to Python

import threading
import time
class wait:
	def __init__(self, t):
		time.sleep(t)


class calculator:
	def calculate(self, expression):
		if (self.clean(expression)) is True:
			result = eval(expression)
			return result
		else:
			error = 'Invalid expression provided'
			raise Exception(error)
		return False
	def clean(self, expression):
		allowed = '1234567890+-*/()'
		for letter in expression:
			if (letter not in allowed) is True:
				return False
		return True
def calc():
	while True:
		expression = input('Enter an expression to be calculated\n')
		print('' + str(calculator().calculate(expression)) + '')
x_0 = threading.Thread(target=calc); x_0.start()

2) FizzBuzz in Vapor

m fizzBuzz(number) {
	range(number) each numb {
		numb % 3 == 0 true {
			'Fizz'
			continue
		}
		numb % 5 == 0 true {
			'FizzBuzz'
			continue
		}
		'[[numb]]'
	}
	-> 'this is a return value'
}

fizzBuzz(101)

2) Transpiled to Python

import threading

def fizzBuzz(number):
	for numb in range(number):
		if (numb % 3 == 0) is True:
			print('Fizz')
			continue
		if (numb % 5 == 0) is True:
			print('FizzBuzz')
			continue
		print('' + str(numb) + '')
	return 'this is a return value'
fizzBuzz(101)

3) keyBoardHandle
( standard library .vap class )

import win32gui
import win32api
import win32con
from ctypes import windll
using winHandle.vap
import time

obj keyBoardHandle {
	keys = ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','1','2','3','4','5','6','7','8','9']
	# VDocs: Press a key down
	m pressKey(_, key, disableKeyRelease = False) {
		type(key) is int true {
			win32api.keybd_event(key, 0, 0, 0)
			not disableKeyRelease true {
				win32api.keybd_event(key, 0, win32con.KEYEVENTF_KEYUP, 0)
			}
		} else {
			key in self.keys true {
				kc = self.getVKCode(key)
				win32api.keybd_event(kc, 0, 0, 0)
				not disableKeyRelease true {
					win32api.keybd_event(kc, 0, win32con.KEYEVENTF_KEYUP, 0)
				}
			}
		}
	}
	# VDocs: Hold the key for 'delay' seconds
	m holdKey(_, key, delay) {
		ts = time.time()
		while(time.time() - ts <= delay) {
			self.pressKey(key, True)
			time.sleep(0.1)
		}
		self.pressKey(key)
	}
	# VDocs: Gets the virtual key code of a single letter
	m getVKCode(_, key) {
		assert-type key str
		result = windll.User32.VkKeyScanW(ord(key))
		shift_state = (result & 0xFF00) >> 8
		vk_key = result & 0xFF
		-> vk_key
	}
}

3) Transpiled to Python

import threading
import win32gui
import win32api
import win32con
from ctypes import windll
import time

class keyBoardHandle:
	keys = ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','1','2','3','4','5','6','7','8','9']

	# VDocs: Press a key down
	def pressKey(self, key, disableKeyRelease = False):
		if (type(key) is int) is True:
			win32api.keybd_event(key, 0, 0, 0)

			if (not disableKeyRelease) is True:
				win32api.keybd_event(key, 0, win32con.KEYEVENTF_KEYUP, 0)
		else:
			if (key in self.keys) is True:
				kc = self.getVKCode(key)
				win32api.keybd_event(kc, 0, 0, 0)

				if (not disableKeyRelease) is True:
					win32api.keybd_event(kc, 0, win32con.KEYEVENTF_KEYUP, 0)

	# VDocs: Hold the key for 'delay' seconds
	def holdKey(self, key, delay):
		ts = time.time()
		while time.time() - ts <= delay:
			self.pressKey(key, True)
			time.sleep(0.1)

		self.pressKey(key)

	# VDocs: Gets the virtual key code of a single letter
	def getVKCode(self, key):
		if str(type(key)) != str(str): raise Exception("assert-type fail: key() is NOT of type str")
		result = windll.User32.VkKeyScanW(ord(key))
		shift_state = (result & 0xFF00) >> 8
		vk_key = result & 0xFF
		return vk_key