Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
mincss
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Taddeüs Kroes
mincss
Commits
70f032a3
Commit
70f032a3
authored
10 years ago
by
Taddeüs Kroes
Browse files
Options
Downloads
Patches
Plain Diff
Lexer now correctly tracks line numbers + some general cleanup
parent
cfccb863
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
lexer.mll
+51
-15
51 additions, 15 deletions
lexer.mll
main.ml
+1
-1
1 addition, 1 deletion
main.ml
parse.ml
+3
-3
3 additions, 3 deletions
parse.ml
parser.mly
+2
-2
2 additions, 2 deletions
parser.mly
types.ml
+2
-2
2 additions, 2 deletions
types.ml
with
59 additions
and
23 deletions
lexer.mll
+
51
−
15
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 ^ "
'
")) }
*)
This diff is collapsed.
Click to expand it.
main.ml
+
1
−
1
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
);
...
...
This diff is collapsed.
Click to expand it.
parse.ml
+
3
−
3
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"
))
This diff is collapsed.
Click to expand it.
parser.mly
+
2
−
2
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
{
"+"
}
...
...
This diff is collapsed.
Click to expand it.
types.ml
+
2
−
2
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
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment