id() (M Functions)
[This content is no longer valid. For the latest information on "M", "Quadrant", SQL Server Modeling Services, and the Repository, see the Model Citizen blog.]
This function sets the identity/name of the projection of a syntax term at parse time.
id( variable reference )
id( literal )
Parameters
In the first syntax option, the variable reference is a variable that has been bound to a text literal.
In the second syntax option, the literal can be an arbitrary string, which can contain spaces and other characters not valid in a Microsoft code name “M” identifier.
Property Value/Return Value
A text string is returned that functions as a label on an output node.
Code Samples
The simplified language used in these examples recognizes 2 to 4 instances of the literal "X". In all the examples, it is assumed that the input to the parser is the string "XX".
The following code defines the grammar for the language, without using the id function.
module test
{
language something
{
syntax Main = a:A => a[];
token A = 'X'#2..4;
}
}
This code returns the following output, when the string "XX" is input.
a[
]
Example
The following code examples illustrate the first syntax.
In the Main
syntax rule, replace the projection "a[]" with "id(a)[]", as shown in the following code.
module test
{
language something
{
syntax Main = a:A => id(a)[];
token A = 'X'#2..4;
}
}
The output now becomes the value of the A
token that was encountered in parsing the input.
XX[
]
The second syntax option allows you to project a label that is not a valid “M” identifier. The following code is an example.
module test
{
language something
{
syntax Main = a:A => id(29)[];
token A = 'X'#2..4;
}
}
This generates the following output.
@[29][
]