Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
M
mincss
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Taddeüs Kroes
mincss
Commits
70f032a3
Commit
70f032a3
authored
Jul 21, 2014
by
Taddeüs Kroes
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Lexer now correctly tracks line numbers + some general cleanup
parent
cfccb863
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
59 additions
and
23 deletions
+59
-23
lexer.mll
lexer.mll
+51
-15
main.ml
main.ml
+1
-1
parse.ml
parse.ml
+3
-3
parser.mly
parser.mly
+2
-2
types.ml
types.ml
+2
-2
No files found.
lexer.mll
View file @
70f032a3
...
...
@@ -5,11 +5,21 @@
open
Parser
open
Types
let
next_line
lexbuf
=
let
advance_pos
lexbuf
=
let
s
=
Lexing
.
lexeme
lexbuf
in
let
rec
search
from
lines
=
try
ignore
(
Str
.
search_forward
(
Str
.
regexp
"
\r\n\\
|
\r\\
|
\n
"
)
s
from
);
search
(
Str
.
match_end
()
)
(
lines
+
1
)
with
Not_found
->
lines
,
String
.
length
s
-
from
in
let
lines
,
cols
=
search
0
0
in
let
pos
=
lexbuf
.
lex_curr_p
in
lexbuf
.
lex_curr_p
<-
{
pos
with
pos_bol
=
lexbuf
.
lex_curr_pos
;
pos_lnum
=
pos
.
pos_lnum
+
1
pos
with
pos_bol
=
lexbuf
.
lex_curr_pos
-
cols
;
pos_lnum
=
pos
.
pos_lnum
+
lines
}
let
strip_quotes
s
=
String
.
sub
s
1
(
String
.
length
s
-
2
)
...
...
@@ -75,10 +85,9 @@ let uagent = ('-' ("webkit" | "moz" | "ms" | "o") '-')?
rule token = parse
| s { S }
| comment (* ignore comments *)
| badcomment { token lexbuf } (* unclosed comment at EOF *)
| "
\
r
\
n
" | '
\r
' | '
\n
' { new_line lexbuf; S }
| [' ' '
\t
' '
\012
']+ { S }
| "
/*
" { comment lexbuf }
| "
<!--
" { CDO }
| "
-->
" { CDC }
...
...
@@ -86,7 +95,7 @@ rule token = parse
| ['>' '~'] as c { COMBINATOR (Char.escaped c) }
| mystring as s { STRING (strip_quotes s) }
| badstring { raise (Syntax
E
rror "
bad
string
") }
| badstring { raise (Syntax
_e
rror "
bad
string
") }
| '#' (name as nm) { HASH nm }
...
...
@@ -99,8 +108,8 @@ rule token = parse
| '@' uagent K E Y F R A M E S { KEYFRAMES_SYM }
| '@' S U P P O R T S { SUPPORTS_SYM }
| (
w | comment)* w A N D w (w | comment)* {
WS_AND }
| (
w | comment)* w O R w (w | comment)* {
WS_OR }
| (
s | comment)* s A N D s (s | comment)* { advance_pos lexbuf;
WS_AND }
| (
s | comment)* s O R s (s | comment)* { advance_pos lexbuf;
WS_OR }
| O N L Y { ONLY }
| N O T { NOT }
...
...
@@ -111,7 +120,7 @@ rule token = parse
| ident as id { IDENT id }
| '!' (
w
| comment)* I M P O R T A N T { IMPORTANT_SYM }
| '!' (
s
| comment)* I M P O R T A N T { IMPORTANT_SYM }
| (num as n) '%' { PERCENTAGE (float_of_string n) }
| (num as n) (E M | E X | P X | C M | M M | I N | P T | P C | D E G |
...
...
@@ -119,9 +128,12 @@ rule token = parse
{ UNIT_VALUE (float_of_string n, u) }
| num as n { NUMBER (float_of_string n) }
| "
url
(
" w (mystring as uri) w "
)
" { URI (strip_quotes uri) }
| "
url
(
" w (url as uri) w "
)
" { URI uri }
| baduri { raise (SyntaxError "
bad
uri
") }
| "
url
(
" w (mystring as uri) w "
)
" { advance_pos lexbuf; URI (strip_quotes uri) }
| "
url
(
" w (url as uri) w "
)
" { advance_pos lexbuf; URI uri }
| baduri { raise (Syntax_error "
bad
uri
") }
(*
| "
url
(
" { url_start lexbuf }
*)
| (ident as fn) '(' { FUNCTION fn }
...
...
@@ -143,4 +155,28 @@ rule token = parse
| eof | '
\000
' { EOF }
| _ as c { raise (SyntaxError ("
unexpected
'
" ^ Char.escaped c ^ "
'
")) }
| _ as c { raise (Syntax_error ("
unexpected
'
" ^ Char.escaped c ^ "
'
")) }
(* Comments *)
and comment = parse
| '
\r
' | '
\n
' | "
\
r
\
n
" { new_line lexbuf; comment lexbuf }
| "
*/
" { token lexbuf }
| eof | '
\000
' { raise (Syntax_error "
unclosed
comment
") }
| _ { comment lexbuf }
(*
(* URLs *)
and url_start = parse
| '
\r
' | '
\n
' | "
\
r
\
n
" { new_line lexbuf; url_start lexbuf }
| [' ' '
\t
' '
\012
']+ { url_start lexbuf }
| urlc+ as uri { url_end uri lexbuf }
| ')' { URI "" }
| mystring as s { url_end (strip_quotes s) lexbuf }
| badstring { raise (Syntax_error "
bad
string
") }
| (eof | '
\000
' | _) as c { raise (Syntax_error ("
unexpected
'
" ^ c ^ "
'
")) }
and url_end uri = parse
| '
\r
' | '
\n
' | "
\
r
\
n
" { new_line lexbuf; url_end uri lexbuf }
| [' ' '
\t
' '
\012
']+ { url_end uri lexbuf }
| ')' { URI uri }
| (eof | '
\000
' | _) as c { raise (Syntax_error ("
unexpected
'
" ^ c ^ "
'
")) }
*)
main.ml
View file @
70f032a3
...
...
@@ -89,7 +89,7 @@ let main () =
handle_args
args
;
exit
0
with
|
Loc
E
rror
(
loc
,
msg
)
->
|
Loc
_e
rror
(
loc
,
msg
)
->
Util
.
prerr_loc_msg
(
args
.
verbose
>=
1
)
loc
(
"Error: "
^
msg
);
|
Failure
err
->
prerr_endline
(
"Error: "
^
err
);
...
...
parse.ml
View file @
70f032a3
...
...
@@ -27,7 +27,7 @@ let parse_input display_name content =
let
lexbuf
=
Lexing
.
from_string
content
in
lexbuf
.
lex_curr_p
<-
{
lexbuf
.
lex_curr_p
with
pos_fname
=
display_name
};
try
Parser
.
stylesheet
Lexer
.
token
lexbuf
with
|
Syntax
E
rror
msg
->
raise
(
Loc
E
rror
(
shift_back
lexbuf
,
msg
))
|
Syntax
_e
rror
msg
->
raise
(
Loc
_e
rror
(
shift_back
lexbuf
,
msg
))
|
Parser
.
Error
->
raise
(
Loc
E
rror
(
shift_back
lexbuf
,
"syntax error"
))
raise
(
Loc
_e
rror
(
shift_back
lexbuf
,
"syntax error"
))
parser.mly
View file @
70f032a3
...
...
@@ -33,7 +33,7 @@
|
Term
left
::
Operator
op
::
Term
right
::
tl
->
transform_ops
(
Term
(
Nary
(
op
,
[
left
;
right
]))
::
tl
)
|
Term
hd
::
tl
->
hd
::
transform_ops
tl
|
Operator
op
::
_
->
raise
(
Syntax
E
rror
(
"unexpected operator
\"
"
^
op
^
"
\"
"
))
|
Operator
op
::
_
->
raise
(
Syntax
_e
rror
(
"unexpected operator
\"
"
^
op
^
"
\"
"
))
in
let
rec
flatten_nary
=
function
|
[]
->
[]
...
...
@@ -277,7 +277,7 @@ term:
{
let
h
=
"[0-9a-fA-F][0-9a-fA-F][0-9a-fA-F]"
in
if
Str
.
string_match
(
Str
.
regexp
(
"^"
^
h
^
"
\\
("
^
h
^
"
\\
)?$"
))
hex
0
then
Hexcolor
(
String
.
lowercase
hex
)
else
raise
(
Syntax
E
rror
(
"invalid color #"
^
hex
))
}
else
raise
(
Syntax
_e
rror
(
"invalid color #"
^
hex
))
}
unary_operator
:
|
MINUS
{
"-"
}
|
PLUS
{
"+"
}
...
...
types.ml
View file @
70f032a3
...
...
@@ -57,6 +57,6 @@ type stylesheet = statement list
type
loc
=
string
*
int
*
int
*
int
*
int
exception
Syntax
E
rror
of
string
exception
Syntax
_e
rror
of
string
exception
Loc
E
rror
of
loc
*
string
exception
Loc
_e
rror
of
loc
*
string
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment