Parse multiple instructions
This commit is contained in:
@@ -3,9 +3,24 @@
|
||||
#load "Parser.fs"
|
||||
#load "Lexer.fs"
|
||||
|
||||
let parse (s:string) =
|
||||
s |> System.Text.Encoding.ASCII.GetBytes |> FSharp.Text.Lexing.LexBuffer<byte>.FromBytes |> Parser.instr(Lexer.read)
|
||||
let mutable failed = false
|
||||
|
||||
parse "abc()"
|
||||
parse "abc(def)"
|
||||
// parse "abc(def,ghi)"
|
||||
let parse (s:string) =
|
||||
let lexbuf = s |> System.Text.Encoding.ASCII.GetBytes |> FSharp.Text.Lexing.LexBuffer<byte>.FromBytes
|
||||
let msg =
|
||||
try
|
||||
sprintf "%A" <| Parser.rung Lexer.read lexbuf
|
||||
with e ->
|
||||
let pos = lexbuf.EndPos
|
||||
let lastToken = System.Text.Encoding.ASCII.GetString lexbuf.Lexeme
|
||||
failed <- true
|
||||
sprintf "Parse failed at %d, last token = %A" pos.AbsoluteOffset lastToken
|
||||
printf "%A -> %s\n" s msg
|
||||
|
||||
|
||||
parse "abc();"
|
||||
parse "abc(def);"
|
||||
parse "abc(def,ghi);"
|
||||
parse "abc(def,ghi) a(b) ;"
|
||||
|
||||
if failed then exit 1 else exit 0
|
Reference in New Issue
Block a user