1# -*- tcl -*- 2# Parsing Expression Grammar 'PEG'. 3# Definition of a human-readable form of parsing expression grammar specification. 4 5package require Tcl 8.5 6package require snit 7package require pt::peg::container 8 9snit::type pt::peg::container::peg { 10 constructor {} { 11 install myg using pt::peg::container ${selfns}::G 12 $myg start {n Grammar} 13 $myg add ALNUM ALPHA AND APOSTROPH ASCII Attribute Char CharOctalFull CharOctalPart CharSpecial CharUnescaped CharUnicode Class CLOSE CLOSEB COLON COMMENT DAPOSTROPH DDIGIT Definition DIGIT DOT END EOF EOL Expression Final Grammar GRAPH Header Ident Identifier IS LEAF Literal LOWER NOT OPEN OPENB PEG PLUS Prefix Primary PRINTABLE PUNCT QUESTION Range SEMICOLON Sequence SLASH SPACE STAR StartExpr Suffix TO UPPER VOID WHITESPACE WORDCHAR XDIGIT 14 $myg modes { 15 ALNUM leaf 16 ALPHA leaf 17 AND leaf 18 APOSTROPH void 19 ASCII leaf 20 Attribute value 21 Char value 22 CharOctalFull leaf 23 CharOctalPart leaf 24 CharSpecial leaf 25 CharUnescaped leaf 26 CharUnicode leaf 27 Class value 28 CLOSE void 29 CLOSEB void 30 COLON void 31 COMMENT void 32 DAPOSTROPH void 33 DDIGIT leaf 34 Definition value 35 DIGIT leaf 36 DOT leaf 37 END void 38 EOF void 39 EOL void 40 Expression value 41 Final void 42 Grammar value 43 GRAPH leaf 44 Header value 45 Ident leaf 46 Identifier value 47 IS void 48 LEAF leaf 49 Literal value 50 LOWER leaf 51 NOT leaf 52 OPEN void 53 OPENB void 54 PEG void 55 PLUS leaf 56 Prefix value 57 Primary value 58 PRINTABLE leaf 59 PUNCT leaf 60 QUESTION leaf 61 Range value 62 SEMICOLON void 63 Sequence value 64 SLASH void 65 SPACE leaf 66 STAR leaf 67 StartExpr value 68 Suffix value 69 TO void 70 UPPER leaf 71 VOID leaf 72 WHITESPACE void 73 WORDCHAR leaf 74 XDIGIT leaf 75 } 76 $myg rules { 77 ALNUM {x {t <} {t a} {t l} {t n} {t u} {t m} {t >} {n WHITESPACE}} 78 ALPHA {x {t <} {t a} {t l} {t p} {t h} {t a} {t >} {n WHITESPACE}} 79 AND {x {t &} {n WHITESPACE}} 80 APOSTROPH {t '} 81 ASCII {x {t <} {t a} {t s} {t c} {t i} {t i} {t >} {n WHITESPACE}} 82 Attribute {x {/ {n VOID} {n LEAF}} {n COLON}} 83 Char {/ {n CharSpecial} {n CharOctalFull} {n CharOctalPart} {n CharUnicode} {n CharUnescaped}} 84 CharOctalFull {x {t \134} {.. 0 2} {.. 0 7} {.. 0 7}} 85 CharOctalPart {x {t \134} {.. 0 7} {? {.. 0 7}}} 86 CharSpecial {x {t \134} {/ {t n} {t r} {t t} {t '} {t \42} {t \133} {t \135} {t \134}}} 87 CharUnescaped {x {! {t \134}} dot} 88 CharUnicode {x {t \134} {t u} xdigit {? {x xdigit {? {x xdigit {? xdigit}}}}}} 89 Class {x {n OPENB} {* {x {! {n CLOSEB}} {n Range}}} {n CLOSEB} {n WHITESPACE}} 90 CLOSE {x {t \51} {n WHITESPACE}} 91 CLOSEB {t \135} 92 COLON {x {t :} {n WHITESPACE}} 93 COMMENT {x {t #} {* {x {! {n EOL}} dot}} {n EOL}} 94 DAPOSTROPH {t \42} 95 DDIGIT {x {t <} {t d} {t d} {t i} {t g} {t i} {t t} {t >} {n WHITESPACE}} 96 Definition {x {? {n Attribute}} {n Identifier} {n IS} {n Expression} {n SEMICOLON}} 97 DIGIT {x {t <} {t d} {t i} {t g} {t i} {t t} {t >} {n WHITESPACE}} 98 DOT {x {t .} {n WHITESPACE}} 99 END {x {t E} {t N} {t D} {n WHITESPACE}} 100 EOF {! dot} 101 EOL {/ {x {t \r} {t \n}} {t \n} {t \r}} 102 Expression {x {n Sequence} {* {x {n SLASH} {n Sequence}}}} 103 Final {x {n END} {n SEMICOLON} {n WHITESPACE}} 104 Grammar {x {n WHITESPACE} {n Header} {* {n Definition}} {n Final} {n EOF}} 105 GRAPH {x {t <} {t g} {t r} {t a} {t p} {t h} {t >} {n WHITESPACE}} 106 Header {x {n PEG} {n Identifier} {n StartExpr}} 107 Ident {x {/ {t _} {t :} alpha} {* {/ {t _} {t :} alnum}}} 108 Identifier {x {n Ident} {n WHITESPACE}} 109 IS {x {t <} {t -} {n WHITESPACE}} 110 LEAF {x {t l} {t e} {t a} {t f} {n WHITESPACE}} 111 Literal {/ {x {n APOSTROPH} {* {x {! {n APOSTROPH}} {n Char}}} {n APOSTROPH} {n WHITESPACE}} {x {n DAPOSTROPH} {* {x {! {n DAPOSTROPH}} {n Char}}} {n DAPOSTROPH} {n WHITESPACE}}} 112 LOWER {x {t <} {t l} {t o} {t w} {t e} {t r} {t >} {n WHITESPACE}} 113 NOT {x {t !} {n WHITESPACE}} 114 OPEN {x {t \50} {n WHITESPACE}} 115 OPENB {t \133} 116 PEG {x {t P} {t E} {t G} {n WHITESPACE}} 117 PLUS {x {t +} {n WHITESPACE}} 118 Prefix {x {? {/ {n AND} {n NOT}}} {n Suffix}} 119 Primary {/ {n ALNUM} {n ALPHA} {n ASCII} {n DDIGIT} {n DIGIT} {n GRAPH} {n LOWER} {n PRINTABLE} {n PUNCT} {n SPACE} {n UPPER} {n WORDCHAR} {n XDIGIT} {n Identifier} {x {n OPEN} {n Expression} {n CLOSE}} {n Literal} {n Class} {n DOT}} 120 PRINTABLE {x {t <} {t p} {t r} {t i} {t n} {t t} {t >} {n WHITESPACE}} 121 PUNCT {x {t <} {t p} {t u} {t n} {t c} {t t} {t >} {n WHITESPACE}} 122 QUESTION {x {t ?} {n WHITESPACE}} 123 Range {/ {x {n Char} {n TO} {n Char}} {n Char}} 124 SEMICOLON {x {t \73} {n WHITESPACE}} 125 Sequence {+ {n Prefix}} 126 SLASH {x {t /} {n WHITESPACE}} 127 SPACE {x {t <} {t s} {t p} {t a} {t c} {t e} {t >} {n WHITESPACE}} 128 STAR {x {t *} {n WHITESPACE}} 129 StartExpr {x {n OPEN} {n Expression} {n CLOSE}} 130 Suffix {x {n Primary} {? {/ {n QUESTION} {n STAR} {n PLUS}}}} 131 TO {t -} 132 UPPER {x {t <} {t u} {t p} {t p} {t e} {t r} {t >} {n WHITESPACE}} 133 VOID {x {t v} {t o} {t i} {t d} {n WHITESPACE}} 134 WHITESPACE {* {/ {t \40} {t \t} {n EOL} {n COMMENT}}} 135 WORDCHAR {x {t <} {t w} {t o} {t r} {t d} {t c} {t h} {t a} {t r} {t >} {n WHITESPACE}} 136 XDIGIT {x {t <} {t x} {t d} {t i} {t g} {t i} {t t} {t >} {n WHITESPACE}} 137 } 138 return 139 } 140 141 component myg 142 delegate method * to myg 143} 144 145package provide pt::peg::container::peg 1 146return 147