def test_character_literal(self): re = NFAToDFA(character_literal) assert re.ShouldAccept(r"'a'") assert re.ShouldAccept(r"'z'") assert re.ShouldAccept(r"'0'") assert re.ShouldAccept(r"'\012'") assert re.ShouldAccept(r"'\t'") assert re.ShouldAccept(r"'\''") assert re.ShouldAccept(r"'\\'") assert not re.ShouldAccept(r"''") assert not re.ShouldAccept(r"'12'") assert not re.ShouldAccept(r"'2\n'")
def test_string_literal(self): re = NFAToDFA(string_literal) assert re.ShouldAccept(r'"a"') assert re.ShouldAccept(r'"jano\ni\"s\ta\012bot"') assert re.ShouldAccept(r'""') assert not re.ShouldAccept(r'""asdf"') assert not re.ShouldAccept(r'"\"asdf""')
def test_java_identifier(self): re = NFAToDFA(identifier) assert re.ShouldAccept('j') assert re.ShouldAccept('jane123') assert re.ShouldAccept('$_123') assert not re.ShouldAccept('3jane') assert not re.ShouldAccept('') self.AssertNotAcceptsRange(re, '&*@!#')
def test_whitespace(self): re = NFAToDFA(whitespace) assert re.ShouldAccept(' ') assert re.ShouldAccept('\x09') assert not re.ShouldAccept('j ') assert not re.ShouldAccept(' j') assert not re.ShouldAccept('kasdjf')
def test_digits(self): re = NFAToDFA(digits) assert re.ShouldAccept('01231') assert re.ShouldAccept('120') assert re.ShouldAccept('000') assert not re.ShouldAccept('0a00') assert not re.ShouldAccept('')
def test_decimal_integer_literal(self): re = NFAToDFA(decimal_integer_literal) assert re.ShouldAccept('0') # assert re.ShouldAccept('0l') assert re.ShouldAccept('1') assert re.ShouldAccept('12300') # assert re.ShouldAccept('12300L') assert not re.ShouldAccept('01') assert not re.ShouldAccept('1a')
def test_boolean_literal(self): re = NFAToDFA(boolean_literal) assert re.ShouldAccept('true') assert re.ShouldAccept('false') assert not re.ShouldAccept('tfa') assert not re.ShouldAccept('')
def test_null_literal(self): re = NFAToDFA(null_literal) assert re.ShouldAccept('null') assert not re.ShouldAccept('')
def test_line_terminator(self): re = NFAToDFA(line_terminator) assert re.ShouldAccept('\x0a') assert re.ShouldAccept('\x0d\x0a') assert not re.ShouldAccept(' ') assert not re.ShouldAccept('\n\r')
def test_convert(self): self.nfa = NFAToDFA(self.nfa) self.test_accept()
def test_traditional_comment(self): re = NFAToDFA(comment) assert re.ShouldAccept("""/** this is a javadoc comment*/""") assert re.ShouldAccept("""/* this comment\r\n// * / end here */""") assert not re.ShouldAccept("""/** * asdf*""") assert not re.ShouldAccept("""**asdf*/""")
def test_end_of_line_comment(self): re = NFAToDFA(comment) assert re.ShouldAccept("""//** this is an end of line\r\n""") assert re.ShouldAccept("""// yup\n""") assert not re.ShouldAccept("""// this comment missing newline""") assert not re.ShouldAccept("""not comment\r\n""")
] unsupported = [ # unsupported keywords t.DEFAULT, t.DO, t.BREAK, t.DOUBLE, t.CASE, t.CATCH, t.FINALLY, t.FLOAT, t.CONST, t.CONTINUE, t.GOTO, t.PRIVATE, t.LONG, t.STRICTFP, t.SUPER, t.SWITCH, t.SYNCHRONIZED, t.THROW, t.THROWS, t.TRANSIENT, t.TRY, t.VOLATILE, # unsupported operators t.TILDE, t.QUESTION_MARK, t.COLON, t.INC, t.DEC, t.XOR, t.LSHIFT, t.RSHIFT, t.R_USHIFT, t.PLUS_EQ, t.MINUS_EQ, t.TIMES_EQ, t.DIV_EQ, t.AND_EQ, t.OR_EQ, t.MOD_EQ, t.LSHIFT_EQ, t.RSHIFT_EQ, t.R_USHIFT_EQ, ] # module exports symbols_map = (keyword_map + literal_map + separator_map + operator_map + common_map) all_exports = (keyword_exports + literal_exports + separator_exports + operator_exports + common_exports) # Convert Exports to DFAs all_exports = [(x[0], NFAToDFA(x[1])) for x in all_exports]