-
Notifications
You must be signed in to change notification settings - Fork 7
Add Autocomplete and Syntax Highlighting #109
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
Open
AaravMalani
wants to merge
24
commits into
main
Choose a base branch
from
add-autocomplete
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
ccf1a8b
Add basic syntax highlighting and autocomplete
AaravMalani a99f731
Add some more documentation
AaravMalani f191853
Added keywords
AaravMalani 528c326
Add autocomplete for all groups based on variant + Fix bug where vari…
AaravMalani 8f05bb1
Add for statements + Fix function names and name declarations coming …
AaravMalani 6a941a2
Merge branch 'main' into add-autocomplete
AaravMalani ae69e32
Migrate to `@sourceacademy/autocomplete`
AaravMalani 7843e98
Merge branch 'main' into add-autocomplete
AaravMalani 5552156
Update `ts-node` to `tsx`
AaravMalani ebc291c
Use `.kind` instead of `.constructor.name` to allow function name ter…
AaravMalani 8840377
Fix the step limit
AaravMalani f426caa
Refactor type narrowing
AaravMalani 60709d0
Remove unused code
AaravMalani 4c5a04e
Fix some bugs (prelude functions not working + `==` not working for e…
AaravMalani 1fac0bb
Add explicit types for every evaluator + fix test cases for parser
AaravMalani d320d0f
Merge branch 'fix-tail-call' into add-autocomplete
AaravMalani dbb08bf
Merge remote-tracking branch 'origin' into add-autocomplete
AaravMalani 152076b
Fix bug regarding missing py_s1_constants.json
AaravMalani 6194145
feat(conductor): add per-evaluator autocomplete and syntax highlighting
MengJit 376926f
style: format PyCseEvaluator.ts
MengJit 78146c0
Merge branch 'main' into add-autocomplete
MengJit 1d73766
Add `range` support + Add test cases
AaravMalani f57b25c
Update chapter 3 tests to use variant 3
AaravMalani 7d59048
Add more chapter-specific test cases
AaravMalani File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| #! /usr/bin/env bash | ||
|
|
||
| # Exit immediately if a command exits with a non-zero status. | ||
| set -e | ||
|
|
||
| JSDOC="$(yarn bin jsdoc)" | ||
| LIB="docs/lib" | ||
| CONF="docs/jsdoc/conf.json" | ||
|
|
||
| # Create the builtins directory if it doesn't exist | ||
| mkdir -p "src/conductor/plugins/autocomplete/builtins" | ||
|
|
||
| # Process every JavaScript file in the docs/lib directory with JSDoc, | ||
| # outputting the AST as JSON to the src/conductor/plugins/autocomplete/builtins directory. | ||
| for file in "$LIB"/*.js; do | ||
| echo "Processing $file..." | ||
| "$JSDOC" -X -c "$CONF" "$file" > "src/conductor/plugins/autocomplete/builtins/$(basename "$file" .js).json" & | ||
| done | ||
| wait | ||
|
|
||
| yarn tsx src/generate-autocomplete.mts | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,227 @@ | ||
| /** | ||
| * Adapted from https://github.com/ajaxorg/ace/blob/master/src/mode/python_highlight_rules.js | ||
| * | ||
| * Copyright (c) 2010, Ajax.org B.V. | ||
| * All rights reserved. | ||
| * | ||
| * Redistribution and use in source and binary forms, with or without | ||
| * modification, are permitted provided that the following conditions are met: | ||
| * * Redistributions of source code must retain the above copyright | ||
| * notice, this list of conditions and the following disclaimer. | ||
| * * Redistributions in binary form must reproduce the above copyright | ||
| * notice, this list of conditions and the following disclaimer in the | ||
| * documentation and/or other materials provided with the distribution. | ||
| * * Neither the name of Ajax.org B.V. nor the | ||
| * names of its contributors may be used to endorse or promote products | ||
| * derived from this software without specific prior written permission. | ||
| * | ||
| * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND | ||
| * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
| * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
| * DISCLAIMED. IN NO EVENT SHALL AJAX.ORG B.V. BE LIABLE FOR ANY | ||
| * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
| * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
| * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
| * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
| * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
| * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| * | ||
| */ | ||
|
|
||
| import { AceRules } from "@sourceacademy/autocomplete"; | ||
| import math from "../../../stdlib/math"; | ||
| import misc from "../../../stdlib/misc"; | ||
| import { getIllegalKeywords, getKeywords } from "./keywords"; | ||
|
|
||
| export default (variant: number) => { | ||
| const keywords = getKeywords(variant).join("|"); | ||
| const illegalKeywords = getIllegalKeywords(variant).join("|"); | ||
| const stdlibBuiltins = new Map([...math.builtins, ...misc.builtins]); | ||
| const builtinConstants = [...stdlibBuiltins.keys()] | ||
| .filter(x => stdlibBuiltins.get(x)?.type !== "builtin") | ||
| .join("|"); | ||
|
|
||
| let builtinFunctions = [...stdlibBuiltins.keys()] | ||
| .filter(x => stdlibBuiltins.get(x)?.type === "builtin") | ||
| .join("|"); | ||
| if (variant >= 3) { | ||
| builtinFunctions += "|range"; | ||
| } | ||
|
|
||
| //var futureReserved = ""; | ||
| const keywordMapper = { | ||
| map: { | ||
| "support.function": builtinFunctions, | ||
| "constant.language": builtinConstants, | ||
| keyword: keywords, | ||
| "invalid.illegal": illegalKeywords, | ||
| }, | ||
| defaultToken: "identifier", | ||
| }; | ||
|
|
||
| const decimalInteger = "(?:(?:[1-9]\\d*)|(?:0))"; | ||
| const octInteger = "(?:0[oO]?[0-7]+)"; | ||
| const hexInteger = "(?:0[xX][\\dA-Fa-f]+)"; | ||
| const binInteger = "(?:0[bB][01]+)"; | ||
| const integer = | ||
| "(?:" + decimalInteger + "|" + octInteger + "|" + hexInteger + "|" + binInteger + ")"; | ||
|
|
||
| const exponent = "(?:[eE][+-]?\\d+)"; | ||
| const fraction = "(?:\\.\\d+)"; | ||
| const intPart = "(?:\\d+)"; | ||
| const pointFloat = "(?:(?:" + intPart + "?" + fraction + ")|(?:" + intPart + "\\.))"; | ||
| const exponentFloat = "(?:(?:" + pointFloat + "|" + intPart + ")" + exponent + ")"; | ||
| const floatNumber = "(?:" + exponentFloat + "|" + pointFloat + ")"; | ||
|
|
||
| const stringEscape = | ||
| "\\\\(x[0-9A-Fa-f]{2}|[0-7]{3}|[\\\\abfnrtv'\"]|U[0-9A-Fa-f]{8}|u[0-9A-Fa-f]{4})"; | ||
| const rules: AceRules = { | ||
| start: [ | ||
| { | ||
| token: "comment", | ||
| regex: "#.*$", | ||
| }, | ||
| { | ||
| token: "string", // multi line """ string start | ||
| regex: '"{3}', | ||
| next: "qqstring3", | ||
| }, | ||
| { | ||
| token: "string", // " string | ||
| regex: '"(?=.)', | ||
| next: "qqstring", | ||
| }, | ||
| { | ||
| token: "string", // multi line ''' string start | ||
| regex: "'{3}", | ||
| next: "qstring3", | ||
| }, | ||
| { | ||
| token: "string", // ' string | ||
| regex: "'(?=.)", | ||
| next: "qstring", | ||
| }, | ||
| { | ||
| token: "keyword.operator", | ||
| regex: "\\+|\\-|\\*|\\*\\*|\\/|\\/\\/|%|@|<<|>>|&|\\||\\^|~|<|>|<=|=>|==|!=|<>|=", | ||
| }, | ||
| { | ||
| token: "punctuation", | ||
| regex: ",|:|;|\\->|\\+=|\\-=|\\*=|\\/=|\\/\\/=|%=|@=|&=|\\|=|^=|>>=|<<=|\\*\\*=", | ||
| }, | ||
| { | ||
| token: "paren.lparen", | ||
| regex: "[\\[\\(\\{]", | ||
| }, | ||
| { | ||
| token: "paren.rparen", | ||
| regex: "[\\]\\)\\}]", | ||
| }, | ||
| { | ||
| token: ["keyword", "text", "entity.name.function"], | ||
| regex: "(def)(\\s+)([\\u00BF-\\u1FFF\\u2C00-\\uD7FF\\w]+)", | ||
| }, | ||
| { | ||
| token: "text", | ||
| regex: "\\s+", | ||
| }, | ||
| { | ||
| include: "constants", | ||
| }, | ||
| ], | ||
| qqstring3: [ | ||
| { | ||
| token: "constant.language.escape", | ||
| regex: stringEscape, | ||
| }, | ||
| { | ||
| token: "string", // multi line """ string end | ||
| regex: '"{3}', | ||
| next: "start", | ||
| }, | ||
| { | ||
| defaultToken: "string", | ||
| }, | ||
| ], | ||
| qstring3: [ | ||
| { | ||
| token: "constant.language.escape", | ||
| regex: stringEscape, | ||
| }, | ||
| { | ||
| token: "string", // multi line ''' string end | ||
| regex: "'{3}", | ||
| next: "start", | ||
| }, | ||
| { | ||
| defaultToken: "string", | ||
| }, | ||
| ], | ||
| qqstring: [ | ||
| { | ||
| token: "constant.language.escape", | ||
| regex: stringEscape, | ||
| }, | ||
| { | ||
| token: "string", | ||
| regex: "\\\\$", | ||
| next: "qqstring", | ||
| }, | ||
| { | ||
| token: "string", | ||
| regex: '"|$', | ||
| next: "start", | ||
| }, | ||
| { | ||
| defaultToken: "string", | ||
| }, | ||
| ], | ||
| qstring: [ | ||
| { | ||
| token: "constant.language.escape", | ||
| regex: stringEscape, | ||
| }, | ||
| { | ||
| token: "string", | ||
| regex: "\\\\$", | ||
| next: "qstring", | ||
| }, | ||
| { | ||
| token: "string", | ||
| regex: "'|$", | ||
| next: "start", | ||
| }, | ||
| { | ||
| defaultToken: "string", | ||
| }, | ||
| ], | ||
| constants: [ | ||
| { | ||
| token: "constant.numeric", // imaginary | ||
| regex: "(?:" + floatNumber + "|\\d+)[jJ]\\b", | ||
| }, | ||
| { | ||
| token: "constant.numeric", // float | ||
| regex: floatNumber, | ||
| }, | ||
| { | ||
| token: "constant.numeric", // long integer | ||
| regex: integer + "[lL]\\b", | ||
| }, | ||
| { | ||
| token: "constant.numeric", // integer | ||
| regex: integer + "\\b", | ||
| }, | ||
| { | ||
| token: ["punctuation", "function.support"], // method | ||
| regex: "(\\.)([a-zA-Z_]+)\\b", | ||
| }, | ||
| { | ||
| token: keywordMapper, | ||
| regex: "[a-zA-Z_$][a-zA-Z0-9_$]*\\b", | ||
| }, | ||
| ], | ||
| }; | ||
|
|
||
| return rules; | ||
| }; |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This loop will fail with
set -eif no.jsfiles are found in the$LIBdirectory because the glob"$LIB"/*.jswill not expand and the script will try to process a file with that literal name. It's good practice to handle cases where no files match the glob pattern.