automatic whitespace for self

This commit is contained in:
Arpad Ryszka 2017-10-29 15:55:12 +01:00
parent ac418bde03
commit 230c01bac3
2 changed files with 45 additions and 40 deletions

View File

@ -25,3 +25,7 @@ ws and nows flags
[problems] [problems]
can the root be an alias? check the commit mechanism can the root be an alias? check the commit mechanism
[documentation]
how the char classes are different from regexp
why need nows when using ws

View File

@ -1,36 +1,36 @@
wschar:alias = " " | "\t" | "\n" | "\b" | "\f" | "\r" | "\v"; wschar:alias = " " | "\t" | "\n" | "\b" | "\f" | "\r" | "\v";
wsc:alias = wschar | comment; wsc:ws = wschar | comment;
block-comment:alias = "/*" ("*" [^/] | [^*])* "*/"; block-comment:alias:nows = "/*" ("*" [^/] | [^*])* "*/";
line-comment:alias = "//" [^\n]*; line-comment:alias:nows = "//" [^\n]*;
comment-segment:alias = line-comment | block-comment; comment-segment:alias:nows = line-comment | block-comment;
ws-no-nl:alias = " " | "\t" | "\b" | "\f" | "\r" | "\v"; ws-no-nl:alias:nows = " " | "\t" | "\b" | "\f" | "\r" | "\v";
comment = comment-segment (ws-no-nl* "\n"? ws-no-nl* comment-segment)*; comment:nows = comment-segment (ws-no-nl* "\n"? ws-no-nl* comment-segment)*;
any-char = "."; // equivalent to [^] any-char = "."; // equivalent to [^]
// caution: newline is accepted // caution: newline is accepted
class-not = "^"; class-not = "^";
class-char = [^\\\[\]\^\-] | "\\" .; class-char:nows = [^\\\[\]\^\-] | "\\" .;
char-range = class-char "-" class-char; char-range:nows = class-char "-" class-char;
char-class = "[" class-not? (class-char | char-range)* "]"; char-class:nows = "[" class-not? (class-char | char-range)* "]";
// newline is accepted // newline is accepted
sequence-char = [^\\"] | "\\" .; sequence-char:nows = [^\\"] | "\\" .;
char-sequence = "\"" sequence-char* "\""; char-sequence:nows = "\"" sequence-char* "\"";
terminal:alias = any-char | char-class | char-sequence; terminal:alias = any-char | char-class | char-sequence;
symbol = [^\\ \n\t\b\f\r\v/.\[\]\"{}\^+*?|():=;]+; symbol:nows = [^\\ \n\t\b\f\r\v/.\[\]\"{}\^+*?|():=;]+;
group:alias = "(" wsc* expression wsc* ")"; group:alias = "(" expression ")";
number:alias = [0-9]+; number:alias:nows = [0-9]+;
count = number; count = number;
count-quantifier = "{" wsc* count wsc* "}"; count-quantifier = "{" count "}";
range-from = number; range-from = number;
range-to = number; range-to = number;
range-quantifier = "{" wsc* range-from? wsc* "," wsc* range-to? wsc* "}"; range-quantifier = "{" range-from? "," range-to? "}";
one-or-more = "+"; one-or-more = "+";
zero-or-more = "*"; zero-or-more = "*";
zero-or-one = "?"; zero-or-one = "?";
@ -40,13 +40,13 @@ quantity:alias = count-quantifier
| zero-or-more | zero-or-more
| zero-or-one; | zero-or-one;
item = (terminal | symbol | group) quantity?; item:nows = (terminal | symbol | group) quantity?;
sequence = item (wsc* item)*; sequence = item+;
element:alias = terminal | symbol | group | sequence; element:alias = terminal | symbol | group | sequence;
// DOC: how the order matters // DOC: how the order matters
choice = element (wsc* "|" wsc* element)+; choice = element ("|" element)+;
// DOC: not having 'not' needs some tricks sometimes // DOC: not having 'not' needs some tricks sometimes
@ -62,7 +62,8 @@ nows = "nows";
doc = "doc"; doc = "doc";
root = "root"; root = "root";
flag:alias = alias | ws | nows | doc | root; flag:alias = alias | ws | nows | doc | root;
definition = symbol (":" flag)* wsc* "=" wsc* expression; definition-name:alias:nows = symbol (":" flag)*;
definition = definition-name "=" expression;
definitions:alias = definition (wsc* ";" (wsc | ";")* definition)*; definitions:alias = definition (";"+ definition)*;
syntax:root = (wsc | ";")* definitions? (wsc | ";")*; syntax:root = ";"* definitions? ";"*;