From 310d264164f413ee96c34715ca874f1781a750f6 Mon Sep 17 00:00:00 2001 From: Vladimir Kalnitsky Date: Tue, 12 Nov 2024 01:02:07 +0400 Subject: [PATCH] Use the word :use instead of :include --- README.md | 7 +-- grammar/MetaPrompt.g4 | 4 +- python/src/eval.py | 4 +- python/src/parse_metaprompt.py | 6 +-- python/src/parser/MetaPrompt.interp | 2 +- python/src/parser/MetaPrompt.tokens | 2 +- python/src/parser/MetaPromptLexer.interp | 6 +-- python/src/parser/MetaPromptLexer.py | 63 ++++++++++++------------ python/src/parser/MetaPromptLexer.tokens | 2 +- python/src/parser/MetaPromptParser.py | 10 ++-- python/tests/test_parser.py | 30 +++++------ 11 files changed, 68 insertions(+), 68 deletions(-) diff --git a/README.md b/README.md index 6e30fb1..9c430e0 100644 --- a/README.md +++ b/README.md @@ -55,7 +55,7 @@ This is an early work-in-progress. Follow [me on twitter](https://x.com/klntsky) - [ ] `[!assertion]` - [x] `[:if ... :then ... :else ...]` - [x] `[$ meta-prompt]` - - [x] `[:include module :param1=value1]` + - [x] `[:use module :param1=value1]` - [ ] `[# comments]` - [ ] Implement an evaluator - [x] meta-prompting @@ -64,7 +64,9 @@ This is an early work-in-progress. Follow [me on twitter](https://x.com/klntsky) - [x] implement a 'manual' evaluator that asks the user to complete LLM inputs - [ ] API provider wrapper classes - [x] OpenAI - - [ ] dynamic model switching + - [ ] Anthropic + - [ ] llama + - [ ] dynamic model switching - [ ] Runtime system - [x] Support variable definition at runtime - [ ] exceptions @@ -76,7 +78,6 @@ This is an early work-in-progress. Follow [me on twitter](https://x.com/klntsky) - [ ] enable function scopes - [ ] Add a module system - [ ] Add a package system -- [ ] Type system? TBD ## Notable sources of inspiration diff --git a/grammar/MetaPrompt.g4 b/grammar/MetaPrompt.g4 index a44a7fb..4368012 100644 --- a/grammar/MetaPrompt.g4 +++ b/grammar/MetaPrompt.g4 @@ -16,7 +16,7 @@ expr1 meta_body : IF_KW exprs THEN_KW exprs ELSE_KW exprs | IF_KW exprs THEN_KW exprs - | INCLUDE parameters? + | USE parameters? | META_KW exprs | VAR_NAME EQ_KW exprs | VAR_NAME @@ -33,7 +33,7 @@ RB : ']'; EQ_KW : '=' ; META_KW : '$' ; CHAR : . ; -INCLUDE : ':include' WS+ [a-zA-Z0-9/_.-]+ WS*; +USE : ':use' WS+ [a-zA-Z0-9/_.-]+ WS*; fragment WS : ' '|'\n'; IF_KW : ':if' ; THEN_KW : ':then' ; diff --git a/python/src/eval.py b/python/src/eval.py index 685c702..7630f45 100644 --- a/python/src/eval.py +++ b/python/src/eval.py @@ -39,10 +39,10 @@ async def eval_ast(ast, runtime): raise ValueError(f"Failed to look up: {ast['name']}") else: yield value - elif ast["type"] == "include": + elif ast["type"] == "use": parameters = ast["parameters"] module_name = ast["module_name"] - raise NotImplementedError("[:include ...] not implemented yet") + raise NotImplementedError("[:use ...] not implemented yet") elif ast["type"] == "assign": var_name = ast["name"] value = await _collect_exprs(ast['exprs'], runtime) diff --git a/python/src/parse_metaprompt.py b/python/src/parse_metaprompt.py index 0d284b4..9821185 100644 --- a/python/src/parse_metaprompt.py +++ b/python/src/parse_metaprompt.py @@ -83,13 +83,13 @@ def visitMeta_body(self, ctx: MetaPromptParser.Meta_bodyContext): "then": then_node, "else": [], } - elif ctx.INCLUDE() is not None: - module_name = ctx.INCLUDE().getText().removeprefix(':include').strip() + elif ctx.USE() is not None: + module_name = ctx.USE().getText().removeprefix(':use').strip() parameters = {} if ctx.parameters() is not None: parameters = self.visit(ctx.parameters()) return { - "type": "include", + "type": "use", "module_name": module_name, "parameters": parameters } diff --git a/python/src/parser/MetaPrompt.interp b/python/src/parser/MetaPrompt.interp index 80b22f3..a627c45 100644 --- a/python/src/parser/MetaPrompt.interp +++ b/python/src/parser/MetaPrompt.interp @@ -18,7 +18,7 @@ RB EQ_KW META_KW CHAR -INCLUDE +USE IF_KW THEN_KW ELSE_KW diff --git a/python/src/parser/MetaPrompt.tokens b/python/src/parser/MetaPrompt.tokens index 43da6a2..d76266d 100644 --- a/python/src/parser/MetaPrompt.tokens +++ b/python/src/parser/MetaPrompt.tokens @@ -3,7 +3,7 @@ RB=2 EQ_KW=3 META_KW=4 CHAR=5 -INCLUDE=6 +USE=6 IF_KW=7 THEN_KW=8 ELSE_KW=9 diff --git a/python/src/parser/MetaPromptLexer.interp b/python/src/parser/MetaPromptLexer.interp index a5a3e20..c54c13a 100644 --- a/python/src/parser/MetaPromptLexer.interp +++ b/python/src/parser/MetaPromptLexer.interp @@ -18,7 +18,7 @@ RB EQ_KW META_KW CHAR -INCLUDE +USE IF_KW THEN_KW ELSE_KW @@ -30,7 +30,7 @@ RB EQ_KW META_KW CHAR -INCLUDE +USE WS IF_KW THEN_KW @@ -45,4 +45,4 @@ mode names: DEFAULT_MODE atn: -[4, 0, 10, 84, 6, -1, 2, 0, 7, 0, 2, 1, 7, 1, 2, 2, 7, 2, 2, 3, 7, 3, 2, 4, 7, 4, 2, 5, 7, 5, 2, 6, 7, 6, 2, 7, 7, 7, 2, 8, 7, 8, 2, 9, 7, 9, 2, 10, 7, 10, 1, 0, 1, 0, 1, 1, 1, 1, 1, 2, 1, 2, 1, 3, 1, 3, 1, 4, 1, 4, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 4, 5, 44, 8, 5, 11, 5, 12, 5, 45, 1, 5, 4, 5, 49, 8, 5, 11, 5, 12, 5, 50, 1, 5, 5, 5, 54, 8, 5, 10, 5, 12, 5, 57, 9, 5, 1, 6, 1, 6, 1, 7, 1, 7, 1, 7, 1, 7, 1, 8, 1, 8, 1, 8, 1, 8, 1, 8, 1, 8, 1, 9, 1, 9, 1, 9, 1, 9, 1, 9, 1, 9, 1, 10, 1, 10, 1, 10, 5, 10, 80, 8, 10, 10, 10, 12, 10, 83, 9, 10, 0, 0, 11, 1, 1, 3, 2, 5, 3, 7, 4, 9, 5, 11, 6, 13, 0, 15, 7, 17, 8, 19, 9, 21, 10, 1, 0, 4, 4, 0, 45, 57, 65, 90, 95, 95, 97, 122, 2, 0, 10, 10, 32, 32, 2, 0, 65, 90, 97, 122, 3, 0, 48, 57, 65, 90, 97, 122, 86, 0, 1, 1, 0, 0, 0, 0, 3, 1, 0, 0, 0, 0, 5, 1, 0, 0, 0, 0, 7, 1, 0, 0, 0, 0, 9, 1, 0, 0, 0, 0, 11, 1, 0, 0, 0, 0, 15, 1, 0, 0, 0, 0, 17, 1, 0, 0, 0, 0, 19, 1, 0, 0, 0, 0, 21, 1, 0, 0, 0, 1, 23, 1, 0, 0, 0, 3, 25, 1, 0, 0, 0, 5, 27, 1, 0, 0, 0, 7, 29, 1, 0, 0, 0, 9, 31, 1, 0, 0, 0, 11, 33, 1, 0, 0, 0, 13, 58, 1, 0, 0, 0, 15, 60, 1, 0, 0, 0, 17, 64, 1, 0, 0, 0, 19, 70, 1, 0, 0, 0, 21, 76, 1, 0, 0, 0, 23, 24, 5, 91, 0, 0, 24, 2, 1, 0, 0, 0, 25, 26, 5, 93, 0, 0, 26, 4, 1, 0, 0, 0, 27, 28, 5, 61, 0, 0, 28, 6, 1, 0, 0, 0, 29, 30, 5, 36, 0, 0, 30, 8, 1, 0, 0, 0, 31, 32, 9, 0, 0, 0, 32, 10, 1, 0, 0, 0, 33, 34, 5, 58, 0, 0, 34, 35, 5, 105, 0, 0, 35, 36, 5, 110, 0, 0, 36, 37, 5, 99, 0, 0, 37, 38, 5, 108, 0, 0, 38, 39, 5, 117, 0, 0, 39, 40, 5, 100, 0, 0, 40, 41, 5, 101, 0, 0, 41, 43, 1, 0, 0, 0, 42, 44, 3, 13, 6, 0, 43, 42, 1, 0, 0, 0, 44, 45, 1, 0, 0, 0, 45, 43, 1, 0, 0, 0, 45, 46, 1, 0, 0, 0, 46, 48, 1, 0, 0, 0, 47, 49, 7, 0, 0, 0, 48, 47, 1, 0, 0, 0, 49, 50, 1, 0, 0, 0, 50, 48, 1, 0, 0, 0, 50, 51, 1, 0, 0, 0, 51, 55, 1, 0, 0, 0, 52, 54, 3, 13, 6, 0, 53, 52, 1, 0, 0, 0, 54, 57, 1, 0, 0, 0, 55, 53, 1, 0, 0, 0, 55, 56, 1, 0, 0, 0, 56, 12, 1, 0, 0, 0, 57, 55, 1, 0, 0, 0, 58, 59, 7, 1, 0, 0, 59, 14, 1, 0, 0, 0, 60, 61, 5, 58, 0, 0, 61, 62, 5, 105, 0, 0, 62, 63, 5, 102, 0, 0, 63, 16, 1, 0, 0, 0, 64, 65, 5, 58, 0, 0, 65, 66, 5, 116, 0, 0, 66, 67, 5, 104, 0, 0, 67, 68, 5, 101, 0, 0, 68, 69, 5, 110, 0, 0, 69, 18, 1, 0, 0, 0, 70, 71, 5, 58, 0, 0, 71, 72, 5, 101, 0, 0, 72, 73, 5, 108, 0, 0, 73, 74, 5, 115, 0, 0, 74, 75, 5, 101, 0, 0, 75, 20, 1, 0, 0, 0, 76, 77, 5, 58, 0, 0, 77, 81, 7, 2, 0, 0, 78, 80, 7, 3, 0, 0, 79, 78, 1, 0, 0, 0, 80, 83, 1, 0, 0, 0, 81, 79, 1, 0, 0, 0, 81, 82, 1, 0, 0, 0, 82, 22, 1, 0, 0, 0, 83, 81, 1, 0, 0, 0, 5, 0, 45, 50, 55, 81, 0] \ No newline at end of file +[4, 0, 10, 80, 6, -1, 2, 0, 7, 0, 2, 1, 7, 1, 2, 2, 7, 2, 2, 3, 7, 3, 2, 4, 7, 4, 2, 5, 7, 5, 2, 6, 7, 6, 2, 7, 7, 7, 2, 8, 7, 8, 2, 9, 7, 9, 2, 10, 7, 10, 1, 0, 1, 0, 1, 1, 1, 1, 1, 2, 1, 2, 1, 3, 1, 3, 1, 4, 1, 4, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 4, 5, 40, 8, 5, 11, 5, 12, 5, 41, 1, 5, 4, 5, 45, 8, 5, 11, 5, 12, 5, 46, 1, 5, 5, 5, 50, 8, 5, 10, 5, 12, 5, 53, 9, 5, 1, 6, 1, 6, 1, 7, 1, 7, 1, 7, 1, 7, 1, 8, 1, 8, 1, 8, 1, 8, 1, 8, 1, 8, 1, 9, 1, 9, 1, 9, 1, 9, 1, 9, 1, 9, 1, 10, 1, 10, 1, 10, 5, 10, 76, 8, 10, 10, 10, 12, 10, 79, 9, 10, 0, 0, 11, 1, 1, 3, 2, 5, 3, 7, 4, 9, 5, 11, 6, 13, 0, 15, 7, 17, 8, 19, 9, 21, 10, 1, 0, 4, 4, 0, 45, 57, 65, 90, 95, 95, 97, 122, 2, 0, 10, 10, 32, 32, 2, 0, 65, 90, 97, 122, 3, 0, 48, 57, 65, 90, 97, 122, 82, 0, 1, 1, 0, 0, 0, 0, 3, 1, 0, 0, 0, 0, 5, 1, 0, 0, 0, 0, 7, 1, 0, 0, 0, 0, 9, 1, 0, 0, 0, 0, 11, 1, 0, 0, 0, 0, 15, 1, 0, 0, 0, 0, 17, 1, 0, 0, 0, 0, 19, 1, 0, 0, 0, 0, 21, 1, 0, 0, 0, 1, 23, 1, 0, 0, 0, 3, 25, 1, 0, 0, 0, 5, 27, 1, 0, 0, 0, 7, 29, 1, 0, 0, 0, 9, 31, 1, 0, 0, 0, 11, 33, 1, 0, 0, 0, 13, 54, 1, 0, 0, 0, 15, 56, 1, 0, 0, 0, 17, 60, 1, 0, 0, 0, 19, 66, 1, 0, 0, 0, 21, 72, 1, 0, 0, 0, 23, 24, 5, 91, 0, 0, 24, 2, 1, 0, 0, 0, 25, 26, 5, 93, 0, 0, 26, 4, 1, 0, 0, 0, 27, 28, 5, 61, 0, 0, 28, 6, 1, 0, 0, 0, 29, 30, 5, 36, 0, 0, 30, 8, 1, 0, 0, 0, 31, 32, 9, 0, 0, 0, 32, 10, 1, 0, 0, 0, 33, 34, 5, 58, 0, 0, 34, 35, 5, 117, 0, 0, 35, 36, 5, 115, 0, 0, 36, 37, 5, 101, 0, 0, 37, 39, 1, 0, 0, 0, 38, 40, 3, 13, 6, 0, 39, 38, 1, 0, 0, 0, 40, 41, 1, 0, 0, 0, 41, 39, 1, 0, 0, 0, 41, 42, 1, 0, 0, 0, 42, 44, 1, 0, 0, 0, 43, 45, 7, 0, 0, 0, 44, 43, 1, 0, 0, 0, 45, 46, 1, 0, 0, 0, 46, 44, 1, 0, 0, 0, 46, 47, 1, 0, 0, 0, 47, 51, 1, 0, 0, 0, 48, 50, 3, 13, 6, 0, 49, 48, 1, 0, 0, 0, 50, 53, 1, 0, 0, 0, 51, 49, 1, 0, 0, 0, 51, 52, 1, 0, 0, 0, 52, 12, 1, 0, 0, 0, 53, 51, 1, 0, 0, 0, 54, 55, 7, 1, 0, 0, 55, 14, 1, 0, 0, 0, 56, 57, 5, 58, 0, 0, 57, 58, 5, 105, 0, 0, 58, 59, 5, 102, 0, 0, 59, 16, 1, 0, 0, 0, 60, 61, 5, 58, 0, 0, 61, 62, 5, 116, 0, 0, 62, 63, 5, 104, 0, 0, 63, 64, 5, 101, 0, 0, 64, 65, 5, 110, 0, 0, 65, 18, 1, 0, 0, 0, 66, 67, 5, 58, 0, 0, 67, 68, 5, 101, 0, 0, 68, 69, 5, 108, 0, 0, 69, 70, 5, 115, 0, 0, 70, 71, 5, 101, 0, 0, 71, 20, 1, 0, 0, 0, 72, 73, 5, 58, 0, 0, 73, 77, 7, 2, 0, 0, 74, 76, 7, 3, 0, 0, 75, 74, 1, 0, 0, 0, 76, 79, 1, 0, 0, 0, 77, 75, 1, 0, 0, 0, 77, 78, 1, 0, 0, 0, 78, 22, 1, 0, 0, 0, 79, 77, 1, 0, 0, 0, 5, 0, 41, 46, 51, 77, 0] \ No newline at end of file diff --git a/python/src/parser/MetaPromptLexer.py b/python/src/parser/MetaPromptLexer.py index 0a4340d..6583c67 100644 --- a/python/src/parser/MetaPromptLexer.py +++ b/python/src/parser/MetaPromptLexer.py @@ -10,34 +10,33 @@ def serializedATN(): return [ - 4,0,10,84,6,-1,2,0,7,0,2,1,7,1,2,2,7,2,2,3,7,3,2,4,7,4,2,5,7,5,2, + 4,0,10,80,6,-1,2,0,7,0,2,1,7,1,2,2,7,2,2,3,7,3,2,4,7,4,2,5,7,5,2, 6,7,6,2,7,7,7,2,8,7,8,2,9,7,9,2,10,7,10,1,0,1,0,1,1,1,1,1,2,1,2, - 1,3,1,3,1,4,1,4,1,5,1,5,1,5,1,5,1,5,1,5,1,5,1,5,1,5,1,5,4,5,44,8, - 5,11,5,12,5,45,1,5,4,5,49,8,5,11,5,12,5,50,1,5,5,5,54,8,5,10,5,12, - 5,57,9,5,1,6,1,6,1,7,1,7,1,7,1,7,1,8,1,8,1,8,1,8,1,8,1,8,1,9,1,9, - 1,9,1,9,1,9,1,9,1,10,1,10,1,10,5,10,80,8,10,10,10,12,10,83,9,10, - 0,0,11,1,1,3,2,5,3,7,4,9,5,11,6,13,0,15,7,17,8,19,9,21,10,1,0,4, - 4,0,45,57,65,90,95,95,97,122,2,0,10,10,32,32,2,0,65,90,97,122,3, - 0,48,57,65,90,97,122,86,0,1,1,0,0,0,0,3,1,0,0,0,0,5,1,0,0,0,0,7, - 1,0,0,0,0,9,1,0,0,0,0,11,1,0,0,0,0,15,1,0,0,0,0,17,1,0,0,0,0,19, - 1,0,0,0,0,21,1,0,0,0,1,23,1,0,0,0,3,25,1,0,0,0,5,27,1,0,0,0,7,29, - 1,0,0,0,9,31,1,0,0,0,11,33,1,0,0,0,13,58,1,0,0,0,15,60,1,0,0,0,17, - 64,1,0,0,0,19,70,1,0,0,0,21,76,1,0,0,0,23,24,5,91,0,0,24,2,1,0,0, - 0,25,26,5,93,0,0,26,4,1,0,0,0,27,28,5,61,0,0,28,6,1,0,0,0,29,30, - 5,36,0,0,30,8,1,0,0,0,31,32,9,0,0,0,32,10,1,0,0,0,33,34,5,58,0,0, - 34,35,5,105,0,0,35,36,5,110,0,0,36,37,5,99,0,0,37,38,5,108,0,0,38, - 39,5,117,0,0,39,40,5,100,0,0,40,41,5,101,0,0,41,43,1,0,0,0,42,44, - 3,13,6,0,43,42,1,0,0,0,44,45,1,0,0,0,45,43,1,0,0,0,45,46,1,0,0,0, - 46,48,1,0,0,0,47,49,7,0,0,0,48,47,1,0,0,0,49,50,1,0,0,0,50,48,1, - 0,0,0,50,51,1,0,0,0,51,55,1,0,0,0,52,54,3,13,6,0,53,52,1,0,0,0,54, - 57,1,0,0,0,55,53,1,0,0,0,55,56,1,0,0,0,56,12,1,0,0,0,57,55,1,0,0, - 0,58,59,7,1,0,0,59,14,1,0,0,0,60,61,5,58,0,0,61,62,5,105,0,0,62, - 63,5,102,0,0,63,16,1,0,0,0,64,65,5,58,0,0,65,66,5,116,0,0,66,67, - 5,104,0,0,67,68,5,101,0,0,68,69,5,110,0,0,69,18,1,0,0,0,70,71,5, - 58,0,0,71,72,5,101,0,0,72,73,5,108,0,0,73,74,5,115,0,0,74,75,5,101, - 0,0,75,20,1,0,0,0,76,77,5,58,0,0,77,81,7,2,0,0,78,80,7,3,0,0,79, - 78,1,0,0,0,80,83,1,0,0,0,81,79,1,0,0,0,81,82,1,0,0,0,82,22,1,0,0, - 0,83,81,1,0,0,0,5,0,45,50,55,81,0 + 1,3,1,3,1,4,1,4,1,5,1,5,1,5,1,5,1,5,1,5,4,5,40,8,5,11,5,12,5,41, + 1,5,4,5,45,8,5,11,5,12,5,46,1,5,5,5,50,8,5,10,5,12,5,53,9,5,1,6, + 1,6,1,7,1,7,1,7,1,7,1,8,1,8,1,8,1,8,1,8,1,8,1,9,1,9,1,9,1,9,1,9, + 1,9,1,10,1,10,1,10,5,10,76,8,10,10,10,12,10,79,9,10,0,0,11,1,1,3, + 2,5,3,7,4,9,5,11,6,13,0,15,7,17,8,19,9,21,10,1,0,4,4,0,45,57,65, + 90,95,95,97,122,2,0,10,10,32,32,2,0,65,90,97,122,3,0,48,57,65,90, + 97,122,82,0,1,1,0,0,0,0,3,1,0,0,0,0,5,1,0,0,0,0,7,1,0,0,0,0,9,1, + 0,0,0,0,11,1,0,0,0,0,15,1,0,0,0,0,17,1,0,0,0,0,19,1,0,0,0,0,21,1, + 0,0,0,1,23,1,0,0,0,3,25,1,0,0,0,5,27,1,0,0,0,7,29,1,0,0,0,9,31,1, + 0,0,0,11,33,1,0,0,0,13,54,1,0,0,0,15,56,1,0,0,0,17,60,1,0,0,0,19, + 66,1,0,0,0,21,72,1,0,0,0,23,24,5,91,0,0,24,2,1,0,0,0,25,26,5,93, + 0,0,26,4,1,0,0,0,27,28,5,61,0,0,28,6,1,0,0,0,29,30,5,36,0,0,30,8, + 1,0,0,0,31,32,9,0,0,0,32,10,1,0,0,0,33,34,5,58,0,0,34,35,5,117,0, + 0,35,36,5,115,0,0,36,37,5,101,0,0,37,39,1,0,0,0,38,40,3,13,6,0,39, + 38,1,0,0,0,40,41,1,0,0,0,41,39,1,0,0,0,41,42,1,0,0,0,42,44,1,0,0, + 0,43,45,7,0,0,0,44,43,1,0,0,0,45,46,1,0,0,0,46,44,1,0,0,0,46,47, + 1,0,0,0,47,51,1,0,0,0,48,50,3,13,6,0,49,48,1,0,0,0,50,53,1,0,0,0, + 51,49,1,0,0,0,51,52,1,0,0,0,52,12,1,0,0,0,53,51,1,0,0,0,54,55,7, + 1,0,0,55,14,1,0,0,0,56,57,5,58,0,0,57,58,5,105,0,0,58,59,5,102,0, + 0,59,16,1,0,0,0,60,61,5,58,0,0,61,62,5,116,0,0,62,63,5,104,0,0,63, + 64,5,101,0,0,64,65,5,110,0,0,65,18,1,0,0,0,66,67,5,58,0,0,67,68, + 5,101,0,0,68,69,5,108,0,0,69,70,5,115,0,0,70,71,5,101,0,0,71,20, + 1,0,0,0,72,73,5,58,0,0,73,77,7,2,0,0,74,76,7,3,0,0,75,74,1,0,0,0, + 76,79,1,0,0,0,77,75,1,0,0,0,77,78,1,0,0,0,78,22,1,0,0,0,79,77,1, + 0,0,0,5,0,41,46,51,77,0 ] class MetaPromptLexer(Lexer): @@ -51,7 +50,7 @@ class MetaPromptLexer(Lexer): EQ_KW = 3 META_KW = 4 CHAR = 5 - INCLUDE = 6 + USE = 6 IF_KW = 7 THEN_KW = 8 ELSE_KW = 9 @@ -65,11 +64,11 @@ class MetaPromptLexer(Lexer): "'['", "']'", "'='", "'$'", "':if'", "':then'", "':else'" ] symbolicNames = [ "", - "LB", "RB", "EQ_KW", "META_KW", "CHAR", "INCLUDE", "IF_KW", - "THEN_KW", "ELSE_KW", "VAR_NAME" ] + "LB", "RB", "EQ_KW", "META_KW", "CHAR", "USE", "IF_KW", "THEN_KW", + "ELSE_KW", "VAR_NAME" ] - ruleNames = [ "LB", "RB", "EQ_KW", "META_KW", "CHAR", "INCLUDE", "WS", - "IF_KW", "THEN_KW", "ELSE_KW", "VAR_NAME" ] + ruleNames = [ "LB", "RB", "EQ_KW", "META_KW", "CHAR", "USE", "WS", "IF_KW", + "THEN_KW", "ELSE_KW", "VAR_NAME" ] grammarFileName = "MetaPrompt.g4" diff --git a/python/src/parser/MetaPromptLexer.tokens b/python/src/parser/MetaPromptLexer.tokens index 43da6a2..d76266d 100644 --- a/python/src/parser/MetaPromptLexer.tokens +++ b/python/src/parser/MetaPromptLexer.tokens @@ -3,7 +3,7 @@ RB=2 EQ_KW=3 META_KW=4 CHAR=5 -INCLUDE=6 +USE=6 IF_KW=7 THEN_KW=8 ELSE_KW=9 diff --git a/python/src/parser/MetaPromptParser.py b/python/src/parser/MetaPromptParser.py index c0b52d7..0065851 100644 --- a/python/src/parser/MetaPromptParser.py +++ b/python/src/parser/MetaPromptParser.py @@ -49,7 +49,7 @@ class MetaPromptParser ( Parser ): "", "':if'", "':then'", "':else'" ] symbolicNames = [ "", "LB", "RB", "EQ_KW", "META_KW", "CHAR", - "INCLUDE", "IF_KW", "THEN_KW", "ELSE_KW", "VAR_NAME" ] + "USE", "IF_KW", "THEN_KW", "ELSE_KW", "VAR_NAME" ] RULE_prompt = 0 RULE_exprs = 1 @@ -68,7 +68,7 @@ class MetaPromptParser ( Parser ): EQ_KW=3 META_KW=4 CHAR=5 - INCLUDE=6 + USE=6 IF_KW=7 THEN_KW=8 ELSE_KW=9 @@ -371,8 +371,8 @@ def THEN_KW(self): def ELSE_KW(self): return self.getToken(MetaPromptParser.ELSE_KW, 0) - def INCLUDE(self): - return self.getToken(MetaPromptParser.INCLUDE, 0) + def USE(self): + return self.getToken(MetaPromptParser.USE, 0) def parameters(self): return self.getTypedRuleContext(MetaPromptParser.ParametersContext,0) @@ -447,7 +447,7 @@ def meta_body(self): elif la_ == 3: self.enterOuterAlt(localctx, 3) self.state = 48 - self.match(MetaPromptParser.INCLUDE) + self.match(MetaPromptParser.USE) self.state = 50 self._errHandler.sync(self) _la = self._input.LA(1) diff --git a/python/tests/test_parser.py b/python/tests/test_parser.py index ca5e725..fce354c 100644 --- a/python/tests/test_parser.py +++ b/python/tests/test_parser.py @@ -23,9 +23,9 @@ def meta(exprs): 'exprs': exprs } -def include(module_name, parameters): +def use(module_name, parameters): return { - 'type': 'include', + 'type': 'use', 'module_name': module_name, 'parameters': parameters } @@ -156,22 +156,22 @@ def test_assign_trailing_bracket(): } ] -def test_include_1(): - result = parse_metaprompt("[:include foo]") +def test_use_1(): + result = parse_metaprompt("[:use foo]") assert result["exprs"] == [ { - 'type': 'include', + 'type': 'use', 'module_name': 'foo', 'parameters': {} } ] -def test_include_2(): - result = parse_metaprompt("[:include foo :asd=hey :foo=bar]") +def test_use_2(): + result = parse_metaprompt("[:use foo :asd=hey :foo=bar]") assert result["exprs"] == [ { - 'type': 'include', + 'type': 'use', 'module_name': 'foo', 'parameters': { 'asd': [ { 'type': 'text', 'text': 'hey ' } ], @@ -181,28 +181,28 @@ def test_include_2(): ] -def test_include_3(): - result = parse_metaprompt("[:include\nfoo\n]") +def test_use_3(): + result = parse_metaprompt("[:use\nfoo\n]") assert result["exprs"] == [ { - 'type': 'include', + 'type': 'use', 'module_name': 'foo', 'parameters': {} } ] -def test_include_nested(): +def test_use_nested(): result = parse_metaprompt( - "[:include foo :asd=[:include bar] hiii :foo=bar]" + "[:use foo :asd=[:use bar] hiii :foo=bar]" ) assert result["exprs"] == [ { - 'type': 'include', + 'type': 'use', 'module_name': 'foo', 'parameters': { 'asd': [ - include('bar', {}), + use('bar', {}), { 'type': 'text', 'text': ' hiii ' } ], 'foo': [ { 'type': 'text', 'text': 'bar' } ]