protected virtual PrimitiveCallNode ParseApiCall(MethodNode parent, BinarySelectorToken token) { PrimitiveCallNode result = new PrimitiveCallNode(parent); List <IPrimitiveCallParameterToken> parameters = new List <IPrimitiveCallParameterToken>(); Token apiConvention = this.GetNextTokenxx(Preference.Default); if (!(apiConvention is KeywordToken)) { this.ReportParserError(result, SemanticErrors.MissingApiConvention, apiConvention); } while (true) { Token tkn = this.GetNextTokenxx(Preference.Default); if (tkn is IPrimitiveCallParameterToken) { parameters.Add((IPrimitiveCallParameterToken)tkn); } else if (Parser.IsApiClosingDelimiter(tkn)) { result.SetContents(token, tkn as BinarySelectorToken, apiConvention as KeywordToken, parameters); return(result); } else { this.ReportParserError(result, SemanticErrors.UnexpectedApiParameterToken, tkn); this.ResidueToken = tkn; result.SetContents(token, tkn as BinarySelectorToken, apiConvention as KeywordToken, parameters); return(result); } } }
public void Test_3_5_10_Selectors_B() { // An unadorned identifier is an identifier which is not immediately preceded by a '#'. // If a ':' followed by an '=' immediately follows an unadorned identifier, // with no intervening white space, then the token is to be parsed as an // identifier followed by an assignmentOperator not as an keyword followed by an '='. Scanner lexer = this.GetLexer("#isGood1Time:="); // Identifier token object obj = lexer.GetToken(); Assert.IsInstanceOfType(obj, typeof(QuotedSelectorToken)); QuotedSelectorToken token = (QuotedSelectorToken)obj; Assert.IsTrue(token.IsValid); Assert.IsNull(token.ScanError); Assert.AreEqual(0, token.StartPosition.Position); Assert.AreEqual(12, token.StopPosition.Position); Assert.AreEqual("isGood1Time:", token.Value); // Assignment token obj = lexer.GetToken(); Assert.IsInstanceOfType(obj, typeof(BinarySelectorToken)); BinarySelectorToken equals = (BinarySelectorToken)obj; Assert.IsTrue(equals.IsValid); Assert.IsNull(equals.ScanError); Assert.AreEqual(13, equals.StartPosition.Position); Assert.AreEqual(13, equals.StopPosition.Position); Assert.AreEqual("=", equals.Value); // Should be the last one obj = lexer.GetToken(); Assert.IsInstanceOfType(obj, typeof(EofToken)); }
/// <summary> /// Test if the token is closing delimiter for Primitive API call statement. /// This is IronSmalltalk extension to the grammar. /// </summary> /// <param name="token">Token to perform the test on.</param> /// <returns>True, if the test succeeds, otherwise false.</returns> public static bool IsApiClosingDelimiter(Token token) { BinarySelectorToken apitoken = token as BinarySelectorToken; if (apitoken == null) { return(false); } return((apitoken.Value == SemanticConstants.PrimitiveClosingDelimiter) || (apitoken.Value == SemanticConstants.AlternativePrimitiveClosingDelimiter)); }
/// <summary> /// Create a new binary message node. /// </summary> /// <param name="parent">The parent message sequence node that defines this message node.</param> /// <param name="token">Token containing the message selector.</param> protected internal BinaryMessageNode(MessageSequenceBase parent, BinarySelectorToken token) : base(parent) { #if DEBUG if (token == null) { throw new ArgumentNullException("token"); } #endif this.SelectorToken = token; }
// Initializes the node after being parsed by the parser. protected internal void SetContents(BinarySelectorToken openingDelimiter, BinarySelectorToken closingDelimiter, KeywordToken apiConvention, IEnumerable <IPrimitiveCallParameterToken> parameters) { this.OpeningDelimiter = openingDelimiter; this.ClosingDelimiter = closingDelimiter; this.ApiConvention = apiConvention; this.ApiParameters.Clear(); foreach (IPrimitiveCallParameterToken param in parameters) { this.ApiParameters.Add(param); } }
public void Test_3_5_5_Operators_B() { Scanner lexer = this.GetLexer("~="); object obj = lexer.GetToken(); Assert.IsInstanceOfType(obj, typeof(BinarySelectorToken)); BinarySelectorToken token = (BinarySelectorToken)obj; Assert.IsTrue(token.IsValid); Assert.IsNull(token.ScanError); Assert.AreEqual(0, token.StartPosition.Position); Assert.AreEqual(1, token.StopPosition.Position); Assert.AreEqual("~=", token.Value); // Should be the last one obj = lexer.GetToken(); Assert.IsInstanceOfType(obj, typeof(EofToken)); }
protected virtual BinaryMessageSequenceNode ParseBinaryMessageSequence(IMessageSequenceParentNode parent, BinarySelectorToken selector) { // PARSE: <binary message>* BinaryMessageSequenceNode result = new BinaryMessageSequenceNode(parent); // NB: ParseBinaryMessage() cannot fail, so we don't check result BinaryMessageNode message = this.ParseBinaryMessage(result, selector); Token token = this.GetNextTokenxx(Preference.Default); BinaryMessageSequenceNode nextMessage = null; if (token is BinarySelectorToken) { nextMessage = this.ParseBinaryMessageSequence(result, (BinarySelectorToken)token); } else { this.ResidueToken = token; } result.SetContents(message, nextMessage); return(result); }
protected virtual BinaryMessageNode ParseBinaryMessage(MessageSequenceBase parent, BinarySelectorToken selector) { // PARSE: <binary message> ::= binarySelector <binary argument> BinaryMessageNode result = new BinaryMessageNode(parent, selector); Token token = this.GetNextTokenxx(Preference.NegativeSign); // Parse the binary argument ... ParseBinaryArgument() does not fail and reports errors self. BinaryArgumentNode argument = this.ParseBinaryArgument(result, token); if (argument != null) { result.SetContents(argument); } return(result); }
protected virtual BinaryKeywordMessageSequenceNode ParseBinaryKeywordMessageSequence(IMessageSequenceParentNode parent, BinarySelectorToken selector) { // PARSE: <binary message>+ [<keyword message>] BinaryKeywordMessageSequenceNode result = new BinaryKeywordMessageSequenceNode(parent); // NB: ParseBinaryMessage() cannot fail, so we don't check result BinaryMessageNode message = this.ParseBinaryMessage(result, selector); Token token = this.GetNextTokenxx(Preference.Default); BinaryKeywordOrKeywordMessageSequenceNode nextMessage = (BinaryKeywordOrKeywordMessageSequenceNode) this.ParseMessages(result, token, MessageType.Binary | MessageType.Keyword); result.SetContents(message, nextMessage); return(result); }