Skip to content

Commit

Permalink
Establishing generic parselets and functions (#105)
Browse files Browse the repository at this point in the history
  • Loading branch information
phorward authored Oct 23, 2023
2 parents b776065 + 03bdb0e commit 2b75daf
Show file tree
Hide file tree
Showing 36 changed files with 3,966 additions and 1,831 deletions.
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,18 @@

Current main branch.

- Implementation of generic parselets
- Syntax changes
- Handle parselet instances
- Handle generic values in intermediate structures
- System-defined parselets in prelude
- `Repeat<P, min: 1, max: void>`
- Implement `Pos<P>`, `Opt<P>`, `Kle<P>`
- Compile `P+` into `Pos<P>`, `P?` into `Opt<P>`, `P*` into `Kle<P>`
- `List<P, Sep: (',' _), empty: true>`
- `Peek<P>`, replaced `peek P` by `Peek<P>`
- `Not<P>`, replaced `not P` by `Not<P>`
- `Expect<P> msg=void`, replaced `expect P` by `Expect<P>`
- v0.6.4:
- Main parselet operates on multiple inputs (Readers) now
- Restructuring parts of VM, `Runtime` renamed into `Thread`
Expand Down
3 changes: 2 additions & 1 deletion ROADMAP.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ This document describes upcoming changes to achieve with a specific version.
## 0.7

- [x] Implement iterators and `for...in`-syntax (#101)
- [ ] Implement generic parselets (#10, #105)
- [x] Implement generic parselets (#10, #105)
- [ ] Implement embedded parselets (#120)
- [ ] New list syntax `[...]`, redefining sequence/`dict` syntax (#100)
- The character-class token syntax was replaced by a `Char`-builtin
- List definition `list = []`
Expand Down
15 changes: 15 additions & 0 deletions build/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ all:
@echo ""
@echo " make builtins update src/_builtins.rs from src/"
@echo " make parser update src/compiler/parse.rs from src/compiler/tokay.tok"
@echo " make prelude update src/compiler/prelude.rs from src/prelude.tok"
@echo ""

# builtins --------------------------------------------------------------------
Expand Down Expand Up @@ -36,3 +37,17 @@ show-parser:

reset-parser:
git checkout $(PARSER)

# prelude ----------------------------------------------------------------------
PRELUDE=../src/compiler/prelude.rs

prelude: $(PRELUDE)

$(PRELUDE): .FORCE
$(ETARENEG) $@ >$@.1 && mv $@.1 $@

show-prelude:
$(ETARENEG) $(PRELUDE) 2>/dev/null

reset-prelude:
git checkout $(PRELUDE)
11 changes: 11 additions & 0 deletions examples/minicalc.tok
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@

Main : @{
Expect<Expr> print("= " + $1)
}

Expr : @{
Expr '+' Int $1 + $3
Int
}

Main
6 changes: 5 additions & 1 deletion src/_builtins.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
use crate::builtin::Builtin;

/*GENERATE cargo run -- _builtins.tok -- `find . -name "*.rs"` */
pub static BUILTINS: [Builtin; 63] = [
pub static BUILTINS: [Builtin; 64] = [
Builtin {
name: "Float",
func: crate::value::token::tokay_token_float,
Expand Down Expand Up @@ -87,6 +87,10 @@ pub static BUILTINS: [Builtin; 63] = [
name: "dict_set_item",
func: crate::value::dict::Dict::tokay_method_dict_set_item,
},
Builtin {
name: "eof",
func: crate::builtin::tokay_function_eof,
},
Builtin {
name: "error",
func: crate::error::tokay_function_error,
Expand Down
8 changes: 7 additions & 1 deletion src/builtin/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,9 @@ tokay_function!("type : @value", value!(value.name()).into());
tokay_function!("debug : @level", {
if let Ok(level) = level.to_usize() {
if level < u8::MAX as usize {
context.unwrap().thread.debug = level as u8;
let context = context.unwrap();
context.debug = level as u8;
//context.thread.debug = level as u8;
return Ok(Accept::Next);
}
}
Expand Down Expand Up @@ -210,3 +212,7 @@ tokay_function!("offset : @", {
])
.into()
});

tokay_function!("eof : @", {
value!(context.unwrap().thread.reader.eof()).into()
});
Loading

0 comments on commit 2b75daf

Please sign in to comment.