[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Using a single quote (') character as a suffix operator in MetaLua
- From: Jaco van der Merwe <jvdmerwe@...>
- Date: Tue, 18 Oct 2011 12:31:05 +0200
I am using MetaLua to extend the syntax of Lua to provide Matlab-like operators on matrix objects. So far I've sucessfully implemented most of the unary and binary operators of Matlab that aren't provided in standard Lua. The one that is giving problems is the matrix transpose operator. In Matlab, the transpose of a matrix M is denoted by M'. The MetaLua code should replace this with a method call to the transpose() function. Here is the MetaLua code:
-{
mlp.lexer:add "'"
mlp.expr.suffix:add {"'", prec = 100, builder = |a, _| `Invoke{a, `String "transpose"}}
}
M = {}
function M:transpose()
return "M transposed"
end
print( M' )
The MetaLua parser fails parsing the line containing "M'" with an "Unterminated string" error. When I change the transpose operator to another character like "!", or "@" it works perfectly. However, the unconjugated transpose operator (.') works despite the fact that it contains a single quote as shown below:
-{
mlp.lexer:add ".'"
mlp.expr.suffix:add {".'", prec = 100, builder = |a, _| `Invoke{a, `String "unconj_transpose"}}
}
M = {}
function M:unconj_transpose()
return "M transposed unconjugated"
end
print( M.' )
I would really like to be able to use the single quote character as the transpose operator. I can understand that the lexer doesn't like an unterminated string, but in this case it should fall back and check if the terminator isn't used as unary operator. I also do not understand why ".'" works, but "'" doesn't.