Class: Mingle::MingleParser
- Inherits:
-
BitGirderClass
- Object
- BitGirderClass
- Mingle::MingleParser
- Defined in:
- lib/mingle.rb
Constant Summary collapse
- QUANTS =
[ SpecialToken::QUESTION_MARK, SpecialToken::PLUS, SpecialToken::ASTERISK ]
- RANGE_OPEN =
[ SpecialToken::OPEN_PAREN, SpecialToken::OPEN_BRACKET ]
- RANGE_CLOSE =
[ SpecialToken::CLOSE_PAREN, SpecialToken::CLOSE_BRACKET ]
Class Method Summary collapse
Instance Method Summary collapse
- #check_trailing ⇒ Object
- #expect_declared_type_name ⇒ Object
- #expect_identified_name ⇒ Object
- #expect_identifier ⇒ Object
- #expect_namespace ⇒ Object
- #expect_number ⇒ Object
- #expect_qname ⇒ Object
- #expect_type_reference ⇒ Object
Class Method Details
.consume_string(s) ⇒ Object
1673 1674 1675 1676 1677 |
# File 'lib/mingle.rb', line 1673 def self.consume_string( s ) p = self.for_string( s ) yield( p ).tap { p.check_trailing } end |
.for_string(s) ⇒ Object
1669 1670 1671 |
# File 'lib/mingle.rb', line 1669 def self.for_string( s ) self.new( :lexer => MingleLexer.as_instance( s ) ) end |
Instance Method Details
#check_trailing ⇒ Object
1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 |
# File 'lib/mingle.rb', line 1262 def check_trailing res = yield if block_given? unless eof? tok, _ = read_tok fail_parse( "Unexpected token: #{tok}" ) end res end |
#expect_declared_type_name ⇒ Object
1366 1367 1368 |
# File 'lib/mingle.rb', line 1366 def expect_declared_type_name expect_typed( DeclaredTypeName ) end |
#expect_identified_name ⇒ Object
1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 |
# File 'lib/mingle.rb', line 1381 def expect_identified_name ns = expect_namespace names = [] begin if tok = poll_special( SpecialToken::FORWARD_SLASH ) names << expect_identifier end end while tok fail_parse( "Missing name", next_loc ) if names.empty? MingleIdentifiedName.send( :new, :namespace => ns, :names => names ) end |
#expect_identifier ⇒ Object
1342 1343 1344 |
# File 'lib/mingle.rb', line 1342 def expect_identifier expect_typed( MingleIdentifier ) end |
#expect_namespace ⇒ Object
1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 |
# File 'lib/mingle.rb', line 1347 def expect_namespace parts = [ expect_identifier ] begin if colon = poll_special( SpecialToken::COLON ) parts << expect_identifier end end while colon poll_special( SpecialToken::ASPERAND ) or fail_unexpected_token( "':' or '@'" ) ver = expect_identifier MingleNamespace.send( :new, :parts => parts, :version => ver ) end |
#expect_number ⇒ Object
1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 |
# File 'lib/mingle.rb', line 1327 def expect_number tok, _ = peek_tok if neg = ( tok == SpecialToken::MINUS ) read_tok end ParsedNumber.new( :negative => neg, :num => expect_typed( NumericToken ) ) end |
#expect_qname ⇒ Object
1371 1372 1373 1374 1375 1376 1377 1378 |
# File 'lib/mingle.rb', line 1371 def expect_qname ns = expect_namespace expect_special( "type path", SpecialToken::FORWARD_SLASH ) nm = expect_declared_type_name QualifiedTypeName.send( :new, :namespace => ns, :name => nm ) end |
#expect_type_reference ⇒ Object
1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 |
# File 'lib/mingle.rb', line 1651 def expect_type_reference at = expect_atomic_type_reference poll_quants.inject( at ) do |typ, quant| case quant when SpecialToken::ASTERISK ListTypeReference.send( :new, :element_type => typ, :allows_empty => true ) when SpecialToken::PLUS ListTypeReference.send( :new, :element_type => typ, :allows_empty => false ) when SpecialToken::QUESTION_MARK NullableTypeReference.send( :new, :type => typ ) end end end |