Skip to content

Commit 134ab0a

Browse files
committed
added URL definition for later processing
1 parent 895d980 commit 134ab0a

2 files changed

Lines changed: 119 additions & 0 deletions

File tree

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
@synopsis{Implements RFC1738 for URL syntax and maps them to `loc` values.}
2+
module lang::paths::URL
3+
4+
lexical URL
5+
= http: "http://" HostPort ( "/" Hpath ( "?" Search)?)?
6+
| ftp: "ftp://" Login ("/" Fpath (";type=" FtpType)?)?
7+
| news: "news:" GroupPart
8+
| nntp: "nntp://" HostPort "/" Group ("/" Digit+)?
9+
| telnet: "telnet://" Login "/"?
10+
| gopher: "gopher://" HostPort ( "/" ( Gtype ( Selector ("%09" Search ("%09" GopherPlusString)? )? )? )? )?
11+
| waisdatabase: "wais://" HostPort "/" Database
12+
| waisindex: "wais://" HostPort "/" Database "?" Search
13+
| waisdoc: "wais://" HostPort "/" Database "/" Wtype "/" Wpath
14+
| mailto: "mailto:" Encoded822addr
15+
| file: "file://" (Host | "localhost")? "/" Fpath
16+
| prospero: "prospero://" HostPort "/" Ppath *[ Fieldspec ]
17+
| other: Scheme ":" SchemePart
18+
;
19+
20+
lexical Ppath = {Psegment "/"}+;
21+
22+
lexical Psegment = (Uchar | [?:@&=])*;
23+
24+
lexical Fieldspec = ";" FieldName "=" FieldValue;
25+
26+
lexical FieldName = (Uchar | [?:@&])*;
27+
28+
lexical FieldValue = (Uchar | [?:@&])*;
29+
30+
lexical Database = Uchar*;
31+
lexical Wtype = Uchar*;
32+
lexical Wpath = Uchar*;
33+
34+
lexical GroupPart = "*" | Group | Article;
35+
36+
lexical Group = Alpha (Alpha | Digit | [\-.+_])*;
37+
38+
lexical Article = (Uchar | [;/?:&=])* "@" Host;
39+
40+
lexical Encoded822addr = Xchar+; // further defined in RFC822
41+
42+
lexical Gtype = Xchar;
43+
lexical Selector = Xchar*;
44+
lexical GopherPlusString = Xchar*;
45+
46+
lexical Hpath = {Hsegment "/"}+;
47+
48+
lexical Hsegment = (Uchar | [;:@&=])*;
49+
50+
lexical Search = (Uchar | [;:@&=])*;
51+
52+
lexical Fpath = {Fsegment "/"}+;
53+
54+
lexical Fsegment= (Uchar | [?:@&=])*;
55+
56+
lexical FtpType = [AIDaid];
57+
58+
lexical Scheme = [a-z0-9+\-.]+;
59+
60+
lexical SchemePart = Xchar* | IpSchemePart;
61+
62+
lexical IpSchemePart = "//" Login ("/" UrlPath);
63+
64+
lexical Login = ( User ( ":" Password )? "@" )? HostPort;
65+
66+
lexical HostPort = Host ( ":" Port )?;
67+
68+
lexical Host = HostName | HostNumber;
69+
70+
lexical HostName = (DomainLabel ".")* TopLabel;
71+
72+
lexical DomainLabel = {AlphaDigit "-"}+;
73+
74+
lexical TopLabel = Alpha {AlphaDigit "-"}+;
75+
76+
lexical HostNumber = Digit+ "." Digit+ "." Digit+ "." Digit+;
77+
78+
lexical Port = Digit+;
79+
80+
lexical User = (Uchar | [;?&=])*;
81+
82+
lexical Password = (Uchar | [;?&=])*;
83+
84+
lexical UrlPath = Xchar* ; //depends on protocol see section 3.1 of RFC1738
85+
86+
lexical Alpha = LowAlpha | HighAlpha;
87+
88+
lexical AlphaDigit = Alpha | Digit;
89+
90+
lexical LowAlpha = [a-z];
91+
92+
lexical HighAlpha = [A-Z];
93+
94+
lexical Digit = [0-9];
95+
96+
lexical Safe = [$ \- _ . +];
97+
98+
lexical Extra = [!*\'(),];
99+
100+
lexical National = [{}|\\^~\[\]`];
101+
102+
lexical Punctuation = [\<\>#%\"];
103+
104+
lexical Reserved = [;/?:@&=];
105+
106+
lexical Hex = Digit | [A-Fa-f];
107+
108+
lexical Escape = "%" Hex Hex;
109+
110+
lexical Unreserved = Alpha | Digit | Safe | Extra;
111+
112+
lexical Uchar = Unreserved | Escape;
113+
114+
lexical Xchar = Unreserved | Reserved | Escape;
115+

‎src/org/rascalmpl/library/lang/paths/Unix.rsc‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ is purely syntactical, and tries to preserve the semantics of the path as much a
1515
@pitfalls{
1616
* the `~` notation is typically a feature of the shell and not of system paths. However it is so commonly
1717
used to refer to the home directories of users that we've added an interpretation here with the `home:///` scheme.
18+
* otherwise, the path syntax may be different from what you have to type in _bash_ or _zsh_. This is because shells
19+
need to reserve characters, like spaces, for different purposes (commandline argument separation). The
20+
current definition is about the path notation that shells like _zsh_ and _bash_, and other programs, have to pass into the string arguments of
21+
OS features, after their own concatenation, splicing, variable expansion, de-escaping and unquoting routines have finished..
1822
}
1923
module lang::paths::Unix
2024

0 commit comments

Comments
 (0)