運算式文法
Note
Microsoft Power Fx 是畫布應用程式語言的新名稱。 當我們從畫布應用程式中擷取語言,將其與其他 Microsoft Power Platform 產品整合並打造開放原始碼時,這些文章仍會持續進行。 從 Microsoft Power Fx 概覽開始以取得對該語言的介紹。
Microsoft Power Fx根據繫結運算式名稱的公式。 就像在 Excel 工作表中一樣,隨著對運算式的入站相依性變更,將重新計算運算式,且名稱的值也會變更,可能會將重新計算級聯爲其他公式。
該文法涵蓋公式的運算式部分。 繫結至名稱以建立公式取決於 Power Fx 的整合方式。 在工作表中,未揭露繫結語法,而是由運算式的編寫位置隱含,例如:在 A1 格輸入 =B1
。 某些情況根本不需要繫結,Power Fx 會做為運算式評估工具使用,例如,位於支援資料庫資料表的計算結果欄中。 對於 Power Apps,在 Power Apps Studio 中透過可在 Power Apps Studio 外部使用的 YAML 序列化格式隱含繫結。
文法慣例
語彙和語法文法會使用「文法生產」來呈現。 每個文法生產都會將非終端符號及該非終端符號的可能擴充定義於非終端或終端符號序列中。 在文法生產中,非終端符號會以斜體樣式顯示,而「終端」符號會以固定寬度的字型顯示。
文法生產的第一行是所要定義非終端符號名稱,後面接著冒號。 每個後續的縮排行,都包含語法的可能擴充,並以非終端或終端符號序列的形式提供。 例如,生產:
GlobalIdentifier:
[@
Identifier]
定義 GlobalIdentifier,其由代用文字[@
,加上識別碼,加上代用文字]
組成。
當非終端符號有多個可能的擴充時,替代項目會列於個別的行上。 下標 "opt" 用於表示選擇性符號。 例如,生產:
FunctionCall:
FunctionIdentifier(
FunctionArgumentsopt)
是下列的簡略版:
FunctionCall:
FunctionIdentifier(
)
FunctionIdentifier(
FunctionArguments)
替代項目通常會列在個別行上,但在有許多替代項目的情況下,片語 "one of" 可能會位於單一行上指定的擴充清單前面。 這是在個別行上列出每個替代項目的簡略版。
例如,生產:
DecimalDigit:之一
0
1
2
3
4
5
6
7
8
9
是下列的簡略版:
DecimalDigit:
0
1
2
3
4
5
6
7
8
9
語彙分析
lexical-unit 生產會定義 Power Fx 運算式的語彙文法。 每個有效的 Power Fx 運算式都符合這個文法。
ExpressionUnit:
ExpressionElementsopt
ExpressionElements:
ExpressionElement
ExpressionElementExpressionElementsopt
ExpressionElement:
Whitespace
Comment
在語彙層級,Power Fx 運算式是由 Whitespace、Comment 和 Token 項目的串流組成。 下列章節將討論這些生產。 只有 Token 項目在語法文法中是重要的。
空格
空白用來分隔 Power Apps 文件內的註解和代用文字。
Whitespace:
任何 Unicode 空格分隔符號 (Zs 類別)
任何 Unicode 行分隔符號 (Zl 類別)
任何 Unicode 段落分隔符號 (Zp 類別)
水平定位字元 (U+0009)
換行字元 (U+000A)
垂直定位字元 (U+000B)
換頁字元 (U+000C)
歸位字元 (U+000D)
新行字元 (U+0085)
註解
支援兩種形式的註解:
- 「單行註解」以
//
字元開頭,並延伸至來源行的結尾。 - 「分隔註解」以
/*
字元開頭,並以*/
字元結尾。 分隔註解可能會跨越多行。
Comment:
DelimitedComment
SingleLineComment
SingleLineComment:
//
SingleLineCommentCharactersopt
SingleLineCommentCharacters:
SingleLineCommentCharacter
SingleLineCommentCharacterSingleLineCommentCharactersopt
SingleLineCommentCharacter:
除 NewLineCharacter 之外的任何 Unicode 字元
DelimitedComment:
/*
DelimitedCommentCharactersopt*/
DelimitedCommentCharacters:
DelimitedCommentCharactersNoAsteriskDelimitedCommentCharactersopt
*
DelimitedCommentAfterAsteriskCharacters
DelimitedCommentAfterAsteriskCharacters:
DelimitedCommentNoSlashAsteriskCharacterDelimitedCommentCharactersopt
*
DelimitedCommentAfterAsteriskCharacters
DelimitedCommentCharactersNoAsterisk:
除 * (星號) 外的任何 Unicode
DelimitedCommentNoSlashAsteriskCharacter:
除 / (正斜線) 或 * (星號) 外的任何 Unicode 字元
註解不會巢狀化。 /*
和 */
的字元序列在單行註解內不具特殊意義,且 //
和 /*
的字元序列在分隔註解內不具特殊意義。
註解不會在文字字串內處理。
下面範例包含兩個分隔註解:
/* Hello, world
*/
"Hello, world" /* This is an example of a text literal */
以下範例包含三個單行註解:
// Hello, world
//
"Hello, world" // This is an example of a text literal
常值
「常值」是值的原始程式碼表示法。
Literal:
LogicalLiteral
NumberLiteral
TextLiteral
邏輯常值
邏輯常值用來撰寫 true 和 false 值並產生邏輯值。
數字常值
數字常值用來撰寫數值,並產生數字值。
NumberLiteral:
DecimalDigitsExponentPartopt
DecimalDigitsDecimalSeparatorDecimalDigitsoptExponentPartopt
DecimalSeparatorDecimalDigitsExponentPartopt
DecimalDigits:
DecimalDigit
DecimalDigitsDecimalDigit
DecimalDigit:之一
0
1
2
3
4
5
6
7
8
9
ExponentPart:
ExponentIndicatorSignoptDecimalDigits
文字常值
文字常值用來撰寫 Unicode 字元序列並產生文字值。 文字常值必須以雙引號括住。 若在文字值中包含雙引號,請重複雙引號,如以下範例所示:
"The ""quoted"" text" // The "quoted" text
TextLiteral:
"
TextLiteralCharactersopt"
TextLiteralCharacters:
TextLiteralCharacterTextLiteralCharactersopt
TextLiteralCharacter:
TextCharacterNoDoubleQuote
DoubleQuoteEscapeSequence
TextCharacterNoDoubleQuote:
除雙引號外的任何 Unicode 字碼指標
DoubleQuoteEscapeSequence:
"
"
Identifiers
「識別碼」是用來參考值的名稱。 識別碼可以是標準識別碼或單引號識別碼。
Identifier:
IdentifierName但不是 Operator 或 ContextKeyword
IdentifierName:
IdentifierStartCharacterIdentifierContinueCharactersopt
'
SingleQuotedIdentifier'
IdentifierStartCharacter:
LetterCharacter
_
IdentifierContinueCharacter:
IdentifierStartCharacter
DecimalDigitCharacter
ConnectingCharacter
CombiningCharacter
FormattingCharacter
IdentifierContinueCharacters:
IdentifierContinueCharacterIdentifierContinueCharactersopt
LetterCharacter:
大寫字母 (Lu) 或小寫字母 (Ll) 類別的任何 Unicode 字元
字首大寫字母 (Lt) 類別的任何 Unicode 字元
此類別的任何 Unicode 字元字母修改器 (Lm) 或其他字母 (Lo)
數字字母 (NI) 類別的任何 Unicode 字元
CombiningCharacter:
此類別的任何 Unicode 字元非空格標示 (Mn) 或結合空格的標示 (Mc)
DecimalDigitCharacter:
十進位數字 (Nd) 類別的任何 Unicode 字元
ConnectingCharacter:
連接器標點符號 (Pc) 類別的任何 Unicode 字元
FormattingCharacter:
格式 (Cf) 類別的任何 Unicode 字元
單引號識別碼
單引號識別碼可包含任何 Unicode 字元序列作為識別碼使用,包括關鍵字、空白、註解和運算子。 單引號字元支援兩個單引號的跳脫序列。
SingleQuotedIdentifier:
SingleQuotedIdentifierCharacters
SingleQuotedIdentifierCharacters:
SingleQuotedIdentifierCharacterSingleQuotedIdentifierCharactersopt
SingleQuotedIdentifierCharacter:
TextCharactersNoSingleQuote
SingleQuoteEscapeSequence
TextCharactersNoSingleQuote:
除 ' (U+0027) 外的任何 Unicode 字元
SingleQuoteEscapeSequence:
'
'
釐清識別碼
DisambiguatedIdentifier:
TableColumnIdentifier
GlobalIdentifier
TableColumnIdentifier:
Identifier[@
Identifier]
GlobalIdentifier:
[@
Identifier]
內容關鍵字
ContextKeyword:
Parent
Self
ThisItem
ThisRecord
區分大小寫
Power Apps 識別碼會區分大小寫。 編寫公式時,製作工具將自動將它們更改為正確的大小寫。
分隔符號
DecimalSeparator:
.
(點號) 用於使用點號做為十進位數字分隔符號的語言,例如 1.23
,
(逗號) 用於使用逗號做為十進位數字分隔符號的語言,例如 1,23
ListSeparator:
,
(逗號),如果 DecimalSeparator 為 .
(點號)
;
(分號) 如果 DecimalSeparator 是 ,
(逗號)
ChainingSeparator:
;
(分號) 如果 DecimalSeparator 是 .
(點號)
;;
(雙分號) 如果 DecimalSeparator 是 ,
(逗號)
Operators
運算子會在公式中用來描述涉及一或多個運算元的作業。 例如,a + b
運算式會使用 +
運算子,將 a
和 b
兩個運算元相加。
運算子:
BinaryOperator
BinaryOperatorRequiresWhitespace
PrefixOperator
PrefixOperatorRequiresWhitespace
PostfixOperator
BinaryOperator:之一
=
<
<=
>
>=
<>
+
-
*
/
^
&
&&
||
in
exactin
BinaryOperatorRequiresWhitespace:
And
Whitespace
Or
Whitespace
PrefixOperatorRequiresWhitespace:
Not
Whitespace
參考運算子
物件參考
參考:
BaseReference
BaseReferenceReferenceOperatorReferenceList
BaseReference:
Identifier
DisambiguatedIdentifier
ContextKeyword
ReferenceList:
Identifier
IdentifierReferenceOperatorReferenceList
內嵌記錄
InlineRecord:
{
InlineRecordListopt}
InlineRecordList:
Identifier:
Expression
Identifier:
ExpressionListSeparatorInlineRecordList
內嵌資料表
InlineTable:
[
InlineTableListopt]
InlineTableList:
Expression
ExpressionListSeparatorInlineTableList
Expression
Expression:
常值
參考
InlineRecord
InlineTable
FunctionCall
(
Expression)
PrefixOperatorExpression
ExpressionPostfixOperator
ExpressionBinaryOperatorExpression
鏈結運算式
ChainedExpression:
Expression
ExpressionChainingSeparatorChainedExpressionopt
公式呼叫
FunctionCall:
FunctionIdentifier(
FunctionArgumentsopt)
FunctionIdentifier:
Identifier
Identifier.
FunctionIdentifier
FunctionArguments:
ChainedExpression
ChainedExpressionListSeparatorFunctionArguments
意見反應
https://aka.ms/ContentUserFeedback。
即將登場:在 2024 年,我們將逐步淘汰 GitHub 問題作為內容的意見反應機制,並將它取代為新的意見反應系統。 如需詳細資訊,請參閱:提交並檢視相關的意見反應