summaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authordpranke <dpranke@chromium.org>2015-04-24 15:24:49 -0700
committerCommit bot <commit-bot@chromium.org>2015-04-24 22:26:10 +0000
commite7678ebda44587a7855835700aeeb9ccc846a1d9 (patch)
tree706e18ddb866dabb8516df3a183d1fcfd3df8568 /tools
parent34ffe6a14d04517f955053850046dbe4dcffebee (diff)
downloadchromium_src-e7678ebda44587a7855835700aeeb9ccc846a1d9.zip
chromium_src-e7678ebda44587a7855835700aeeb9ccc846a1d9.tar.gz
chromium_src-e7678ebda44587a7855835700aeeb9ccc846a1d9.tar.bz2
Add 'gn help grammar' contents to 'gn help all'.
R=mdempsky@chromium.org BUG=468851 Review URL: https://codereview.chromium.org/1106003002 Cr-Commit-Position: refs/heads/master@{#326905}
Diffstat (limited to 'tools')
-rw-r--r--tools/gn/command_help.cc1
-rw-r--r--tools/gn/docs/reference.md125
2 files changed, 126 insertions, 0 deletions
diff --git a/tools/gn/command_help.cc b/tools/gn/command_help.cc
index 7679b17..fc4e4e1 100644
--- a/tools/gn/command_help.cc
+++ b/tools/gn/command_help.cc
@@ -120,6 +120,7 @@ void PrintAllHelp() {
PrintLongHelp(kBuildArgs_Help);
PrintLongHelp(kDotfile_Help);
+ PrintLongHelp(kGrammar_Help);
PrintLongHelp(kInputConversion_Help);
PrintLongHelp(kLabelPattern_Help);
PrintLongHelp(kSourceExpansion_Help);
diff --git a/tools/gn/docs/reference.md b/tools/gn/docs/reference.md
index a405a34..5df04a6 100644
--- a/tools/gn/docs/reference.md
+++ b/tools/gn/docs/reference.md
@@ -4073,6 +4073,131 @@
```
+## **GN build language grammar**
+
+### **Tokens**
+
+```
+ GN build files are read as sequences of tokens. While splitting the
+ file into tokens, the next token is the longest sequence of characters
+ that form a valid token.
+
+```
+
+### **White space and comments**
+
+```
+ White space is comprised of spaces (U+0020), horizontal tabs (U+0009),
+ carriage returns (U+000D), and newlines (U+000A).
+
+ Comments start at the character "#" and stop at the next newline.
+
+ White space and comments are ignored except that they may separate
+ tokens that would otherwise combine into a single token.
+
+```
+
+### **Identifiers**
+
+```
+ Identifiers name variables and functions.
+
+ identifier = letter { letter | digit } .
+ letter = "A" ... "Z" | "a" ... "z" | "_" .
+ digit = "0" ... "9" .
+
+```
+
+### **Keywords**
+
+```
+ The following keywords are reserved and may not be used as
+ identifiers:
+
+ else false if true
+
+```
+
+### **Integer literals**
+
+```
+ An integer literal represents a decimal integer value.
+
+ integer = [ "-" ] digit { digit } .
+
+ Leading zeros and negative zero are disallowed.
+
+```
+
+### **String literals**
+
+```
+ A string literal represents a string value consisting of the quoted
+ characters with possible escape sequences and variable expansions.
+
+ string = `"` { char | escape | expansion } `"` .
+ escape = `\` ( "$" | `"` | char ) .
+ expansion = "$" ( identifier | "{" identifier "}" ) .
+ char = /* any character except "$", `"`, or newline */ .
+
+ After a backslash, certain sequences represent special characters:
+
+ \" U+0022 quotation mark
+ \$ U+0024 dollar sign
+ \\ U+005C backslash
+
+ All other backslashes represent themselves.
+
+```
+
+### **Punctuation**
+
+```
+ The following character sequences represent punctuation:
+
+ + += == != ( )
+ - -= < <= [ ]
+ ! = > >= { }
+ && || . ,
+
+```
+
+### **Grammar**
+
+```
+ The input tokens form a syntax tree following a context-free grammar:
+
+ File = StatementList .
+
+ Statement = Assignment | Call | Condition .
+ Assignment = identifier AssignOp Expr .
+ Call = identifier "(" [ ExprList ] ")" [ Block ] .
+ Condition = "if" "(" Expr ")" Block
+ [ "else" ( Condition | Block ) ] .
+ Block = "{" StatementList "}" .
+ StatementList = { Statement } .
+
+ Expr = UnaryExpr | Expr BinaryOp Expr .
+ UnaryExpr = PrimaryExpr | UnaryOp UnaryExpr .
+ PrimaryExpr = identifier | integer | string | Call
+ | identifier "[" Expr "]"
+ | identifier "." identifier
+ | "(" Expr ")"
+ | "[" [ ExprList [ "," ] ] "]" .
+ ExprList = Expr { "," Expr } .
+
+ AssignOp = "=" | "+=" | "-=" .
+ UnaryOp = "!" .
+ BinaryOp = "+" | "-" // highest priority
+ | "<" | "<=" | ">" | ">="
+ | "==" | "!="
+ | "&&"
+ | "||" . // lowest priority
+
+ All binary operators are left-associative.
+
+
+```
## **input_conversion**: Specifies how to transform input to a variable.
```