1
0
treerack/syntax.treerack

85 lines
3.1 KiB
Plaintext
Raw Normal View History

2026-05-30 20:14:24 +02:00
/*
foo
*/
// bar
// bar
// baz
/* foo
bar baz */ // foo bar baz
wschar:alias = // foo
/* bar */
" " | "\t" | "\n" | "\b" | "\f" | "\r" | "\v";
wsc:ws = wschar | comment;
block-comment:alias:nows = /* foo */ // bar
"/*" ("*" [^/] | [^*])* "*/";
line-comment:alias:nows = /*
foo
*/
"//" [^\n]*;
2026-06-01 20:28:39 +02:00
comment-segment:alias:nows = // bar
line-comment | block-comment;
ws-no-nl:alias:nows = " "
| "\t"
| "\b"
/* this one */ /* is a */
| "\f"
/* form feed */ /* for sure */
| "\r"
| "\v";
comment:nows = comment-segment
/* segment is not the best name */ /* but */
( ws-no-nl*
"\n"?
ws-no-nl*
/* fine */
comment-segment
)*;
any-char = "."; // equivalent to [^]
2017-06-25 17:51:08 +02:00
// caution: newline is accepted
/* class not */
class-not = "^";
class-char:nows = [^\\\[\]\^\-] | "\\" .; /* foo
bar */
char-range:nows = class-char "-" class-char; // foo
2017-10-29 15:55:12 +01:00
char-class:nows = "[" class-not? (class-char | char-range)* "]";
2017-06-25 17:51:08 +02:00
2017-06-26 02:20:23 +02:00
// newline is accepted
2017-10-29 15:55:12 +01:00
sequence-char:nows = [^\\"] | "\\" .;
char-sequence:nows = "\"" sequence-char* "\"";
terminal:alias = any-char | char-class | char-sequence;
symbol:nows = [^\\ \n\t\b\f\r\v/.\[\]\"{}\^+*?|():=;]+;
group:alias = "(" expression ")";
number:alias:nows = [0-9]+;
count = number;
count-quantifier = "{" count "}";
range-from = number;
range-to = number;
range-quantifier = "{" range-from? "," range-to? "}";
one-or-more = "+";
zero-or-more = "*";
zero-or-one = "?";
quantity:alias = count-quantifier | range-quantifier | one-or-more | zero-or-more | zero-or-one;
item:nows = (terminal | symbol | group) quantity?;
sequence = item+;
option:alias = terminal | symbol | group | sequence;
2017-06-25 17:51:08 +02:00
2017-06-26 02:20:23 +02:00
// DOC: how the order matters
2017-11-02 22:19:03 +01:00
choice = option ("|" option)+;
2017-06-25 17:51:08 +02:00
// DOC: not having 'not' needs some tricks sometimes
expression:alias = terminal | symbol | group | sequence | choice;
alias = "alias";
2017-10-29 15:55:12 +01:00
ws = "ws";
nows = "nows";
2019-02-02 18:07:10 +01:00
kw = "kw";
nokw = "nokw";
failpass = "failpass";
2017-10-29 15:55:12 +01:00
root = "root";
flag:alias = alias | ws | nows | kw | nokw | failpass | root;
2017-10-29 15:55:12 +01:00
definition-name:alias:nows = symbol (":" flag)*;
definition = definition-name "=" expression;
definitions:alias = definition (";"+ definition)*;
syntax:root = ";"* definitions? ";"*;