Runtime: add method dispatch for array/string/dict/number (.len, .push, .pop, .keys, .values, .has, .toInt) Stdlib: delete global len/push/pop/keys/values/has Tests/docs/examples: migrate to method style; add tests/test_builtin_methods_style.bob All tests pass Breaking: global len/push/pop/keys/values/has removed; use methods instead Parser/AST: add class/extends/extension/super, field initializers Runtime: shared methods with this injection; classParents/classTemplates; super resolution; ownerClass/currentClass; extension lookup order Builtins: method dispatch for array/string/dict/number (.len/.push/.pop/.keys/.values/.has/.toInt); remove global forms Tests/docs/examples: add/refresh for classes, inheritance, super, polymorphism; migrate to method style; all tests pass VS Code extension: update grammar/readme/snippets for new features
3.9 KiB
3.9 KiB
Bob Language Extension for VS Code
This extension provides syntax highlighting and language support for the Bob programming language in Visual Studio Code and Cursor.
Features
- Syntax Highlighting: Full syntax highlighting for Bob language constructs
- Code Snippets: Useful code snippets for common Bob patterns
- Auto-closing Brackets: Automatic bracket and quote pairing
- Indentation: Smart indentation for Bob code blocks
- Comments: Support for line and block comments
- Folding: Code folding support with region markers
Supported Syntax
Keywords
- Control flow:
if,else,while,for,break,continue,return - Variable declaration:
var - Function declaration:
func - Classes and OOP:
class,extends,extension,this,super - Logical operators:
and,or,not
Built-in Functions
print(),assert(),input(),type(),toString(),toNumber(),toInt(),time(),sleep(),printRaw()- Arrays/Dictionaries (preferred method style):
arr.len(),arr.push(...),arr.pop(),dict.len(),dict.keys(),dict.values(),dict.has() - Global forms still available:
len(x),push(arr, ...),pop(arr),keys(dict),values(dict),has(dict, key) - Misc:
random(),eval()
Data Types
- Numbers (integers, floats, binary
0b1010, hex0xFF) - Strings (single and double quoted)
- Booleans (
true,false) - None value (
none) - Arrays (
[1, 2, 3])
Operators
- Arithmetic:
+,-,*,/,% - Comparison:
==,!=,<,>,<=,>= - Logical:
&&,||,! - Bitwise:
&,|,^,<<,>>,~ - Compound assignment:
+=,-=,*=,/=,%=,&=,|=,^=,<<=,>>= - Ternary:
condition ? valueIfTrue : valueIfFalse - String multiplication:
"hello" * 3
Installation
From Source
- Clone this repository
- Run
npm installto install dependencies - Run
npm run compileto build the extension - Press
F5in VS Code to launch the extension in a new window
Manual Installation
- Copy the extension files to your VS Code extensions directory
- Restart VS Code
- Open a
.bobfile to see syntax highlighting
Usage
Code Snippets
Type the following prefixes and press Tab to insert code snippets:
func- Function definitionif- If statementifelse- If-else statementwhile- While loopfor- For loopvar- Variable declarationprint- Print statementassert- Assert statementanon- Anonymous functionreturn- Return statementbreak- Break statementcontinue- Continue statementcomment- Comment blocktest- Test functionarray- Array declarationarrayaccess- Array accessarrayassign- Array assignmentlen- Array lengthpush- Array pushpop- Array poprandom- Random numbersleep- Sleep functionprintraw- Print raweval- Eval function
File Association
Files with the .bob extension will automatically be recognized as Bob language files.
Example
// This is a comment
var message = "Hello, Bob!";
print(message);
// Array operations (method style)
var numbers = [1, 2, 3, 4, 5];
print("Array length: " + numbers.len());
numbers.push(6);
print("Popped: " + numbers.pop());
print("First element: " + numbers[0]);
// Function with ternary operator
func factorial(n) {
if (n <= 1) {
return 1;
}
return n * factorial(n - 1);
}
var result = factorial(5);
var status = result > 100 ? "large" : "small";
assert(result == 120, "Factorial calculation failed");
// String multiplication
var repeated = "hello" * 3; // "hellohellohello"
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
This extension is licensed under the MIT License.