peg.ebnf: fix a couple of typos in docs

db4
Keita Haga 2011-01-15 01:11:37 +09:00
parent 72d91eea8d
commit 0048670ad7
1 changed files with 42 additions and 42 deletions

View File

@ -1,19 +1,19 @@
! Copyright (C) 2009 Chris Double. ! Copyright (C) 2009 Chris Double.
! See http://factorcode.org/license.txt for BSD license. ! See http://factorcode.org/license.txt for BSD license.
USING: help.syntax help.markup peg peg.search ; USING: help.syntax help.markup peg peg.search ;
IN: peg.ebnf IN: peg.ebnf
HELP: <EBNF HELP: <EBNF
{ $syntax "<EBNF ...ebnf... EBNF>" } { $syntax "<EBNF ...ebnf... EBNF>" }
{ $values { "...ebnf..." "EBNF DSL text" } } { $values { "...ebnf..." "EBNF DSL text" } }
{ $description { $description
"Creates a " { $vocab-link "peg" } "Creates a " { $vocab-link "peg" }
" object that parses a string using the syntax " " object that parses a string using the syntax "
"defined with the EBNF DSL. The peg object can be run using the " { $link parse } "defined with the EBNF DSL. The peg object can be run using the " { $link parse }
" word and can be used with the " { $link search } " and " { $link replace } " words." " word and can be used with the " { $link search } " and " { $link replace } " words."
} }
{ $examples { $examples
{ $example { $example
"USING: kernel prettyprint peg.ebnf peg.search ;" "USING: kernel prettyprint peg.ebnf peg.search ;"
"\"abcdab\" <EBNF rule=\"a\" \"b\" => [[ drop \"foo\" ]] EBNF> replace ." "\"abcdab\" <EBNF rule=\"a\" \"b\" => [[ drop \"foo\" ]] EBNF> replace ."
"\"foocdfoo\"" "\"foocdfoo\""
@ -23,15 +23,15 @@ HELP: <EBNF
HELP: [EBNF HELP: [EBNF
{ $syntax "[EBNF ...ebnf... EBNF]" } { $syntax "[EBNF ...ebnf... EBNF]" }
{ $values { "...ebnf..." "EBNF DSL text" } } { $values { "...ebnf..." "EBNF DSL text" } }
{ $description { $description
"Creates and calls a quotation that parses a string using the syntax " "Creates and calls a quotation that parses a string using the syntax "
"defined with the EBNF DSL. The quotation has stack effect " "defined with the EBNF DSL. The quotation has stack effect "
{ $snippet "( string -- ast )" } " where 'string' is the text to be parsed " { $snippet "( string -- ast )" } " where 'string' is the text to be parsed "
"and 'ast' is the resulting abstract syntax tree. If the parsing fails the " "and 'ast' is the resulting abstract syntax tree. If the parsing fails the "
"quotation throws an exception." "quotation throws an exception."
} }
{ $examples { $examples
{ $example { $example
"USING: prettyprint peg.ebnf ;" "USING: prettyprint peg.ebnf ;"
"\"ab\" [EBNF rule=\"a\" \"b\" EBNF] ." "\"ab\" [EBNF rule=\"a\" \"b\" EBNF] ."
"V{ \"a\" \"b\" }" "V{ \"a\" \"b\" }"
@ -41,15 +41,15 @@ HELP: [EBNF
HELP: EBNF: HELP: EBNF:
{ $syntax "EBNF: word ...ebnf... ;EBNF" } { $syntax "EBNF: word ...ebnf... ;EBNF" }
{ $values { "word" "a word" } { "...ebnf..." "EBNF DSL text" } } { $values { "word" "a word" } { "...ebnf..." "EBNF DSL text" } }
{ $description { $description
"Defines a word that when called will parse a string using the syntax " "Defines a word that when called will parse a string using the syntax "
"defined with the EBNF DSL. The word has stack effect " "defined with the EBNF DSL. The word has stack effect "
{ $snippet "( string -- ast )" } " where 'string' is the text to be parsed " { $snippet "( string -- ast )" } " where 'string' is the text to be parsed "
"and 'ast' is the resulting abstract syntax tree. If the parsing fails the " "and 'ast' is the resulting abstract syntax tree. If the parsing fails the "
"word throws an exception." "word throws an exception."
} }
{ $examples { $examples
{ $example { $example
"USING: prettyprint peg.ebnf ;" "USING: prettyprint peg.ebnf ;"
"IN: scratchpad" "IN: scratchpad"
"EBNF: foo rule=\"a\" \"b\" ;EBNF" "EBNF: foo rule=\"a\" \"b\" ;EBNF"
@ -62,7 +62,7 @@ ARTICLE: "peg.ebnf.strings" "Strings"
"A string in a rule will match that sequence of characters from the input string. " "A string in a rule will match that sequence of characters from the input string. "
"The AST result from the match is the string itself." "The AST result from the match is the string itself."
{ $examples { $examples
{ $example { $example
"USING: prettyprint peg.ebnf ;" "USING: prettyprint peg.ebnf ;"
"\"helloworld\" [EBNF rule=\"hello\" \"world\" EBNF] ." "\"helloworld\" [EBNF rule=\"hello\" \"world\" EBNF] ."
"V{ \"hello\" \"world\" }" "V{ \"hello\" \"world\" }"
@ -73,7 +73,7 @@ ARTICLE: "peg.ebnf.any" "Any"
"A full stop character (.) will match any single token in the input string. " "A full stop character (.) will match any single token in the input string. "
"The AST resulting from this is the token itself." "The AST resulting from this is the token itself."
{ $examples { $examples
{ $example { $example
"USING: prettyprint peg.ebnf ;" "USING: prettyprint peg.ebnf ;"
"\"abc\" [EBNF rule=\"a\" . \"c\" EBNF] ." "\"abc\" [EBNF rule=\"a\" . \"c\" EBNF] ."
"V{ \"a\" 98 \"c\" }" "V{ \"a\" 98 \"c\" }"
@ -86,12 +86,12 @@ ARTICLE: "peg.ebnf.sequence" "Sequence"
"goes. The AST result is a vector containing the results of each rule element in " "goes. The AST result is a vector containing the results of each rule element in "
"the sequence." "the sequence."
{ $examples { $examples
{ $example { $example
"USING: prettyprint peg.ebnf ;" "USING: prettyprint peg.ebnf ;"
"\"abbba\" [EBNF rule=\"a\" (\"b\")* \"a\" EBNF] ." "\"abbba\" [EBNF rule=\"a\" (\"b\")* \"a\" EBNF] ."
"V{ \"a\" V{ \"b\" \"b\" \"b\" } \"a\" }" "V{ \"a\" V{ \"b\" \"b\" \"b\" } \"a\" }"
} }
} }
; ;
ARTICLE: "peg.ebnf.choice" "Choice" ARTICLE: "peg.ebnf.choice" "Choice"
@ -99,7 +99,7 @@ ARTICLE: "peg.ebnf.choice" "Choice"
"are matched against the input stream in order. If a match succeeds then the remaining " "are matched against the input stream in order. If a match succeeds then the remaining "
"choices are discarded and the result of the match is the AST result of the choice." "choices are discarded and the result of the match is the AST result of the choice."
{ $examples { $examples
{ $example { $example
"USING: prettyprint peg.ebnf ;" "USING: prettyprint peg.ebnf ;"
"\"a\" [EBNF rule=\"a\" | \"b\" | \"c\" EBNF] ." "\"a\" [EBNF rule=\"a\" | \"b\" | \"c\" EBNF] ."
"\"a\"" "\"a\""
@ -114,15 +114,15 @@ ARTICLE: "peg.ebnf.choice" "Choice"
"\"d\" [EBNF rule=\"a\" | \"b\" | \"c\" EBNF] ." "\"d\" [EBNF rule=\"a\" | \"b\" | \"c\" EBNF] ."
"Peg parsing error at character position 0.\nExpected token 'c' or token 'b' or token 'a'" "Peg parsing error at character position 0.\nExpected token 'c' or token 'b' or token 'a'"
} }
} }
; ;
ARTICLE: "peg.ebnf.option" "Option" ARTICLE: "peg.ebnf.option" "Option"
"Any rule element followed by a question mark (?) is considered optional. The " "Any rule element followed by a question mark (?) is considered optional. The "
"rule is tested against the input. If it succeeds the result is stored in the AST. " "rule is tested against the input. If it succeeds the result is stored in the AST. "
"If it fails then the parse still suceeds and false (f) is stored in the AST." "If it fails then the parse still succeeds and false (f) is stored in the AST."
{ $examples { $examples
{ $example { $example
"USING: prettyprint peg.ebnf ;" "USING: prettyprint peg.ebnf ;"
"\"abc\" [EBNF rule=\"a\" \"b\"? \"c\" EBNF] ." "\"abc\" [EBNF rule=\"a\" \"b\"? \"c\" EBNF] ."
"V{ \"a\" \"b\" \"c\" }" "V{ \"a\" \"b\" \"c\" }"
@ -132,7 +132,7 @@ ARTICLE: "peg.ebnf.option" "Option"
"\"ac\" [EBNF rule=\"a\" \"b\"? \"c\" EBNF] ." "\"ac\" [EBNF rule=\"a\" \"b\"? \"c\" EBNF] ."
"V{ \"a\" f \"c\" }" "V{ \"a\" f \"c\" }"
} }
} }
; ;
ARTICLE: "peg.ebnf.character-class" "Character Class" ARTICLE: "peg.ebnf.character-class" "Character Class"
@ -143,12 +143,12 @@ ARTICLE: "peg.ebnf.character-class" "Character Class"
"The AST resulting from the match is an integer of the character code for the " "The AST resulting from the match is an integer of the character code for the "
"character that matched." "character that matched."
{ $examples { $examples
{ $example { $example
"USING: prettyprint peg.ebnf ;" "USING: prettyprint peg.ebnf ;"
"\"123\" [EBNF rule=[0-9]+ EBNF] ." "\"123\" [EBNF rule=[0-9]+ EBNF] ."
"V{ 49 50 51 }" "V{ 49 50 51 }"
} }
} }
; ;
ARTICLE: "peg.ebnf.one-or-more" "One or more" ARTICLE: "peg.ebnf.one-or-more" "One or more"
@ -156,12 +156,12 @@ ARTICLE: "peg.ebnf.one-or-more" "One or more"
"from the input string. The AST result is the vector of the AST results from " "from the input string. The AST result is the vector of the AST results from "
"the matched rule." "the matched rule."
{ $examples { $examples
{ $example { $example
"USING: prettyprint peg.ebnf ;" "USING: prettyprint peg.ebnf ;"
"\"aab\" [EBNF rule=\"a\"+ \"b\" EBNF] ." "\"aab\" [EBNF rule=\"a\"+ \"b\" EBNF] ."
"V{ V{ \"a\" \"a\" } \"b\" }" "V{ V{ \"a\" \"a\" } \"b\" }"
} }
} }
; ;
ARTICLE: "peg.ebnf.zero-or-more" "Zero or more" ARTICLE: "peg.ebnf.zero-or-more" "Zero or more"
@ -169,7 +169,7 @@ ARTICLE: "peg.ebnf.zero-or-more" "Zero or more"
"from the input string. The AST result is the vector of the AST results from " "from the input string. The AST result is the vector of the AST results from "
"the matched rule. This will be empty if there are no matches." "the matched rule. This will be empty if there are no matches."
{ $examples { $examples
{ $example { $example
"USING: prettyprint peg.ebnf ;" "USING: prettyprint peg.ebnf ;"
"\"aab\" [EBNF rule=\"a\"* \"b\" EBNF] ." "\"aab\" [EBNF rule=\"a\"* \"b\" EBNF] ."
"V{ V{ \"a\" \"a\" } \"b\" }" "V{ V{ \"a\" \"a\" } \"b\" }"
@ -179,7 +179,7 @@ ARTICLE: "peg.ebnf.zero-or-more" "Zero or more"
"\"b\" [EBNF rule=\"a\"* \"b\" EBNF] ." "\"b\" [EBNF rule=\"a\"* \"b\" EBNF] ."
"V{ V{ } \"b\" }" "V{ V{ } \"b\" }"
} }
} }
; ;
ARTICLE: "peg.ebnf.and" "And" ARTICLE: "peg.ebnf.and" "And"
@ -190,12 +190,12 @@ ARTICLE: "peg.ebnf.and" "And"
"does not leave any result in the AST. This can be used for lookahead and " "does not leave any result in the AST. This can be used for lookahead and "
"disambiguation in choices." "disambiguation in choices."
{ $examples { $examples
{ $example { $example
"USING: prettyprint peg.ebnf ;" "USING: prettyprint peg.ebnf ;"
"\"ab\" [EBNF rule=&(\"a\") \"a\" \"b\" EBNF] ." "\"ab\" [EBNF rule=&(\"a\") \"a\" \"b\" EBNF] ."
"V{ \"a\" \"b\" }" "V{ \"a\" \"b\" }"
} }
} }
; ;
ARTICLE: "peg.ebnf.not" "Not" ARTICLE: "peg.ebnf.not" "Not"
@ -206,20 +206,20 @@ ARTICLE: "peg.ebnf.not" "Not"
"however and does not leave any result in the AST. This can be used for lookahead and " "however and does not leave any result in the AST. This can be used for lookahead and "
"disambiguation in choices." "disambiguation in choices."
{ $examples { $examples
{ $example { $example
"USING: prettyprint peg.ebnf ;" "USING: prettyprint peg.ebnf ;"
"\"<abcd>\" [EBNF rule=\"<\" (!(\">\") .)* \">\" EBNF] ." "\"<abcd>\" [EBNF rule=\"<\" (!(\">\") .)* \">\" EBNF] ."
"V{ \"<\" V{ 97 98 99 100 } \">\" }" "V{ \"<\" V{ 97 98 99 100 } \">\" }"
} }
} }
; ;
ARTICLE: "peg.ebnf.action" "Action" ARTICLE: "peg.ebnf.action" "Action"
"An action is a quotation that is run after a rule matches. The quotation " "An action is a quotation that is run after a rule matches. The quotation "
"consumes the AST of the rule match and leaves a new AST as the result. " "consumes the AST of the rule match and leaves a new AST as the result. "
"The stack effect of the action can be " { $snippet "( ast -- ast )" } " or " "The stack effect of the action can be " { $snippet "( ast -- ast )" } " or "
{ $snippet "( -- ast )" } ". " { $snippet "( -- ast )" } ". "
"If it is the latter then the original AST is implcitly dropped and will be " "If it is the latter then the original AST is implicitly dropped and will be "
"replaced by the AST left on the stack. This is mostly useful if variables are " "replaced by the AST left on the stack. This is mostly useful if variables are "
"used in the rule since they can be referenced like locals in the action quotation. " "used in the rule since they can be referenced like locals in the action quotation. "
"The action is defined by having a ' => ' at the end of a rule and " "The action is defined by having a ' => ' at the end of a rule and "
@ -227,7 +227,7 @@ ARTICLE: "peg.ebnf.action" "Action"
"If an action leaves the object 'ignore' on the stack then the result of that " "If an action leaves the object 'ignore' on the stack then the result of that "
"action will not be put in the AST of the result." "action will not be put in the AST of the result."
{ $examples { $examples
{ $example { $example
"USING: prettyprint peg.ebnf strings ;" "USING: prettyprint peg.ebnf strings ;"
"\"<abcd>\" [EBNF rule=\"<\" ((!(\">\") .)* => [[ >string ]]) \">\" EBNF] ." "\"<abcd>\" [EBNF rule=\"<\" ((!(\">\") .)* => [[ >string ]]) \">\" EBNF] ."
"V{ \"<\" \"abcd\" \">\" }" "V{ \"<\" \"abcd\" \">\" }"
@ -237,17 +237,17 @@ ARTICLE: "peg.ebnf.action" "Action"
"\"123\" [EBNF rule=[0-9]+ => [[ string>number ]] EBNF] ." "\"123\" [EBNF rule=[0-9]+ => [[ string>number ]] EBNF] ."
"123" "123"
} }
} }
; ;
ARTICLE: "peg.ebnf.semantic-action" "Semantic Action" ARTICLE: "peg.ebnf.semantic-action" "Semantic Action"
"Semantic actions allow providing a quotation that gets run on the AST of a " "Semantic actions allow providing a quotation that gets run on the AST of a "
"matched rule that returns success or failure. The result of the parse is decided by " "matched rule that returns success or failure. The result of the parse is decided by "
"the result of the semantic action. The stack effect for the quotation is " "the result of the semantic action. The stack effect for the quotation is "
{ $snippet ( ast -- ? ) } ". " { $snippet ( ast -- ? ) } ". "
"A semantic action follows the rule it applies to and is delimeted by '?[' and ']?'." "A semantic action follows the rule it applies to and is delimeted by '?[' and ']?'."
{ $examples { $examples
{ $example { $example
"USING: prettyprint peg.ebnf math math.parser ;" "USING: prettyprint peg.ebnf math math.parser ;"
"\"1\" [EBNF rule=[0-9] ?[ digit> odd? ]? EBNF] ." "\"1\" [EBNF rule=[0-9] ?[ digit> odd? ]? EBNF] ."
"49" "49"
@ -257,7 +257,7 @@ ARTICLE: "peg.ebnf.semantic-action" "Semantic Action"
"\"2\" [EBNF rule=[0-9] ?[ digit> odd? ]? EBNF] ." "\"2\" [EBNF rule=[0-9] ?[ digit> odd? ]? EBNF] ."
"Sequence index out of bounds\nindex 0\nseq V{ }" "Sequence index out of bounds\nindex 0\nseq V{ }"
} }
} }
; ;
ARTICLE: "peg.ebnf.variable" "Variable" ARTICLE: "peg.ebnf.variable" "Variable"
@ -265,12 +265,12 @@ ARTICLE: "peg.ebnf.variable" "Variable"
"followed by the variable name. These can then be used in rule actions to refer to " "followed by the variable name. These can then be used in rule actions to refer to "
"the AST result of the rule element with that variable name." "the AST result of the rule element with that variable name."
{ $examples { $examples
{ $example { $example
"USING: prettyprint peg.ebnf math.parser ;" "USING: prettyprint peg.ebnf math.parser ;"
"\"1+2\" [EBNF rule=[0-9]:a \"+\" [0-9]:b => [[ a digit> b digit> + ]] EBNF] ." "\"1+2\" [EBNF rule=[0-9]:a \"+\" [0-9]:b => [[ a digit> b digit> + ]] EBNF] ."
"3" "3"
} }
} }
; ;
ARTICLE: "peg.ebnf.foreign-rules" "Foreign Rules" ARTICLE: "peg.ebnf.foreign-rules" "Foreign Rules"
@ -283,7 +283,7 @@ ARTICLE: "peg.ebnf.foreign-rules" "Foreign Rules"
{ $vocab-link "peg" } " defined parser and it will be called to perform the parse " { $vocab-link "peg" } " defined parser and it will be called to perform the parse "
"for that rule." "for that rule."
{ $examples { $examples
{ $code { $code
"USING: prettyprint peg.ebnf ;" "USING: prettyprint peg.ebnf ;"
"EBNF: parse-string" "EBNF: parse-string"
"StringBody = (!('\"') .)*" "StringBody = (!('\"') .)*"
@ -302,7 +302,7 @@ ARTICLE: "peg.ebnf.foreign-rules" "Foreign Rules"
"abc = <foreign a-token> 'b' 'c'" "abc = <foreign a-token> 'b' 'c'"
";EBNF" ";EBNF"
} }
} }
; ;
ARTICLE: "peg.ebnf.tokenizers" "Tokenizers" ARTICLE: "peg.ebnf.tokenizers" "Tokenizers"
@ -441,7 +441,7 @@ ARTICLE: "peg.ebnf" "EBNF"
POSTPONE: EBNF: POSTPONE: EBNF:
} }
"The EBNF syntax is composed of a series of rules of the form: " "The EBNF syntax is composed of a series of rules of the form: "
{ $code { $code
"rule1 = ..." "rule1 = ..."
"rule2 = ..." "rule2 = ..."
} }
@ -469,7 +469,7 @@ ARTICLE: "peg.ebnf" "EBNF"
"own tokenizer that for an EBNF grammar, and write the grammar in terms of " "own tokenizer that for an EBNF grammar, and write the grammar in terms of "
"those tokens, allowing you to ignore the whitespace issue. The tokenizer " "those tokens, allowing you to ignore the whitespace issue. The tokenizer "
"can be changed at various parts in the grammar as needed. The JavaScript grammar " "can be changed at various parts in the grammar as needed. The JavaScript grammar "
"does this to define the optional semicolon rule for example." "does this to define the optional semicolon rule for example."
{ $subsections "peg.ebnf.tokenizers" } { $subsections "peg.ebnf.tokenizers" }
; ;