Skip to content

Commit ec271d7

Browse files
committed
Fix parsing of values (chaining of identifier, function call, method call)
1 parent a8d5b66 commit ec271d7

File tree

3 files changed

+6
-7
lines changed

3 files changed

+6
-7
lines changed

include/minja/minja.hpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2205,7 +2205,7 @@ class Parser {
22052205

22062206
auto value = parseValue();
22072207

2208-
while (it != end && consumeSpaces() && peekSymbols({ "[", "." })) {
2208+
while (it != end && consumeSpaces() && peekSymbols({ "[", ".", "(" })) {
22092209
if (!consumeToken("[").empty()) {
22102210
std::shared_ptr<Expression> index;
22112211
auto slice_loc = get_location();
@@ -2250,15 +2250,13 @@ class Parser {
22502250
auto key = std::make_shared<LiteralExpr>(identifier->location, Value(identifier->get_name()));
22512251
value = std::make_shared<SubscriptExpr>(identifier->location, std::move(value), std::move(key));
22522252
}
2253+
} else if (peekSymbols({ "(" })) {
2254+
auto callParams = parseCallArgs();
2255+
value = std::make_shared<CallExpr>(get_location(), std::move(value), std::move(callParams));
22532256
}
22542257
consumeSpaces();
22552258
}
22562259

2257-
if (peekSymbols({ "(" })) {
2258-
auto location = get_location();
2259-
auto callParams = parseCallArgs();
2260-
value = std::make_shared<CallExpr>(location, std::move(value), std::move(callParams));
2261-
}
22622260
return value;
22632261
}
22642262

tests/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,7 @@ set(MODEL_IDS
324324
Qwen/Qwen3-235B-A22B-Thinking-2507
325325
Qwen/Qwen3-Coder-30B-A3B-Instruct
326326
Qwen/QwQ-32B
327+
zai-org/GLM-4.6
327328

328329
# Broken, TODO:
329330
# ai21labs/AI21-Jamba-1.5-Large # https://github.com/google/minja/issues/8

tests/test-syntax.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
#include <gmock/gmock-matchers.h>
1212

1313
#include <fstream>
14-
#include <iostream>
1514
#include <string>
1615

1716
static std::string render_python(const std::string & template_str, const json & bindings, const minja::Options & options) {
@@ -373,6 +372,7 @@ TEST(SyntaxTest, SimpleCases) {
373372
{}, {}
374373
)
375374
);
375+
EXPECT_EQ("False", render("{{ trim(' a ').endswith(' ') }}", {} , {})); // Test parsing of expression (chaining of identifier, function call, method call)
376376
}
377377
EXPECT_EQ(
378378
"[0, 1, 2][0, 2]",

0 commit comments

Comments
 (0)