Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding class features #257

Open
wants to merge 36 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
c18ae59
added Callable Function
thecodacus Mar 17, 2022
81b60da
added function declaration
thecodacus Mar 17, 2022
507de14
return statement added in parser
thecodacus Mar 18, 2022
f3aa56d
callable functions and function return is working
thecodacus Mar 18, 2022
74b5630
Merge branch 'develop' into issue-170
thecodacus Mar 18, 2022
774d9c1
Update index.ts
thecodacus Mar 18, 2022
fc93884
Update scope.ts
thecodacus Mar 18, 2022
0ffb32e
Update printStatement.ts
thecodacus Mar 18, 2022
57c70a8
bugfix
thecodacus Mar 18, 2022
08fd24d
docs updated
thecodacus Mar 18, 2022
44189c8
Merge branch 'develop' into issue-170
thecodacus Mar 18, 2022
6051d32
docs fix
thecodacus Mar 18, 2022
085aa46
Merge branch 'issue-170' of https://github.com/thecodacus/bhai-lang i…
thecodacus Mar 18, 2022
3336243
docs fix
thecodacus Mar 18, 2022
52dd0c6
bugfix
thecodacus Mar 18, 2022
3dc5b92
clean up
thecodacus Mar 18, 2022
cfb22a7
class tokenizer added
thecodacus Mar 19, 2022
89d995f
dot expression added in the parser
thecodacus Mar 19, 2022
4948049
Update dataClass.ts
thecodacus Mar 19, 2022
f53d781
type fix
thecodacus Mar 19, 2022
962b6b4
class declaretion in progress
thecodacus Mar 19, 2022
f89fc4f
clean up
thecodacus Mar 20, 2022
6689e46
Basic class added
thecodacus Mar 20, 2022
575ed2e
accessing class members working
thecodacus Mar 20, 2022
c06b202
Merge branch 'develop' into issue-170
thecodacus Mar 21, 2022
a73c468
syntax updated
thecodacus Mar 21, 2022
bd11d03
conflict fix and merged
thecodacus Mar 21, 2022
3853cf8
test cases updated
thecodacus Mar 21, 2022
1b22846
Merge branch 'issue-170' into adding-class
thecodacus Mar 21, 2022
1058b1f
added requested changes
thecodacus Apr 9, 2022
9c33313
fixed function argument parsing
thecodacus Jul 30, 2022
567b961
added test cases
thecodacus Jul 30, 2022
c399f6d
Merge branch 'issue-170' into adding-class
thecodacus Jul 30, 2022
e02f30b
class bugfix
thecodacus Jul 30, 2022
900f5b7
bugfix
thecodacus Nov 28, 2022
8f55ab7
UI fix
thecodacus Nov 28, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
157 changes: 71 additions & 86 deletions apps/docs/components/Code/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,101 +7,86 @@ import { sendEvents } from "../../helpers";
import CodeEditor from "./CodeEditor";
import Terminal from "./Terminal";


const initialCode = `
hi bhai
bol bhai "Hello World";

bhai ye hai a = 3;
bhai ye hai b = 0;

jab tak bhai (b < 5) {
bol bhai b;

agar bhai (b == a) {
bol bhai "b is equal to a";
} nahi to bhai (b == 0) {
bol bhai "b is equal to zero";
samajh le bhai kutta{
bhai ye hai nam;
apna funda janam(nam){
iska.nam = nam;
bol bhai iska.nam,":kau kau";
}
apna funda bhouk(){
bol bhai iska.nam+":bhou bhou";
}

b += 1;
}
bhai ye hai jimmi = kutta("jimmi");
jimmi.bhouk();
bol bhai "iska name hai",jimmi.nam;

bye bhai
`;

const Code = (props: Props) => {
const {} = props;
const [code, setCode] = useState(initialCode);
const [output, setOutput] = useState<{ value: string; isError: boolean }[]>(
[]
);
const [isSuccess, setIsSuccess] = useState<boolean | null>(null);

const handleChange = (newCode: string) => {
setCode(newCode);
};

const executeCode = () => {
let orignalConsoleLog = console.log;
const outputList = [];
let isExecusionSuccess = true;
console.log = function (...args) {
outputList.push({ value: args.join("\n"), isError: false });
};

try {
interpreter.interpret(code);
} catch (e) {
if (e instanceof Error) {
isExecusionSuccess = false;
outputList.push({ value: e.message, isError: true });
} else {
console.error(e);
}
}

sendEvents("CodeExecuted", {success: isExecusionSuccess});

setIsSuccess(isExecusionSuccess);
setOutput(outputList);
console.log = orignalConsoleLog;
};

const clearCode = () => {
sendEvents("CodeCleared");
setCode("");
setIsSuccess(null);
setOutput([]);
};

return (
<div id="playground" className="mx-4 sm:mx-12">
<div className="sm:flex justify-between items-center">
<h2 className="text-3xl font-extrabold tracking-tight text-gray-100 sm:text-4xl my-4">
Playground
</h2>
<div className="flex">
<button
disabled={!code}
onClick={executeCode}
className="mx-2 flex items-center justify-center px-8 border border-transparent text-base font-medium rounded-md text-white bg-bhagwa-600 hover:bg-bhagwa-700 md:text-lg md:px-10 my-4 sm:my-8 sm:py-3 disabled:opacity-40"
>
Run
</button>

<button
onClick={clearCode}
className="mx-2 flex items-center justify-center px-8 border border-transparent text-base font-medium rounded-md text-bhagwa-700 bg-bhagwa-300 hover:bg-bhagwa-400 md:text-lg md:px-10 my-4 sm:my-8 sm:py-3"
>
Clear
</button>
</div>
</div>
<CodeEditor handleChange={handleChange} code={code} />
<Terminal output={output} isSuccess={isSuccess} />
</div>
);
const {} = props;
const [code, setCode] = useState(initialCode);
const [output, setOutput] = useState<{ value: string; isError: boolean }[]>([]);
const [isSuccess, setIsSuccess] = useState<boolean | null>(null);

const handleChange = (newCode: string) => {
setCode(newCode);
};

const executeCode = () => {
let orignalConsoleLog = console.log;
const outputList = [];
let isExecusionSuccess = true;
console.log = function (...args) {
outputList.push({ value: args.join("\n"), isError: false });
};

try {
interpreter.interpret(code);
} catch (e) {
if (e instanceof Error) {
isExecusionSuccess = false;
outputList.push({ value: e.message, isError: true });
} else {
console.error(e);
}
}

sendEvents("CodeExecuted", { success: isExecusionSuccess });

setIsSuccess(isExecusionSuccess);
setOutput(outputList);
console.log = orignalConsoleLog;
};

const clearCode = () => {
sendEvents("CodeCleared");
setCode("");
setIsSuccess(null);
setOutput([]);
};

return (
<div id="playground" className="mx-4 sm:mx-12">
<div className="sm:flex justify-between items-center">
<h2 className="text-3xl font-extrabold tracking-tight text-gray-100 sm:text-4xl my-4">Playground</h2>
<div className="flex">
<button disabled={!code} onClick={executeCode} className="mx-2 flex items-center justify-center px-8 border border-transparent text-base font-medium rounded-md text-white bg-bhagwa-600 hover:bg-bhagwa-700 md:text-lg md:px-10 my-4 sm:my-8 sm:py-3 disabled:opacity-40">
Run
</button>

<button onClick={clearCode} className="mx-2 flex items-center justify-center px-8 border border-transparent text-base font-medium rounded-md text-bhagwa-700 bg-bhagwa-300 hover:bg-bhagwa-400 md:text-lg md:px-10 my-4 sm:my-8 sm:py-3">
Clear
</button>
</div>
</div>
<CodeEditor handleChange={handleChange} code={code} />
<Terminal output={output} isSuccess={isSuccess} />
</div>
);
};
type Props = {};
export default React.memo(Code);