| Crates.io | oak-smalltalk |
| lib.rs | oak-smalltalk |
| version | 0.0.1 |
| created_at | 2025-10-22 03:21:49.331616+00 |
| updated_at | 2026-01-23 05:19:06.708055+00 |
| description | Smalltalk language parser with support for modern Smalltalk syntax and features. |
| homepage | https://github.com/ygg-lang/oaks |
| repository | https://github.com/ygg-lang/oaks |
| max_upload_size | |
| id | 1894876 |
| size | 88,613 |
oak-smalltalkThis crate provides a comprehensive parser for the Smalltalk language, built using the oaks parsing framework. It includes a lexer and language definition to facilitate parsing Smalltalk code with support for modern Smalltalk syntax and features.
To use the oak-smalltalk parser, you typically need to interact with SmalltalkLanguage and SmalltalkLexer.
SmalltalkLanguageThe SmalltalkLanguage struct defines the grammar and rules for Smalltalk. It implements the Language trait from the oaks framework.
use oak_smalltalk::SmalltalkLanguage;
let language = SmalltalkLanguage::default();
SmalltalkLexerThe SmalltalkLexer is responsible for tokenizing the input Smalltalk code based on the SmalltalkLanguage definition.
use oak_smalltalk::{SmalltalkLanguage, SmalltalkLexer};
use oak_core::lexer::{Lexer, LexInput};
// Initialize the language
let language = Box::leak(Box::new(SmalltalkLanguage::default()));
// Create a lexer instance
let lexer = SmalltalkLexer::new(language);
// Prepare the input source code
let source_code = r#"
"Class definition example"
Object subclass: #Person
instanceVariableNames: 'name age'
classVariableNames: ''
poolDictionaries: ''
category: 'Examples-Classes'!
!Person methodsFor: 'accessing'!
name
"Return the person's name"
^name!
name: aName
"Set the person's name"
name := aName!
age
"Return the person's age"
^age!
age: anAge
"Set the person's age"
age := anAge!
! !
"#;
let input = LexInput::new(source_code, 0, None);
// Lex the input
let lex_output = lexer.lex(input);
// You can now process the lex_output which contains the tokens
println!("Lexed tokens: {:?}", lex_output.tokens);
"Class definition"
Object subclass: #MyClass
instanceVariableNames: 'var1 var2'
classVariableNames: 'ClassVar'
poolDictionaries: ''
category: 'MyCategory'!
!MyClass methodsFor: 'category'!
methodName: parameter
"Method comment"
| localVar1 localVar2 |
localVar1 := parameter.
^localVar1 * 2!
! !
"Numbers"
42 "integer"
3.14159 "float"
1.23e-4 "scientific notation"
16rFF "hexadecimal"
8r755 "octal"
"Strings and Characters"
'Hello World' "string"
$a "character"
"Symbols"
#selector "symbol"
#'multi word' "symbol with spaces"
"Arrays"
#(1 2 3 4 5) "literal array"
#('hello' 'world' #symbol) "mixed array"
"Unary messages"
object method
array size
dictionary keys
"Binary messages"
1 + 2
3 * 4
5 < 10
"Keyword messages"
dictionary at: 'key' put: 'value'
array copyFrom: 1 to: 5
string replaceFrom: 1 to: 3 with: 'new'
"Simple block"
[42] value
"Block with parameter"
[:x | x * x] value: 5
"Block with multiple parameters"
[:x :y | x + y] value: 3 value: 4
"Block with local variables"
[
| temp |
temp := 10.
temp * 2
] value
"Conditionals"
x > 0 ifTrue: ['positive'] ifFalse: ['non-positive']
"Loops"
1 to: 10 do: [:i | Transcript show: i printString; cr]
"Collection iteration"
#(1 2 3 4 5) do: [:each | Transcript show: each printString; cr]
#(1 2 3 4 5) select: [:each | each even]
#(1 2 3 4 5) collect: [:each | each * 2]
This parser integrates seamlessly with the Oaks framework, providing:
oak-highlight for multi-language syntax highlightingoak-pretty-print for code formattingFor comprehensive examples of Smalltalk syntax and usage patterns, see the test files in the tests/ directory, particularly tests/lexer/basic.st which contains extensive examples of Smalltalk language features.
The Smalltalk parser is actively developed and supports core Smalltalk syntax. Future enhancements may include:
This example demonstrates the power and flexibility of the Oaks framework for parsing complex object-oriented languages like Smalltalk.