aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChimrod <>2023-09-28 11:44:12 +0200
committerChimrod <>2023-09-29 10:00:21 +0200
commit4efc1d21441c5e9ad7f24a3e473bbbd8025de124 (patch)
tree6aecbef816a6380138248bd93621d8c69aefa514
parent7fc4021d888b4f16f8fa87c0ea1df68d3806df64 (diff)
Allow the parsing for the whole compiled file
-rw-r--r--bin/qsp_parser.ml20
-rw-r--r--lib/expression_parser.messages187
-rw-r--r--lib/parser.mly2
3 files changed, 92 insertions, 117 deletions
diff --git a/bin/qsp_parser.ml b/bin/qsp_parser.ml
index f2b21f9..0459fe2 100644
--- a/bin/qsp_parser.ml
+++ b/bin/qsp_parser.ml
@@ -43,14 +43,22 @@ let () =
let file_name = List.hd file_names in
let ic = Stdlib.open_in file_name in
+
(*let lexer = Lexing.from_channel ~with_positions:true ic in*)
- let lexer = Sedlexing.Utf8.from_channel ic in
- let result =
- Qparser.Analyzer.parse
- (module Qsp_syntax.Type_of)
- (module Sedlexing.Utf8)
- lexer
+ let lexer, mod_ =
+ match Filename.extension file_name with
+ | ".qsrc" ->
+ ( Sedlexing.Utf8.from_channel ic,
+ (module Sedlexing.Utf8 : Qparser.Lexer.Encoding) )
+ | ".txt" ->
+ ( Sedlexing.Utf16.from_channel ic (Some Little_endian),
+ (module struct
+ let lexeme lexbuf = Sedlexing.Utf16.lexeme lexbuf Little_endian true
+ end : Qparser.Lexer.Encoding) )
+ | _ -> raise (Failure "unknown extension")
in
+
+ let result = Qparser.Analyzer.parse (module Qsp_syntax.Type_of) mod_ lexer in
match result with
| Ok f -> (
let report = List.fold_left (f []) ~init:[] ~f:(filter_report filters) in
diff --git a/lib/expression_parser.messages b/lib/expression_parser.messages
index e9a83c6..e91dafe 100644
--- a/lib/expression_parser.messages
+++ b/lib/expression_parser.messages
@@ -188,7 +188,7 @@ main: LOCATION_START EOL IDENT AMPERSAND END
##
## Ends in an error in state: 171.
##
-## main -> list(EOL) LOCATION_START nonempty_list(EOL) list(line_statement) . LOCATION_END list(EOL) EOF [ # ]
+## main -> list(EOL) LOCATION_START nonempty_list(EOL) list(line_statement) . LOCATION_END [ # ]
##
## The known suffix of the stack is as follows:
## list(EOL) LOCATION_START nonempty_list(EOL) list(line_statement)
@@ -247,6 +247,57 @@ main: LOCATION_START EOL INTEGER SET
Unexpected expression here.
+main: LOCATION_START EOL IF IDENT COLUMN EOL ELIF INTEGER SET
+##
+## Ends in an error in state: 153.
+##
+## elif -> ELIF expression . COLUMN nonempty_list(EOL) list(line_statement) [ END ELSE ELIF ]
+## expression -> expression . EQUAL expression [ STAR PLUS OR MOD MINUS LT GT EXCLAMATION EQUAL DIV COLUMN AND ]
+## expression -> expression . LT GT expression [ STAR PLUS OR MOD MINUS LT GT EXCLAMATION EQUAL DIV COLUMN AND ]
+## expression -> expression . EXCLAMATION expression [ STAR PLUS OR MOD MINUS LT GT EXCLAMATION EQUAL DIV COLUMN AND ]
+## expression -> expression . PLUS expression [ STAR PLUS OR MOD MINUS LT GT EXCLAMATION EQUAL DIV COLUMN AND ]
+## expression -> expression . MINUS expression [ STAR PLUS OR MOD MINUS LT GT EXCLAMATION EQUAL DIV COLUMN AND ]
+## expression -> expression . STAR expression [ STAR PLUS OR MOD MINUS LT GT EXCLAMATION EQUAL DIV COLUMN AND ]
+## expression -> expression . DIV expression [ STAR PLUS OR MOD MINUS LT GT EXCLAMATION EQUAL DIV COLUMN AND ]
+## expression -> expression . MOD expression [ STAR PLUS OR MOD MINUS LT GT EXCLAMATION EQUAL DIV COLUMN AND ]
+## expression -> expression . GT expression [ STAR PLUS OR MOD MINUS LT GT EXCLAMATION EQUAL DIV COLUMN AND ]
+## expression -> expression . LT expression [ STAR PLUS OR MOD MINUS LT GT EXCLAMATION EQUAL DIV COLUMN AND ]
+## expression -> expression . GT EQUAL expression [ STAR PLUS OR MOD MINUS LT GT EXCLAMATION EQUAL DIV COLUMN AND ]
+## expression -> expression . LT EQUAL expression [ STAR PLUS OR MOD MINUS LT GT EXCLAMATION EQUAL DIV COLUMN AND ]
+## expression -> expression . EQUAL GT expression [ STAR PLUS OR MOD MINUS LT GT EXCLAMATION EQUAL DIV COLUMN AND ]
+## expression -> expression . EQUAL LT expression [ STAR PLUS OR MOD MINUS LT GT EXCLAMATION EQUAL DIV COLUMN AND ]
+## expression -> expression . AND expression [ STAR PLUS OR MOD MINUS LT GT EXCLAMATION EQUAL DIV COLUMN AND ]
+## expression -> expression . OR expression [ STAR PLUS OR MOD MINUS LT GT EXCLAMATION EQUAL DIV COLUMN AND ]
+##
+## The known suffix of the stack is as follows:
+## ELIF expression
+##
+
+The `ELIF` expression does not end properly. A `:` is expected before any instruction.
+
+main: LOCATION_START EOL IF IDENT COLUMN EOL ELIF IDENT COLUMN EOL IDENT AMPERSAND LOCATION_END
+##
+## Ends in an error in state: 169.
+##
+## list(elif) -> elif . list(elif) [ END ELSE ]
+##
+## The known suffix of the stack is as follows:
+## elif
+##
+## WARNING: This example involves spurious reductions.
+## This implies that, although the LR(1) items shown above provide an
+## accurate view of the past (what has been recognized so far), they
+## may provide an INCOMPLETE view of the future (what was expected next).
+## In state 122, spurious reduction of production nonempty_list(AMPERSAND) -> AMPERSAND
+## In state 131, spurious reduction of production list(EOL) ->
+## In state 132, spurious reduction of production line_statement -> instruction nonempty_list(AMPERSAND) list(EOL)
+## In state 127, spurious reduction of production list(line_statement) ->
+## In state 128, spurious reduction of production list(line_statement) -> line_statement list(line_statement)
+## In state 156, spurious reduction of production elif -> ELIF expression COLUMN nonempty_list(EOL) list(line_statement)
+##
+
+Unclosed `ELIF` block.
+
main: LOCATION_START EOL R_PAREN
##
## Ends in an error in state: 6.
@@ -1553,20 +1604,12 @@ main: LOCATION_START EOL IDENT AMPERSAND R_PAREN
main: LOCATION_START EOL IDENT AMPERSAND EOL EOF
##
-## Ends in an error in state: 127.
+## Ends in an error in state: 1.
##
-## list(line_statement) -> line_statement . list(line_statement) [ LOCATION_END END ELSE ELIF ]
+## list(EOL) -> EOL . list(EOL) [ STAR SET PLUS OBJ NO MINUS L_PAREN LOCATION_START LOCATION_END LITERAL LET KEYWORD INTEGER IF IDENT FUNCTION END ELSE ELIF COMMENT COLUMN ACT ]
##
## The known suffix of the stack is as follows:
-## line_statement
-##
-## WARNING: This example involves spurious reductions.
-## This implies that, although the LR(1) items shown above provide an
-## accurate view of the past (what has been recognized so far), they
-## may provide an INCOMPLETE view of the future (what was expected next).
-## In state 1, spurious reduction of production list(EOL) ->
-## In state 2, spurious reduction of production list(EOL) -> EOL list(EOL)
-## In state 132, spurious reduction of production line_statement -> instruction nonempty_list(AMPERSAND) list(EOL)
+## EOL
##
<YOUR SYNTAX ERROR MESSAGE HERE>
@@ -1735,34 +1778,6 @@ main: LOCATION_START EOL IF IDENT COLUMN EOL ELIF STAR
<YOUR SYNTAX ERROR MESSAGE HERE>
-main: LOCATION_START EOL IF IDENT COLUMN EOL ELIF INTEGER SET
-##
-## Ends in an error in state: 153.
-##
-## elif -> ELIF expression . COLUMN nonempty_list(EOL) list(line_statement) [ END ELSE ELIF ]
-## expression -> expression . EQUAL expression [ STAR PLUS OR MOD MINUS LT GT EXCLAMATION EQUAL DIV COLUMN AND ]
-## expression -> expression . LT GT expression [ STAR PLUS OR MOD MINUS LT GT EXCLAMATION EQUAL DIV COLUMN AND ]
-## expression -> expression . EXCLAMATION expression [ STAR PLUS OR MOD MINUS LT GT EXCLAMATION EQUAL DIV COLUMN AND ]
-## expression -> expression . PLUS expression [ STAR PLUS OR MOD MINUS LT GT EXCLAMATION EQUAL DIV COLUMN AND ]
-## expression -> expression . MINUS expression [ STAR PLUS OR MOD MINUS LT GT EXCLAMATION EQUAL DIV COLUMN AND ]
-## expression -> expression . STAR expression [ STAR PLUS OR MOD MINUS LT GT EXCLAMATION EQUAL DIV COLUMN AND ]
-## expression -> expression . DIV expression [ STAR PLUS OR MOD MINUS LT GT EXCLAMATION EQUAL DIV COLUMN AND ]
-## expression -> expression . MOD expression [ STAR PLUS OR MOD MINUS LT GT EXCLAMATION EQUAL DIV COLUMN AND ]
-## expression -> expression . GT expression [ STAR PLUS OR MOD MINUS LT GT EXCLAMATION EQUAL DIV COLUMN AND ]
-## expression -> expression . LT expression [ STAR PLUS OR MOD MINUS LT GT EXCLAMATION EQUAL DIV COLUMN AND ]
-## expression -> expression . GT EQUAL expression [ STAR PLUS OR MOD MINUS LT GT EXCLAMATION EQUAL DIV COLUMN AND ]
-## expression -> expression . LT EQUAL expression [ STAR PLUS OR MOD MINUS LT GT EXCLAMATION EQUAL DIV COLUMN AND ]
-## expression -> expression . EQUAL GT expression [ STAR PLUS OR MOD MINUS LT GT EXCLAMATION EQUAL DIV COLUMN AND ]
-## expression -> expression . EQUAL LT expression [ STAR PLUS OR MOD MINUS LT GT EXCLAMATION EQUAL DIV COLUMN AND ]
-## expression -> expression . AND expression [ STAR PLUS OR MOD MINUS LT GT EXCLAMATION EQUAL DIV COLUMN AND ]
-## expression -> expression . OR expression [ STAR PLUS OR MOD MINUS LT GT EXCLAMATION EQUAL DIV COLUMN AND ]
-##
-## The known suffix of the stack is as follows:
-## ELIF expression
-##
-
-The `ELIF` expression does not end properly. A `:` is expected before any instruction.
-
main: LOCATION_START EOL IF IDENT COLUMN EOL ELIF IDENT COLUMN STAR
##
## Ends in an error in state: 154.
@@ -1856,77 +1871,11 @@ main: LOCATION_START EOL IF IDENT COLUMN EOL END IF STAR
<YOUR SYNTAX ERROR MESSAGE HERE>
-main: LOCATION_START EOL IF IDENT COLUMN EOL ELIF IDENT COLUMN EOL IDENT AMPERSAND LOCATION_END
-##
-## Ends in an error in state: 169.
-##
-## list(elif) -> elif . list(elif) [ END ELSE ]
-##
-## The known suffix of the stack is as follows:
-## elif
-##
-## WARNING: This example involves spurious reductions.
-## This implies that, although the LR(1) items shown above provide an
-## accurate view of the past (what has been recognized so far), they
-## may provide an INCOMPLETE view of the future (what was expected next).
-## In state 122, spurious reduction of production nonempty_list(AMPERSAND) -> AMPERSAND
-## In state 131, spurious reduction of production list(EOL) ->
-## In state 132, spurious reduction of production line_statement -> instruction nonempty_list(AMPERSAND) list(EOL)
-## In state 127, spurious reduction of production list(line_statement) ->
-## In state 128, spurious reduction of production list(line_statement) -> line_statement list(line_statement)
-## In state 156, spurious reduction of production elif -> ELIF expression COLUMN nonempty_list(EOL) list(line_statement)
-##
-
-Unclosed `ELIF` block.
-
-main: LOCATION_START EOL LOCATION_END STAR
-##
-## Ends in an error in state: 172.
-##
-## main -> list(EOL) LOCATION_START nonempty_list(EOL) list(line_statement) LOCATION_END . list(EOL) EOF [ # ]
-##
-## The known suffix of the stack is as follows:
-## list(EOL) LOCATION_START nonempty_list(EOL) list(line_statement) LOCATION_END
-##
-
-<YOUR SYNTAX ERROR MESSAGE HERE>
-
-main: LOCATION_START EOL LOCATION_END EOL STAR
-##
-## Ends in an error in state: 173.
-##
-## main -> list(EOL) LOCATION_START nonempty_list(EOL) list(line_statement) LOCATION_END list(EOL) . EOF [ # ]
-##
-## The known suffix of the stack is as follows:
-## list(EOL) LOCATION_START nonempty_list(EOL) list(line_statement) LOCATION_END list(EOL)
-##
-## WARNING: This example involves spurious reductions.
-## This implies that, although the LR(1) items shown above provide an
-## accurate view of the past (what has been recognized so far), they
-## may provide an INCOMPLETE view of the future (what was expected next).
-## In state 1, spurious reduction of production list(EOL) ->
-## In state 2, spurious reduction of production list(EOL) -> EOL list(EOL)
-##
-
-<YOUR SYNTAX ERROR MESSAGE HERE>
-
-main: EOL R_PAREN
-##
-## Ends in an error in state: 1.
-##
-## list(EOL) -> EOL . list(EOL) [ STAR SET PLUS OBJ NO MINUS L_PAREN LOCATION_START LOCATION_END LITERAL LET KEYWORD INTEGER IF IDENT FUNCTION EOF END ELSE ELIF COMMENT COLUMN ACT ]
-##
-## The known suffix of the stack is as follows:
-## EOL
-##
-
-<YOUR SYNTAX ERROR MESSAGE HERE>
-
main: EOL STAR
##
## Ends in an error in state: 4.
##
-## main -> list(EOL) . LOCATION_START nonempty_list(EOL) list(line_statement) LOCATION_END list(EOL) EOF [ # ]
+## main -> list(EOL) . LOCATION_START nonempty_list(EOL) list(line_statement) LOCATION_END [ # ]
##
## The known suffix of the stack is as follows:
## list(EOL)
@@ -1945,7 +1894,7 @@ main: LOCATION_START STAR
##
## Ends in an error in state: 5.
##
-## main -> list(EOL) LOCATION_START . nonempty_list(EOL) list(line_statement) LOCATION_END list(EOL) EOF [ # ]
+## main -> list(EOL) LOCATION_START . nonempty_list(EOL) list(line_statement) LOCATION_END [ # ]
##
## The known suffix of the stack is as follows:
## list(EOL) LOCATION_START
@@ -1957,7 +1906,7 @@ main: LOCATION_START EOL END
##
## Ends in an error in state: 8.
##
-## main -> list(EOL) LOCATION_START nonempty_list(EOL) . list(line_statement) LOCATION_END list(EOL) EOF [ # ]
+## main -> list(EOL) LOCATION_START nonempty_list(EOL) . list(line_statement) LOCATION_END [ # ]
##
## The known suffix of the stack is as follows:
## list(EOL) LOCATION_START nonempty_list(EOL)
@@ -2010,3 +1959,23 @@ main: LOCATION_START EOL MINUS INTEGER SET
##
<YOUR SYNTAX ERROR MESSAGE HERE>
+
+main: LOCATION_START EOL IDENT AMPERSAND EOL LOCATION_START
+##
+## Ends in an error in state: 127.
+##
+## list(line_statement) -> line_statement . list(line_statement) [ LOCATION_END END ELSE ELIF ]
+##
+## The known suffix of the stack is as follows:
+## line_statement
+##
+## WARNING: This example involves spurious reductions.
+## This implies that, although the LR(1) items shown above provide an
+## accurate view of the past (what has been recognized so far), they
+## may provide an INCOMPLETE view of the future (what was expected next).
+## In state 1, spurious reduction of production list(EOL) ->
+## In state 2, spurious reduction of production list(EOL) -> EOL list(EOL)
+## In state 132, spurious reduction of production line_statement -> instruction nonempty_list(AMPERSAND) list(EOL)
+##
+
+<YOUR SYNTAX ERROR MESSAGE HERE>
diff --git a/lib/parser.mly b/lib/parser.mly
index 35aebaf..353aaab 100644
--- a/lib/parser.mly
+++ b/lib/parser.mly
@@ -14,8 +14,6 @@ main:
EOL+
expressions = line_statement*
LOCATION_END
- EOL*
- EOF
{
Analyzer.Location.location $loc expressions
}