Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 80 lines (68 sloc) 3.461 kb
9d64d20 @colomon Directories.
authored
1 use v6;
f7b55cd @colomon Make the file-reading tests (and new script) remove comments before pars...
authored
2 # use Grammar::Tracer;
9d64d20 @colomon Directories.
authored
3
4 grammar ISO_10303_21::Grammar
5 {
6 token space { " " }
7 token digit { <[0..9]> }
8 token lower { <[a..z]> }
f64f79a @colomon Add some of the higher level things.
authored
9 token upper { <[A..Z]> | '_' }
9d64d20 @colomon Directories.
authored
10 token special { '!' | '"' | '*' | '$' | '%' | '&' | '.' | '#'
11 | '+' | ',' | '-' | '(' | ')' | '?' | '/' | ':'
12 | ';' | '<' | '=' | '>' | '@' | '[' | ']' | '{'
13 | '|' | '}' | '^' | '`' | '~' }
14 token reverse_solidus { '\\' }
15 token apostrophe { "'" }
16 token character { <space> | <digit> | <lower> | <upper> | <special> | <reverse_solidus> | <apostrophe> }
f0797bf @colomon Some tokens!
authored
17
18 token standard_keyword { <upper> [ <upper> | <digit> ]* }
19 token user_defined_keyword { '!' <upper> [ <upper> | <digit> ]* }
20 token keyword { <user_defined_keyword> | <standard_keyword> }
21
22 token sign { '+' | '-' }
fde2d1f @colomon Lots of tokens!
authored
23 token integer { <sign>? <digit> <digit>* }
24 token real { <sign>? <digit>+ '.' <digit>* [ 'E' <sign>? <digit>+ ]? }
25
ff14d08 @colomon Add the control directives to strings.
authored
26 token hex_one { <hex> <hex> }
27 token hex_two { <hex_one> <hex_one> }
28 token hex_four { <hex_two> <hex_two> }
29 token page { <reverse_solidus> 'S' <reverse_solidus> <character> }
30 token alphabet { <reverse_solidus> 'P' <upper> <reverse_solidus> <character> }
31 token end_extended { <reverse_solidus> 'X0' <reverse_solidus> }
32 token extended2 { <reverse_solidus> 'X2' <reverse_solidus> <hex_two>+ <end_extended> }
33 token extended4 { <reverse_solidus> 'X4' <reverse_solidus> <hex_four>+ <end_extended> }
34 token arbitrary { <reverse_solidus> 'X' <reverse_solidus> <hex_one> }
35 token control_directive { <page> | <alphabet> | <extended2> | <extended4> | <arbitrary> }
36
fde2d1f @colomon Lots of tokens!
authored
37 token non_q_char { <special> | <digit> | <space> | <lower> | <upper> }
ff14d08 @colomon Add the control directives to strings.
authored
38 token string { "'" [ <non_q_char> | [<apostrophe> ** 2] | [<reverse_solidus> ** 2] | <control_directive> ]* "'" }
fde2d1f @colomon Lots of tokens!
authored
39
40 token entity_instance_name { '#' <digit>+ }
41 token enumeration { '.' <upper> [ <upper> | <digit> ]* '.' }
42
43 token hex { <[0..9]> | <[A..F]> }
44 token binary { '"' <[0..3]> <hex>* '"' }
f64f79a @colomon Add some of the higher level things.
authored
45
46 token parameter { <typed_parameter> | <untyped_parameter> | <omitted_parameter> }
47 token omitted_parameter { '*' }
48 token untyped_parameter { '$' | <real> | <integer> | <string>
49 | <entity_instance_name> | <enumeration> | <binary> | <list_of_parameters> }
50 rule typed_parameter { <keyword> '(' <parameter> ')' }
51 rule list_of_parameters { '(' [ <parameter> ]* % [ ',' ] ')' }
52 rule parameter_list { [ <parameter> ]+ % [ ',' ] }
53
54 rule header_entity { <keyword> '(' <parameter_list> ')' ';' }
55 rule header_entity_list { <header_entity>+ }
56 rule header_section {
57 "HEADER;"
58 <header_entity> <header_entity> <header_entity>
59 <header_entity_list>?
60 "ENDSEC;"
61 }
f56b998 @colomon Rules and tests for recognizing entities.
authored
62
63 rule simple_record { <keyword> '(' <parameter_list>? ')' }
64 rule subsuper_record { '(' <simple_record>+ ')' }
65 rule simple_entity_instance { <entity_instance_name> '=' <simple_record> ';' }
66 rule complex_entity_instance { <entity_instance_name> '=' <subsuper_record> ';' }
67 rule entity_instance { <simple_entity_instance> | <complex_entity_instance> }
8c25fdb @colomon Parse a full file!
authored
68
69 rule data_section {
70 "DATA" [ '(' <parameter_list> ')']? ';'
71 <entity_instance>*
72 "ENDSEC" ';'
73 }
74
75 rule exchange_file {
76 "ISO-10303-21;"
77 <header_section> <data_section>+
78 "END-ISO-10303-21;"
79 }
9d64d20 @colomon Directories.
authored
80 }
Something went wrong with that request. Please try again.