Parse compound names in function handles
This commit is contained in:
parent
b033cb6f7d
commit
e5d0b0fe2e
@ -358,7 +358,20 @@ namespace Parser.Tests
|
||||
var actual = sut.ParseExpression();
|
||||
Assert.IsInstanceOf<NamedFunctionHandleNode>(actual);
|
||||
var f = (NamedFunctionHandleNode) actual;
|
||||
Assert.AreEqual("sqrt", f.IdentifierName.Token.PureToken.LiteralText);
|
||||
Assert.AreEqual(1, f.FunctionName.Names.Count);
|
||||
Assert.AreEqual("sqrt", f.FunctionName.Names[0].Token.PureToken.LiteralText);
|
||||
Assert.AreEqual(text, actual.FullText);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ParseFunctionHandleWithCompoundName()
|
||||
{
|
||||
var text = "@a.b.c";
|
||||
var sut = CreateParser(text);
|
||||
var actual = sut.ParseExpression();
|
||||
Assert.IsInstanceOf<NamedFunctionHandleNode>(actual);
|
||||
var f = (NamedFunctionHandleNode) actual;
|
||||
Assert.AreEqual(3, f.FunctionName.Names.Count);
|
||||
Assert.AreEqual(text, actual.FullText);
|
||||
}
|
||||
|
||||
|
@ -554,15 +554,32 @@ namespace Parser
|
||||
}
|
||||
}
|
||||
|
||||
private CompoundNameNode ParseCompoundName()
|
||||
{
|
||||
var lastToken = EatToken(TokenKind.Identifier);
|
||||
var firstName = Factory.IdentifierName(lastToken);
|
||||
var nodes = new List<SyntaxNode> {firstName};
|
||||
while (CurrentToken.Kind == TokenKind.Dot
|
||||
&& !lastToken.TrailingTrivia.Any())
|
||||
{
|
||||
var dot = Factory.Token(EatToken());
|
||||
nodes.Add(dot);
|
||||
lastToken = EatToken(TokenKind.Identifier);
|
||||
nodes.Add(Factory.IdentifierName(lastToken));
|
||||
}
|
||||
|
||||
return Factory.CompoundName(nodes);
|
||||
}
|
||||
|
||||
private FunctionHandleNode ParseFunctionHandle()
|
||||
{
|
||||
var atSign = EatToken();
|
||||
if (CurrentToken.Kind == TokenKind.Identifier)
|
||||
{
|
||||
var identifierName = EatToken(TokenKind.Identifier);
|
||||
var compoundName = ParseCompoundName();
|
||||
return Factory.NamedFunctionHandle(
|
||||
Factory.Token(atSign),
|
||||
Factory.IdentifierName(identifierName));
|
||||
compoundName);
|
||||
} else if (CurrentToken.Kind == TokenKind.OpeningBracket)
|
||||
{
|
||||
var inputs = ParseFunctionInputDescription();
|
||||
|
@ -323,6 +323,17 @@ namespace Parser
|
||||
return result;
|
||||
}
|
||||
|
||||
public CompoundNameNode CompoundName(List<SyntaxNode> nodes)
|
||||
{
|
||||
var result = new CompoundNameNode(
|
||||
nodes,
|
||||
nodes
|
||||
.OfType<IdentifierNameNode>()
|
||||
.ToList());
|
||||
SetParent(result);
|
||||
return result;
|
||||
}
|
||||
|
||||
public ArrayLiteralExpressionNode ArrayLiteralExpression(
|
||||
TokenNode openingSquareBracket,
|
||||
ArrayElementListNode elements,
|
||||
@ -544,17 +555,17 @@ namespace Parser
|
||||
|
||||
public NamedFunctionHandleNode NamedFunctionHandle(
|
||||
TokenNode atSign,
|
||||
IdentifierNameNode identifierName)
|
||||
CompoundNameNode functionName)
|
||||
{
|
||||
var children = new List<SyntaxNode>
|
||||
{
|
||||
atSign,
|
||||
identifierName
|
||||
functionName
|
||||
};
|
||||
var result = new NamedFunctionHandleNode(
|
||||
children,
|
||||
atSign,
|
||||
identifierName);
|
||||
functionName);
|
||||
SetParent(result);
|
||||
return result;
|
||||
}
|
||||
|
@ -451,6 +451,19 @@ namespace Parser
|
||||
|
||||
}
|
||||
|
||||
public class CompoundNameNode : ExpressionNode
|
||||
{
|
||||
public List<IdentifierNameNode> Names;
|
||||
|
||||
public CompoundNameNode(
|
||||
List<SyntaxNode> children,
|
||||
List<IdentifierNameNode> names
|
||||
) : base(children)
|
||||
{
|
||||
Names = names;
|
||||
}
|
||||
}
|
||||
|
||||
public class MemberAccessNode : ExpressionNode
|
||||
{
|
||||
public SyntaxNode LeftOperand { get; }
|
||||
@ -598,15 +611,15 @@ namespace Parser
|
||||
public class NamedFunctionHandleNode : FunctionHandleNode
|
||||
{
|
||||
public TokenNode AtSign { get; }
|
||||
public IdentifierNameNode IdentifierName { get; }
|
||||
public CompoundNameNode FunctionName { get; }
|
||||
|
||||
public NamedFunctionHandleNode(
|
||||
List<SyntaxNode> children,
|
||||
TokenNode atSign,
|
||||
IdentifierNameNode identifierName) : base(children)
|
||||
CompoundNameNode functionName) : base(children)
|
||||
{
|
||||
AtSign = atSign;
|
||||
IdentifierName = identifierName;
|
||||
FunctionName = functionName;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -11,7 +11,7 @@ namespace ProjectConsole
|
||||
class Program
|
||||
{
|
||||
//private const string BaseDirectory = @"C:\Program Files\MATLAB\R2018a\toolbox\matlab\";
|
||||
private const string BaseDirectory = @"/Applications/MATLAB_R2017b.app/toolbox/matlab/guide/";
|
||||
private const string BaseDirectory = @"/Applications/MATLAB_R2017b.app/toolbox/matlab/";
|
||||
|
||||
private static HashSet<string> skipFiles = new HashSet<string>
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user