From 04bec7b657570c821fb079a24877fe821c75751f Mon Sep 17 00:00:00 2001 From: Vladimir Kalnitsky Date: Fri, 22 Nov 2024 22:57:27 +0400 Subject: [PATCH] Implement parser for FFI calls --- grammar/MetaPrompt.g4 | 11 +- python/src/parse_metaprompt.py | 21 +- python/src/parser/MetaPrompt.interp | 7 +- python/src/parser/MetaPrompt.tokens | 33 +-- python/src/parser/MetaPromptLexer.interp | 8 +- python/src/parser/MetaPromptLexer.py | 141 +++++----- python/src/parser/MetaPromptLexer.tokens | 33 +-- python/src/parser/MetaPromptListener.py | 9 + python/src/parser/MetaPromptParser.py | 330 ++++++++++++++--------- python/src/parser/MetaPromptVisitor.py | 5 + python/tests/test_parser.py | 28 +- 11 files changed, 391 insertions(+), 235 deletions(-) diff --git a/grammar/MetaPrompt.g4 b/grammar/MetaPrompt.g4 index c71dc01..8330af9 100644 --- a/grammar/MetaPrompt.g4 +++ b/grammar/MetaPrompt.g4 @@ -25,11 +25,12 @@ meta_body : IF_KW exprs THEN_KW exprs ELSE_KW exprs | IF_KW exprs THEN_KW exprs | CHOOSE_KW exprs option+ default_option? - | USE parameters? + | USE parameters | META_PROMPT exprs | COMMENT_KW exprs | VAR_NAME EQ_KW exprs | VAR_NAME + | CALL positional_args parameters ; option @@ -40,8 +41,12 @@ default_option : DEFAULT_KW exprs ; +positional_args + : (WITH_KW exprs)* + ; + parameters - : (VAR_NAME EQ_KW exprs)+ + : (VAR_NAME EQ_KW exprs)* ; text: CHAR+ ; @@ -56,10 +61,12 @@ fragment ESCAPED : ESCAPE ESCAPEE; fragment ESCAPEE : (LB | ESCAPE); fragment ESCAPE : '\\'; USE : ':use' WS+ [a-zA-Z0-9/_.-]+ WS*; +CALL : '@' [a-zA-Z_][a-zA-Z0-9_]* WS*; fragment WS : ' '|'\n'; IF_KW : ':if' ; CHOOSE_KW : ':choose' ; OPTION_KW : ':option' ; +WITH_KW : ':with' ; DEFAULT_KW : ':default' ; IS_KW : ':is' ; THEN_KW : ':then' ; diff --git a/python/src/parse_metaprompt.py b/python/src/parse_metaprompt.py index c25b1c6..6ffef45 100644 --- a/python/src/parse_metaprompt.py +++ b/python/src/parse_metaprompt.py @@ -100,6 +100,11 @@ def visitParameters(self, ctx: MetaPromptParser.ParametersContext): parameters[name.getText()[1:]] = self.visit(exprs) return parameters + def visitPositional_args( + self, ctx: MetaPromptParser.Positional_argsContext + ): + return [self.visit(expr) for expr in ctx.exprs()] + def visitOption(self, ctx: MetaPromptParser.OptionContext): exprs = ctx.exprs() option = self.visit(exprs[0]) @@ -155,15 +160,25 @@ def visitMeta_body(self, ctx: MetaPromptParser.Meta_bodyContext): 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()) + parameters = self.visit(ctx.parameters()) return { "type": "use", "module_name": module_name, "parameters": parameters, } + elif ctx.CALL() is not None: + function_name = ctx.CALL().getText().removeprefix("@").strip() + parameters = self.visit(ctx.parameters()) + positional_args = self.visit(ctx.positional_args()) + + return { + "type": "call", + "name": function_name, + "named_args": parameters, + "positional_args": positional_args, + } + elif ctx.VAR_NAME() is not None: # slice the ":" var_name = ctx.VAR_NAME().getText()[1:] diff --git a/python/src/parser/MetaPrompt.interp b/python/src/parser/MetaPrompt.interp index 8cbba96..6551799 100644 --- a/python/src/parser/MetaPrompt.interp +++ b/python/src/parser/MetaPrompt.interp @@ -7,9 +7,11 @@ null '#' null null +null ':if' ':choose' ':option' +':with' ':default' ':is' ':then' @@ -25,9 +27,11 @@ META_PROMPT COMMENT_KW CHAR USE +CALL IF_KW CHOOSE_KW OPTION_KW +WITH_KW DEFAULT_KW IS_KW THEN_KW @@ -42,9 +46,10 @@ expr1 meta_body option default_option +positional_args parameters text atn: -[4, 1, 15, 105, 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, 1, 0, 1, 0, 1, 0, 1, 1, 5, 1, 23, 8, 1, 10, 1, 12, 1, 26, 9, 1, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 3, 2, 43, 8, 2, 1, 3, 1, 3, 3, 3, 47, 8, 3, 1, 4, 1, 4, 1, 4, 1, 4, 1, 4, 1, 4, 1, 4, 1, 4, 1, 4, 1, 4, 1, 4, 1, 4, 1, 4, 1, 4, 1, 4, 4, 4, 64, 8, 4, 11, 4, 12, 4, 65, 1, 4, 3, 4, 69, 8, 4, 1, 4, 1, 4, 3, 4, 73, 8, 4, 1, 4, 1, 4, 1, 4, 1, 4, 1, 4, 1, 4, 1, 4, 1, 4, 3, 4, 83, 8, 4, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 6, 1, 6, 1, 6, 1, 7, 1, 7, 1, 7, 4, 7, 96, 8, 7, 11, 7, 12, 7, 97, 1, 8, 4, 8, 101, 8, 8, 11, 8, 12, 8, 102, 1, 8, 1, 24, 0, 9, 0, 2, 4, 6, 8, 10, 12, 14, 16, 0, 0, 120, 0, 18, 1, 0, 0, 0, 2, 24, 1, 0, 0, 0, 4, 42, 1, 0, 0, 0, 6, 46, 1, 0, 0, 0, 8, 82, 1, 0, 0, 0, 10, 84, 1, 0, 0, 0, 12, 89, 1, 0, 0, 0, 14, 95, 1, 0, 0, 0, 16, 100, 1, 0, 0, 0, 18, 19, 3, 2, 1, 0, 19, 20, 5, 0, 0, 1, 20, 1, 1, 0, 0, 0, 21, 23, 3, 4, 2, 0, 22, 21, 1, 0, 0, 0, 23, 26, 1, 0, 0, 0, 24, 25, 1, 0, 0, 0, 24, 22, 1, 0, 0, 0, 25, 3, 1, 0, 0, 0, 26, 24, 1, 0, 0, 0, 27, 28, 5, 1, 0, 0, 28, 29, 3, 6, 3, 0, 29, 30, 5, 2, 0, 0, 30, 43, 1, 0, 0, 0, 31, 43, 3, 16, 8, 0, 32, 43, 5, 2, 0, 0, 33, 43, 5, 1, 0, 0, 34, 43, 5, 5, 0, 0, 35, 43, 5, 4, 0, 0, 36, 43, 5, 3, 0, 0, 37, 43, 5, 15, 0, 0, 38, 43, 5, 9, 0, 0, 39, 43, 5, 10, 0, 0, 40, 43, 5, 11, 0, 0, 41, 43, 5, 12, 0, 0, 42, 27, 1, 0, 0, 0, 42, 31, 1, 0, 0, 0, 42, 32, 1, 0, 0, 0, 42, 33, 1, 0, 0, 0, 42, 34, 1, 0, 0, 0, 42, 35, 1, 0, 0, 0, 42, 36, 1, 0, 0, 0, 42, 37, 1, 0, 0, 0, 42, 38, 1, 0, 0, 0, 42, 39, 1, 0, 0, 0, 42, 40, 1, 0, 0, 0, 42, 41, 1, 0, 0, 0, 43, 5, 1, 0, 0, 0, 44, 47, 3, 8, 4, 0, 45, 47, 3, 2, 1, 0, 46, 44, 1, 0, 0, 0, 46, 45, 1, 0, 0, 0, 47, 7, 1, 0, 0, 0, 48, 49, 5, 8, 0, 0, 49, 50, 3, 2, 1, 0, 50, 51, 5, 13, 0, 0, 51, 52, 3, 2, 1, 0, 52, 53, 5, 14, 0, 0, 53, 54, 3, 2, 1, 0, 54, 83, 1, 0, 0, 0, 55, 56, 5, 8, 0, 0, 56, 57, 3, 2, 1, 0, 57, 58, 5, 13, 0, 0, 58, 59, 3, 2, 1, 0, 59, 83, 1, 0, 0, 0, 60, 61, 5, 9, 0, 0, 61, 63, 3, 2, 1, 0, 62, 64, 3, 10, 5, 0, 63, 62, 1, 0, 0, 0, 64, 65, 1, 0, 0, 0, 65, 63, 1, 0, 0, 0, 65, 66, 1, 0, 0, 0, 66, 68, 1, 0, 0, 0, 67, 69, 3, 12, 6, 0, 68, 67, 1, 0, 0, 0, 68, 69, 1, 0, 0, 0, 69, 83, 1, 0, 0, 0, 70, 72, 5, 7, 0, 0, 71, 73, 3, 14, 7, 0, 72, 71, 1, 0, 0, 0, 72, 73, 1, 0, 0, 0, 73, 83, 1, 0, 0, 0, 74, 75, 5, 4, 0, 0, 75, 83, 3, 2, 1, 0, 76, 77, 5, 5, 0, 0, 77, 83, 3, 2, 1, 0, 78, 79, 5, 15, 0, 0, 79, 80, 5, 3, 0, 0, 80, 83, 3, 2, 1, 0, 81, 83, 5, 15, 0, 0, 82, 48, 1, 0, 0, 0, 82, 55, 1, 0, 0, 0, 82, 60, 1, 0, 0, 0, 82, 70, 1, 0, 0, 0, 82, 74, 1, 0, 0, 0, 82, 76, 1, 0, 0, 0, 82, 78, 1, 0, 0, 0, 82, 81, 1, 0, 0, 0, 83, 9, 1, 0, 0, 0, 84, 85, 5, 10, 0, 0, 85, 86, 3, 2, 1, 0, 86, 87, 5, 12, 0, 0, 87, 88, 3, 2, 1, 0, 88, 11, 1, 0, 0, 0, 89, 90, 5, 11, 0, 0, 90, 91, 3, 2, 1, 0, 91, 13, 1, 0, 0, 0, 92, 93, 5, 15, 0, 0, 93, 94, 5, 3, 0, 0, 94, 96, 3, 2, 1, 0, 95, 92, 1, 0, 0, 0, 96, 97, 1, 0, 0, 0, 97, 95, 1, 0, 0, 0, 97, 98, 1, 0, 0, 0, 98, 15, 1, 0, 0, 0, 99, 101, 5, 6, 0, 0, 100, 99, 1, 0, 0, 0, 101, 102, 1, 0, 0, 0, 102, 100, 1, 0, 0, 0, 102, 103, 1, 0, 0, 0, 103, 17, 1, 0, 0, 0, 9, 24, 42, 46, 65, 68, 72, 82, 97, 102] \ No newline at end of file +[4, 1, 17, 117, 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, 1, 0, 1, 0, 1, 0, 1, 1, 5, 1, 25, 8, 1, 10, 1, 12, 1, 28, 9, 1, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 3, 2, 45, 8, 2, 1, 3, 1, 3, 3, 3, 49, 8, 3, 1, 4, 1, 4, 1, 4, 1, 4, 1, 4, 1, 4, 1, 4, 1, 4, 1, 4, 1, 4, 1, 4, 1, 4, 1, 4, 1, 4, 1, 4, 4, 4, 66, 8, 4, 11, 4, 12, 4, 67, 1, 4, 3, 4, 71, 8, 4, 1, 4, 1, 4, 1, 4, 1, 4, 1, 4, 1, 4, 1, 4, 1, 4, 1, 4, 1, 4, 1, 4, 1, 4, 1, 4, 1, 4, 3, 4, 87, 8, 4, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 6, 1, 6, 1, 6, 1, 7, 1, 7, 5, 7, 99, 8, 7, 10, 7, 12, 7, 102, 9, 7, 1, 8, 1, 8, 1, 8, 5, 8, 107, 8, 8, 10, 8, 12, 8, 110, 9, 8, 1, 9, 4, 9, 113, 8, 9, 11, 9, 12, 9, 114, 1, 9, 1, 26, 0, 10, 0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 0, 0, 132, 0, 20, 1, 0, 0, 0, 2, 26, 1, 0, 0, 0, 4, 44, 1, 0, 0, 0, 6, 48, 1, 0, 0, 0, 8, 86, 1, 0, 0, 0, 10, 88, 1, 0, 0, 0, 12, 93, 1, 0, 0, 0, 14, 100, 1, 0, 0, 0, 16, 108, 1, 0, 0, 0, 18, 112, 1, 0, 0, 0, 20, 21, 3, 2, 1, 0, 21, 22, 5, 0, 0, 1, 22, 1, 1, 0, 0, 0, 23, 25, 3, 4, 2, 0, 24, 23, 1, 0, 0, 0, 25, 28, 1, 0, 0, 0, 26, 27, 1, 0, 0, 0, 26, 24, 1, 0, 0, 0, 27, 3, 1, 0, 0, 0, 28, 26, 1, 0, 0, 0, 29, 30, 5, 1, 0, 0, 30, 31, 3, 6, 3, 0, 31, 32, 5, 2, 0, 0, 32, 45, 1, 0, 0, 0, 33, 45, 3, 18, 9, 0, 34, 45, 5, 2, 0, 0, 35, 45, 5, 1, 0, 0, 36, 45, 5, 5, 0, 0, 37, 45, 5, 4, 0, 0, 38, 45, 5, 3, 0, 0, 39, 45, 5, 17, 0, 0, 40, 45, 5, 10, 0, 0, 41, 45, 5, 11, 0, 0, 42, 45, 5, 13, 0, 0, 43, 45, 5, 14, 0, 0, 44, 29, 1, 0, 0, 0, 44, 33, 1, 0, 0, 0, 44, 34, 1, 0, 0, 0, 44, 35, 1, 0, 0, 0, 44, 36, 1, 0, 0, 0, 44, 37, 1, 0, 0, 0, 44, 38, 1, 0, 0, 0, 44, 39, 1, 0, 0, 0, 44, 40, 1, 0, 0, 0, 44, 41, 1, 0, 0, 0, 44, 42, 1, 0, 0, 0, 44, 43, 1, 0, 0, 0, 45, 5, 1, 0, 0, 0, 46, 49, 3, 8, 4, 0, 47, 49, 3, 2, 1, 0, 48, 46, 1, 0, 0, 0, 48, 47, 1, 0, 0, 0, 49, 7, 1, 0, 0, 0, 50, 51, 5, 9, 0, 0, 51, 52, 3, 2, 1, 0, 52, 53, 5, 15, 0, 0, 53, 54, 3, 2, 1, 0, 54, 55, 5, 16, 0, 0, 55, 56, 3, 2, 1, 0, 56, 87, 1, 0, 0, 0, 57, 58, 5, 9, 0, 0, 58, 59, 3, 2, 1, 0, 59, 60, 5, 15, 0, 0, 60, 61, 3, 2, 1, 0, 61, 87, 1, 0, 0, 0, 62, 63, 5, 10, 0, 0, 63, 65, 3, 2, 1, 0, 64, 66, 3, 10, 5, 0, 65, 64, 1, 0, 0, 0, 66, 67, 1, 0, 0, 0, 67, 65, 1, 0, 0, 0, 67, 68, 1, 0, 0, 0, 68, 70, 1, 0, 0, 0, 69, 71, 3, 12, 6, 0, 70, 69, 1, 0, 0, 0, 70, 71, 1, 0, 0, 0, 71, 87, 1, 0, 0, 0, 72, 73, 5, 7, 0, 0, 73, 87, 3, 16, 8, 0, 74, 75, 5, 4, 0, 0, 75, 87, 3, 2, 1, 0, 76, 77, 5, 5, 0, 0, 77, 87, 3, 2, 1, 0, 78, 79, 5, 17, 0, 0, 79, 80, 5, 3, 0, 0, 80, 87, 3, 2, 1, 0, 81, 87, 5, 17, 0, 0, 82, 83, 5, 8, 0, 0, 83, 84, 3, 14, 7, 0, 84, 85, 3, 16, 8, 0, 85, 87, 1, 0, 0, 0, 86, 50, 1, 0, 0, 0, 86, 57, 1, 0, 0, 0, 86, 62, 1, 0, 0, 0, 86, 72, 1, 0, 0, 0, 86, 74, 1, 0, 0, 0, 86, 76, 1, 0, 0, 0, 86, 78, 1, 0, 0, 0, 86, 81, 1, 0, 0, 0, 86, 82, 1, 0, 0, 0, 87, 9, 1, 0, 0, 0, 88, 89, 5, 11, 0, 0, 89, 90, 3, 2, 1, 0, 90, 91, 5, 14, 0, 0, 91, 92, 3, 2, 1, 0, 92, 11, 1, 0, 0, 0, 93, 94, 5, 13, 0, 0, 94, 95, 3, 2, 1, 0, 95, 13, 1, 0, 0, 0, 96, 97, 5, 12, 0, 0, 97, 99, 3, 2, 1, 0, 98, 96, 1, 0, 0, 0, 99, 102, 1, 0, 0, 0, 100, 98, 1, 0, 0, 0, 100, 101, 1, 0, 0, 0, 101, 15, 1, 0, 0, 0, 102, 100, 1, 0, 0, 0, 103, 104, 5, 17, 0, 0, 104, 105, 5, 3, 0, 0, 105, 107, 3, 2, 1, 0, 106, 103, 1, 0, 0, 0, 107, 110, 1, 0, 0, 0, 108, 106, 1, 0, 0, 0, 108, 109, 1, 0, 0, 0, 109, 17, 1, 0, 0, 0, 110, 108, 1, 0, 0, 0, 111, 113, 5, 6, 0, 0, 112, 111, 1, 0, 0, 0, 113, 114, 1, 0, 0, 0, 114, 112, 1, 0, 0, 0, 114, 115, 1, 0, 0, 0, 115, 19, 1, 0, 0, 0, 9, 26, 44, 48, 67, 70, 86, 100, 108, 114] \ No newline at end of file diff --git a/python/src/parser/MetaPrompt.tokens b/python/src/parser/MetaPrompt.tokens index 472b663..b26b970 100644 --- a/python/src/parser/MetaPrompt.tokens +++ b/python/src/parser/MetaPrompt.tokens @@ -5,21 +5,24 @@ META_PROMPT=4 COMMENT_KW=5 CHAR=6 USE=7 -IF_KW=8 -CHOOSE_KW=9 -OPTION_KW=10 -DEFAULT_KW=11 -IS_KW=12 -THEN_KW=13 -ELSE_KW=14 -VAR_NAME=15 +CALL=8 +IF_KW=9 +CHOOSE_KW=10 +OPTION_KW=11 +WITH_KW=12 +DEFAULT_KW=13 +IS_KW=14 +THEN_KW=15 +ELSE_KW=16 +VAR_NAME=17 '['=1 ']'=2 '#'=5 -':if'=8 -':choose'=9 -':option'=10 -':default'=11 -':is'=12 -':then'=13 -':else'=14 +':if'=9 +':choose'=10 +':option'=11 +':with'=12 +':default'=13 +':is'=14 +':then'=15 +':else'=16 diff --git a/python/src/parser/MetaPromptLexer.interp b/python/src/parser/MetaPromptLexer.interp index 8ed8f42..913d094 100644 --- a/python/src/parser/MetaPromptLexer.interp +++ b/python/src/parser/MetaPromptLexer.interp @@ -7,9 +7,11 @@ null '#' null null +null ':if' ':choose' ':option' +':with' ':default' ':is' ':then' @@ -25,9 +27,11 @@ META_PROMPT COMMENT_KW CHAR USE +CALL IF_KW CHOOSE_KW OPTION_KW +WITH_KW DEFAULT_KW IS_KW THEN_KW @@ -45,10 +49,12 @@ ESCAPED ESCAPEE ESCAPE USE +CALL WS IF_KW CHOOSE_KW OPTION_KW +WITH_KW DEFAULT_KW IS_KW THEN_KW @@ -63,4 +69,4 @@ mode names: DEFAULT_MODE atn: -[4, 0, 15, 150, 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, 2, 11, 7, 11, 2, 12, 7, 12, 2, 13, 7, 13, 2, 14, 7, 14, 2, 15, 7, 15, 2, 16, 7, 16, 2, 17, 7, 17, 2, 18, 7, 18, 1, 0, 1, 0, 1, 1, 1, 1, 1, 2, 1, 2, 1, 2, 3, 2, 47, 8, 2, 1, 3, 3, 3, 50, 8, 3, 1, 3, 5, 3, 53, 8, 3, 10, 3, 12, 3, 56, 9, 3, 1, 3, 1, 3, 1, 4, 1, 4, 1, 5, 1, 5, 3, 5, 64, 8, 5, 1, 6, 1, 6, 1, 6, 1, 7, 1, 7, 3, 7, 71, 8, 7, 1, 8, 1, 8, 1, 9, 1, 9, 1, 9, 1, 9, 1, 9, 1, 9, 4, 9, 81, 8, 9, 11, 9, 12, 9, 82, 1, 9, 4, 9, 86, 8, 9, 11, 9, 12, 9, 87, 1, 9, 5, 9, 91, 8, 9, 10, 9, 12, 9, 94, 9, 9, 1, 10, 1, 10, 1, 11, 1, 11, 1, 11, 1, 11, 1, 12, 1, 12, 1, 12, 1, 12, 1, 12, 1, 12, 1, 12, 1, 12, 1, 13, 1, 13, 1, 13, 1, 13, 1, 13, 1, 13, 1, 13, 1, 13, 1, 14, 1, 14, 1, 14, 1, 14, 1, 14, 1, 14, 1, 14, 1, 14, 1, 14, 1, 15, 1, 15, 1, 15, 1, 15, 1, 16, 1, 16, 1, 16, 1, 16, 1, 16, 1, 16, 1, 17, 1, 17, 1, 17, 1, 17, 1, 17, 1, 17, 1, 18, 1, 18, 1, 18, 5, 18, 146, 8, 18, 10, 18, 12, 18, 149, 9, 18, 0, 0, 19, 1, 1, 3, 2, 5, 3, 7, 4, 9, 5, 11, 6, 13, 0, 15, 0, 17, 0, 19, 7, 21, 0, 23, 8, 25, 9, 27, 10, 29, 11, 31, 12, 33, 13, 35, 14, 37, 15, 1, 0, 4, 3, 0, 65, 90, 95, 95, 97, 122, 4, 0, 48, 57, 65, 90, 95, 95, 97, 122, 4, 0, 45, 57, 65, 90, 95, 95, 97, 122, 2, 0, 10, 10, 32, 32, 154, 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, 19, 1, 0, 0, 0, 0, 23, 1, 0, 0, 0, 0, 25, 1, 0, 0, 0, 0, 27, 1, 0, 0, 0, 0, 29, 1, 0, 0, 0, 0, 31, 1, 0, 0, 0, 0, 33, 1, 0, 0, 0, 0, 35, 1, 0, 0, 0, 0, 37, 1, 0, 0, 0, 1, 39, 1, 0, 0, 0, 3, 41, 1, 0, 0, 0, 5, 46, 1, 0, 0, 0, 7, 49, 1, 0, 0, 0, 9, 59, 1, 0, 0, 0, 11, 63, 1, 0, 0, 0, 13, 65, 1, 0, 0, 0, 15, 70, 1, 0, 0, 0, 17, 72, 1, 0, 0, 0, 19, 74, 1, 0, 0, 0, 21, 95, 1, 0, 0, 0, 23, 97, 1, 0, 0, 0, 25, 101, 1, 0, 0, 0, 27, 109, 1, 0, 0, 0, 29, 117, 1, 0, 0, 0, 31, 126, 1, 0, 0, 0, 33, 130, 1, 0, 0, 0, 35, 136, 1, 0, 0, 0, 37, 142, 1, 0, 0, 0, 39, 40, 5, 91, 0, 0, 40, 2, 1, 0, 0, 0, 41, 42, 5, 93, 0, 0, 42, 4, 1, 0, 0, 0, 43, 47, 5, 61, 0, 0, 44, 45, 5, 63, 0, 0, 45, 47, 5, 61, 0, 0, 46, 43, 1, 0, 0, 0, 46, 44, 1, 0, 0, 0, 47, 6, 1, 0, 0, 0, 48, 50, 7, 0, 0, 0, 49, 48, 1, 0, 0, 0, 49, 50, 1, 0, 0, 0, 50, 54, 1, 0, 0, 0, 51, 53, 7, 1, 0, 0, 52, 51, 1, 0, 0, 0, 53, 56, 1, 0, 0, 0, 54, 52, 1, 0, 0, 0, 54, 55, 1, 0, 0, 0, 55, 57, 1, 0, 0, 0, 56, 54, 1, 0, 0, 0, 57, 58, 5, 36, 0, 0, 58, 8, 1, 0, 0, 0, 59, 60, 5, 35, 0, 0, 60, 10, 1, 0, 0, 0, 61, 64, 3, 13, 6, 0, 62, 64, 9, 0, 0, 0, 63, 61, 1, 0, 0, 0, 63, 62, 1, 0, 0, 0, 64, 12, 1, 0, 0, 0, 65, 66, 3, 17, 8, 0, 66, 67, 3, 15, 7, 0, 67, 14, 1, 0, 0, 0, 68, 71, 3, 1, 0, 0, 69, 71, 3, 17, 8, 0, 70, 68, 1, 0, 0, 0, 70, 69, 1, 0, 0, 0, 71, 16, 1, 0, 0, 0, 72, 73, 5, 92, 0, 0, 73, 18, 1, 0, 0, 0, 74, 75, 5, 58, 0, 0, 75, 76, 5, 117, 0, 0, 76, 77, 5, 115, 0, 0, 77, 78, 5, 101, 0, 0, 78, 80, 1, 0, 0, 0, 79, 81, 3, 21, 10, 0, 80, 79, 1, 0, 0, 0, 81, 82, 1, 0, 0, 0, 82, 80, 1, 0, 0, 0, 82, 83, 1, 0, 0, 0, 83, 85, 1, 0, 0, 0, 84, 86, 7, 2, 0, 0, 85, 84, 1, 0, 0, 0, 86, 87, 1, 0, 0, 0, 87, 85, 1, 0, 0, 0, 87, 88, 1, 0, 0, 0, 88, 92, 1, 0, 0, 0, 89, 91, 3, 21, 10, 0, 90, 89, 1, 0, 0, 0, 91, 94, 1, 0, 0, 0, 92, 90, 1, 0, 0, 0, 92, 93, 1, 0, 0, 0, 93, 20, 1, 0, 0, 0, 94, 92, 1, 0, 0, 0, 95, 96, 7, 3, 0, 0, 96, 22, 1, 0, 0, 0, 97, 98, 5, 58, 0, 0, 98, 99, 5, 105, 0, 0, 99, 100, 5, 102, 0, 0, 100, 24, 1, 0, 0, 0, 101, 102, 5, 58, 0, 0, 102, 103, 5, 99, 0, 0, 103, 104, 5, 104, 0, 0, 104, 105, 5, 111, 0, 0, 105, 106, 5, 111, 0, 0, 106, 107, 5, 115, 0, 0, 107, 108, 5, 101, 0, 0, 108, 26, 1, 0, 0, 0, 109, 110, 5, 58, 0, 0, 110, 111, 5, 111, 0, 0, 111, 112, 5, 112, 0, 0, 112, 113, 5, 116, 0, 0, 113, 114, 5, 105, 0, 0, 114, 115, 5, 111, 0, 0, 115, 116, 5, 110, 0, 0, 116, 28, 1, 0, 0, 0, 117, 118, 5, 58, 0, 0, 118, 119, 5, 100, 0, 0, 119, 120, 5, 101, 0, 0, 120, 121, 5, 102, 0, 0, 121, 122, 5, 97, 0, 0, 122, 123, 5, 117, 0, 0, 123, 124, 5, 108, 0, 0, 124, 125, 5, 116, 0, 0, 125, 30, 1, 0, 0, 0, 126, 127, 5, 58, 0, 0, 127, 128, 5, 105, 0, 0, 128, 129, 5, 115, 0, 0, 129, 32, 1, 0, 0, 0, 130, 131, 5, 58, 0, 0, 131, 132, 5, 116, 0, 0, 132, 133, 5, 104, 0, 0, 133, 134, 5, 101, 0, 0, 134, 135, 5, 110, 0, 0, 135, 34, 1, 0, 0, 0, 136, 137, 5, 58, 0, 0, 137, 138, 5, 101, 0, 0, 138, 139, 5, 108, 0, 0, 139, 140, 5, 115, 0, 0, 140, 141, 5, 101, 0, 0, 141, 36, 1, 0, 0, 0, 142, 143, 5, 58, 0, 0, 143, 147, 7, 0, 0, 0, 144, 146, 7, 1, 0, 0, 145, 144, 1, 0, 0, 0, 146, 149, 1, 0, 0, 0, 147, 145, 1, 0, 0, 0, 147, 148, 1, 0, 0, 0, 148, 38, 1, 0, 0, 0, 149, 147, 1, 0, 0, 0, 10, 0, 46, 49, 54, 63, 70, 82, 87, 92, 147, 0] \ No newline at end of file +[4, 0, 17, 174, 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, 2, 11, 7, 11, 2, 12, 7, 12, 2, 13, 7, 13, 2, 14, 7, 14, 2, 15, 7, 15, 2, 16, 7, 16, 2, 17, 7, 17, 2, 18, 7, 18, 2, 19, 7, 19, 2, 20, 7, 20, 1, 0, 1, 0, 1, 1, 1, 1, 1, 2, 1, 2, 1, 2, 3, 2, 51, 8, 2, 1, 3, 3, 3, 54, 8, 3, 1, 3, 5, 3, 57, 8, 3, 10, 3, 12, 3, 60, 9, 3, 1, 3, 1, 3, 1, 4, 1, 4, 1, 5, 1, 5, 3, 5, 68, 8, 5, 1, 6, 1, 6, 1, 6, 1, 7, 1, 7, 3, 7, 75, 8, 7, 1, 8, 1, 8, 1, 9, 1, 9, 1, 9, 1, 9, 1, 9, 1, 9, 4, 9, 85, 8, 9, 11, 9, 12, 9, 86, 1, 9, 4, 9, 90, 8, 9, 11, 9, 12, 9, 91, 1, 9, 5, 9, 95, 8, 9, 10, 9, 12, 9, 98, 9, 9, 1, 10, 1, 10, 1, 10, 5, 10, 103, 8, 10, 10, 10, 12, 10, 106, 9, 10, 1, 10, 5, 10, 109, 8, 10, 10, 10, 12, 10, 112, 9, 10, 1, 11, 1, 11, 1, 12, 1, 12, 1, 12, 1, 12, 1, 13, 1, 13, 1, 13, 1, 13, 1, 13, 1, 13, 1, 13, 1, 13, 1, 14, 1, 14, 1, 14, 1, 14, 1, 14, 1, 14, 1, 14, 1, 14, 1, 15, 1, 15, 1, 15, 1, 15, 1, 15, 1, 15, 1, 16, 1, 16, 1, 16, 1, 16, 1, 16, 1, 16, 1, 16, 1, 16, 1, 16, 1, 17, 1, 17, 1, 17, 1, 17, 1, 18, 1, 18, 1, 18, 1, 18, 1, 18, 1, 18, 1, 19, 1, 19, 1, 19, 1, 19, 1, 19, 1, 19, 1, 20, 1, 20, 1, 20, 5, 20, 170, 8, 20, 10, 20, 12, 20, 173, 9, 20, 0, 0, 21, 1, 1, 3, 2, 5, 3, 7, 4, 9, 5, 11, 6, 13, 0, 15, 0, 17, 0, 19, 7, 21, 8, 23, 0, 25, 9, 27, 10, 29, 11, 31, 12, 33, 13, 35, 14, 37, 15, 39, 16, 41, 17, 1, 0, 4, 3, 0, 65, 90, 95, 95, 97, 122, 4, 0, 48, 57, 65, 90, 95, 95, 97, 122, 4, 0, 45, 57, 65, 90, 95, 95, 97, 122, 2, 0, 10, 10, 32, 32, 180, 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, 19, 1, 0, 0, 0, 0, 21, 1, 0, 0, 0, 0, 25, 1, 0, 0, 0, 0, 27, 1, 0, 0, 0, 0, 29, 1, 0, 0, 0, 0, 31, 1, 0, 0, 0, 0, 33, 1, 0, 0, 0, 0, 35, 1, 0, 0, 0, 0, 37, 1, 0, 0, 0, 0, 39, 1, 0, 0, 0, 0, 41, 1, 0, 0, 0, 1, 43, 1, 0, 0, 0, 3, 45, 1, 0, 0, 0, 5, 50, 1, 0, 0, 0, 7, 53, 1, 0, 0, 0, 9, 63, 1, 0, 0, 0, 11, 67, 1, 0, 0, 0, 13, 69, 1, 0, 0, 0, 15, 74, 1, 0, 0, 0, 17, 76, 1, 0, 0, 0, 19, 78, 1, 0, 0, 0, 21, 99, 1, 0, 0, 0, 23, 113, 1, 0, 0, 0, 25, 115, 1, 0, 0, 0, 27, 119, 1, 0, 0, 0, 29, 127, 1, 0, 0, 0, 31, 135, 1, 0, 0, 0, 33, 141, 1, 0, 0, 0, 35, 150, 1, 0, 0, 0, 37, 154, 1, 0, 0, 0, 39, 160, 1, 0, 0, 0, 41, 166, 1, 0, 0, 0, 43, 44, 5, 91, 0, 0, 44, 2, 1, 0, 0, 0, 45, 46, 5, 93, 0, 0, 46, 4, 1, 0, 0, 0, 47, 51, 5, 61, 0, 0, 48, 49, 5, 63, 0, 0, 49, 51, 5, 61, 0, 0, 50, 47, 1, 0, 0, 0, 50, 48, 1, 0, 0, 0, 51, 6, 1, 0, 0, 0, 52, 54, 7, 0, 0, 0, 53, 52, 1, 0, 0, 0, 53, 54, 1, 0, 0, 0, 54, 58, 1, 0, 0, 0, 55, 57, 7, 1, 0, 0, 56, 55, 1, 0, 0, 0, 57, 60, 1, 0, 0, 0, 58, 56, 1, 0, 0, 0, 58, 59, 1, 0, 0, 0, 59, 61, 1, 0, 0, 0, 60, 58, 1, 0, 0, 0, 61, 62, 5, 36, 0, 0, 62, 8, 1, 0, 0, 0, 63, 64, 5, 35, 0, 0, 64, 10, 1, 0, 0, 0, 65, 68, 3, 13, 6, 0, 66, 68, 9, 0, 0, 0, 67, 65, 1, 0, 0, 0, 67, 66, 1, 0, 0, 0, 68, 12, 1, 0, 0, 0, 69, 70, 3, 17, 8, 0, 70, 71, 3, 15, 7, 0, 71, 14, 1, 0, 0, 0, 72, 75, 3, 1, 0, 0, 73, 75, 3, 17, 8, 0, 74, 72, 1, 0, 0, 0, 74, 73, 1, 0, 0, 0, 75, 16, 1, 0, 0, 0, 76, 77, 5, 92, 0, 0, 77, 18, 1, 0, 0, 0, 78, 79, 5, 58, 0, 0, 79, 80, 5, 117, 0, 0, 80, 81, 5, 115, 0, 0, 81, 82, 5, 101, 0, 0, 82, 84, 1, 0, 0, 0, 83, 85, 3, 23, 11, 0, 84, 83, 1, 0, 0, 0, 85, 86, 1, 0, 0, 0, 86, 84, 1, 0, 0, 0, 86, 87, 1, 0, 0, 0, 87, 89, 1, 0, 0, 0, 88, 90, 7, 2, 0, 0, 89, 88, 1, 0, 0, 0, 90, 91, 1, 0, 0, 0, 91, 89, 1, 0, 0, 0, 91, 92, 1, 0, 0, 0, 92, 96, 1, 0, 0, 0, 93, 95, 3, 23, 11, 0, 94, 93, 1, 0, 0, 0, 95, 98, 1, 0, 0, 0, 96, 94, 1, 0, 0, 0, 96, 97, 1, 0, 0, 0, 97, 20, 1, 0, 0, 0, 98, 96, 1, 0, 0, 0, 99, 100, 5, 64, 0, 0, 100, 104, 7, 0, 0, 0, 101, 103, 7, 1, 0, 0, 102, 101, 1, 0, 0, 0, 103, 106, 1, 0, 0, 0, 104, 102, 1, 0, 0, 0, 104, 105, 1, 0, 0, 0, 105, 110, 1, 0, 0, 0, 106, 104, 1, 0, 0, 0, 107, 109, 3, 23, 11, 0, 108, 107, 1, 0, 0, 0, 109, 112, 1, 0, 0, 0, 110, 108, 1, 0, 0, 0, 110, 111, 1, 0, 0, 0, 111, 22, 1, 0, 0, 0, 112, 110, 1, 0, 0, 0, 113, 114, 7, 3, 0, 0, 114, 24, 1, 0, 0, 0, 115, 116, 5, 58, 0, 0, 116, 117, 5, 105, 0, 0, 117, 118, 5, 102, 0, 0, 118, 26, 1, 0, 0, 0, 119, 120, 5, 58, 0, 0, 120, 121, 5, 99, 0, 0, 121, 122, 5, 104, 0, 0, 122, 123, 5, 111, 0, 0, 123, 124, 5, 111, 0, 0, 124, 125, 5, 115, 0, 0, 125, 126, 5, 101, 0, 0, 126, 28, 1, 0, 0, 0, 127, 128, 5, 58, 0, 0, 128, 129, 5, 111, 0, 0, 129, 130, 5, 112, 0, 0, 130, 131, 5, 116, 0, 0, 131, 132, 5, 105, 0, 0, 132, 133, 5, 111, 0, 0, 133, 134, 5, 110, 0, 0, 134, 30, 1, 0, 0, 0, 135, 136, 5, 58, 0, 0, 136, 137, 5, 119, 0, 0, 137, 138, 5, 105, 0, 0, 138, 139, 5, 116, 0, 0, 139, 140, 5, 104, 0, 0, 140, 32, 1, 0, 0, 0, 141, 142, 5, 58, 0, 0, 142, 143, 5, 100, 0, 0, 143, 144, 5, 101, 0, 0, 144, 145, 5, 102, 0, 0, 145, 146, 5, 97, 0, 0, 146, 147, 5, 117, 0, 0, 147, 148, 5, 108, 0, 0, 148, 149, 5, 116, 0, 0, 149, 34, 1, 0, 0, 0, 150, 151, 5, 58, 0, 0, 151, 152, 5, 105, 0, 0, 152, 153, 5, 115, 0, 0, 153, 36, 1, 0, 0, 0, 154, 155, 5, 58, 0, 0, 155, 156, 5, 116, 0, 0, 156, 157, 5, 104, 0, 0, 157, 158, 5, 101, 0, 0, 158, 159, 5, 110, 0, 0, 159, 38, 1, 0, 0, 0, 160, 161, 5, 58, 0, 0, 161, 162, 5, 101, 0, 0, 162, 163, 5, 108, 0, 0, 163, 164, 5, 115, 0, 0, 164, 165, 5, 101, 0, 0, 165, 40, 1, 0, 0, 0, 166, 167, 5, 58, 0, 0, 167, 171, 7, 0, 0, 0, 168, 170, 7, 1, 0, 0, 169, 168, 1, 0, 0, 0, 170, 173, 1, 0, 0, 0, 171, 169, 1, 0, 0, 0, 171, 172, 1, 0, 0, 0, 172, 42, 1, 0, 0, 0, 173, 171, 1, 0, 0, 0, 12, 0, 50, 53, 58, 67, 74, 86, 91, 96, 104, 110, 171, 0] \ No newline at end of file diff --git a/python/src/parser/MetaPromptLexer.py b/python/src/parser/MetaPromptLexer.py index b641398..ad7ef11 100644 --- a/python/src/parser/MetaPromptLexer.py +++ b/python/src/parser/MetaPromptLexer.py @@ -10,57 +10,66 @@ def serializedATN(): return [ - 4,0,15,150,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, + 4,0,17,174,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,2,11,7,11,2,12,7,12,2, - 13,7,13,2,14,7,14,2,15,7,15,2,16,7,16,2,17,7,17,2,18,7,18,1,0,1, - 0,1,1,1,1,1,2,1,2,1,2,3,2,47,8,2,1,3,3,3,50,8,3,1,3,5,3,53,8,3,10, - 3,12,3,56,9,3,1,3,1,3,1,4,1,4,1,5,1,5,3,5,64,8,5,1,6,1,6,1,6,1,7, - 1,7,3,7,71,8,7,1,8,1,8,1,9,1,9,1,9,1,9,1,9,1,9,4,9,81,8,9,11,9,12, - 9,82,1,9,4,9,86,8,9,11,9,12,9,87,1,9,5,9,91,8,9,10,9,12,9,94,9,9, - 1,10,1,10,1,11,1,11,1,11,1,11,1,12,1,12,1,12,1,12,1,12,1,12,1,12, - 1,12,1,13,1,13,1,13,1,13,1,13,1,13,1,13,1,13,1,14,1,14,1,14,1,14, - 1,14,1,14,1,14,1,14,1,14,1,15,1,15,1,15,1,15,1,16,1,16,1,16,1,16, - 1,16,1,16,1,17,1,17,1,17,1,17,1,17,1,17,1,18,1,18,1,18,5,18,146, - 8,18,10,18,12,18,149,9,18,0,0,19,1,1,3,2,5,3,7,4,9,5,11,6,13,0,15, - 0,17,0,19,7,21,0,23,8,25,9,27,10,29,11,31,12,33,13,35,14,37,15,1, - 0,4,3,0,65,90,95,95,97,122,4,0,48,57,65,90,95,95,97,122,4,0,45,57, - 65,90,95,95,97,122,2,0,10,10,32,32,154,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,19,1,0,0,0,0,23, - 1,0,0,0,0,25,1,0,0,0,0,27,1,0,0,0,0,29,1,0,0,0,0,31,1,0,0,0,0,33, - 1,0,0,0,0,35,1,0,0,0,0,37,1,0,0,0,1,39,1,0,0,0,3,41,1,0,0,0,5,46, - 1,0,0,0,7,49,1,0,0,0,9,59,1,0,0,0,11,63,1,0,0,0,13,65,1,0,0,0,15, - 70,1,0,0,0,17,72,1,0,0,0,19,74,1,0,0,0,21,95,1,0,0,0,23,97,1,0,0, - 0,25,101,1,0,0,0,27,109,1,0,0,0,29,117,1,0,0,0,31,126,1,0,0,0,33, - 130,1,0,0,0,35,136,1,0,0,0,37,142,1,0,0,0,39,40,5,91,0,0,40,2,1, - 0,0,0,41,42,5,93,0,0,42,4,1,0,0,0,43,47,5,61,0,0,44,45,5,63,0,0, - 45,47,5,61,0,0,46,43,1,0,0,0,46,44,1,0,0,0,47,6,1,0,0,0,48,50,7, - 0,0,0,49,48,1,0,0,0,49,50,1,0,0,0,50,54,1,0,0,0,51,53,7,1,0,0,52, - 51,1,0,0,0,53,56,1,0,0,0,54,52,1,0,0,0,54,55,1,0,0,0,55,57,1,0,0, - 0,56,54,1,0,0,0,57,58,5,36,0,0,58,8,1,0,0,0,59,60,5,35,0,0,60,10, - 1,0,0,0,61,64,3,13,6,0,62,64,9,0,0,0,63,61,1,0,0,0,63,62,1,0,0,0, - 64,12,1,0,0,0,65,66,3,17,8,0,66,67,3,15,7,0,67,14,1,0,0,0,68,71, - 3,1,0,0,69,71,3,17,8,0,70,68,1,0,0,0,70,69,1,0,0,0,71,16,1,0,0,0, - 72,73,5,92,0,0,73,18,1,0,0,0,74,75,5,58,0,0,75,76,5,117,0,0,76,77, - 5,115,0,0,77,78,5,101,0,0,78,80,1,0,0,0,79,81,3,21,10,0,80,79,1, - 0,0,0,81,82,1,0,0,0,82,80,1,0,0,0,82,83,1,0,0,0,83,85,1,0,0,0,84, - 86,7,2,0,0,85,84,1,0,0,0,86,87,1,0,0,0,87,85,1,0,0,0,87,88,1,0,0, - 0,88,92,1,0,0,0,89,91,3,21,10,0,90,89,1,0,0,0,91,94,1,0,0,0,92,90, - 1,0,0,0,92,93,1,0,0,0,93,20,1,0,0,0,94,92,1,0,0,0,95,96,7,3,0,0, - 96,22,1,0,0,0,97,98,5,58,0,0,98,99,5,105,0,0,99,100,5,102,0,0,100, - 24,1,0,0,0,101,102,5,58,0,0,102,103,5,99,0,0,103,104,5,104,0,0,104, - 105,5,111,0,0,105,106,5,111,0,0,106,107,5,115,0,0,107,108,5,101, - 0,0,108,26,1,0,0,0,109,110,5,58,0,0,110,111,5,111,0,0,111,112,5, - 112,0,0,112,113,5,116,0,0,113,114,5,105,0,0,114,115,5,111,0,0,115, - 116,5,110,0,0,116,28,1,0,0,0,117,118,5,58,0,0,118,119,5,100,0,0, - 119,120,5,101,0,0,120,121,5,102,0,0,121,122,5,97,0,0,122,123,5,117, - 0,0,123,124,5,108,0,0,124,125,5,116,0,0,125,30,1,0,0,0,126,127,5, - 58,0,0,127,128,5,105,0,0,128,129,5,115,0,0,129,32,1,0,0,0,130,131, - 5,58,0,0,131,132,5,116,0,0,132,133,5,104,0,0,133,134,5,101,0,0,134, - 135,5,110,0,0,135,34,1,0,0,0,136,137,5,58,0,0,137,138,5,101,0,0, - 138,139,5,108,0,0,139,140,5,115,0,0,140,141,5,101,0,0,141,36,1,0, - 0,0,142,143,5,58,0,0,143,147,7,0,0,0,144,146,7,1,0,0,145,144,1,0, - 0,0,146,149,1,0,0,0,147,145,1,0,0,0,147,148,1,0,0,0,148,38,1,0,0, - 0,149,147,1,0,0,0,10,0,46,49,54,63,70,82,87,92,147,0 + 13,7,13,2,14,7,14,2,15,7,15,2,16,7,16,2,17,7,17,2,18,7,18,2,19,7, + 19,2,20,7,20,1,0,1,0,1,1,1,1,1,2,1,2,1,2,3,2,51,8,2,1,3,3,3,54,8, + 3,1,3,5,3,57,8,3,10,3,12,3,60,9,3,1,3,1,3,1,4,1,4,1,5,1,5,3,5,68, + 8,5,1,6,1,6,1,6,1,7,1,7,3,7,75,8,7,1,8,1,8,1,9,1,9,1,9,1,9,1,9,1, + 9,4,9,85,8,9,11,9,12,9,86,1,9,4,9,90,8,9,11,9,12,9,91,1,9,5,9,95, + 8,9,10,9,12,9,98,9,9,1,10,1,10,1,10,5,10,103,8,10,10,10,12,10,106, + 9,10,1,10,5,10,109,8,10,10,10,12,10,112,9,10,1,11,1,11,1,12,1,12, + 1,12,1,12,1,13,1,13,1,13,1,13,1,13,1,13,1,13,1,13,1,14,1,14,1,14, + 1,14,1,14,1,14,1,14,1,14,1,15,1,15,1,15,1,15,1,15,1,15,1,16,1,16, + 1,16,1,16,1,16,1,16,1,16,1,16,1,16,1,17,1,17,1,17,1,17,1,18,1,18, + 1,18,1,18,1,18,1,18,1,19,1,19,1,19,1,19,1,19,1,19,1,20,1,20,1,20, + 5,20,170,8,20,10,20,12,20,173,9,20,0,0,21,1,1,3,2,5,3,7,4,9,5,11, + 6,13,0,15,0,17,0,19,7,21,8,23,0,25,9,27,10,29,11,31,12,33,13,35, + 14,37,15,39,16,41,17,1,0,4,3,0,65,90,95,95,97,122,4,0,48,57,65,90, + 95,95,97,122,4,0,45,57,65,90,95,95,97,122,2,0,10,10,32,32,180,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,19,1,0,0,0,0,21,1,0,0,0,0,25,1,0,0,0,0,27,1,0,0,0,0,29,1, + 0,0,0,0,31,1,0,0,0,0,33,1,0,0,0,0,35,1,0,0,0,0,37,1,0,0,0,0,39,1, + 0,0,0,0,41,1,0,0,0,1,43,1,0,0,0,3,45,1,0,0,0,5,50,1,0,0,0,7,53,1, + 0,0,0,9,63,1,0,0,0,11,67,1,0,0,0,13,69,1,0,0,0,15,74,1,0,0,0,17, + 76,1,0,0,0,19,78,1,0,0,0,21,99,1,0,0,0,23,113,1,0,0,0,25,115,1,0, + 0,0,27,119,1,0,0,0,29,127,1,0,0,0,31,135,1,0,0,0,33,141,1,0,0,0, + 35,150,1,0,0,0,37,154,1,0,0,0,39,160,1,0,0,0,41,166,1,0,0,0,43,44, + 5,91,0,0,44,2,1,0,0,0,45,46,5,93,0,0,46,4,1,0,0,0,47,51,5,61,0,0, + 48,49,5,63,0,0,49,51,5,61,0,0,50,47,1,0,0,0,50,48,1,0,0,0,51,6,1, + 0,0,0,52,54,7,0,0,0,53,52,1,0,0,0,53,54,1,0,0,0,54,58,1,0,0,0,55, + 57,7,1,0,0,56,55,1,0,0,0,57,60,1,0,0,0,58,56,1,0,0,0,58,59,1,0,0, + 0,59,61,1,0,0,0,60,58,1,0,0,0,61,62,5,36,0,0,62,8,1,0,0,0,63,64, + 5,35,0,0,64,10,1,0,0,0,65,68,3,13,6,0,66,68,9,0,0,0,67,65,1,0,0, + 0,67,66,1,0,0,0,68,12,1,0,0,0,69,70,3,17,8,0,70,71,3,15,7,0,71,14, + 1,0,0,0,72,75,3,1,0,0,73,75,3,17,8,0,74,72,1,0,0,0,74,73,1,0,0,0, + 75,16,1,0,0,0,76,77,5,92,0,0,77,18,1,0,0,0,78,79,5,58,0,0,79,80, + 5,117,0,0,80,81,5,115,0,0,81,82,5,101,0,0,82,84,1,0,0,0,83,85,3, + 23,11,0,84,83,1,0,0,0,85,86,1,0,0,0,86,84,1,0,0,0,86,87,1,0,0,0, + 87,89,1,0,0,0,88,90,7,2,0,0,89,88,1,0,0,0,90,91,1,0,0,0,91,89,1, + 0,0,0,91,92,1,0,0,0,92,96,1,0,0,0,93,95,3,23,11,0,94,93,1,0,0,0, + 95,98,1,0,0,0,96,94,1,0,0,0,96,97,1,0,0,0,97,20,1,0,0,0,98,96,1, + 0,0,0,99,100,5,64,0,0,100,104,7,0,0,0,101,103,7,1,0,0,102,101,1, + 0,0,0,103,106,1,0,0,0,104,102,1,0,0,0,104,105,1,0,0,0,105,110,1, + 0,0,0,106,104,1,0,0,0,107,109,3,23,11,0,108,107,1,0,0,0,109,112, + 1,0,0,0,110,108,1,0,0,0,110,111,1,0,0,0,111,22,1,0,0,0,112,110,1, + 0,0,0,113,114,7,3,0,0,114,24,1,0,0,0,115,116,5,58,0,0,116,117,5, + 105,0,0,117,118,5,102,0,0,118,26,1,0,0,0,119,120,5,58,0,0,120,121, + 5,99,0,0,121,122,5,104,0,0,122,123,5,111,0,0,123,124,5,111,0,0,124, + 125,5,115,0,0,125,126,5,101,0,0,126,28,1,0,0,0,127,128,5,58,0,0, + 128,129,5,111,0,0,129,130,5,112,0,0,130,131,5,116,0,0,131,132,5, + 105,0,0,132,133,5,111,0,0,133,134,5,110,0,0,134,30,1,0,0,0,135,136, + 5,58,0,0,136,137,5,119,0,0,137,138,5,105,0,0,138,139,5,116,0,0,139, + 140,5,104,0,0,140,32,1,0,0,0,141,142,5,58,0,0,142,143,5,100,0,0, + 143,144,5,101,0,0,144,145,5,102,0,0,145,146,5,97,0,0,146,147,5,117, + 0,0,147,148,5,108,0,0,148,149,5,116,0,0,149,34,1,0,0,0,150,151,5, + 58,0,0,151,152,5,105,0,0,152,153,5,115,0,0,153,36,1,0,0,0,154,155, + 5,58,0,0,155,156,5,116,0,0,156,157,5,104,0,0,157,158,5,101,0,0,158, + 159,5,110,0,0,159,38,1,0,0,0,160,161,5,58,0,0,161,162,5,101,0,0, + 162,163,5,108,0,0,163,164,5,115,0,0,164,165,5,101,0,0,165,40,1,0, + 0,0,166,167,5,58,0,0,167,171,7,0,0,0,168,170,7,1,0,0,169,168,1,0, + 0,0,170,173,1,0,0,0,171,169,1,0,0,0,171,172,1,0,0,0,172,42,1,0,0, + 0,173,171,1,0,0,0,12,0,50,53,58,67,74,86,91,96,104,110,171,0 ] class MetaPromptLexer(Lexer): @@ -76,32 +85,34 @@ class MetaPromptLexer(Lexer): COMMENT_KW = 5 CHAR = 6 USE = 7 - IF_KW = 8 - CHOOSE_KW = 9 - OPTION_KW = 10 - DEFAULT_KW = 11 - IS_KW = 12 - THEN_KW = 13 - ELSE_KW = 14 - VAR_NAME = 15 + CALL = 8 + IF_KW = 9 + CHOOSE_KW = 10 + OPTION_KW = 11 + WITH_KW = 12 + DEFAULT_KW = 13 + IS_KW = 14 + THEN_KW = 15 + ELSE_KW = 16 + VAR_NAME = 17 channelNames = [ u"DEFAULT_TOKEN_CHANNEL", u"HIDDEN" ] modeNames = [ "DEFAULT_MODE" ] literalNames = [ "", - "'['", "']'", "'#'", "':if'", "':choose'", "':option'", "':default'", - "':is'", "':then'", "':else'" ] + "'['", "']'", "'#'", "':if'", "':choose'", "':option'", "':with'", + "':default'", "':is'", "':then'", "':else'" ] symbolicNames = [ "", "LB", "RB", "EQ_KW", "META_PROMPT", "COMMENT_KW", "CHAR", "USE", - "IF_KW", "CHOOSE_KW", "OPTION_KW", "DEFAULT_KW", "IS_KW", "THEN_KW", - "ELSE_KW", "VAR_NAME" ] + "CALL", "IF_KW", "CHOOSE_KW", "OPTION_KW", "WITH_KW", "DEFAULT_KW", + "IS_KW", "THEN_KW", "ELSE_KW", "VAR_NAME" ] ruleNames = [ "LB", "RB", "EQ_KW", "META_PROMPT", "COMMENT_KW", "CHAR", - "ESCAPED", "ESCAPEE", "ESCAPE", "USE", "WS", "IF_KW", - "CHOOSE_KW", "OPTION_KW", "DEFAULT_KW", "IS_KW", "THEN_KW", - "ELSE_KW", "VAR_NAME" ] + "ESCAPED", "ESCAPEE", "ESCAPE", "USE", "CALL", "WS", "IF_KW", + "CHOOSE_KW", "OPTION_KW", "WITH_KW", "DEFAULT_KW", "IS_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 472b663..b26b970 100644 --- a/python/src/parser/MetaPromptLexer.tokens +++ b/python/src/parser/MetaPromptLexer.tokens @@ -5,21 +5,24 @@ META_PROMPT=4 COMMENT_KW=5 CHAR=6 USE=7 -IF_KW=8 -CHOOSE_KW=9 -OPTION_KW=10 -DEFAULT_KW=11 -IS_KW=12 -THEN_KW=13 -ELSE_KW=14 -VAR_NAME=15 +CALL=8 +IF_KW=9 +CHOOSE_KW=10 +OPTION_KW=11 +WITH_KW=12 +DEFAULT_KW=13 +IS_KW=14 +THEN_KW=15 +ELSE_KW=16 +VAR_NAME=17 '['=1 ']'=2 '#'=5 -':if'=8 -':choose'=9 -':option'=10 -':default'=11 -':is'=12 -':then'=13 -':else'=14 +':if'=9 +':choose'=10 +':option'=11 +':with'=12 +':default'=13 +':is'=14 +':then'=15 +':else'=16 diff --git a/python/src/parser/MetaPromptListener.py b/python/src/parser/MetaPromptListener.py index 8313345..82659f9 100644 --- a/python/src/parser/MetaPromptListener.py +++ b/python/src/parser/MetaPromptListener.py @@ -71,6 +71,15 @@ def exitDefault_option(self, ctx:MetaPromptParser.Default_optionContext): pass + # Enter a parse tree produced by MetaPromptParser#positional_args. + def enterPositional_args(self, ctx:MetaPromptParser.Positional_argsContext): + pass + + # Exit a parse tree produced by MetaPromptParser#positional_args. + def exitPositional_args(self, ctx:MetaPromptParser.Positional_argsContext): + pass + + # Enter a parse tree produced by MetaPromptParser#parameters. def enterParameters(self, ctx:MetaPromptParser.ParametersContext): pass diff --git a/python/src/parser/MetaPromptParser.py b/python/src/parser/MetaPromptParser.py index 7e27d21..2a7c483 100644 --- a/python/src/parser/MetaPromptParser.py +++ b/python/src/parser/MetaPromptParser.py @@ -10,41 +10,45 @@ def serializedATN(): return [ - 4,1,15,105,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,1,0,1,0,1,0,1,1,5,1,23,8,1,10,1,12,1,26,9,1,1, - 2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,3,2,43, - 8,2,1,3,1,3,3,3,47,8,3,1,4,1,4,1,4,1,4,1,4,1,4,1,4,1,4,1,4,1,4,1, - 4,1,4,1,4,1,4,1,4,4,4,64,8,4,11,4,12,4,65,1,4,3,4,69,8,4,1,4,1,4, - 3,4,73,8,4,1,4,1,4,1,4,1,4,1,4,1,4,1,4,1,4,3,4,83,8,4,1,5,1,5,1, - 5,1,5,1,5,1,6,1,6,1,6,1,7,1,7,1,7,4,7,96,8,7,11,7,12,7,97,1,8,4, - 8,101,8,8,11,8,12,8,102,1,8,1,24,0,9,0,2,4,6,8,10,12,14,16,0,0,120, - 0,18,1,0,0,0,2,24,1,0,0,0,4,42,1,0,0,0,6,46,1,0,0,0,8,82,1,0,0,0, - 10,84,1,0,0,0,12,89,1,0,0,0,14,95,1,0,0,0,16,100,1,0,0,0,18,19,3, - 2,1,0,19,20,5,0,0,1,20,1,1,0,0,0,21,23,3,4,2,0,22,21,1,0,0,0,23, - 26,1,0,0,0,24,25,1,0,0,0,24,22,1,0,0,0,25,3,1,0,0,0,26,24,1,0,0, - 0,27,28,5,1,0,0,28,29,3,6,3,0,29,30,5,2,0,0,30,43,1,0,0,0,31,43, - 3,16,8,0,32,43,5,2,0,0,33,43,5,1,0,0,34,43,5,5,0,0,35,43,5,4,0,0, - 36,43,5,3,0,0,37,43,5,15,0,0,38,43,5,9,0,0,39,43,5,10,0,0,40,43, - 5,11,0,0,41,43,5,12,0,0,42,27,1,0,0,0,42,31,1,0,0,0,42,32,1,0,0, - 0,42,33,1,0,0,0,42,34,1,0,0,0,42,35,1,0,0,0,42,36,1,0,0,0,42,37, - 1,0,0,0,42,38,1,0,0,0,42,39,1,0,0,0,42,40,1,0,0,0,42,41,1,0,0,0, - 43,5,1,0,0,0,44,47,3,8,4,0,45,47,3,2,1,0,46,44,1,0,0,0,46,45,1,0, - 0,0,47,7,1,0,0,0,48,49,5,8,0,0,49,50,3,2,1,0,50,51,5,13,0,0,51,52, - 3,2,1,0,52,53,5,14,0,0,53,54,3,2,1,0,54,83,1,0,0,0,55,56,5,8,0,0, - 56,57,3,2,1,0,57,58,5,13,0,0,58,59,3,2,1,0,59,83,1,0,0,0,60,61,5, - 9,0,0,61,63,3,2,1,0,62,64,3,10,5,0,63,62,1,0,0,0,64,65,1,0,0,0,65, - 63,1,0,0,0,65,66,1,0,0,0,66,68,1,0,0,0,67,69,3,12,6,0,68,67,1,0, - 0,0,68,69,1,0,0,0,69,83,1,0,0,0,70,72,5,7,0,0,71,73,3,14,7,0,72, - 71,1,0,0,0,72,73,1,0,0,0,73,83,1,0,0,0,74,75,5,4,0,0,75,83,3,2,1, - 0,76,77,5,5,0,0,77,83,3,2,1,0,78,79,5,15,0,0,79,80,5,3,0,0,80,83, - 3,2,1,0,81,83,5,15,0,0,82,48,1,0,0,0,82,55,1,0,0,0,82,60,1,0,0,0, - 82,70,1,0,0,0,82,74,1,0,0,0,82,76,1,0,0,0,82,78,1,0,0,0,82,81,1, - 0,0,0,83,9,1,0,0,0,84,85,5,10,0,0,85,86,3,2,1,0,86,87,5,12,0,0,87, - 88,3,2,1,0,88,11,1,0,0,0,89,90,5,11,0,0,90,91,3,2,1,0,91,13,1,0, - 0,0,92,93,5,15,0,0,93,94,5,3,0,0,94,96,3,2,1,0,95,92,1,0,0,0,96, - 97,1,0,0,0,97,95,1,0,0,0,97,98,1,0,0,0,98,15,1,0,0,0,99,101,5,6, - 0,0,100,99,1,0,0,0,101,102,1,0,0,0,102,100,1,0,0,0,102,103,1,0,0, - 0,103,17,1,0,0,0,9,24,42,46,65,68,72,82,97,102 + 4,1,17,117,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,1,0,1,0,1,0,1,1,5,1,25,8,1,10,1,12,1,28, + 9,1,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2, + 3,2,45,8,2,1,3,1,3,3,3,49,8,3,1,4,1,4,1,4,1,4,1,4,1,4,1,4,1,4,1, + 4,1,4,1,4,1,4,1,4,1,4,1,4,4,4,66,8,4,11,4,12,4,67,1,4,3,4,71,8,4, + 1,4,1,4,1,4,1,4,1,4,1,4,1,4,1,4,1,4,1,4,1,4,1,4,1,4,1,4,3,4,87,8, + 4,1,5,1,5,1,5,1,5,1,5,1,6,1,6,1,6,1,7,1,7,5,7,99,8,7,10,7,12,7,102, + 9,7,1,8,1,8,1,8,5,8,107,8,8,10,8,12,8,110,9,8,1,9,4,9,113,8,9,11, + 9,12,9,114,1,9,1,26,0,10,0,2,4,6,8,10,12,14,16,18,0,0,132,0,20,1, + 0,0,0,2,26,1,0,0,0,4,44,1,0,0,0,6,48,1,0,0,0,8,86,1,0,0,0,10,88, + 1,0,0,0,12,93,1,0,0,0,14,100,1,0,0,0,16,108,1,0,0,0,18,112,1,0,0, + 0,20,21,3,2,1,0,21,22,5,0,0,1,22,1,1,0,0,0,23,25,3,4,2,0,24,23,1, + 0,0,0,25,28,1,0,0,0,26,27,1,0,0,0,26,24,1,0,0,0,27,3,1,0,0,0,28, + 26,1,0,0,0,29,30,5,1,0,0,30,31,3,6,3,0,31,32,5,2,0,0,32,45,1,0,0, + 0,33,45,3,18,9,0,34,45,5,2,0,0,35,45,5,1,0,0,36,45,5,5,0,0,37,45, + 5,4,0,0,38,45,5,3,0,0,39,45,5,17,0,0,40,45,5,10,0,0,41,45,5,11,0, + 0,42,45,5,13,0,0,43,45,5,14,0,0,44,29,1,0,0,0,44,33,1,0,0,0,44,34, + 1,0,0,0,44,35,1,0,0,0,44,36,1,0,0,0,44,37,1,0,0,0,44,38,1,0,0,0, + 44,39,1,0,0,0,44,40,1,0,0,0,44,41,1,0,0,0,44,42,1,0,0,0,44,43,1, + 0,0,0,45,5,1,0,0,0,46,49,3,8,4,0,47,49,3,2,1,0,48,46,1,0,0,0,48, + 47,1,0,0,0,49,7,1,0,0,0,50,51,5,9,0,0,51,52,3,2,1,0,52,53,5,15,0, + 0,53,54,3,2,1,0,54,55,5,16,0,0,55,56,3,2,1,0,56,87,1,0,0,0,57,58, + 5,9,0,0,58,59,3,2,1,0,59,60,5,15,0,0,60,61,3,2,1,0,61,87,1,0,0,0, + 62,63,5,10,0,0,63,65,3,2,1,0,64,66,3,10,5,0,65,64,1,0,0,0,66,67, + 1,0,0,0,67,65,1,0,0,0,67,68,1,0,0,0,68,70,1,0,0,0,69,71,3,12,6,0, + 70,69,1,0,0,0,70,71,1,0,0,0,71,87,1,0,0,0,72,73,5,7,0,0,73,87,3, + 16,8,0,74,75,5,4,0,0,75,87,3,2,1,0,76,77,5,5,0,0,77,87,3,2,1,0,78, + 79,5,17,0,0,79,80,5,3,0,0,80,87,3,2,1,0,81,87,5,17,0,0,82,83,5,8, + 0,0,83,84,3,14,7,0,84,85,3,16,8,0,85,87,1,0,0,0,86,50,1,0,0,0,86, + 57,1,0,0,0,86,62,1,0,0,0,86,72,1,0,0,0,86,74,1,0,0,0,86,76,1,0,0, + 0,86,78,1,0,0,0,86,81,1,0,0,0,86,82,1,0,0,0,87,9,1,0,0,0,88,89,5, + 11,0,0,89,90,3,2,1,0,90,91,5,14,0,0,91,92,3,2,1,0,92,11,1,0,0,0, + 93,94,5,13,0,0,94,95,3,2,1,0,95,13,1,0,0,0,96,97,5,12,0,0,97,99, + 3,2,1,0,98,96,1,0,0,0,99,102,1,0,0,0,100,98,1,0,0,0,100,101,1,0, + 0,0,101,15,1,0,0,0,102,100,1,0,0,0,103,104,5,17,0,0,104,105,5,3, + 0,0,105,107,3,2,1,0,106,103,1,0,0,0,107,110,1,0,0,0,108,106,1,0, + 0,0,108,109,1,0,0,0,109,17,1,0,0,0,110,108,1,0,0,0,111,113,5,6,0, + 0,112,111,1,0,0,0,113,114,1,0,0,0,114,112,1,0,0,0,114,115,1,0,0, + 0,115,19,1,0,0,0,9,26,44,48,67,70,86,100,108,114 ] class MetaPromptParser ( Parser ): @@ -58,12 +62,14 @@ class MetaPromptParser ( Parser ): sharedContextCache = PredictionContextCache() literalNames = [ "", "'['", "']'", "", "", - "'#'", "", "", "':if'", "':choose'", - "':option'", "':default'", "':is'", "':then'", "':else'" ] + "'#'", "", "", "", "':if'", + "':choose'", "':option'", "':with'", "':default'", + "':is'", "':then'", "':else'" ] symbolicNames = [ "", "LB", "RB", "EQ_KW", "META_PROMPT", "COMMENT_KW", - "CHAR", "USE", "IF_KW", "CHOOSE_KW", "OPTION_KW", - "DEFAULT_KW", "IS_KW", "THEN_KW", "ELSE_KW", "VAR_NAME" ] + "CHAR", "USE", "CALL", "IF_KW", "CHOOSE_KW", "OPTION_KW", + "WITH_KW", "DEFAULT_KW", "IS_KW", "THEN_KW", "ELSE_KW", + "VAR_NAME" ] RULE_prompt = 0 RULE_exprs = 1 @@ -72,11 +78,12 @@ class MetaPromptParser ( Parser ): RULE_meta_body = 4 RULE_option = 5 RULE_default_option = 6 - RULE_parameters = 7 - RULE_text = 8 + RULE_positional_args = 7 + RULE_parameters = 8 + RULE_text = 9 ruleNames = [ "prompt", "exprs", "expr", "expr1", "meta_body", "option", - "default_option", "parameters", "text" ] + "default_option", "positional_args", "parameters", "text" ] EOF = Token.EOF LB=1 @@ -86,14 +93,16 @@ class MetaPromptParser ( Parser ): COMMENT_KW=5 CHAR=6 USE=7 - IF_KW=8 - CHOOSE_KW=9 - OPTION_KW=10 - DEFAULT_KW=11 - IS_KW=12 - THEN_KW=13 - ELSE_KW=14 - VAR_NAME=15 + CALL=8 + IF_KW=9 + CHOOSE_KW=10 + OPTION_KW=11 + WITH_KW=12 + DEFAULT_KW=13 + IS_KW=14 + THEN_KW=15 + ELSE_KW=16 + VAR_NAME=17 def __init__(self, input:TokenStream, output:TextIO = sys.stdout): super().__init__(input, output) @@ -144,9 +153,9 @@ def prompt(self): self.enterRule(localctx, 0, self.RULE_prompt) try: self.enterOuterAlt(localctx, 1) - self.state = 18 + self.state = 20 self.exprs() - self.state = 19 + self.state = 21 self.match(MetaPromptParser.EOF) except RecognitionException as re: localctx.exception = re @@ -197,14 +206,14 @@ def exprs(self): self.enterRule(localctx, 2, self.RULE_exprs) try: self.enterOuterAlt(localctx, 1) - self.state = 24 + self.state = 26 self._errHandler.sync(self) _alt = self._interp.adaptivePredict(self._input,0,self._ctx) while _alt!=1 and _alt!=ATN.INVALID_ALT_NUMBER: if _alt==1+1: - self.state = 21 + self.state = 23 self.expr() - self.state = 26 + self.state = 28 self._errHandler.sync(self) _alt = self._interp.adaptivePredict(self._input,0,self._ctx) @@ -287,82 +296,82 @@ def expr(self): localctx = MetaPromptParser.ExprContext(self, self._ctx, self.state) self.enterRule(localctx, 4, self.RULE_expr) try: - self.state = 42 + self.state = 44 self._errHandler.sync(self) la_ = self._interp.adaptivePredict(self._input,1,self._ctx) if la_ == 1: self.enterOuterAlt(localctx, 1) - self.state = 27 + self.state = 29 self.match(MetaPromptParser.LB) - self.state = 28 + self.state = 30 self.expr1() - self.state = 29 + self.state = 31 self.match(MetaPromptParser.RB) pass elif la_ == 2: self.enterOuterAlt(localctx, 2) - self.state = 31 + self.state = 33 self.text() pass elif la_ == 3: self.enterOuterAlt(localctx, 3) - self.state = 32 + self.state = 34 self.match(MetaPromptParser.RB) pass elif la_ == 4: self.enterOuterAlt(localctx, 4) - self.state = 33 + self.state = 35 self.match(MetaPromptParser.LB) pass elif la_ == 5: self.enterOuterAlt(localctx, 5) - self.state = 34 + self.state = 36 self.match(MetaPromptParser.COMMENT_KW) pass elif la_ == 6: self.enterOuterAlt(localctx, 6) - self.state = 35 + self.state = 37 self.match(MetaPromptParser.META_PROMPT) pass elif la_ == 7: self.enterOuterAlt(localctx, 7) - self.state = 36 + self.state = 38 self.match(MetaPromptParser.EQ_KW) pass elif la_ == 8: self.enterOuterAlt(localctx, 8) - self.state = 37 + self.state = 39 self.match(MetaPromptParser.VAR_NAME) pass elif la_ == 9: self.enterOuterAlt(localctx, 9) - self.state = 38 + self.state = 40 self.match(MetaPromptParser.CHOOSE_KW) pass elif la_ == 10: self.enterOuterAlt(localctx, 10) - self.state = 39 + self.state = 41 self.match(MetaPromptParser.OPTION_KW) pass elif la_ == 11: self.enterOuterAlt(localctx, 11) - self.state = 40 + self.state = 42 self.match(MetaPromptParser.DEFAULT_KW) pass elif la_ == 12: self.enterOuterAlt(localctx, 12) - self.state = 41 + self.state = 43 self.match(MetaPromptParser.IS_KW) pass @@ -416,18 +425,18 @@ def expr1(self): localctx = MetaPromptParser.Expr1Context(self, self._ctx, self.state) self.enterRule(localctx, 6, self.RULE_expr1) try: - self.state = 46 + self.state = 48 self._errHandler.sync(self) la_ = self._interp.adaptivePredict(self._input,2,self._ctx) if la_ == 1: self.enterOuterAlt(localctx, 1) - self.state = 44 + self.state = 46 self.meta_body() pass elif la_ == 2: self.enterOuterAlt(localctx, 2) - self.state = 45 + self.state = 47 self.exprs() pass @@ -497,6 +506,13 @@ def VAR_NAME(self): def EQ_KW(self): return self.getToken(MetaPromptParser.EQ_KW, 0) + def CALL(self): + return self.getToken(MetaPromptParser.CALL, 0) + + def positional_args(self): + return self.getTypedRuleContext(MetaPromptParser.Positional_argsContext,0) + + def getRuleIndex(self): return MetaPromptParser.RULE_meta_body @@ -523,60 +539,60 @@ def meta_body(self): self.enterRule(localctx, 8, self.RULE_meta_body) self._la = 0 # Token type try: - self.state = 82 + self.state = 86 self._errHandler.sync(self) - la_ = self._interp.adaptivePredict(self._input,6,self._ctx) + la_ = self._interp.adaptivePredict(self._input,5,self._ctx) if la_ == 1: self.enterOuterAlt(localctx, 1) - self.state = 48 - self.match(MetaPromptParser.IF_KW) - self.state = 49 - self.exprs() self.state = 50 - self.match(MetaPromptParser.THEN_KW) + self.match(MetaPromptParser.IF_KW) self.state = 51 self.exprs() self.state = 52 - self.match(MetaPromptParser.ELSE_KW) + self.match(MetaPromptParser.THEN_KW) self.state = 53 self.exprs() + self.state = 54 + self.match(MetaPromptParser.ELSE_KW) + self.state = 55 + self.exprs() pass elif la_ == 2: self.enterOuterAlt(localctx, 2) - self.state = 55 + self.state = 57 self.match(MetaPromptParser.IF_KW) - self.state = 56 + self.state = 58 self.exprs() - self.state = 57 + self.state = 59 self.match(MetaPromptParser.THEN_KW) - self.state = 58 + self.state = 60 self.exprs() pass elif la_ == 3: self.enterOuterAlt(localctx, 3) - self.state = 60 + self.state = 62 self.match(MetaPromptParser.CHOOSE_KW) - self.state = 61 + self.state = 63 self.exprs() - self.state = 63 + self.state = 65 self._errHandler.sync(self) _la = self._input.LA(1) while True: - self.state = 62 + self.state = 64 self.option() - self.state = 65 + self.state = 67 self._errHandler.sync(self) _la = self._input.LA(1) - if not (_la==10): + if not (_la==11): break - self.state = 68 + self.state = 70 self._errHandler.sync(self) _la = self._input.LA(1) - if _la==11: - self.state = 67 + if _la==13: + self.state = 69 self.default_option() @@ -584,16 +600,10 @@ def meta_body(self): elif la_ == 4: self.enterOuterAlt(localctx, 4) - self.state = 70 - self.match(MetaPromptParser.USE) self.state = 72 - self._errHandler.sync(self) - _la = self._input.LA(1) - if _la==15: - self.state = 71 - self.parameters() - - + self.match(MetaPromptParser.USE) + self.state = 73 + self.parameters() pass elif la_ == 5: @@ -628,6 +638,16 @@ def meta_body(self): self.match(MetaPromptParser.VAR_NAME) pass + elif la_ == 9: + self.enterOuterAlt(localctx, 9) + self.state = 82 + self.match(MetaPromptParser.CALL) + self.state = 83 + self.positional_args() + self.state = 84 + self.parameters() + pass + except RecognitionException as re: localctx.exception = re @@ -684,13 +704,13 @@ def option(self): self.enterRule(localctx, 10, self.RULE_option) try: self.enterOuterAlt(localctx, 1) - self.state = 84 + self.state = 88 self.match(MetaPromptParser.OPTION_KW) - self.state = 85 + self.state = 89 self.exprs() - self.state = 86 + self.state = 90 self.match(MetaPromptParser.IS_KW) - self.state = 87 + self.state = 91 self.exprs() except RecognitionException as re: localctx.exception = re @@ -741,9 +761,9 @@ def default_option(self): self.enterRule(localctx, 12, self.RULE_default_option) try: self.enterOuterAlt(localctx, 1) - self.state = 89 + self.state = 93 self.match(MetaPromptParser.DEFAULT_KW) - self.state = 90 + self.state = 94 self.exprs() except RecognitionException as re: localctx.exception = re @@ -754,6 +774,74 @@ def default_option(self): return localctx + class Positional_argsContext(ParserRuleContext): + __slots__ = 'parser' + + def __init__(self, parser, parent:ParserRuleContext=None, invokingState:int=-1): + super().__init__(parent, invokingState) + self.parser = parser + + def WITH_KW(self, i:int=None): + if i is None: + return self.getTokens(MetaPromptParser.WITH_KW) + else: + return self.getToken(MetaPromptParser.WITH_KW, i) + + def exprs(self, i:int=None): + if i is None: + return self.getTypedRuleContexts(MetaPromptParser.ExprsContext) + else: + return self.getTypedRuleContext(MetaPromptParser.ExprsContext,i) + + + def getRuleIndex(self): + return MetaPromptParser.RULE_positional_args + + def enterRule(self, listener:ParseTreeListener): + if hasattr( listener, "enterPositional_args" ): + listener.enterPositional_args(self) + + def exitRule(self, listener:ParseTreeListener): + if hasattr( listener, "exitPositional_args" ): + listener.exitPositional_args(self) + + def accept(self, visitor:ParseTreeVisitor): + if hasattr( visitor, "visitPositional_args" ): + return visitor.visitPositional_args(self) + else: + return visitor.visitChildren(self) + + + + + def positional_args(self): + + localctx = MetaPromptParser.Positional_argsContext(self, self._ctx, self.state) + self.enterRule(localctx, 14, self.RULE_positional_args) + self._la = 0 # Token type + try: + self.enterOuterAlt(localctx, 1) + self.state = 100 + self._errHandler.sync(self) + _la = self._input.LA(1) + while _la==12: + self.state = 96 + self.match(MetaPromptParser.WITH_KW) + self.state = 97 + self.exprs() + self.state = 102 + self._errHandler.sync(self) + _la = self._input.LA(1) + + except RecognitionException as re: + localctx.exception = re + self._errHandler.reportError(self, re) + self._errHandler.recover(self, re) + finally: + self.exitRule() + return localctx + + class ParametersContext(ParserRuleContext): __slots__ = 'parser' @@ -803,25 +891,23 @@ def accept(self, visitor:ParseTreeVisitor): def parameters(self): localctx = MetaPromptParser.ParametersContext(self, self._ctx, self.state) - self.enterRule(localctx, 14, self.RULE_parameters) + self.enterRule(localctx, 16, self.RULE_parameters) self._la = 0 # Token type try: self.enterOuterAlt(localctx, 1) - self.state = 95 + self.state = 108 self._errHandler.sync(self) _la = self._input.LA(1) - while True: - self.state = 92 + while _la==17: + self.state = 103 self.match(MetaPromptParser.VAR_NAME) - self.state = 93 + self.state = 104 self.match(MetaPromptParser.EQ_KW) - self.state = 94 + self.state = 105 self.exprs() - self.state = 97 + self.state = 110 self._errHandler.sync(self) _la = self._input.LA(1) - if not (_la==15): - break except RecognitionException as re: localctx.exception = re @@ -868,20 +954,20 @@ def accept(self, visitor:ParseTreeVisitor): def text(self): localctx = MetaPromptParser.TextContext(self, self._ctx, self.state) - self.enterRule(localctx, 16, self.RULE_text) + self.enterRule(localctx, 18, self.RULE_text) try: self.enterOuterAlt(localctx, 1) - self.state = 100 + self.state = 112 self._errHandler.sync(self) _alt = 1 while _alt!=2 and _alt!=ATN.INVALID_ALT_NUMBER: if _alt == 1: - self.state = 99 + self.state = 111 self.match(MetaPromptParser.CHAR) else: raise NoViableAltException(self) - self.state = 102 + self.state = 114 self._errHandler.sync(self) _alt = self._interp.adaptivePredict(self._input,8,self._ctx) diff --git a/python/src/parser/MetaPromptVisitor.py b/python/src/parser/MetaPromptVisitor.py index 92a567d..01ab919 100644 --- a/python/src/parser/MetaPromptVisitor.py +++ b/python/src/parser/MetaPromptVisitor.py @@ -44,6 +44,11 @@ def visitDefault_option(self, ctx:MetaPromptParser.Default_optionContext): return self.visitChildren(ctx) + # Visit a parse tree produced by MetaPromptParser#positional_args. + def visitPositional_args(self, ctx:MetaPromptParser.Positional_argsContext): + return self.visitChildren(ctx) + + # Visit a parse tree produced by MetaPromptParser#parameters. def visitParameters(self, ctx:MetaPromptParser.ParametersContext): return self.visitChildren(ctx) diff --git a/python/tests/test_parser.py b/python/tests/test_parser.py index f5dff9b..93f8437 100644 --- a/python/tests/test_parser.py +++ b/python/tests/test_parser.py @@ -5,7 +5,6 @@ from parse_utils import remove_extra_whitespace - def t(text): return {"type": "text", "text": text} @@ -64,6 +63,15 @@ def option(option, description): return {"option": option, "description": description} +def call(name, pos_args, named_args): + return { + "type": "call", + "name": name, + "positional_args": pos_args, + "named_args": named_args, + } + + def test_empty(): result = parse_metaprompt("") assert result["exprs"] == [] @@ -372,16 +380,12 @@ def test_choose_no_default(): ] -def test_extra_ws_1(): - assert _remove_extra_whitespace( - [ - assign("asd", []), - t("\n"), - assign("asd", []), - ] - ) == [ - assign("asd", []), - assign("asd", []), +def test_call(): + result = parse_metaprompt( + "[@writeFile :with filename.txt :with hello, world!]" + ) + assert result["exprs"] == [ + call("writeFile", [[t(" filename.txt ")], [t(" hello, world!")]], {}) ] @@ -397,6 +401,8 @@ def test_extra_ws_1(): assign("asd", []), ] + +# TODO: more tests for remove_extra_whitespace def test_extra_ws_2(): assert remove_extra_whitespace( [