diff options
Diffstat (limited to 'lib/qparser')
-rw-r--r-- | lib/qparser/lexer.ml | 12 | ||||
-rw-r--r-- | lib/qparser/parser.mly | 9 | ||||
-rw-r--r-- | lib/qparser/tokens.mly | 2 |
3 files changed, 17 insertions, 6 deletions
diff --git a/lib/qparser/lexer.ml b/lib/qparser/lexer.ml index 30d151b..4e9aa27 100644 --- a/lib/qparser/lexer.ml +++ b/lib/qparser/lexer.ml @@ -188,16 +188,20 @@ let rec parse_token : Lexbuf.t -> token = | '#', Star space, location -> (* Extract the location name *) let ident = Lexbuf.content buffer in - let () = + let ident_name = match Str.string_match location_name ident 0 with - | false -> () - | true -> Sedlexing.set_filename lexbuf (Str.matched_group 1 ident) + | false -> ident + | true -> Str.matched_group 1 ident in (* Restart the line number (new location here) *) Lexbuf.start buffer; - LOCATION_START ident + LOCATION_START + (fun () -> + Sedlexing.set_filename lexbuf ident_name; + (* Restart the line number (new location here) *) + ident_name) | '_', Star space, eol, Star space -> (* The _ character can be used to break lines *) parse_token buffer diff --git a/lib/qparser/parser.mly b/lib/qparser/parser.mly index 73d77b7..6fc9b8f 100644 --- a/lib/qparser/parser.mly +++ b/lib/qparser/parser.mly @@ -25,7 +25,7 @@ main: | before_location* - LOCATION_START + start_location EOL+ instructions = line_statement* LOCATION_END @@ -38,6 +38,13 @@ before_location: | EOL {} | COMMENT EOL { } +(* Defer the registration here, and ensure we get a valid rule. *) +start_location: + | l = LOCATION_START + { + ignore (l ()) + } + (* All these statement should terminate with EOL *) line_statement: | COMMENT EOL+ { Analyzer.Instruction.comment $loc } diff --git a/lib/qparser/tokens.mly b/lib/qparser/tokens.mly index ddbc4cf..90e9e14 100644 --- a/lib/qparser/tokens.mly +++ b/lib/qparser/tokens.mly @@ -1,4 +1,4 @@ -%token <string>LOCATION_START +%token <unit -> string>LOCATION_START %token LOCATION_END %token PLUS |