Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit88e9f94

Browse files
committed
Fixed the string lexer
1 parentefbaf76 commit88e9f94

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

‎lexer.mll‎

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
2-
exceptionIllegalCharacter ofchar
3-
exceptionUnterminatedComment
2+
exceptionUnterminated_comment
3+
exceptionUnterminated_string
44

55
letnext_linelexbuf=
66
let pos= lexbuf.Lexing.lex_curr_pin
@@ -24,7 +24,11 @@ rule top = parse
2424
| newline { next_line lexbuf;Parser.NL }
2525
|"print" {Parser.PRINT }
2626
|"'" [^'\'']"'"as s {Parser.CHAR s.[1] }
27-
|"\"" [^'"']*"\""as s {Parser.STRING s }(* FIXME*)
27+
|"'\\n'" {Parser.CHAR'\n' }
28+
|"'\\t'" {Parser.CHAR'\t' }
29+
|"'\\\\'" {Parser.CHAR'\\' }
30+
|"'\\''" {Parser.CHAR'\'' }
31+
|"\"" {Parser.STRING (string lexbuf) }
2832
|"broadcast"|"bc" {Parser.BROADCAST }
2933
| lidas l {Parser.LOWER_ID l }
3034
|"=" {Parser.EQUAL }
@@ -47,5 +51,15 @@ and comment = parse
4751
) }
4852
|newline{ next_line lexbuf; comment lexbuf }
4953
|"(*"{ incr inner_comments_number; comment lexbuf }
50-
|eof{ raiseUnterminatedComment }
54+
|eof{ raiseUnterminated_comment }
5155
|_{ comment lexbuf }
56+
57+
(* FIXME inefficient but easy to read*)
58+
andstring=parse
59+
|"\\n"{ "\n" ^ string lexbuf }
60+
|"\\t"{ "\t" ^ string lexbuf }
61+
|"\\\\"{ "\\" ^ string lexbuf }
62+
|"\\\""{ "\"" ^ string lexbuf }
63+
|"\""{ "" }
64+
|eof{ raise Unterminated_string }
65+
|_asc{String.make 1 c ^ string lexbuf }

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp