Skip to content

Commit

Permalink
Re-enable resolver for Python (#1671)
Browse files Browse the repository at this point in the history
* Enabled resolver and updated pylib tests

* Update python parser test

* Replace is_number with is_int and is_float in specs

* Change order of names in title page

* bumping version

* updating to latest py-slang and scm-slang

* bumping again

---------

Co-authored-by: henz <[email protected]>
  • Loading branch information
JJtan2002 and martin-henz authored Apr 14, 2024
1 parent 4449127 commit ecd5955
Show file tree
Hide file tree
Showing 9 changed files with 77 additions and 64 deletions.
2 changes: 1 addition & 1 deletion docs/specs/source_python_1.tex
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

\begin{document}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\docheader{2024}{Python}{\S 1}{Ken Jin, Han Yizhan, Tan Jia Jun, Martin Henz}
\docheader{2024}{Python}{\S 1}{Han Yizhan, Tan Jia Jun, Ooi Ken Jin, Martin Henz}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\input source_python_intro.tex
Expand Down
2 changes: 1 addition & 1 deletion docs/specs/source_python_misc.tex
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ \subsection*{MISC Library}
\item \href{https://sourceacademy.org/sicpjs/2.4.3\#p6}{\texttt{undefined}},
\texttt{\href{https://www.ecma-international.org/ecma-262/9.0/index.html\#sec-value-properties-of-the-global-object-nan}{\color{DarkBlue}NaN}}, \texttt{\href{https://www.ecma-international.org/ecma-262/9.0/index.html\#sec-value-properties-of-the-global-object-infinity}{\color{DarkBlue}Infinity}}: \textit{primitive}, refer to JavaScript's undefined,
NaN (``Not a Number'') and Infinity values, respectively.
\item \href{https://sourceacademy.org/sicpjs/4.1.2\#p2}{\lstinline{is_boolean(x)}}, \href{https://sourceacademy.org/sicpjs/2.3.2\#p5}{\lstinline{is_number(x)}}, \verb#is_int#\texttt{(x)}, \verb#is_float#\texttt{(x)}
\item \href{https://sourceacademy.org/sicpjs/4.1.2\#p2}{\lstinline{is_boolean(x)}}, \href{https://sourceacademy.org/sicpjs/2.3.2\#p5}{\lstinline{is_float(x), is_int(x)}}
\href{https://sourceacademy.org/sicpjs/2.3.2\#p7}{\lstinline{is_string(x)}}, \href{https://sourceacademy.org/sicpjs/4.1.2\#p2}{\lstinline{is_undefined(x)}}, \verb#is_function#\texttt{(x)}: \textit{primitive}, returns \texttt{true} if the type of \texttt{x} matches the function name and \texttt{false} if it does not. Following
JavaScript, we specify that \verb#is_number# returns \texttt{true} for \texttt{NaN} and \texttt{Infinity}.
\item \texttt{prompt(s)}: \textit{primitive}, pops up a window that displays the \emph{string} \texttt{s}, provides
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "js-slang",
"version": "1.0.66",
"version": "1.0.68",
"license": "Apache-2.0",
"description": "Javascript-based implementations of Source, written in Typescript",
"keywords": [
Expand Down
2 changes: 1 addition & 1 deletion src/parser/__tests__/python.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ describe('Python parser', () => {
})
describe('Python 1 tests', () => {
it('allows usage of builtins/preludes', () => {
const code = `display("hello from python")`
const code = `print("hello from python")`

const prgm = parserPython1.parse(code, context)
if (prgm !== null) {
Expand Down
2 changes: 1 addition & 1 deletion src/parser/python/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export class PythonParser implements Parser<AcornOptions> {
throw new Error('Unreachable path')
}
})()
return parsePythonToEstreeAst(programStr, chapterNum, false)
return parsePythonToEstreeAst(programStr, chapterNum, true)
} catch (error) {
if (error instanceof SyntaxError) {
error = new FatalSyntaxError(positionToSourceLocation((error as any).loc), error.toString())
Expand Down
2 changes: 1 addition & 1 deletion src/py-slang
67 changes: 40 additions & 27 deletions src/stdlib/__tests__/__snapshots__/pylib.ts.snap
Original file line number Diff line number Diff line change
@@ -1,9 +1,22 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`adding a string and an integer is ok: expectResult 1`] = `
Object {
"alertResult": Array [],
"code": "\\"a\\" + 1",
"displayResult": Array [],
"numErrors": 0,
"parsedErrors": "",
"result": "a1",
"resultStatus": "finished",
"visualiseListResult": Array [],
}
`;

exports[`adding an integer and a float is ok: expectResult 1`] = `
Object {
"alertResult": Array [],
"code": "__py_adder(1.0, BigInt(2))",
"code": "1.0 + 2",
"displayResult": Array [],
"numErrors": 0,
"parsedErrors": "",
Expand All @@ -16,7 +29,7 @@ Object {
exports[`adding two floats is ok: expectResult 1`] = `
Object {
"alertResult": Array [],
"code": "__py_adder(1.0, 2.0)",
"code": "1.0 + 2.0",
"displayResult": Array [],
"numErrors": 0,
"parsedErrors": "",
Expand All @@ -29,7 +42,7 @@ Object {
exports[`adding two integers is ok: expectResult 1`] = `
Object {
"alertResult": Array [],
"code": "__py_adder(BigInt(1), BigInt(2))",
"code": "1 + 2",
"displayResult": Array [],
"numErrors": 0,
"parsedErrors": "",
Expand All @@ -42,7 +55,7 @@ Object {
exports[`cannot divide non-number values: expectParsedError 1`] = `
Object {
"alertResult": Array [],
"code": "__py_divider(\\"a\\", 2)",
"code": "\\"a\\" / 2",
"displayResult": Array [],
"numErrors": 1,
"parsedErrors": "Line 1: Error: Expected number on left hand side of operation, got string.",
Expand All @@ -55,7 +68,7 @@ Object {
exports[`cannot floor non-number values: expectParsedError 1`] = `
Object {
"alertResult": Array [],
"code": "__py_floorer(\\"a\\", 2)",
"code": "\\"a\\" // 2",
"displayResult": Array [],
"numErrors": 1,
"parsedErrors": "Line 1: Error: Expected number on left hand side of operation, got string.",
Expand All @@ -68,7 +81,7 @@ Object {
exports[`cannot mod non-number values: expectParsedError 1`] = `
Object {
"alertResult": Array [],
"code": "__py_modder(\\"a\\", 2)",
"code": "\\"a\\" % 2",
"displayResult": Array [],
"numErrors": 1,
"parsedErrors": "Line 1: Error: Expected number on left hand side of operation, got string.",
Expand All @@ -81,10 +94,10 @@ Object {
exports[`cannot multiply non-number values: expectParsedError 1`] = `
Object {
"alertResult": Array [],
"code": "__py_multiplier(\\"a\\", 2)",
"code": "True * 2",
"displayResult": Array [],
"numErrors": 1,
"parsedErrors": "Line 1: Error: Expected number on left hand side of operation, got string.",
"parsedErrors": "Line 1: Error: Expected number on left hand side of operation, got boolean.",
"result": undefined,
"resultStatus": "error",
"visualiseListResult": Array [],
Expand All @@ -94,7 +107,7 @@ Object {
exports[`cannot power non-number values: expectParsedError 1`] = `
Object {
"alertResult": Array [],
"code": "__py_powerer(\\"a\\", 2)",
"code": "\\"a\\" ** 2",
"displayResult": Array [],
"numErrors": 1,
"parsedErrors": "Line 1: Error: Expected number on left hand side of operation, got string.",
Expand All @@ -107,7 +120,7 @@ Object {
exports[`dividing float and float is ok: expectResult 1`] = `
Object {
"alertResult": Array [],
"code": "__py_divider(1.0, 2.0)",
"code": "1.0 / 2.0",
"displayResult": Array [],
"numErrors": 0,
"parsedErrors": "",
Expand All @@ -120,7 +133,7 @@ Object {
exports[`dividing integer and float is ok: expectResult 1`] = `
Object {
"alertResult": Array [],
"code": "__py_divider(BigInt(2), 1.0)",
"code": "2 / 1.0",
"displayResult": Array [],
"numErrors": 0,
"parsedErrors": "",
Expand All @@ -133,7 +146,7 @@ Object {
exports[`dividing integer and integer is ok: expectResult 1`] = `
Object {
"alertResult": Array [],
"code": "__py_divider(BigInt(1), BigInt(2))",
"code": "1 / 2",
"displayResult": Array [],
"numErrors": 0,
"parsedErrors": "",
Expand All @@ -146,7 +159,7 @@ Object {
exports[`flooring float and float is ok: expectResult 1`] = `
Object {
"alertResult": Array [],
"code": "__py_floorer(1.0, 2.0)",
"code": "1.0 // 2.0",
"displayResult": Array [],
"numErrors": 0,
"parsedErrors": "",
Expand All @@ -159,7 +172,7 @@ Object {
exports[`flooring integer and float is ok: expectResult 1`] = `
Object {
"alertResult": Array [],
"code": "__py_floorer(BigInt(2), 1.0)",
"code": "2 // 1.0",
"displayResult": Array [],
"numErrors": 0,
"parsedErrors": "",
Expand All @@ -172,7 +185,7 @@ Object {
exports[`flooring integer and integer is ok: expectResult 1`] = `
Object {
"alertResult": Array [],
"code": "__py_floorer(BigInt(2), BigInt(1))",
"code": "2 // 1",
"displayResult": Array [],
"numErrors": 0,
"parsedErrors": "",
Expand All @@ -185,7 +198,7 @@ Object {
exports[`minusing an integer from a float is ok: expectResult 1`] = `
Object {
"alertResult": Array [],
"code": "__py_minuser(1.0, BigInt(2))",
"code": "1.0 - 2",
"displayResult": Array [],
"numErrors": 0,
"parsedErrors": "",
Expand All @@ -198,7 +211,7 @@ Object {
exports[`minusing two floats is ok: expectResult 1`] = `
Object {
"alertResult": Array [],
"code": "__py_minuser(1.0, 2.0)",
"code": "1.0 - 2.0",
"displayResult": Array [],
"numErrors": 0,
"parsedErrors": "",
Expand All @@ -211,7 +224,7 @@ Object {
exports[`minusing two integers is ok: expectResult 1`] = `
Object {
"alertResult": Array [],
"code": "__py_minuser(BigInt(1), BigInt(2))",
"code": "1 - 2",
"displayResult": Array [],
"numErrors": 0,
"parsedErrors": "",
Expand All @@ -224,7 +237,7 @@ Object {
exports[`modding float and float is ok: expectResult 1`] = `
Object {
"alertResult": Array [],
"code": "__py_modder(1.0, 2.0)",
"code": "1.0 % 2.0",
"displayResult": Array [],
"numErrors": 0,
"parsedErrors": "",
Expand All @@ -237,7 +250,7 @@ Object {
exports[`modding integer and float is ok: expectResult 1`] = `
Object {
"alertResult": Array [],
"code": "__py_modder(BigInt(2), 1.0)",
"code": "2 % 1.0",
"displayResult": Array [],
"numErrors": 0,
"parsedErrors": "",
Expand All @@ -250,7 +263,7 @@ Object {
exports[`modding integer and integer is ok: expectResult 1`] = `
Object {
"alertResult": Array [],
"code": "__py_modder(BigInt(2), BigInt(1))",
"code": "2 % 1",
"displayResult": Array [],
"numErrors": 0,
"parsedErrors": "",
Expand All @@ -263,7 +276,7 @@ Object {
exports[`multiplying float and float is ok: expectResult 1`] = `
Object {
"alertResult": Array [],
"code": "__py_multiplier(1.0, 2.0)",
"code": "1.0 * 2.0",
"displayResult": Array [],
"numErrors": 0,
"parsedErrors": "",
Expand All @@ -276,7 +289,7 @@ Object {
exports[`multiplying integer and float is ok: expectResult 1`] = `
Object {
"alertResult": Array [],
"code": "__py_multiplier(1.0, BigInt(2))",
"code": "1.0 * 2",
"displayResult": Array [],
"numErrors": 0,
"parsedErrors": "",
Expand All @@ -289,7 +302,7 @@ Object {
exports[`multiplying integer and integer is ok: expectResult 1`] = `
Object {
"alertResult": Array [],
"code": "__py_multiplier(BigInt(1), BigInt(2))",
"code": "1 * 2",
"displayResult": Array [],
"numErrors": 0,
"parsedErrors": "",
Expand All @@ -302,7 +315,7 @@ Object {
exports[`powering float and float is ok: expectResult 1`] = `
Object {
"alertResult": Array [],
"code": "__py_powerer(1.0, 2.0)",
"code": "1.0 ** 2.0",
"displayResult": Array [],
"numErrors": 0,
"parsedErrors": "",
Expand All @@ -315,7 +328,7 @@ Object {
exports[`powering integer and float is ok: expectResult 1`] = `
Object {
"alertResult": Array [],
"code": "__py_powerer(BigInt(2), 1.0)",
"code": "2 ** 1.0",
"displayResult": Array [],
"numErrors": 0,
"parsedErrors": "",
Expand All @@ -328,7 +341,7 @@ Object {
exports[`powering integer and integer is ok: expectResult 1`] = `
Object {
"alertResult": Array [],
"code": "__py_powerer(BigInt(2), BigInt(1))",
"code": "2 ** 1",
"displayResult": Array [],
"numErrors": 0,
"parsedErrors": "",
Expand Down
Loading

0 comments on commit ecd5955

Please sign in to comment.