Skip to content

Commit

Permalink
pegex refo
Browse files Browse the repository at this point in the history
  • Loading branch information
ingydotnet committed Sep 20, 2011
1 parent 261fdf1 commit e2cb718
Show file tree
Hide file tree
Showing 3 changed files with 99 additions and 83 deletions.
26 changes: 14 additions & 12 deletions testml.pgx
@@ -1,4 +1,4 @@
TOP: <NEVER> <code_section> <data_section>
testml_document: <code_section> <data_section>?

# General Tokens
escape: /[0nt]/
Expand All @@ -7,11 +7,11 @@ blank_line: /<BLANK>*<EOL>/
comment: /<HASH><line>/
ws: /(?:<BLANK>|<EOL>|<comment>)/

quoted_string: <single_quoted_string> | <double_quoted_string>
quoted_string: -<single_quoted_string> | -<double_quoted_string>

single_quoted_string: /(?:<SINGLE>(([^<BREAK><BACK><SINGLE>]|<BACK><SINGLE>|<BACK><BACK>)*?)<SINGLE>)/
single_quoted_string: /(?:<SINGLE>((?:[^<BREAK><BACK><SINGLE>]|<BACK><SINGLE>|<BACK><BACK>)*?)<SINGLE>)/

double_quoted_string: /(?:<DOUBLE>(([^<BREAK><BACK><DOUBLE>]|<BACK><DOUBLE>|<BACK><BACK>|<BACK><escape>)*?)<DOUBLE>)/
double_quoted_string: /(?:<DOUBLE>((?:[^<BREAK><BACK><DOUBLE>]|<BACK><DOUBLE>|<BACK><BACK>|<BACK><escape>)*?)<DOUBLE>)/

unquoted_string: /([^<BLANKS><BREAK><HASH>](?:[^<BREAK><HASH>]*[^<BLANKS><BREAK><HASH>])?)/

Expand Down Expand Up @@ -39,7 +39,7 @@ semicolon:

code_expression:
<code_object>
<unit_call>*
-<unit_call>*

unit_call:
!<assertion_call_test>
Expand All @@ -54,11 +54,13 @@ code_object:
<transform_object>

function_object:
<function_signature>?
/<ws>*<LCURLY><ws>*/
-<function_signature>?
<function_start>
[ /<ws>+/ | <assignment_statement> | <code_statement>]*
/<ws>*<RCURLY>/

function_start: /<ws>*(<LCURLY>)<ws>*/

function_signature:
/<LPAREN><ws>*/
<function_variables>?
Expand Down Expand Up @@ -90,7 +92,7 @@ call_indicator: /(?:<DOT><ws>*|<ws>*<DOT>)/

transform_argument_list:
/<LPAREN><ws>*/
<transform_arguments>?
-<transform_arguments>?
/<ws>*<RPAREN>/

transform_arguments:
Expand All @@ -116,7 +118,7 @@ assertion_function_eq:

assertion_ok: <assertion_function_ok>

assertion_function_ok: /<call_indicator>OK<empty_parens>?/
assertion_function_ok: /<call_indicator>(OK)<empty_parens>?/

assertion_has: <assertion_operator_has> | <assertion_function_has>

Expand All @@ -136,8 +138,8 @@ data_section: <data_block>*

data_block:
<block_header>
[ <blank_line> | <comment> ]*
<block_point>*
.[ <blank_line> | <comment> ]*
-<block_point>*

block_header:
<block_marker>
Expand Down Expand Up @@ -176,4 +178,4 @@ user_point_name: /<LOWER><WORD>*/

core_point_name: /<UPPER><WORD>*/

point_phrase: /(<unquoted_string>)/
point_phrase: -<unquoted_string>
84 changes: 45 additions & 39 deletions testml.pgx.json
@@ -1,21 +1,5 @@
{
"+top" : "TOP",
"NEVER" : {
".rgx" : "(?!)"
},
"TOP" : {
".all" : [
{
".ref" : "NEVER"
},
{
".ref" : "code_section"
},
{
".ref" : "data_section"
}
]
},
"+top" : "testml_document",
"assertion_call" : {
".any" : [
{
Expand Down Expand Up @@ -69,7 +53,7 @@
]
},
"assertion_function_ok" : {
".rgx" : "(?:\\.(?:[\\ \\t]|\\r?\\n|\\#.*\\r?\\n)*|(?:[\\ \\t]|\\r?\\n|\\#.*\\r?\\n)*\\.)OK(?:\\((?:[\\ \\t]|\\r?\\n|\\#.*\\r?\\n)*\\))?"
".rgx" : "(?:\\.(?:[\\ \\t]|\\r?\\n|\\#.*\\r?\\n)*|(?:[\\ \\t]|\\r?\\n|\\#.*\\r?\\n)*\\.)(OK)(?:\\((?:[\\ \\t]|\\r?\\n|\\#.*\\r?\\n)*\\))?"
},
"assertion_has" : {
".any" : [
Expand Down Expand Up @@ -129,7 +113,7 @@
".ref" : "block_marker"
},
{
"+mod" : "?",
"+qty" : "?",
".all" : [
{
".rgx" : "[\\ \\t]+"
Expand Down Expand Up @@ -169,7 +153,8 @@
".ref" : "code_object"
},
{
"+mod" : "*",
"+qty" : "*",
"-pass" : 1,
".ref" : "unit_call"
}
]
Expand All @@ -194,7 +179,7 @@
]
},
"code_section" : {
"+mod" : "*",
"+qty" : "*",
".any" : [
{
".rgx" : "(?:[\\ \\t]|\\r?\\n|\\#.*\\r?\\n)+"
Expand All @@ -213,7 +198,7 @@
".ref" : "code_expression"
},
{
"+mod" : "?",
"+qty" : "?",
".ref" : "assertion_call"
},
{
Expand All @@ -233,7 +218,8 @@
".ref" : "block_header"
},
{
"+mod" : "*",
"+qty" : "*",
"-skip" : 1,
".any" : [
{
".ref" : "blank_line"
Expand All @@ -244,29 +230,31 @@
]
},
{
"+mod" : "*",
"+qty" : "*",
"-pass" : 1,
".ref" : "block_point"
}
]
},
"data_section" : {
"+mod" : "*",
"+qty" : "*",
".ref" : "data_block"
},
"double_quoted_string" : {
".rgx" : "(?:\"(([^\\n\\\\\"]|\\\\\"|\\\\\\\\|\\\\[0nt])*?)\")"
".rgx" : "(?:\"((?:[^\\n\\\\\"]|\\\\\"|\\\\\\\\|\\\\[0nt])*?)\")"
},
"function_object" : {
".all" : [
{
"+mod" : "?",
"+qty" : "?",
"-pass" : 1,
".ref" : "function_signature"
},
{
".rgx" : "(?:[\\ \\t]|\\r?\\n|\\#.*\\r?\\n)*\\{(?:[\\ \\t]|\\r?\\n|\\#.*\\r?\\n)*"
".ref" : "function_start"
},
{
"+mod" : "*",
"+qty" : "*",
".any" : [
{
".rgx" : "(?:[\\ \\t]|\\r?\\n|\\#.*\\r?\\n)+"
Expand All @@ -290,14 +278,17 @@
".rgx" : "\\((?:[\\ \\t]|\\r?\\n|\\#.*\\r?\\n)*"
},
{
"+mod" : "?",
"+qty" : "?",
".ref" : "function_variables"
},
{
".rgx" : "(?:[\\ \\t]|\\r?\\n|\\#.*\\r?\\n)*\\)"
}
]
},
"function_start" : {
".rgx" : "(?:[\\ \\t]|\\r?\\n|\\#.*\\r?\\n)*(\\{)(?:[\\ \\t]|\\r?\\n|\\#.*\\r?\\n)*"
},
"function_variable" : {
".rgx" : "([a-zA-Z]\\w*)"
},
Expand All @@ -307,7 +298,7 @@
".ref" : "function_variable"
},
{
"+mod" : "*",
"+qty" : "*",
".all" : [
{
".rgx" : "(?:[\\ \\t]|\\r?\\n|\\#.*\\r?\\n)*,(?:[\\ \\t]|\\r?\\n|\\#.*\\r?\\n)*"
Expand Down Expand Up @@ -370,10 +361,10 @@
]
},
"point_lines" : {
".rgx" : "((?:(?!===|---).*\\r?\\n)*)"
".rgx" : "((?:(?!===|\\-\\-\\-).*\\r?\\n)*)"
},
"point_marker" : {
".rgx" : "---"
".rgx" : "\\-\\-\\-"
},
"point_name" : {
".rgx" : "([a-z]\\w*|[A-Z]\\w*)"
Expand All @@ -382,14 +373,17 @@
".rgx" : "(\\*[a-z]\\w*)"
},
"point_phrase" : {
".rgx" : "(([^\\ \\t\\n\\#](?:[^\\n\\#]*[^\\ \\t\\n\\#])?))"
"-pass" : 1,
".ref" : "unquoted_string"
},
"quoted_string" : {
".any" : [
{
"-pass" : 1,
".ref" : "single_quoted_string"
},
{
"-pass" : 1,
".ref" : "double_quoted_string"
}
]
Expand All @@ -405,11 +399,22 @@
]
},
"single_quoted_string" : {
".rgx" : "(?:'(([^\\n\\\\']|\\\\'|\\\\\\\\)*?)')"
".rgx" : "(?:'((?:[^\\n\\\\']|\\\\'|\\\\\\\\)*?)')"
},
"string_object" : {
".ref" : "quoted_string"
},
"testml_document" : {
".all" : [
{
".ref" : "code_section"
},
{
"+qty" : "?",
".ref" : "data_section"
}
]
},
"transform_argument" : {
".ref" : "code_expression"
},
Expand All @@ -419,7 +424,8 @@
".rgx" : "\\((?:[\\ \\t]|\\r?\\n|\\#.*\\r?\\n)*"
},
{
"+mod" : "?",
"+qty" : "?",
"-pass" : 1,
".ref" : "transform_arguments"
},
{
Expand All @@ -433,7 +439,7 @@
".ref" : "transform_argument"
},
{
"+mod" : "*",
"+qty" : "*",
".all" : [
{
".rgx" : "(?:[\\ \\t]|\\r?\\n|\\#.*\\r?\\n)*,(?:[\\ \\t]|\\r?\\n|\\#.*\\r?\\n)*"
Expand Down Expand Up @@ -461,15 +467,15 @@
".ref" : "transform_name"
},
{
"+mod" : "?",
"+qty" : "?",
".ref" : "transform_argument_list"
}
]
},
"unit_call" : {
".all" : [
{
"+mod" : "!",
"+asr" : -1,
".ref" : "assertion_call_test"
},
{
Expand Down

0 comments on commit e2cb718

Please sign in to comment.