Skip to content

Commit

Permalink
infixの優先順位を0~30以内に収まっているかチェックするように
Browse files Browse the repository at this point in the history
  • Loading branch information
elipmoc committed Aug 16, 2018
1 parent 0525bf8 commit b0dd7c7
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
15 changes: 9 additions & 6 deletions src/compile/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ use combine::char::{digit, newline, space, string, tab};
use combine::easy;
use combine::parser::combinator::try;
use combine::stream;
use combine::stream::state::{DefaultPositioned, SourcePosition, State};
use combine::{eof, error, many, many1, ParseError, Parser, Positioned, Stream, StreamOnce};
use combine::stream::state::State;
use combine::{eof, many, many1, unexpected, value, Parser, Stream};
/*
BNF
<program> := {<stmt>}
Expand All @@ -19,9 +19,6 @@ BNF
*/

#[derive(Debug)]
struct Position {}

pub fn parse(
s: &str,
) -> Result<
Expand Down Expand Up @@ -98,13 +95,19 @@ parser!{
}).
skip(many1::<Vec<_>,_>(space_parser())),
num_parser().
then(|num_s|
match num_s.parse::<i8>(){
Ok(num) if (0<=num && num<=30) =>value(num).left(),
_=>unexpected("not 0 <= number <= 30 ").map(|_|0).right()
}
).
skip(many1::<Vec<_>,_>(space_parser())),
op_parser()
).
map(|(ty,priority,op)|{
ast::InfixAST{
ty: ty,
priority:ast::Priority(priority.parse::<i8>().unwrap()),
priority:ast::Priority(priority),
op:op
}
})
Expand Down
3 changes: 1 addition & 2 deletions test.rsc
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
infixl 1 +
fuga
infixr 1 -
infixr 25 -

1+2+3-4-5-6

0 comments on commit b0dd7c7

Please sign in to comment.